Skip to content

Commit

Permalink
ntlm: Moved the native Target Info clean-up from HTTP specific function
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-caveman2k committed Nov 9, 2014
1 parent 474442d commit 40ee1ba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
14 changes: 2 additions & 12 deletions lib/curl_ntlm.c
Expand Up @@ -229,21 +229,11 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)

void Curl_http_ntlm_cleanup(struct connectdata *conn)
{
#ifdef USE_WINDOWS_SSPI
Curl_sasl_ntlm_cleanup(&conn->ntlm);
Curl_sasl_ntlm_cleanup(&conn->proxyntlm);
#elif defined(NTLM_WB_ENABLED)
Curl_ntlm_wb_cleanup(conn);
#else
(void)conn;
#endif

#ifndef USE_WINDOWS_SSPI
Curl_safefree(conn->ntlm.target_info);
conn->ntlm.target_info_len = 0;

Curl_safefree(conn->proxyntlm.target_info);
conn->proxyntlm.target_info_len = 0;
#if defined(NTLM_WB_ENABLED)
Curl_ntlm_wb_cleanup(conn);
#endif
}

Expand Down
11 changes: 9 additions & 2 deletions lib/curl_ntlm_msgs.c
Expand Up @@ -401,6 +401,7 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
unsigned long attrs;
TimeStamp expiry; /* For Windows 9x compatibility of SSPI calls */

/* Clean up any former leftovers and initialise to defaults */
Curl_sasl_ntlm_cleanup(ntlm);

/* Query the security package for NTLM */
Expand Down Expand Up @@ -493,7 +494,9 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
domain are empty */
(void)userp;
(void)passwdp;
(void)ntlm;

/* Clean up any former leftovers and initialise to defaults */
Curl_sasl_ntlm_cleanup(ntlm);

#if USE_NTLM2SESSION
#define NTLM2FLAG NTLMFLAG_NEGOTIATE_NTLM2_KEY
Expand Down Expand Up @@ -993,7 +996,11 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
return CURLE_CONV_FAILED;

/* Return with binary blob encoded into base64 */
return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, outlen);
result = Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, outlen);

Curl_sasl_ntlm_cleanup(ntlm);

return result;
#endif
}

Expand Down
31 changes: 28 additions & 3 deletions lib/curl_sasl.c
Expand Up @@ -1182,6 +1182,28 @@ CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
return Curl_ntlm_create_type3_message(data, userp, passwdp, ntlm, outptr,
outlen);
}

#if !defined(USE_WINDOWS_SSPI)
/*
* Curl_sasl_ntlm_cleanup()
*
* This is used to clean up the ntlm specific data.
*
* Parameters:
*
* ntlm [in/out] - The ntlm data struct being cleaned up.
*
*/
void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm)
{
/* Free the target info */
Curl_safefree(ntlm->target_info);

/* Reset any variables */
ntlm->target_info_len = 0;
}
#endif /* !USE_WINDOWS_SSPI */

#endif /* USE_NTLM */

/*
Expand Down Expand Up @@ -1240,13 +1262,16 @@ void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused)
if(authused == SASL_MECH_GSSAPI) {
Curl_sasl_gssapi_cleanup(&conn->krb5);
}
#ifdef USE_NTLM
#endif

#if defined(USE_NTLM)
/* Cleanup the ntlm structure */
else if(authused == SASL_MECH_NTLM) {
if(authused == SASL_MECH_NTLM) {
Curl_sasl_ntlm_cleanup(&conn->ntlm);
}
#endif
#else

#if !defined(USE_KRB5) && !defined(USE_NTLM)
/* Reserved for future use */
(void)conn;
(void)authused;
Expand Down
2 changes: 0 additions & 2 deletions lib/curl_sasl.h
Expand Up @@ -149,10 +149,8 @@ CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
struct ntlmdata *ntlm,
char **outptr, size_t *outlen);

#if defined(USE_WINDOWS_SSPI)
/* This is used to clean up the ntlm specific data */
void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm);
#endif

#endif /* USE_NTLM */

Expand Down

0 comments on commit 40ee1ba

Please sign in to comment.