Browse Source

Replace usage of BDSM_DEBUG macro by BDSM_dbg

Julien 'Lta' BALLET 11 years ago
parent
commit
3846ae0847
5 changed files with 34 additions and 38 deletions
  1. 2 10
      bin/dsm.c
  2. 1 1
      doc/Doxyfile.in
  3. 19 9
      src/smb_session.c
  4. 7 10
      src/smb_share.c
  5. 5 8
      src/smb_trans2.c

+ 2 - 10
bin/dsm.c

@@ -68,25 +68,17 @@ int main(int ac, char **av)
   smb_session_t *session;
   session = smb_session_new();
   if (smb_session_connect(session, av[1], addr.sin_addr.s_addr))
-    printf("Successfully connected to %s\n", av[1]);
-  else
   {
-    printf("Unable to connect to %s\n", av[1]);
-    exit(42);
-  }
-  if (smb_negotiate(session))
-  {
-    fprintf(stderr, "Dialect/Security Mode negotation success.\n");
+    printf("Successfully connected to %s\n", av[1]);
     fprintf(stderr, "Session key is 0x%x\n", session->srv.session_key);
     fprintf(stderr, "Challenge key is 0x%lx\n", session->srv.challenge);
   }
   else
   {
-    printf("Unable to negotiate SMB Dialect\n");
+    printf("Unable to connect to %s\n", av[1]);
     exit(42);
   }
 
-
   if (smb_authenticate(session, av[1], av[2], av[3]))
   {
     if (session->guest)

+ 1 - 1
doc/Doxyfile.in

@@ -967,7 +967,7 @@ USE_HTAGS              = NO
 # See also: Section \class.
 # The default value is: YES.
 
-VERBATIM_HEADERS       = YES
+VERBATIM_HEADERS       = NO
 
 #---------------------------------------------------------------------------
 # Configuration options related to the alphabetical class index

+ 19 - 9
src/smb_session.c

@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <assert.h>
 
+#include "bdsm/debug.h"
 #include "bdsm/smb_session.h"
 #include "bdsm/smb_ntlm.h"
 
@@ -39,12 +40,21 @@ void            smb_session_destroy(smb_session_t *s)
 {
   if (s != NULL)
   {
+    // FIXME Free smb_share and smb_file
     if (s->nb_session != NULL)
       netbios_session_destroy(s->nb_session);
     free(s);
   }
 }
 
+int             smb_session_state(smb_session_t *s)
+{
+  if (s != NULL)
+    return (s->state);
+  else
+    return (SMB_STATE_ERROR);
+}
+
 int             smb_session_connect(smb_session_t *s, char *name, uint32_t ip)
 {
   assert(s != NULL && name != NULL);
@@ -56,7 +66,11 @@ int             smb_session_connect(smb_session_t *s, char *name, uint32_t ip)
 
   memcpy(s->srv.name, name, strlen(name) + 1);
   s->state = SMB_STATE_NETBIOS_OK;
-  return (1);
+
+  if (!smb_negotiate(s))
+    return (0);
+
+  return(1);
 
   error:
     s->state = SMB_STATE_ERROR;
@@ -103,8 +117,7 @@ size_t          smb_session_recv_msg(smb_session_t *s, smb_message_t *msg)
   payload_size |= (nb_packet->flags & 0x01) << 16; // XXX If this is the case we overran our recv_buffer
   if (payload_size > recv_size - sizeof(netbios_session_packet_t))
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "smb_session_recv_msg: Packet size mismatch\n");
+    BDSM_dbg("smb_session_recv_msg: Packet size mismatch\n");
     return(0);
   }
 
@@ -365,24 +378,21 @@ int             smb_authenticate(smb_session_t *s, const char *domain,
   if (!smb_session_send_msg(s, msg))
   {
     smb_message_destroy(msg);
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to send Session Setup AndX message\n");
+    BDSM_dbg("Unable to send Session Setup AndX message\n");
     return (0);
   }
   smb_message_destroy(msg);
 
   if (smb_session_recv_msg(s, &answer) == 0)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to get Session Setup AndX reply\n");
+    BDSM_dbg("Unable to get Session Setup AndX reply\n");
     return (0);
   }
 
   smb_session_resp_t *r = (smb_session_resp_t *)answer.packet->payload;
   if (answer.packet->header.status != NT_STATUS_SUCCESS)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Session Setup AndX : failure.\n");
+    BDSM_dbg("Session Setup AndX : failure.\n");
     return (0);
   }
 

+ 7 - 10
src/smb_share.c

@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdio.h>
 
+#include "bdsm/debug.h"
 #include "bdsm/smb_utils.h"
 #include "bdsm/smb_share.h"
 #include "bdsm/smb_file.h"
@@ -92,7 +93,7 @@ smb_tid         smb_tree_connect(smb_session_t *s, const char *name)
 int           smb_tree_disconnect(smb_session_t *s, smb_tid tid)
 {
   assert(s != NULL && tid);
-  fprintf(stderr, "smb_tree_disconnect: NOT IMPLEMENTED YET\n");
+  BDSM_dbg("smb_tree_disconnect: NOT IMPLEMENTED YET\n");
   return (0);
 }
 
@@ -107,7 +108,7 @@ static size_t   smb_share_parse_enum(smb_message_t *msg,
   smb_share_list_t  *s;
 
   assert(msg != NULL && list != NULL);
-  // Let's skip smb parameters, DCE/RPC stuff until we are at the begginning of
+  // Let's skip smb parameters and DCE/RPC stuff until we are at the begginning of
   // NetShareCtrl
 
   share_count = *((uint32_t *)(msg->packet->payload + 60));
@@ -121,7 +122,6 @@ static size_t   smb_share_parse_enum(smb_message_t *msg,
   {
     uint32_t name_len, com_len;
 
-
     name_len = *((uint32_t *)data);   // Read 'Max Count', make it a multiple of 2
     data    += 3 * sizeof(uint32_t);  // Move pointer to beginning of Name.
     memcpy(s[i].name, data, name_len * 2); // Those are unicode strings.
@@ -140,8 +140,7 @@ static size_t   smb_share_parse_enum(smb_message_t *msg,
 }
 
 // We should normally implement SCERPC and SRVSVC to perform a share list. But
-// since these two protocols have no other use for use, we'll do it the trash
-// way
+// since these two protocols have no other use for us, we'll do it the trash way
 // PS: Worst function _EVER_. I don't understand a bit myself
 size_t          smb_share_list(smb_session_t *s, smb_share_list_t **list)
 {
@@ -230,9 +229,8 @@ size_t          smb_share_list(smb_session_t *s, smb_share_list_t **list)
   res = smb_session_recv_msg(s, &resp);
   if (!res || resp.packet->payload[68])
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Bind call failed: 0x%hhx (reason = 0x%hhx)\n",
-              resp.packet->payload[68], resp.packet->payload[70]);
+    BDSM_dbg("Bind call failed: 0x%hhx (reason = 0x%hhx)\n",
+            resp.packet->payload[68], resp.packet->payload[70]);
     return (0);
   }
 
@@ -312,8 +310,7 @@ size_t          smb_share_list(smb_session_t *s, smb_share_list_t **list)
   res = smb_session_recv_msg(s, &resp);
   if (!res && (uint32_t)resp.packet->payload[resp.payload_size - 4])
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "NetShareEnumAll call failed.\n");
+    BDSM_dbg("NetShareEnumAll call failed.\n");
     return (0);
   }
 

+ 5 - 8
src/smb_trans2.c

@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <assert.h>
 
+#include "bdsm/debug.h"
 #include "bdsm/smb_trans2.h"
 
 static smb_file_t *smb_find_parse(smb_message_t *msg)
@@ -120,16 +121,14 @@ smb_file_t  *smb_find(smb_session_t *s, smb_tid tid, const char *pattern)
   smb_message_destroy(msg);
   if (!res)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to query pattern: %s\n", pattern);
+    BDSM_dbg("Unable to query pattern: %s\n", pattern);
     return (NULL);
   }
 
   if (!smb_session_recv_msg(s, &reply)
       || reply.packet->header.status != NT_STATUS_SUCCESS)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to recv msg or failure for %s\n", pattern);
+    BDSM_dbg("Unable to recv msg or failure for %s\n", pattern);
     return (NULL);
   }
 
@@ -191,16 +190,14 @@ smb_file_t  *smb_stat(smb_session_t *s, smb_tid tid, const char *path)
   smb_message_destroy(msg);
   if (!res)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to query pattern: %s\n", path);
+    BDSM_dbg("Unable to query pattern: %s\n", path);
     return (NULL);
   }
 
   if (!smb_session_recv_msg(s, &reply)
       || reply.packet->header.status != NT_STATUS_SUCCESS)
   {
-    if (BDSM_DEBUG)
-      fprintf(stderr, "Unable to recv msg or failure for %s\n", path);
+    BDSM_dbg("Unable to recv msg or failure for %s\n", path);
     return (NULL);
   }