From: Amos Jeffries Date: Fri, 24 Apr 2009 07:06:46 +0000 (-0600) Subject: Fix many syntax warnings in smb_lm X-Git-Tag: SQUID_3_2_0_1~1043 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a19a836de24b3e33b64f4359ca1f5b87fe8b8eab;p=thirdparty%2Fsquid.git Fix many syntax warnings in smb_lm Now compiled with the same CFLAGS as the rest of Squid. This is tested up to gcc 3.4 standards now. Some may still be raised by later gcc versions. - fixes const correctness on several functions and globals - fixes .h wrapping on several files - adds prototype definitions for all functions - adds several missing includes - adds docs for some functions to auto-doc output TODO: Not all code audited, only the bits shown broken right now. This helper contains a large amount of nasty duplicate code and re-implements several encryption algoritms that should probably be sourced from secure places. --- diff --git a/helpers/ntlm_auth/smb_lm/libntlmssp.c b/helpers/ntlm_auth/smb_lm/libntlmssp.c index 537e551817..6cdc16ed41 100644 --- a/helpers/ntlm_auth/smb_lm/libntlmssp.c +++ b/helpers/ntlm_auth/smb_lm/libntlmssp.c @@ -42,7 +42,7 @@ SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, char *server, cha /* this one is reallllly haackiish. We really should be using anything from smblib-priv.h */ -static char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", +static char const *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", "MICROSOFT NETWORKS 1.03", "MICROSOFT NETWORKS 3.0", "DOS LANMAN1.0", diff --git a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c index 7c97d14395..b06eadb8ae 100644 --- a/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c +++ b/helpers/ntlm_auth/smb_lm/ntlm_smb_lm_auth.c @@ -26,9 +26,10 @@ /* these are part of rfcnb-priv.h and smblib-priv.h */ extern int SMB_Get_Error_Msg(int msg, char *msgbuf, int len); -extern int SMB_Get_Last_Error(); -extern int SMB_Get_Last_SMB_Err(); -extern int RFCNB_Get_Last_Error(); +extern int SMB_Get_Last_Error(void); +extern int SMB_Get_Last_SMB_Err(void); +extern int RFCNB_Get_Last_Error(void); + #include @@ -53,6 +54,14 @@ extern int RFCNB_Get_Last_Error(); #include #endif +/* local functions */ +void send_bh_or_ld(char const *bhmessage, ntlm_authenticate * failedauth, int authlen); +void usage(void); +void process_options(int argc, char *argv[]); +const char * obtain_challenge(void); +void manage_request(void); + + #ifdef DEBUG char error_messages_buffer[BUFFER_SIZE]; #endif @@ -101,7 +110,7 @@ lc(char *string) void -send_bh_or_ld(char *bhmessage, ntlm_authenticate * failedauth, int authlen) +send_bh_or_ld(char const *bhmessage, ntlm_authenticate * failedauth, int authlen) { #ifdef NTLM_FAIL_OPEN char *creds = NULL; @@ -228,7 +237,8 @@ process_options(int argc, char *argv[]) last_dc->next = controllers; /* close the queue, now it's circular */ } -/* tries connecting to the domain controllers in the "controllers" ring, +/** + * tries connecting to the domain controllers in the "controllers" ring, * with failover if the adequate option is specified. */ const char * diff --git a/helpers/ntlm_auth/smb_lm/smbval/md4.c b/helpers/ntlm_auth/smb_lm/smbval/md4.c index 5318045029..8bcf494c6d 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/md4.c +++ b/helpers/ntlm_auth/smb_lm/smbval/md4.c @@ -26,6 +26,7 @@ */ #include #include "std-defines.h" /* for the types */ +#include "md4.h" static uint32 A, B, C, D; diff --git a/helpers/ntlm_auth/smb_lm/smbval/md4.h b/helpers/ntlm_auth/smb_lm/smbval/md4.h index 91733de761..f2ad749654 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/md4.h +++ b/helpers/ntlm_auth/smb_lm/smbval/md4.h @@ -1 +1,6 @@ -void mdfour(unsigned char *out, unsigned char *in, int n); +#ifndef __SMB_LM_SMBVAL_MD4_H +#define __SMB_LM_SMBVAL_MD4_H + +extern void mdfour(unsigned char *out, unsigned char *in, int n); + +#endif /* __SMB_LM_SMBVAL_MD4_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-common.h b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-common.h index 84f5a3dfe8..653fb698aa 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-common.h +++ b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-common.h @@ -23,6 +23,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef _SMB_LM_SMBVAL_RFCNB_COMMON_H +#define _SMB_LM_SMBVAL_RFCNB_COMMON_H + /* A data structure we need */ typedef struct RFCNB_Pkt { @@ -32,3 +35,5 @@ typedef struct RFCNB_Pkt { struct RFCNB_Pkt *next; } RFCNB_Pkt; + +#endif /* _SMB_LM_SMBVAL_RFCNB_COMMON_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-error.h b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-error.h index e03ca5d992..0cb89995c6 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-error.h +++ b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-error.h @@ -48,7 +48,7 @@ #define RFCNBE_Timeout 16 /* IO Timed out */ /* Text strings for the error responses */ -extern char *RFCNB_Error_Strings[]; +extern char const *RFCNB_Error_Strings[]; /* * static char *RFCNB_Error_Strings[] = { * diff --git a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.c b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.c index e51956e8f5..d9700067e8 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.c +++ b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.c @@ -32,18 +32,22 @@ #include #include -int RFCNB_Timeout = 0; /* Timeout in seconds ... */ +/* local functions */ +void rfcnb_alarm(int sig); +int RFCNB_Set_Timeout(int seconds); +int RFCNB_Discard_Rest(struct RFCNB_Con *con, int len); + +/* local globals */ + +int RFCNB_Timeout = 0; /**< Timeout in seconds ... */ void rfcnb_alarm(int sig) { - fprintf(stderr, "IO Timed out ...\n"); - } -/* Set timeout value and setup signal handling */ - +/** Set timeout value and setup signal handling */ int RFCNB_Set_Timeout(int seconds) { @@ -79,9 +83,9 @@ RFCNB_Set_Timeout(int seconds) } -/* Discard the rest of an incoming packet as we do not have space for it - * in the buffer we allocated or were passed ... */ - +/** Discard the rest of an incoming packet as we do not have space for it + * in the buffer we allocated or were passed ... + */ int RFCNB_Discard_Rest(struct RFCNB_Con *con, int len) { @@ -122,14 +126,13 @@ RFCNB_Discard_Rest(struct RFCNB_Con *con, int len) } -/* Send an RFCNB packet to the connection. +/** Send an RFCNB packet to the connection. * * We just send each of the blocks linked together ... * * If we can, try to send it as one iovec ... * */ - int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) { @@ -212,14 +215,12 @@ RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) } -/* Read an RFCNB packet off the connection. +/** Read an RFCNB packet off the connection. * * We read the first 4 bytes, that tells us the length, then read the * rest. We should implement a timeout, but we don't just yet * */ - - int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) { diff --git a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.h b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.h index 46180d0030..06aa5f5f46 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.h +++ b/helpers/ntlm_auth/smb_lm/smbval/rfcnb-io.h @@ -23,8 +23,13 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); +#ifndef _SMB_LM_SMBVAL_RFCNB_IO_H +#define _SMB_LM_SMBVAL_RFCNB_IO_H -int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); +extern int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); -void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); +extern int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len); + +extern void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); + +#endif /* _SMB_LM_SMBVAL_RFCNB_IO_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/rfcnb.h b/helpers/ntlm_auth/smb_lm/smbval/rfcnb.h index fb8bc207d0..eff6d7a268 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/rfcnb.h +++ b/helpers/ntlm_auth/smb_lm/smbval/rfcnb.h @@ -23,11 +23,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef SMB_LM_SMBVAL_RFCNB_H +#define SMB_LM_SMBVAL_RFCNB_H + /* Error responses */ #include "rfcnb-error.h" #include "rfcnb-common.h" #include "smblib-priv.h" +#include "rfcnb-priv.h" /* Defines we need */ @@ -35,21 +39,22 @@ /* Definition of routines we define */ -void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, - int port); +extern void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address, int port); + +extern int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *Data, int Length); -int RFCNB_Send(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); +extern int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); -int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length); +extern int RFCNB_Hangup(struct RFCNB_Con *con_Handle); -int RFCNB_Hangup(void *con_Handle); +extern void *RFCNB_Listen(void); -void *RFCNB_Listen(); +extern void RFCNB_Get_Error(char *buffer, int buf_len); -void RFCNB_Get_Error(char *buffer, int buf_len); +extern struct RFCNB_Pkt *RFCNB_Alloc_Pkt(int n); -struct RFCNB_Pkt *RFCNB_Alloc_Pkt(int n); +extern void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); -void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt); +extern int RFCNB_Set_Sock_NoDelay(struct RFCNB_Con *con_Handle, BOOL yn); -int RFCNB_Set_Sock_NoDelay(void *con_Handle, BOOL yn); +#endif /* SMB_LM_SMBVAL_RFCNB_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/session.c b/helpers/ntlm_auth/smb_lm/smbval/session.c index 14a9401165..65776a3602 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/session.c +++ b/helpers/ntlm_auth/smb_lm/smbval/session.c @@ -35,10 +35,19 @@ int RFCNB_saved_errno = 0; #include "rfcnb-priv.h" #include "rfcnb-util.h" #include "rfcnb-io.h" +#include "rfcnb.h" + + +/* local functions */ + +int RFCNB_Get_Last_Error(void); +int RFCNB_Get_Last_Errno(void); +void RFCNB_Get_Error_Msg(int code, char *msg_buf, int len); +void RFCNB_Register_Print_Routine(void (*fn) ()); /* global data structures */ -char *RFCNB_Error_Strings[] = { +char const * RFCNB_Error_Strings[] = { "RFCNBE_OK: Routine completed successfully.", "RFCNBE_NoSpace: No space available for a malloc call.", diff --git a/helpers/ntlm_auth/smb_lm/smbval/smbdes.c b/helpers/ntlm_auth/smb_lm/smbval/smbdes.c index 8b0ccdfb7f..8e1931219f 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smbdes.c +++ b/helpers/ntlm_auth/smb_lm/smbval/smbdes.c @@ -45,6 +45,11 @@ * up with a different answer to the one above) */ +#include "smbdes.h" + +/* local functions */ +void cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key); +void cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key); static int perm1[56] = {57, 49, 41, 33, 25, 17, 9, diff --git a/helpers/ntlm_auth/smb_lm/smbval/smbdes.h b/helpers/ntlm_auth/smb_lm/smbval/smbdes.h index 5a431140dd..057fc22101 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smbdes.h +++ b/helpers/ntlm_auth/smb_lm/smbval/smbdes.h @@ -1,2 +1,7 @@ -void E_P16(unsigned char *p14, unsigned char *p16); -void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24); +#ifndef __SMB_LM_SMBVAL_SMBDES_H +#define __SMB_LM_SMBVAL_SMBDES_H + +extern void E_P16(unsigned char *p14, unsigned char *p16); +extern void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24); + +#endif /* __SMB_LM_SMBVAL_SMBDES_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.c b/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.c index c585cecb93..3bbf4a2f7a 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.c +++ b/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.c @@ -31,13 +31,18 @@ #include "smblib-priv.h" #include "md4.h" #include "smbdes.h" + #define uchar unsigned char extern int DEBUGLEVEL; #include "byteorder.h" +#include "smbencrypt.h" +/* local functions */ char *StrnCpy(char *dest, char *src, int n); void strupper(char *s); +void E_md4hash(uchar * passwd, uchar * p16); +void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16); /* * This implements the X/Open SMB password encryption @@ -91,10 +96,9 @@ _my_mbstowcs(int16 * dst, uchar * src, int len) return i; } -/* +/** * Creates the MD4 Hash of the users password in NT UNICODE. */ - void E_md4hash(uchar * passwd, uchar * p16) { @@ -115,7 +119,6 @@ E_md4hash(uchar * passwd, uchar * p16) } /* Does the NT MD4 hash then des encryption. */ - void SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24) { @@ -127,8 +130,7 @@ SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24) E_P24(p21, c8, p24); } -/* Does both the NT and LM owfs of a user's password */ - +/** Does both the NT and LM owfs of a user's password */ void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16) { diff --git a/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.h b/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.h index bf3b13f2b5..cee12f7e66 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.h +++ b/helpers/ntlm_auth/smb_lm/smbval/smbencrypt.h @@ -1,3 +1,9 @@ -void SMBencrypt(uchar * passwd, uchar * c8, uchar * p24); -void SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24); +#ifndef __SMB_LM_SMBVAL_SMBENCRYPT_H +#define __SMB_LM_SMBVAL_SMBENCRYPT_H + + +extern void SMBencrypt(uchar * passwd, uchar * c8, uchar * p24); +extern void SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24); + +#endif /* __SMB_LM_SMBVAL_SMBENCRYPT_H */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/smblib-priv.h b/helpers/ntlm_auth/smb_lm/smbval/smblib-priv.h index 93dce361c2..0530de7362 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smblib-priv.h +++ b/helpers/ntlm_auth/smb_lm/smbval/smblib-priv.h @@ -500,7 +500,7 @@ typedef enum { /* We must make it possible for callers to specify these ... */ #if 0 -extern char *SMB_Prots[]; +extern char const *SMB_Prots[]; /* * static char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", @@ -637,19 +637,19 @@ extern int SMBlib_errno; extern int SMBlib_SMB_Error; /* last Error */ #endif -SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con, SMB_Tree_Handle tree, - char *path, char *password, char *dev); +extern SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con, SMB_Tree_Handle tree, + char *path, char *password, char const *dev); -int SMB_Init(); -void SMB_Get_My_Name(char *name, int len); -int SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]); -int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); +extern int SMB_Init(void); +extern void SMB_Get_My_Name(char *name, int len); +extern int SMB_Negotiate(SMB_Handle_Type Con_Handle, char const *Prots[]); +extern int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle); -int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, +extern int SMB_Logon_Server(SMB_Handle_Type Con_Handle, char *UserName, char *PassWord, char *UserDomain, int precrypted); -int SMB_Get_Error_Msg(int msg, char *msgbuf, int len); +extern int SMB_Get_Error_Msg(int msg, char *msgbuf, int len); -int SMB_Get_Last_Error(); +extern int SMB_Get_Last_Error(void); #endif /* __SMBLIB_PRIV_H__ */ diff --git a/helpers/ntlm_auth/smb_lm/smbval/smblib-util.c b/helpers/ntlm_auth/smb_lm/smbval/smblib-util.c index f74b27c390..07b7b6712b 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smblib-util.c +++ b/helpers/ntlm_auth/smb_lm/smbval/smblib-util.c @@ -29,6 +29,19 @@ #include "rfcnb.h" +/* local functions */ +char * SMB_DOSTimToStr(int DOS_time); +char * SMB_AtrToStr(int attribs, BOOL verbose); +int SMB_Get_Tree_MBS(SMB_Tree_Handle tree); +int SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle); +int SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle); +int SMB_Get_Protocol(SMB_Handle_Type Con_Handle); +int SMB_Figure_Protocol(char const *dialects[], int prot_index); +int SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard); +// int SMB_Get_Last_Error(void); +int SMB_Get_Last_SMB_Err(void); + + /* global data structures */ static int SMB_Types[] = {SMB_P_Core, @@ -46,7 +59,7 @@ static int SMB_Types[] = {SMB_P_Core, -1 }; -static char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", +static char const *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", "MICROSOFT NETWORKS 1.03", "MICROSOFT NETWORKS 3.0", "DOS LANMAN1.0", @@ -62,7 +75,7 @@ static char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0", }; /* Print out an SMB pkt in all its gory detail ... */ - +#if 0 // DEAD CODE void SMB_Print_Pkt(FILE fd, RFCNB_Pkt * pkt, BOOL command, int Offset, int Len) { @@ -79,6 +92,7 @@ SMB_Print_Pkt(FILE fd, RFCNB_Pkt * pkt, BOOL command, int Offset, int Len) /* etc */ } +#endif /* 0 */ /* Convert a DOS Date_Time to a local host type date time for printing */ @@ -105,10 +119,11 @@ SMB_DOSTimToStr(int DOS_time) } -/* Convert an attribute byte/word etc to a string ... We return a pointer +/** + * Convert an attribute byte/word etc to a string ... We return a pointer * to a static string which we guarantee is long enough. If verbose is - * true, we print out long form of strings ... */ - + * true, we print out long form of strings ... + */ char * SMB_AtrToStr(int attribs, BOOL verbose) { @@ -138,8 +153,7 @@ SMB_AtrToStr(int attribs, BOOL verbose) } -/* Pick up the Max Buffer Size from the Tree Structure ... */ - +/** Pick up the Max Buffer Size from the Tree Structure ... */ int SMB_Get_Tree_MBS(SMB_Tree_Handle tree) { @@ -150,8 +164,7 @@ SMB_Get_Tree_MBS(SMB_Tree_Handle tree) } } -/* Pick up the Max buffer size */ - +/** Pick up the Max buffer size */ int SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle) { @@ -162,8 +175,8 @@ SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle) } } -/* Pickup the protocol index from the connection structure */ +/* Pickup the protocol index from the connection structure */ int SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle) { @@ -175,8 +188,7 @@ SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle) } -/* Pick up the protocol from the connection structure */ - +/** Pick up the protocol from the connection structure */ int SMB_Get_Protocol(SMB_Handle_Type Con_Handle) { @@ -188,12 +200,13 @@ SMB_Get_Protocol(SMB_Handle_Type Con_Handle) } -/* Figure out what protocol was accepted, given the list of dialect strings */ -/* We offered, and the index back from the server. We allow for a user */ -/* supplied list, and assume that it is a subset of our list */ - +/** + * Figure out what protocol was accepted, given the list of dialect strings + * We offered, and the index back from the server. We allow for a user + * supplied list, and assume that it is a subset of our list + */ int -SMB_Figure_Protocol(char *dialects[], int prot_index) +SMB_Figure_Protocol(char const *dialects[], int prot_index) { int i; @@ -226,7 +239,7 @@ SMB_Figure_Protocol(char *dialects[], int prot_index) /* none acceptible, and our return value is 0 if ok, <0 if problems */ int -SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) +SMB_Negotiate(SMB_Handle_Type Con_Handle, char const *Prots[]) { struct RFCNB_Pkt *pkt; int prots_len, i, pkt_len, prot, alloc_len; @@ -237,9 +250,7 @@ SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) prots_len = 0; for (i = 0; Prots[i] != NULL; i++) { - prots_len = prots_len + strlen(Prots[i]) + 2; /* Account for null etc */ - } /* The -1 accounts for the one byte smb_buf we have because some systems */ @@ -251,25 +262,19 @@ SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) /* Which is a problem, because the encryption key len eec may be long */ if (pkt_len < (SMB_hdr_wct_offset + (19 * 2) + 40)) { - alloc_len = SMB_hdr_wct_offset + (19 * 2) + 40; - } else { - alloc_len = pkt_len; - } pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(alloc_len); if (pkt == NULL) { - SMBlib_errno = SMBlibE_NoSpace; return (SMBlibE_BAD); - } - /* Now plug in the bits we need */ + /* Now plug in the bits we need */ memset(SMB_Hdr(pkt), 0, SMB_negp_len); SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */ *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBnegprot; @@ -278,7 +283,6 @@ SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle->mid); SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle->uid); *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0; - SSVAL(SMB_Hdr(pkt), SMB_negp_bcc_offset, prots_len); /* Now copy the prot strings in with the right stuff */ @@ -286,82 +290,65 @@ SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) p = (char *) (SMB_Hdr(pkt) + SMB_negp_buf_offset); for (i = 0; Prots[i] != NULL; i++) { - *p = SMBdialectID; strcpy(p + 1, Prots[i]); p = p + strlen(Prots[i]) + 2; /* Adjust len of p for null plus dialectID */ - } /* Now send the packet and sit back ... */ - if (RFCNB_Send(Con_Handle->Trans_Connect, pkt, pkt_len) < 0) { - - #ifdef DEBUG fprintf(stderr, "Error sending negotiate protocol\n"); #endif - RFCNB_Free_Pkt(pkt); SMBlib_errno = -SMBlibE_SendFailed; /* Failed, check lower layer errno */ return (SMBlibE_BAD); - } - /* Now get the response ... */ + /* Now get the response ... */ if (RFCNB_Recv(Con_Handle->Trans_Connect, pkt, alloc_len) < 0) { - #ifdef DEBUG fprintf(stderr, "Error receiving response to negotiate\n"); #endif - RFCNB_Free_Pkt(pkt); SMBlib_errno = -SMBlibE_RecvFailed; /* Failed, check lower layer errno */ return (SMBlibE_BAD); - } - if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ + if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */ #ifdef DEBUG fprintf(stderr, "SMB_Negotiate failed with errorclass = %i, Error Code = %i\n", CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset), SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset)); #endif - SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset); RFCNB_Free_Pkt(pkt); SMBlib_errno = SMBlibE_Remote; return (SMBlibE_BAD); - } - if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { + if (SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset) == 0xFFFF) { #ifdef DEBUG fprintf(stderr, "None of our protocols was accepted ... "); #endif - RFCNB_Free_Pkt(pkt); SMBlib_errno = SMBlibE_NegNoProt; return (SMBlibE_BAD); - } + /* Now, unpack the info from the response, if any and evaluate the proto */ /* selected. We must make sure it is one we like ... */ - Con_Handle->prot_IDX = prot = SVAL(SMB_Hdr(pkt), SMB_negrCP_idx_offset); Con_Handle->protocol = SMB_Figure_Protocol(Prots, prot); if (Con_Handle->protocol == SMB_P_Unknown) { /* No good ... */ - RFCNB_Free_Pkt(pkt); SMBlib_errno = SMBlibE_ProtUnknown; return (SMBlibE_BAD); - } switch (CVAL(SMB_Hdr(pkt), SMB_hdr_wct_offset)) { case 0x01: /* No more info ... */ - break; case 13: /* Up to and including LanMan 2.1 */ @@ -385,7 +372,6 @@ SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[]) p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle->Encrypt_Key_Len); strncpy(p, Con_Handle->Svr_PDom, sizeof(Con_Handle->Svr_PDom) - 1); - break; case 17: /* NT LM 0.12 and LN LM 1.0 */ @@ -459,7 +445,7 @@ SMB_TreeConnect(SMB_Handle_Type Con_Handle, SMB_Tree_Handle Tree_Handle, char *path, char *password, - char *device) + char const *device) { struct RFCNB_Pkt *pkt; int param_len, pkt_len; @@ -730,9 +716,9 @@ SMB_Get_Last_Error() } -/* Pick up the last error returned in an SMB packet */ -/* We will need macros to extract error class and error code */ - +/** Pick up the last error returned in an SMB packet + * We will need macros to extract error class and error code + */ int SMB_Get_Last_SMB_Err() { @@ -745,7 +731,7 @@ SMB_Get_Last_SMB_Err() /* Keep this table in sync with the message codes in smblib-common.h */ -static char *SMBlib_Error_Messages[] = { +static char const *SMBlib_Error_Messages[] = { "Request completed sucessfully.", "Server returned a non-zero SMB Error Class and Code.", diff --git a/helpers/ntlm_auth/smb_lm/smbval/smblib.c b/helpers/ntlm_auth/smb_lm/smbval/smblib.c index 3c8073751b..36edea8603 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/smblib.c +++ b/helpers/ntlm_auth/smb_lm/smbval/smblib.c @@ -40,6 +40,14 @@ int SMBlib_SMB_Error; #include +/* local functions */ +int SMB_Term(void); +SMB_Handle_Type SMB_Create_Con_Handle(void); +int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn); +SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, char *server, char *NTdomain); +SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, SMB_Tree_Handle * tree, char *service, char *username, char *password); + + /* #define DEBUG */ SMB_State_Types SMBlib_State; @@ -79,38 +87,28 @@ SMB_Term() } -/* SMB_Create: Create a connection structure and return for later use */ -/* We have other helper routines to set variables */ - +/** + * SMB_Create: Create a connection structure and return for later use + * We have other helper routines to set variables + */ SMB_Handle_Type SMB_Create_Con_Handle() { - SMBlib_errno = SMBlibE_NotImpl; return (NULL); - } int SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn) { - - if (RFCNB_Set_Sock_NoDelay(Con_Handle->Trans_Connect, yn) < 0) { - -#ifdef DEBUG -#endif - fprintf(stderr, "Setting no-delay on TCP socket failed ...\n"); - } return (0); - } /* SMB_Connect_Server: Connect to a server, but don't negotiate protocol */ /* or anything else ... */ - SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, char *server, char *NTdomain) @@ -210,7 +208,7 @@ SMB_Connect_Server(SMB_Handle_Type Con_Handle, /* If Con_Handle == NULL then create a handle and connect, otherwise */ /* use the handle passed */ -char *SMB_Prots_Restrict[] = {"PC NETWORK PROGRAM 1.0", +char const *SMB_Prots_Restrict[] = {"PC NETWORK PROGRAM 1.0", NULL }; @@ -303,22 +301,18 @@ SMB_Connect(SMB_Handle_Type Con_Handle, return NULL; } - /* Now, negotiate the protocol */ + /* Now, negotiate the protocol */ if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { /* Hmmm what should we do here ... We have a connection, but could not * negotiate ... */ - return NULL; - } - /* Now connect to the service ... */ + /* Now connect to the service ... */ if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { - return NULL; - } return (con); diff --git a/helpers/ntlm_auth/smb_lm/smbval/valid.c b/helpers/ntlm_auth/smb_lm/smbval/valid.c index 62a608c9a6..f481decbc2 100644 --- a/helpers/ntlm_auth/smb_lm/smbval/valid.c +++ b/helpers/ntlm_auth/smb_lm/smbval/valid.c @@ -22,13 +22,13 @@ int Valid_User(char *username, char *password, char *server, char *backup, char *domain) { int pass_is_precrypted_p = 0; - char *SMB_Prots[] = { + char const *SMB_Prots[] = { /* "PC NETWORK PROGRAM 1.0", */ /* "MICROSOFT NETWORKS 1.03", */ /* "MICROSOFT NETWORKS 3.0", */ - (char*)"LANMAN1.0", - (char*)"LM1.2X002", - (char*)"Samba", + "LANMAN1.0", + "LM1.2X002", + "Samba", /* "NT LM 0.12", */ /* "NT LANMAN 1.0", */ NULL @@ -63,13 +63,13 @@ Valid_User(char *username, char *password, char *server, char *backup, char *dom void * NTLM_Connect(char *server, char *backup, char *domain, char *nonce) { - char *SMB_Prots[] = { + char const *SMB_Prots[] = { /* "PC NETWORK PROGRAM 1.0", */ /* "MICROSOFT NETWORKS 1.03", */ /* "MICROSOFT NETWORKS 3.0", */ - (char*)"LANMAN1.0", - (char*)"LM1.2X002", - (char*)"Samba", + "LANMAN1.0", + "LM1.2X002", + "Samba", /* "NT LM 0.12", */ /* "NT LANMAN 1.0", */ NULL