浏览代码

Remove all compilation warning

Julien 'Lta' BALLET 11 年之前
父节点
当前提交
36f14f432e
共有 11 个文件被更改,包括 103 次插入98 次删除
  1. 2 4
      Makefile.am
  2. 1 1
      bin/discover.c
  3. 1 1
      include/bdsm/smb_ntlm.h
  4. 3 3
      include/bdsm/smb_types.h
  5. 1 1
      src/netbios_session.c
  6. 5 1
      src/netbios_utils.c
  7. 4 0
      src/smb_message.c
  8. 79 81
      src/smb_ntlm.c
  9. 4 2
      src/smb_session.c
  10. 2 3
      src/smb_spnego.c
  11. 1 1
      src/smb_utils.c

+ 2 - 4
Makefile.am

@@ -7,7 +7,7 @@ EXTRA_DIST =
 CFLAGS = -I$(top_srcdir)/contrib -I$(top_srcdir)/include @TASN1_CFLAGS@
 
 if DEBUG
-AM_CFLAGS = -O0 -g3 -Wall #-Wextra
+AM_CFLAGS = -O0 -g3 -Wall -Wextra #-Werror
 else
 AM_CFLAGS = -O2
 endif
@@ -78,7 +78,7 @@ libdsm_la_LDFLAGS = -version-info @BDSM_LIBTOOL_VERSION@ LTLIBICONV @TASN1_LIBS@
 bin_PROGRAMS =
 
 if PROGRAMS
-bin_PROGRAMS += dsm dsm_discover dsm_inverse dsm_lookup dsm_ntlm
+bin_PROGRAMS += dsm dsm_discover dsm_inverse dsm_lookup
 endif
 
 dsm_SOURCES = bin/dsm.c
@@ -89,8 +89,6 @@ dsm_inverse_SOURCES = bin/inverse.c
 
 dsm_lookup_SOURCES = bin/lookup.c
 
-dsm_ntlm_SOURCES = bin/ntlm.c
-
 LDADD = libdsm.la
 
 if HAVE_DOXYGEN

+ 1 - 1
bin/discover.c

@@ -27,7 +27,7 @@
 
 #include "bdsm.h"
 
-int main(int ac, char **av)
+int main()
 {
   netbios_ns        *ns;
   netbios_ns_entry  *entry;

+ 1 - 1
include/bdsm/smb_ntlm.h

@@ -93,7 +93,7 @@ void        smb_ntlm2_hash(const char *username, const char *password,
 // You have to free() the blob after usage
 size_t      smb_ntlm_make_blob(smb_ntlm_blob **blob, uint64_t ts,
                                uint64_t user_challenge, void *tgt,
-                               size_t tgt_sz, uint64_t ts2);
+                               size_t tgt_sz);
 // Returned response is blob_size + 16 long. You'll have to free it
 uint8_t     *smb_ntlm2_response(smb_ntlmh *hash_v2, uint64_t srv_challenge,
                                 uint8_t *blob, size_t blob_size);

+ 3 - 3
include/bdsm/smb_types.h

@@ -97,9 +97,9 @@ typedef struct smb_transport_s {
 // An structure to store user credentials;
 // login:password@domain (also DOMAIN\login)
 typedef struct {
-    const char *    domain;
-    const char *    login;
-    const char *    password;
+    char *    domain;
+    char *    login;
+    char *    password;
 } smb_creds;
 
 /**

+ 1 - 1
src/netbios_session.c

@@ -188,7 +188,7 @@ ssize_t           netbios_session_packet_recv(netbios_session *s, void **data)
     return (-1);
   }
 
-  if (res > sizeof(netbios_session_packet) && data != NULL)
+  if ((size_t)res > sizeof(netbios_session_packet) && data != NULL)
     *data = (void *)s->packet->payload;
   else if (data != NULL)
     *data = NULL;

+ 5 - 1
src/netbios_utils.c

@@ -78,10 +78,12 @@ void  netbios_name_level1_decode(const char *encoded_name, char *name)
   name[NETBIOS_NAME_LENGTH] = 0;
 }
 
-
+// XXX: Supports domain
 char  *netbios_name_encode(const char *name, char *domain,
                            unsigned type)
 {
+  (void )domain; // Unused yet
+
   size_t    encoded_size = 34; // length byte + 32 bytes for encoded name + terminator
   char      *encoded_name;
 
@@ -101,6 +103,8 @@ char  *netbios_name_encode(const char *name, char *domain,
 int             netbios_name_decode(const char *encoded_name,
                                     char *name, char **domain)
 {
+  (void )domain; // Unused yet
+
   size_t  encoded_length;
 
   if (!encoded_name || !name)

+ 4 - 0
src/smb_message.c

@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "bdsm/debug.h"
 #include "bdsm/netbios_session.h"
 #include "bdsm/smb_message.h"
 #include "bdsm/smb_utils.h"
@@ -138,6 +139,9 @@ size_t          smb_message_put_utf16(smb_message *msg, const char *src_enc,
   res = smb_message_append(msg, utf_str, utf_str_len);
   free(utf_str);
 
+  if (src_enc != NULL)
+    BDSM_dbg("smb_message_put_utf16: src_enc not supported. We use system locale\n");
+
   // fprintf(stderr, "put_utf16, adds %d bytes, cursor is at %d\n",
   //         utf_str_len, msg->cursor);
 

+ 79 - 81
src/smb_ntlm.c

@@ -137,91 +137,91 @@ uint8_t     *smb_ntlm2_response(smb_ntlmh *hash_v2, uint64_t srv_challenge,
 uint8_t     *smb_lm2_response(smb_ntlmh *hash_v2, uint64_t srv_challenge,
                               uint64_t user_challenge)
 {
-  smb_ntlm2_response(hash_v2, srv_challenge, &user_challenge, 8);
+  return (smb_ntlm2_response(hash_v2, srv_challenge, (void *)&user_challenge, 8));
 }
 
-static void   _wcamelcase(char *str)
-{
-  int first = 1;
-
-  assert (str != NULL);
-
-  while(*str)
-  {
-    if (isalpha(*str))
-    {
-      if (first)
-        *str = toupper(*str);
-      else
-        *str = tolower(*str);
-    }
-    first = 0;
-    str += 2;
-  }
-}
-
-#define __NAME_ENCODE_APPEND(type, item)  \
-  *res = type;                            \
-  res += 2;                               \
-  *(uint16_t *)res = item##_sz - 2;       \
-  res += 2;                               \
-  memcpy(res, item, item##_sz - 2);       \
-  res += item##_sz - 2;                   \
-
-static size_t _ntlm_name_encode(char **names, const char *domain,
-                                const char *host, uint64_t ts2)
-{
-  char    *wdomain, *whost, *wdomain_camel, *whost_camel;
-  size_t  wdomain_sz, whost_sz, wdomain_camel_sz, whost_camel_sz;
-  char    *res;
-  size_t  res_sz;
-
-  assert(names != NULL && domain != NULL && host != NULL);
-
-  wdomain_sz        = smb_to_utf16(domain, strlen(domain) + 1, &wdomain);
-  wdomain_camel_sz  = smb_to_utf16(domain, strlen(domain) + 1, &wdomain_camel);
-  whost_sz          = smb_to_utf16(host, strlen(host) + 1, &whost);
-  whost_camel_sz    = smb_to_utf16(host, strlen(host) + 1, &whost_camel);
-
-  _wcamelcase(wdomain_camel);
-  _wcamelcase(whost_camel);
-
-  res_sz = (wdomain_sz - 2) * 2 + (whost_sz - 2) * 2 + 8 + 6 * 4;
-  *names = res = malloc(res_sz);
-  assert(res != NULL);
-  memset(res, 0, res_sz);
-
-  __NAME_ENCODE_APPEND(2, wdomain)
-  __NAME_ENCODE_APPEND(1, whost)
-  __NAME_ENCODE_APPEND(4, wdomain_camel)
-  __NAME_ENCODE_APPEND(3, whost_camel)
-
-  *res = 7;
-  res += 2;
-  *res = 8;
-  res += 2;
-  *(uint64_t *)res = ts2;
-  res += 8;
-
-  free(wdomain);
-  free(wdomain_camel);
-  free(whost);
-  free(whost_camel);
-
-  return (res_sz);
-}
+// static void   _wcamelcase(char *str)
+// {
+//   int first = 1;
+
+//   assert (str != NULL);
+
+//   while(*str)
+//   {
+//     if (isalpha(*str))
+//     {
+//       if (first)
+//         *str = toupper(*str);
+//       else
+//         *str = tolower(*str);
+//     }
+//     first = 0;
+//     str += 2;
+//   }
+// }
+
+// // This was test code to encode the name the way the server looked to expect
+// // it. But apparently we just had to sent him back his own data.
+
+/* #define __NAME_ENCODE_APPEND(type, item)  \
+   *res = type;                            \
+   res += 2;                               \
+   *(uint16_t *)res = item##_sz - 2;       \
+   res += 2;                               \
+   memcpy(res, item, item##_sz - 2);       \
+   res += item##_sz - 2;                   \
+*/
+// static size_t _ntlm_name_encode(char **names, const char *domain,
+//                                 const char *host, uint64_t ts2)
+// {
+//   char    *wdomain, *whost, *wdomain_camel, *whost_camel;
+//   size_t  wdomain_sz, whost_sz, wdomain_camel_sz, whost_camel_sz;
+//   char    *res;
+//   size_t  res_sz;
+
+//   assert(names != NULL && domain != NULL && host != NULL);
+
+//   wdomain_sz        = smb_to_utf16(domain, strlen(domain) + 1, &wdomain);
+//   wdomain_camel_sz  = smb_to_utf16(domain, strlen(domain) + 1, &wdomain_camel);
+//   whost_sz          = smb_to_utf16(host, strlen(host) + 1, &whost);
+//   whost_camel_sz    = smb_to_utf16(host, strlen(host) + 1, &whost_camel);
+
+//   _wcamelcase(wdomain_camel);
+//   _wcamelcase(whost_camel);
+
+//   res_sz = (wdomain_sz - 2) * 2 + (whost_sz - 2) * 2 + 8 + 6 * 4;
+//   *names = res = malloc(res_sz);
+//   assert(res != NULL);
+//   memset(res, 0, res_sz);
+
+//   __NAME_ENCODE_APPEND(2, wdomain)
+//   __NAME_ENCODE_APPEND(1, whost)
+//   __NAME_ENCODE_APPEND(4, wdomain_camel)
+//   __NAME_ENCODE_APPEND(3, whost_camel)
+
+//   *res = 7;
+//   res += 2;
+//   *res = 8;
+//   res += 2;
+//   *(uint64_t *)res = ts2;
+//   res += 8;
+
+//   free(wdomain);
+//   free(wdomain_camel);
+//   free(whost);
+//   free(whost_camel);
+
+//   return (res_sz);
+// }
 
 size_t      smb_ntlm_make_blob(smb_ntlm_blob **out_blob, uint64_t ts,
                                uint64_t user_challenge, void *tgt_info,
-                               size_t tgt_sz, uint64_t ts2)
+                               size_t tgt_sz)
 {
   smb_ntlm_blob *blob;
-  //char          *names;
-  //size_t        names_sz;
 
-  assert(blob != NULL && tgt_info != NULL);
+  assert(out_blob != NULL && tgt_info != NULL);
 
-  //names_sz = _ntlm_name_encode(&names, domain, host, ts2);
   blob = malloc(tgt_sz + sizeof(smb_ntlm_blob));
 
   memset((void *)blob, 0, sizeof(smb_ntlm_blob));
@@ -230,7 +230,6 @@ size_t      smb_ntlm_make_blob(smb_ntlm_blob **out_blob, uint64_t ts,
   blob->challenge = user_challenge;
 
   memcpy(blob->target, tgt_info, tgt_sz);
-  //free(names);
 
   *out_blob = blob;
   return (sizeof(smb_ntlm_blob) + tgt_sz);
@@ -245,7 +244,7 @@ void        smb_ntlm2_session_key(smb_ntlmh *hash_v2, void *ntlm2,
   HMAC_MD5(&hash_v2, 16, ntlm2, 16, &hmac_ntlm2);
 
   rc4_init(&rc4, hmac_ntlm2, 16);
-  rc4_crypt(&rc4, xkey, xkey_crypt, 16);
+  rc4_crypt(&rc4, (void *)xkey, (void *)xkey_crypt, 16);
 }
 
 
@@ -306,11 +305,10 @@ void        smb_ntlmssp_response(uint64_t srv_challenge, uint64_t srv_ts,
   smb_ntlm2_hash(user, password, domain, &hash_v2);
   user_challenge = smb_ntlm_generate_challenge();
   smb_ntlm_generate_xkey(&xkey);
-  blob_size = smb_ntlm_make_blob(&blob, srv_ts, user_challenge, tgt, tgt_sz,
-                                 srv_ts + 4200);
+  blob_size = smb_ntlm_make_blob(&blob, srv_ts, user_challenge, tgt, tgt_sz);
 
   lm2   = smb_lm2_response(&hash_v2, srv_challenge, smb_ntlm_generate_challenge());
-  ntlm2 = smb_ntlm2_response(&hash_v2, srv_challenge, blob, blob_size);
+  ntlm2 = smb_ntlm2_response(&hash_v2, srv_challenge, (void *)blob, blob_size);
   smb_ntlm2_session_key(&hash_v2, ntlm2, &xkey, &xkey_crypt);
 
   *token_sz = sizeof(smb_ntlmssp_auth)

+ 4 - 2
src/smb_session.c

@@ -159,6 +159,8 @@ int             smb_session_connect(smb_session *s, const char *name,
 // xsec == 1 -> add Extended security flag
 static int        smb_negotiate(smb_session *s, int xsec)
 {
+  (void)xsec; // FIXME
+
   const char          *dialects[] = SMB_DIALECTS;
   smb_message         *msg = NULL;
   smb_message         answer;
@@ -230,8 +232,8 @@ static int        smb_session_login_ntlm(smb_session *s, const char *domain,
   uint8_t               *ntlm2 = NULL;
   smb_ntlmh             hash_v2;
   uint64_t              user_challenge;
-  uint8_t               blob[128];
-  size_t                blob_size;
+  //uint8_t               blob[128];
+  //size_t                blob_size;
 
   msg = smb_message_new(SMB_CMD_SETUP, 512);
   smb_message_set_andx_members(msg);

+ 2 - 3
src/smb_spnego.c

@@ -65,7 +65,7 @@ static void     clean_asn1(smb_session *s)
     asn1_delete_structure(&s->spnego.asn1_def);
 }
 
-static int      negotiate(smb_session *s, const char *domain, const char *user)
+static int      negotiate(smb_session *s, const char *domain)
 {
   smb_message           *msg = NULL;
   smb_session_xsec_req  *req = NULL;
@@ -305,14 +305,13 @@ static int      auth(smb_session *s, const char *domain, const char *user,
 int             smb_session_login_spnego(smb_session *s, const char *domain,
                                          const char *user, const char *password)
 {
-  smb_message   resp;
   int           res;
   assert(s != NULL && domain != NULL && user != NULL && password != NULL);
 
   if (!init_asn1(s))
     return (0);
 
-  if (!negotiate(s, domain, user))
+  if (!negotiate(s, domain))
     goto error;
   if (!challenge(s))
     goto error;

+ 1 - 1
src/smb_utils.c

@@ -55,7 +55,7 @@ static size_t smb_iconv(const char *src, size_t src_len, char **dst,
     return (0);
   }
 
-  if ((ic = iconv_open(dst_enc, src_enc)) < 0)
+  if ((ic = iconv_open(dst_enc, src_enc)) == (iconv_t)-1)
   {
     fprintf(stderr, "Unable to open iconv to convert from %s to %s\n",
             src_enc, dst_enc);