From: Amos Jeffries Date: Sun, 23 Aug 2009 04:13:58 +0000 (+1200) Subject: Author: Guido Serassio X-Git-Tag: SQUID_3_1_0_14~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8fa1077d60e599ac1db0d52e8f01041460b13597;p=thirdparty%2Fsquid.git Author: Guido Serassio Windows port: fix mswin_negotiate_auth.exe crash when executing a LocalCall authentication with verbose debug enabled - Also ran source format --- diff --git a/helpers/negotiate_auth/mswin_sspi/libnegotiatessp.c b/helpers/negotiate_auth/mswin_sspi/libnegotiatessp.c index 35f6f6b3dd..7d40a8b667 100644 --- a/helpers/negotiate_auth/mswin_sspi/libnegotiatessp.c +++ b/helpers/negotiate_auth/mswin_sspi/libnegotiatessp.c @@ -22,7 +22,8 @@ typedef unsigned char uchar; #include #endif -void hex_dump(void *data, int size) +void +hex_dump(void *data, int size) { /* dumps size bytes of *data to stdout. Looks like: * [0000] 75 6E 6B 6E 6F 77 6E 20 @@ -39,39 +40,37 @@ void hex_dump(void *data, int size) int n; char bytestr[4] = {0}; char addrstr[10] = {0}; - char hexstr[ 16*3 + 5] = {0}; - char charstr[16*1 + 5] = {0}; - for (n=1;n<=size;n++) { - if (n%16 == 1) { + char hexstr[16 * 3 + 5] = {0}; + char charstr[16 * 1 + 5] = {0}; + for (n = 1; n <= size; n++) { + if (n % 16 == 1) { /* store address for this line */ snprintf(addrstr, sizeof(addrstr), "%.4x", - ((unsigned int)p-(unsigned int)data) ); + ((unsigned int) p - (unsigned int) data)); } - c = *p; if (xisalnum(c) == 0) { c = '.'; } - /* store hex str (for left side) */ snprintf(bytestr, sizeof(bytestr), "%02X ", *p); - strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); + strncat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1); /* store char str (for right side) */ snprintf(bytestr, sizeof(bytestr), "%c", c); - strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); + strncat(charstr, bytestr, sizeof(charstr) - strlen(charstr) - 1); - if (n%16 == 0) { + if (n % 16 == 0) { /* line completed */ fprintf(stderr, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); hexstr[0] = 0; charstr[0] = 0; - } else if (n%8 == 0) { + } else if (n % 8 == 0) { /* half line: add whitespaces */ - strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); - strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); + strncat(hexstr, " ", sizeof(hexstr) - strlen(hexstr) - 1); + strncat(charstr, " ", sizeof(charstr) - strlen(charstr) - 1); } - p++; /* next byte */ + p++; /* next byte */ } if (strlen(hexstr) > 0) { @@ -80,4 +79,3 @@ void hex_dump(void *data, int size) } } } - diff --git a/helpers/negotiate_auth/mswin_sspi/negotiate.h b/helpers/negotiate_auth/mswin_sspi/negotiate.h index d546f84ced..e04aa06aaa 100644 --- a/helpers/negotiate_auth/mswin_sspi/negotiate.h +++ b/helpers/negotiate_auth/mswin_sspi/negotiate.h @@ -67,21 +67,21 @@ debug(char *format,...) #if FAIL_DEBUG if (debug_enabled || fail_debug_enabled) { #else - if (debug_enabled) { +if (debug_enabled) { #endif - va_list args; + va_list args; - va_start(args,format); - fprintf(stderr, "negotiate-auth[%d]: ",getpid()); - vfprintf(stderr, format, args); - va_end(args); + va_start(args,format); + fprintf(stderr, "negotiate-auth[%d]: ",getpid()); + vfprintf(stderr, format, args); + va_end(args); #if FAIL_DEBUG - fail_debug_enabled = 0; + fail_debug_enabled = 0; #endif - } + } #endif /* _SQUID_MSWIN_ */ #endif /* DEBUG */ - } +} #endif /* __GNUC__ */ diff --git a/helpers/negotiate_auth/mswin_sspi/negotiate_auth.c b/helpers/negotiate_auth/mswin_sspi/negotiate_auth.c index 548f445306..e9e73746a7 100644 --- a/helpers/negotiate_auth/mswin_sspi/negotiate_auth.c +++ b/helpers/negotiate_auth/mswin_sspi/negotiate_auth.c @@ -1,3 +1,4 @@ + /* * mswin_negotiate_auth: helper for Negotiate Authentication for Squid Cache * @@ -79,15 +80,15 @@ void helperfail(const char *reason) { #if FAIL_DEBUG - fail_debug_enabled =1; + fail_debug_enabled = 1; #endif SEND2("BH %s", reason); } /* - options: - -d enable debugging. - -v enable verbose Negotiate packet debugging. + * options: + * -d enable debugging. + * -v enable verbose Negotiate packet debugging. */ char *my_program_name = NULL; @@ -108,7 +109,7 @@ process_options(int argc, char *argv[]) { int opt, had_error = 0; - opterr =0; + opterr = 0; while (-1 != (opt = getopt(argc, argv, "hdv"))) { switch (opt) { case 'd': @@ -142,15 +143,15 @@ manage_request() char *c, *decoded; int plen, status; int oversized = 0; - char * ErrorMessage; - static char cred[SSP_MAX_CRED_LEN+1]; + char *ErrorMessage; + static char cred[SSP_MAX_CRED_LEN + 1]; BOOL Done = FALSE; try_again: if (fgets(buf, BUFFER_SIZE, stdin) == NULL) return 0; - c = memchr(buf, '\n', BUFFER_SIZE); /* safer against overrun than strchr */ + c = memchr(buf, '\n', BUFFER_SIZE); /* safer against overrun than strchr */ if (c) { if (oversized) { helperfail("illegal request received"); @@ -183,27 +184,30 @@ try_again: return 1; } /* Obtain server blob against SSPI */ - plen = (strlen(buf) - 3) * 3 / 4; /* we only need it here. Optimization */ + plen = (strlen(buf) - 3) * 3 / 4; /* we only need it here. Optimization */ c = (char *) SSP_MakeNegotiateBlob(decoded, plen, &Done, &status, cred); if (status == SSP_OK) { if (Done) { - lc(cred); /* let's lowercase them for our convenience */ + lc(cred); /* let's lowercase them for our convenience */ have_serverblob = 0; Done = FALSE; if (Negotiate_packet_debug_enabled) { - printf("AF %s %s\n",c,cred); decoded = base64_decode(c); debug("sending 'AF' %s to squid with data:\n", cred); - hex_dump(decoded, (strlen(c) * 3) / 4); + if (c != NULL) + hex_dump(decoded, (strlen(c) * 3) / 4); + else + fprintf(stderr, "No data available.\n"); + printf("AF %s %s\n", c, cred); } else SEND3("AF %s %s", c, cred); } else { if (Negotiate_packet_debug_enabled) { - printf("TT %s\n",c); decoded = base64_decode(c); debug("sending 'TT' to squid with data:\n"); hex_dump(decoded, (strlen(c) * 3) / 4); + printf("TT %s\n", c); } else { SEND2("TT %s", c); } @@ -213,7 +217,6 @@ try_again: helperfail("can't obtain server blob"); return 1; } - if (memcmp(buf, "KK ", 3) == 0) { /* authenticate-request */ if (!have_serverblob) { helperfail("invalid server blob"); @@ -228,9 +231,8 @@ try_again: SEND("NA * Packet format error, couldn't base64-decode"); return 1; } - /* check against SSPI */ - plen = (strlen(buf) - 3) * 3 / 4; /* we only need it here. Optimization */ + plen = (strlen(buf) - 3) * 3 / 4; /* we only need it here. Optimization */ c = (char *) SSP_ValidateNegotiateCredentials(decoded, plen, &Done, &status, cred); if (status == SSP_ERROR) { @@ -241,8 +243,8 @@ try_again: FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ - (LPTSTR) &ErrorMessage, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ + (LPTSTR) & ErrorMessage, 0, NULL); if (ErrorMessage[strlen(ErrorMessage) - 1] == '\n') @@ -253,32 +255,34 @@ try_again: LocalFree(ErrorMessage); return 1; } - if (Done) { lc(cred); /* let's lowercase them for our convenience */ have_serverblob = 0; Done = FALSE; if (Negotiate_packet_debug_enabled) { - printf("AF %s %s\n",c,cred); decoded = base64_decode(c); debug("sending 'AF' %s to squid with data:\n", cred); - hex_dump(decoded, (strlen(c) * 3) / 4); + if (c != NULL) + hex_dump(decoded, (strlen(c) * 3) / 4); + else + fprintf(stderr, "No data available.\n"); + printf("AF %s %s\n", c, cred); } else { SEND3("AF %s %s", c, cred); } return 1; } else { if (Negotiate_packet_debug_enabled) { - printf("TT %s\n",c); decoded = base64_decode(c); debug("sending 'TT' to squid with data:\n"); hex_dump(decoded, (strlen(c) * 3) / 4); + printf("TT %s\n", c); } else SEND2("TT %s", c); return 1; } - } else { /* not an auth-request */ + } else { /* not an auth-request */ helperfail("illegal request received"); fprintf(stderr, "Illegal request received: '%s'\n", buf); return 1;