From d535cff77517214015e2d495677c40cfdec93053 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Thu, 25 Aug 2011 15:09:30 +0200 Subject: http NTLM: refactoring followup Output of Curl_ntlm_create_type1_message() and Curl_ntlm_create_type3_message() functions is now already base64 encoded. --- lib/http_ntlm.c | 65 ++++++++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 45 deletions(-) (limited to 'lib/http_ntlm.c') diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index c5ee679a9..6e07fe977 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -453,13 +453,10 @@ CURLcode Curl_output_ntlm_sso(struct connectdata *conn, CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy) { - size_t size = 0; char *base64 = NULL; - size_t base64_sz = 0; - unsigned char ntlmbuf[NTLM_BUFSIZE]; CURLcode error; - /* point to the address of the pointer that holds the string to sent to the + /* point to the address of the pointer that holds the string to send to the server, which is for a plain host or for a HTTP proxy */ char **allocuserpwd; @@ -514,61 +511,39 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, switch(ntlm->state) { case NTLMSTATE_TYPE1: default: /* for the weird cases we (re)start here */ - /* Create a type-1 message */ - - error = Curl_ntlm_create_type1_message(userp, passwdp, - ntlm, ntlmbuf, &size); + error = Curl_ntlm_create_type1_message(userp, passwdp, ntlm, &base64); if(error) return error; - if(size > 0) { - /* convert the binary blob into base64 */ - error = Curl_base64_encode(NULL, (char *)ntlmbuf, size, - &base64, &base64_sz); - if(error) - return error; - - if(base64_sz > 0) { - Curl_safefree(*allocuserpwd); - *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n", - proxy ? "Proxy-" : "", - base64); - DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd)); - free(base64); - } + if(base64) { + Curl_safefree(*allocuserpwd); + *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n", + proxy ? "Proxy-" : "", + base64); + DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd)); + free(base64); } - break; case NTLMSTATE_TYPE2: /* We already received the type-2 message, create a type-3 message */ - error = Curl_ntlm_create_type3_message(conn->data, userp, passwdp, - ntlm, ntlmbuf, &size); + ntlm, &base64); if(error) return error; - if(size > 0) { - /* convert the binary blob into base64 */ - error = Curl_base64_encode(NULL, (char *)ntlmbuf, size, - &base64, &base64_sz); - if(error) - return error; - - if(base64_sz > 0) { - Curl_safefree(*allocuserpwd); - *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n", - proxy ? "Proxy-" : "", - base64); - DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd)); - free(base64); - - ntlm->state = NTLMSTATE_TYPE3; /* we sent a type-3 */ - authp->done = TRUE; - } - } + if(base64) { + Curl_safefree(*allocuserpwd); + *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n", + proxy ? "Proxy-" : "", + base64); + DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd)); + free(base64); + ntlm->state = NTLMSTATE_TYPE3; /* we send a type-3 */ + authp->done = TRUE; + } break; case NTLMSTATE_TYPE3: -- cgit v1.2.3