Loading lib/curl_sasl.c +36 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,39 @@ CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data, return Curl_base64_encode(data, plainauth, 2 * ulen + plen + 2, outptr, outlen); } /* * Curl_sasl_create_login_message() * * This is used to generate an already encoded login message containing the * user name or password ready for sending to the recipient. * * Parameters: * * data [in] - The session handle. * userp [in] - The user name. * outptr [in/out] - The address where a pointer to newly allocated memory * holding the result will be stored upon completion. * outlen [out] - The length of the output message. * * Returns CURLE_OK on success. */ CURLcode Curl_sasl_create_login_message(struct SessionHandle *data, const char* valuep, char **outptr, size_t *outlen) { size_t vlen = strlen(valuep); if(!vlen) { *outptr = strdup("="); if(*outptr) { *outlen = (size_t) 1; return CURLE_OK; } *outlen = 0; return CURLE_OUT_OF_MEMORY; } return Curl_base64_encode(data, valuep, vlen, outptr, outlen); } lib/curl_sasl.h +7 −1 Original line number Diff line number Diff line Loading @@ -33,10 +33,16 @@ #define SASL_AUTH_EXTERNAL 0x0020 #define SASL_AUTH_NTLM 0x0040 /* This is to generate a base64 encoded plain authentication message */ /* This is used to generate a base64 encoded plain authentication message */ CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data, const char* userp, const char* passwdp, char **outptr, size_t *outlen); /* This is used to generate a base64 encoded login authentication message containing either the user name or password details */ CURLcode Curl_sasl_create_login_message(struct SessionHandle *data, const char* valuep, char **outptr, size_t *outlen); #endif /* HEADER_CURL_SASL_H */ lib/smtp.c +6 −22 Original line number Diff line number Diff line Loading @@ -383,25 +383,6 @@ static CURLcode smtp_state_helo(struct connectdata *conn) return CURLE_OK; } static CURLcode smtp_auth_login(struct connectdata *conn, const char *valuep, char **outptr, size_t *outlen) { size_t vlen = strlen(valuep); if(!vlen) { *outptr = strdup("="); if(*outptr) { *outlen = (size_t) 1; return CURLE_OK; } *outlen = 0; return CURLE_OUT_OF_MEMORY; } return Curl_base64_encode(conn->data, valuep, vlen, outptr, outlen); } #ifdef USE_NTLM static CURLcode smtp_auth_ntlm_type1_message(struct connectdata *conn, char **outptr, size_t *outlen) Loading Loading @@ -459,7 +440,8 @@ static CURLcode smtp_authenticate(struct connectdata *conn) state1 = SMTP_AUTHLOGIN; state2 = SMTP_AUTHPASSWD; smtpc->authused = SASL_AUTH_LOGIN; result = smtp_auth_login(conn, conn->user, &initresp, &len); result = Curl_sasl_create_login_message(conn->data, conn->user, &initresp, &len); } else if(smtpc->authmechs & SASL_AUTH_PLAIN) { mech = "PLAIN"; Loading Loading @@ -685,7 +667,8 @@ static CURLcode smtp_state_authlogin_resp(struct connectdata *conn, result = CURLE_LOGIN_DENIED; } else { result = smtp_auth_login(conn, conn->user, &authuser, &len); result = Curl_sasl_create_login_message(conn->data, conn->user, &authuser, &len); if(!result) { if(authuser) { Loading Loading @@ -718,7 +701,8 @@ static CURLcode smtp_state_authpasswd_resp(struct connectdata *conn, result = CURLE_LOGIN_DENIED; } else { result = smtp_auth_login(conn, conn->passwd, &authpasswd, &len); result = Curl_sasl_create_login_message(conn->data, conn->passwd, &authpasswd, &len); if(!result) { if(authpasswd) { Loading Loading
lib/curl_sasl.c +36 −0 Original line number Diff line number Diff line Loading @@ -77,3 +77,39 @@ CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data, return Curl_base64_encode(data, plainauth, 2 * ulen + plen + 2, outptr, outlen); } /* * Curl_sasl_create_login_message() * * This is used to generate an already encoded login message containing the * user name or password ready for sending to the recipient. * * Parameters: * * data [in] - The session handle. * userp [in] - The user name. * outptr [in/out] - The address where a pointer to newly allocated memory * holding the result will be stored upon completion. * outlen [out] - The length of the output message. * * Returns CURLE_OK on success. */ CURLcode Curl_sasl_create_login_message(struct SessionHandle *data, const char* valuep, char **outptr, size_t *outlen) { size_t vlen = strlen(valuep); if(!vlen) { *outptr = strdup("="); if(*outptr) { *outlen = (size_t) 1; return CURLE_OK; } *outlen = 0; return CURLE_OUT_OF_MEMORY; } return Curl_base64_encode(data, valuep, vlen, outptr, outlen); }
lib/curl_sasl.h +7 −1 Original line number Diff line number Diff line Loading @@ -33,10 +33,16 @@ #define SASL_AUTH_EXTERNAL 0x0020 #define SASL_AUTH_NTLM 0x0040 /* This is to generate a base64 encoded plain authentication message */ /* This is used to generate a base64 encoded plain authentication message */ CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data, const char* userp, const char* passwdp, char **outptr, size_t *outlen); /* This is used to generate a base64 encoded login authentication message containing either the user name or password details */ CURLcode Curl_sasl_create_login_message(struct SessionHandle *data, const char* valuep, char **outptr, size_t *outlen); #endif /* HEADER_CURL_SASL_H */
lib/smtp.c +6 −22 Original line number Diff line number Diff line Loading @@ -383,25 +383,6 @@ static CURLcode smtp_state_helo(struct connectdata *conn) return CURLE_OK; } static CURLcode smtp_auth_login(struct connectdata *conn, const char *valuep, char **outptr, size_t *outlen) { size_t vlen = strlen(valuep); if(!vlen) { *outptr = strdup("="); if(*outptr) { *outlen = (size_t) 1; return CURLE_OK; } *outlen = 0; return CURLE_OUT_OF_MEMORY; } return Curl_base64_encode(conn->data, valuep, vlen, outptr, outlen); } #ifdef USE_NTLM static CURLcode smtp_auth_ntlm_type1_message(struct connectdata *conn, char **outptr, size_t *outlen) Loading Loading @@ -459,7 +440,8 @@ static CURLcode smtp_authenticate(struct connectdata *conn) state1 = SMTP_AUTHLOGIN; state2 = SMTP_AUTHPASSWD; smtpc->authused = SASL_AUTH_LOGIN; result = smtp_auth_login(conn, conn->user, &initresp, &len); result = Curl_sasl_create_login_message(conn->data, conn->user, &initresp, &len); } else if(smtpc->authmechs & SASL_AUTH_PLAIN) { mech = "PLAIN"; Loading Loading @@ -685,7 +667,8 @@ static CURLcode smtp_state_authlogin_resp(struct connectdata *conn, result = CURLE_LOGIN_DENIED; } else { result = smtp_auth_login(conn, conn->user, &authuser, &len); result = Curl_sasl_create_login_message(conn->data, conn->user, &authuser, &len); if(!result) { if(authuser) { Loading Loading @@ -718,7 +701,8 @@ static CURLcode smtp_state_authpasswd_resp(struct connectdata *conn, result = CURLE_LOGIN_DENIED; } else { result = smtp_auth_login(conn, conn->passwd, &authpasswd, &len); result = Curl_sasl_create_login_message(conn->data, conn->passwd, &authpasswd, &len); if(!result) { if(authpasswd) { Loading