diff options
-rw-r--r-- | lib/curl_ntlm.c | 47 | ||||
-rw-r--r-- | lib/curl_ntlm.h | 12 | ||||
-rw-r--r-- | lib/http_ntlm.c | 65 |
3 files changed, 47 insertions, 77 deletions
diff --git a/lib/curl_ntlm.c b/lib/curl_ntlm.c index b555f5ab6..ea8936eb3 100644 --- a/lib/curl_ntlm.c +++ b/lib/curl_ntlm.c @@ -684,28 +684,25 @@ static void unicodecpy(unsigned char *dest, /* * Curl_ntlm_create_type1_message() * - * This is used to generate a ntlm type-1 message ready for encoding - * and sending to the recipient, be it a: HTTP, SMTP or POP3 server, + * This is used to generate an already encoded NTLM type-1 message ready + * for sending to the recipient, be it a: HTTP, SMTP or POP3 server, * using the appropriate compile time crypo API. * * Parameters: * * userp [in] - The user name in the format User or Domain\User. * passdwp [in] - The user's password. - * ntlm [in] - The ntlm data struct being used and modified. - * ntlmbuf [in] - Pointer to preallocated buffer to receive message. - * sizep [out] - Size of message written into output buffer. + * ntlm [in/out] - The ntlm data struct being used and modified. + * outptr [in/out] - The adress where a pointer to newly allocated memory + * holding the result will be stored upon completion. * * Returns CURLE_OK on success. */ CURLcode Curl_ntlm_create_type1_message(const char *userp, const char *passwdp, struct ntlmdata *ntlm, - unsigned char *ntlmbuf, - size_t *sizep) + char **outptr) { - size_t size; - /* NTLM type-1 message structure: Index Description Content @@ -720,6 +717,10 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp, (*) -> Optional */ + unsigned char ntlmbuf[NTLM_BUFSIZE]; + size_t base64_sz = 0; + size_t size; + #ifdef USE_WINDOWS_SSPI SecBuffer buf; @@ -895,17 +896,15 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp, fprintf(stderr, "\n****\n"); }); - /* Return the message size */ - *sizep = size; - - return CURLE_OK; + /* Return with binary blob encoded into base64 */ + return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, &base64_sz); } /* * Curl_ntlm_create_type3_message() * - * This is used to generate a ntlm type-3 message ready for encoding - * and sending to the recipient, be it a: HTTP, SMTP or POP3 server, + * This is used to generate an already encoded NTLM type-3 message ready + * for sending to the recipient, be it a: HTTP, SMTP or POP3 server, * using the appropriate compile time crypo API. * * Parameters: @@ -913,9 +912,9 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp, * data [in] - The session handle. * userp [in] - The user name in the format User or Domain\User. * passdwp [in] - The user's password. - * ntlm [in] - The ntlm data struct being used and modified. - * ntlmbuf [in] - Pointer to preallocated buffer to receive message. - * sizep [out] - Size of message written into output buffer. + * ntlm [in/out] - The ntlm data struct being used and modified. + * outptr [in/out] - The adress where a pointer to newly allocated memory + * holding the result will be stored upon completion. * * Returns CURLE_OK on success. */ @@ -923,8 +922,7 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data, const char *userp, const char *passwdp, struct ntlmdata *ntlm, - unsigned char *ntlmbuf, - size_t *sizep) + char **outptr) { /* NTLM type-3 message structure: @@ -944,7 +942,8 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data, (*) -> Optional */ - + unsigned char ntlmbuf[NTLM_BUFSIZE]; + size_t base64_sz = 0; size_t size; #ifdef USE_WINDOWS_SSPI @@ -1294,10 +1293,8 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data, #endif - /* Return the message size */ - *sizep = size; - - return CURLE_OK; + /* Return with binary blob encoded into base64 */ + return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, &base64_sz); } #endif /* USE_NTLM */ diff --git a/lib/curl_ntlm.h b/lib/curl_ntlm.h index 24021033a..ef3dfc1e4 100644 --- a/lib/curl_ntlm.h +++ b/lib/curl_ntlm.h @@ -24,22 +24,20 @@ #ifdef USE_NTLM -/* This is to generate a ntlm type-1 message */ +/* This is to generate a base64 encoded NTLM type-1 message */ CURLcode Curl_ntlm_create_type1_message(const char *userp, const char *passwdp, struct ntlmdata *ntlm, - unsigned char *ntlmbuf, - size_t *size); + char **outptr); -/* This is to generate a ntlm type-3 message */ +/* This is to generate a base64 encoded NTLM type-3 message */ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data, const char *userp, const char *passwdp, struct ntlmdata *ntlm, - unsigned char *ntlmbuf, - size_t *size); + char **outptr); -/* This is to decode a ntlm type-2 message */ +/* This is to decode a NTLM type-2 message */ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data, const char* header, struct ntlmdata* ntlm); 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: |