Browse Source

Move smb_session_xxx_msg to their own file/header

Julien 'Lta' BALLET 11 years ago
parent
commit
83d50d198e
9 changed files with 122 additions and 69 deletions
  1. 18 16
      Makefile.am
  2. 0 7
      include/bdsm/smb_session.h
  3. 32 0
      include/bdsm/smb_session_msg.h
  4. 1 0
      src/smb_file.c
  5. 1 46
      src/smb_session.c
  6. 66 0
      src/smb_session_msg.c
  7. 1 0
      src/smb_share.c
  8. 1 0
      src/smb_spnego.c
  9. 2 0
      src/smb_trans2.c

+ 18 - 16
Makefile.am

@@ -34,12 +34,13 @@ bdsm_HEADERS = \
     include/bdsm/smb_types.h    \
     include/bdsm/smb_utils.h
 noinst_HEADERS = \
-    include/bdsm/smb_packets.h    \
-    include/bdsm/smb_transport.h  \
-    include/bdsm/smb_spnego.h     \
-    contrib/spnego/spnego_asn1.h  \
-    contrib/mdx/md4.h             \
-    contrib/mdx/md5.h             \
+		include/bdsm/smb_session_msg.h \
+    include/bdsm/smb_packets.h     \
+    include/bdsm/smb_transport.h   \
+    include/bdsm/smb_spnego.h      \
+    contrib/spnego/spnego_asn1.h   \
+    contrib/mdx/md4.h              \
+    contrib/mdx/md5.h              \
     contrib/rc4/rc4.h
 
 lib_LTLIBRARIES = libdsm.la
@@ -55,16 +56,17 @@ libdsm_la_SOURCES = \
     src/netbios_query.c     \
     src/netbios_session.c   \
     src/netbios_utils.c     \
-    src/smb_fd.c        \
-    src/smb_file.c      \
-    src/smb_spnego.c    \
-    src/smb_message.c   \
-    src/smb_ntlm.c      \
-    src/smb_session.c   \
-    src/smb_share.c     \
-    src/smb_stat.c      \
-    src/smb_trans2.c    \
-    src/smb_transport.c \
+    src/smb_fd.c            \
+    src/smb_file.c          \
+    src/smb_spnego.c        \
+    src/smb_message.c       \
+    src/smb_ntlm.c          \
+    src/smb_session.c       \
+    src/smb_session_msg.c   \
+    src/smb_share.c         \
+    src/smb_stat.c          \
+    src/smb_trans2.c        \
+    src/smb_transport.c     \
     src/smb_utils.c
 
 pkgconfigdir = $(libdir)/pkgconfig

+ 0 - 7
include/bdsm/smb_session.h

@@ -100,13 +100,6 @@ void            smb_session_set_creds(smb_session *s, const char *domain,
 #define SMB_CREDS_MAXLEN 128
 
 
-// ---------------------------------
-// Internal stuff, maybe move this somewhere else
-int             smb_session_send_msg(smb_session *s, smb_message *msg);
-// msg->packet will be updated to point on received data. You don't own this
-// memory. It'll be reused on next recv_msg
-ssize_t         smb_session_recv_msg(smb_session *s, smb_message *msg);
-// --------------------------------
 
 /**
  * @brief Establish a connection and negotiate a session protocol with a remote

+ 32 - 0
include/bdsm/smb_session_msg.h

@@ -0,0 +1,32 @@
+//---------------------------------------------------------------------------
+//  __________________    _________  _____            _____  .__         ._.
+//  \______   \______ \  /   _____/ /     \          /  _  \ |__| ____   | |
+//   |    |  _/|    |  \ \_____  \ /  \ /  \        /  /_\  \|  _/ __ \  | |
+//   |    |   \|    `   \/        /    Y    \      /    |    |  \  ___/   \|
+//   |______  /_______  /_______  \____|__  / /\   \____|__  |__|\___ |   __
+//          \/        \/        \/        \/  )/           \/        \/   \/
+//
+// This file is part of libdsm. Copyright © 2014 VideoLabs SAS
+//
+// Author: Julien 'Lta' BALLET <contact@lta.io>
+//
+// This program is free software. It comes without any warranty, to the extent
+// permitted by applicable law. You can redistribute it and/or modify it under
+// the terms of the Do What The Fuck You Want To Public License, Version 2, as
+// published by Sam Hocevar. See the COPYING file for more details.
+//----------------------------------------------------------------------------
+
+#ifndef __BDSM_SMB_SESSION_MSG_H_
+#define __BDSM_SMB_SESSION_MSG_H_
+
+#include "bdsm/smb_types.h"
+
+// Send a smb message for the provided smb_session
+int             smb_session_send_msg(smb_session *s, smb_message *msg);
+
+// msg->packet will be updated to point on received data. You don't own this
+// memory. It'll be reused on next recv_msg
+ssize_t         smb_session_recv_msg(smb_session *s, smb_message *msg);
+
+
+#endif

+ 1 - 0
src/smb_file.c

@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdio.h>
 
+#include "bdsm/smb_session_msg.h"
 #include "bdsm/smb_fd.h"
 #include "bdsm/smb_utils.h"
 #include "bdsm/smb_file.h"

+ 1 - 46
src/smb_session.c

@@ -23,6 +23,7 @@
 
 #include "bdsm/debug.h"
 #include "bdsm/smb_session.h"
+#include "bdsm/smb_session_msg.h"
 #include "bdsm/smb_ntlm.h"
 #include "bdsm/smb_spnego.h"
 #include "bdsm/smb_transport.h"
@@ -155,52 +156,6 @@ int             smb_session_connect(smb_session *s, const char *name,
     return (0);
 }
 
-int             smb_session_send_msg(smb_session *s, smb_message *msg)
-{
-  size_t        pkt_sz;
-
-  assert(s != NULL && s->state >= SMB_STATE_NETBIOS_OK);
-  assert(s->transport.session != NULL);
-  assert(msg != NULL && msg->packet != NULL);
-
-  msg->packet->header.flags   = 0x18;
-  msg->packet->header.flags2  = 0xc843;
-  // msg->packet->header.flags2  = 0xc043; // w/o extended security;
-  msg->packet->header.uid = s->srv.uid;
-
-  s->transport.pkt_init(s->transport.session);
-
-  pkt_sz = sizeof(smb_packet) + msg->cursor;
-  if (!s->transport.pkt_append(s->transport.session, (void *)msg->packet, pkt_sz))
-    return (0);
-  if (!s->transport.send(s->transport.session))
-    return (0);
-
-  return (1);
-}
-
-ssize_t         smb_session_recv_msg(smb_session *s, smb_message *msg)
-{
-  void                      *data;
-  ssize_t                   payload_size;
-
-  assert(s != NULL && s->transport.session != NULL);
-
-  payload_size = s->transport.recv(s->transport.session, &data);
-  if(payload_size <= 0)
-    return (0);
-
-  if (msg != NULL)
-  {
-    msg->packet = (smb_packet *)data;
-    msg->payload_size = payload_size - sizeof(smb_header);
-    msg->cursor       = 0;
-  }
-
-  return (payload_size - sizeof(smb_header));
-}
-
-
 // xsec == 1 -> add Extended security flag
 static int        smb_negotiate(smb_session *s, int xsec)
 {

+ 66 - 0
src/smb_session_msg.c

@@ -0,0 +1,66 @@
+//---------------------------------------------------------------------------
+//  __________________    _________  _____            _____  .__         ._.
+//  \______   \______ \  /   _____/ /     \          /  _  \ |__| ____   | |
+//   |    |  _/|    |  \ \_____  \ /  \ /  \        /  /_\  \|  _/ __ \  | |
+//   |    |   \|    `   \/        /    Y    \      /    |    |  \  ___/   \|
+//   |______  /_______  /_______  \____|__  / /\   \____|__  |__|\___ |   __
+//          \/        \/        \/        \/  )/           \/        \/   \/
+//
+// This file is part of libdsm. Copyright © 2014 VideoLabs SAS
+//
+// Author: Julien 'Lta' BALLET <contact@lta.io>
+//
+// This program is free software. It comes without any warranty, to the extent
+// permitted by applicable law. You can redistribute it and/or modify it under
+// the terms of the Do What The Fuck You Want To Public License, Version 2, as
+// published by Sam Hocevar. See the COPYING file for more details.
+//----------------------------------------------------------------------------
+
+#include <assert.h>
+
+#include "bdsm/smb_session.h"
+
+int             smb_session_send_msg(smb_session *s, smb_message *msg)
+{
+  size_t        pkt_sz;
+
+  assert(s != NULL && s->state >= SMB_STATE_NETBIOS_OK);
+  assert(s->transport.session != NULL);
+  assert(msg != NULL && msg->packet != NULL);
+
+  msg->packet->header.flags   = 0x18;
+  msg->packet->header.flags2  = 0xc843;
+  // msg->packet->header.flags2  = 0xc043; // w/o extended security;
+  msg->packet->header.uid = s->srv.uid;
+
+  s->transport.pkt_init(s->transport.session);
+
+  pkt_sz = sizeof(smb_packet) + msg->cursor;
+  if (!s->transport.pkt_append(s->transport.session, (void *)msg->packet, pkt_sz))
+    return (0);
+  if (!s->transport.send(s->transport.session))
+    return (0);
+
+  return (1);
+}
+
+ssize_t         smb_session_recv_msg(smb_session *s, smb_message *msg)
+{
+  void                      *data;
+  ssize_t                   payload_size;
+
+  assert(s != NULL && s->transport.session != NULL);
+
+  payload_size = s->transport.recv(s->transport.session, &data);
+  if(payload_size <= 0)
+    return (0);
+
+  if (msg != NULL)
+  {
+    msg->packet = (smb_packet *)data;
+    msg->payload_size = payload_size - sizeof(smb_header);
+    msg->cursor       = 0;
+  }
+
+  return (payload_size - sizeof(smb_header));
+}

+ 1 - 0
src/smb_share.c

@@ -23,6 +23,7 @@
 #include <stdio.h>
 
 #include "bdsm/debug.h"
+#include "bdsm/smb_session_msg.h"
 #include "bdsm/smb_utils.h"
 #include "bdsm/smb_fd.h"
 #include "bdsm/smb_share.h"

+ 1 - 0
src/smb_spnego.c

@@ -23,6 +23,7 @@
 
 #include "bdsm/debug.h"
 #include "bdsm/smb_session.h"
+#include "bdsm/smb_session_msg.h"
 #include "bdsm/smb_ntlm.h"
 #include "spnego/spnego_asn1.h"
 

+ 2 - 0
src/smb_trans2.c

@@ -22,6 +22,8 @@
 #include <assert.h>
 
 #include "bdsm/debug.h"
+#include "bdsm/smb_message.h"
+#include "bdsm/smb_session_msg.h"
 #include "bdsm/smb_utils.h"
 #include "bdsm/smb_stat.h"