1
0
mirror of https://github.com/moparisthebest/curl synced 2025-02-28 09:21:50 -05:00

smtp.c: Re-factored smtp_auth_login_user() for use with passwords

In preparation for moving to the SASL module re-factored the
smtp_auth_login_user() function to smtp_auth_login() so that it can be
used for both user names and passwords as sending both of these under
the login authentication mechanism is the same.
This commit is contained in:
Steve Holme 2012-05-31 22:49:14 +01:00
parent 2c6d32b864
commit f86432b119

View File

@ -383,22 +383,23 @@ static CURLcode smtp_state_helo(struct connectdata *conn)
return CURLE_OK; return CURLE_OK;
} }
static CURLcode smtp_auth_login_user(struct connectdata *conn, static CURLcode smtp_auth_login(struct connectdata *conn, const char *valuep,
char **outptr, size_t *outlen) char **outptr, size_t *outlen)
{ {
size_t ulen = strlen(conn->user); size_t vlen = strlen(valuep);
if(!ulen) { if(!vlen) {
*outptr = strdup("="); *outptr = strdup("=");
if(*outptr) { if(*outptr) {
*outlen = (size_t) 1; *outlen = (size_t) 1;
return CURLE_OK; return CURLE_OK;
} }
*outlen = 0; *outlen = 0;
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
return Curl_base64_encode(conn->data, conn->user, ulen, outptr, outlen); return Curl_base64_encode(conn->data, valuep, vlen, outptr, outlen);
} }
#ifdef USE_NTLM #ifdef USE_NTLM
@ -458,7 +459,7 @@ static CURLcode smtp_authenticate(struct connectdata *conn)
state1 = SMTP_AUTHLOGIN; state1 = SMTP_AUTHLOGIN;
state2 = SMTP_AUTHPASSWD; state2 = SMTP_AUTHPASSWD;
smtpc->authused = SASL_AUTH_LOGIN; smtpc->authused = SASL_AUTH_LOGIN;
result = smtp_auth_login_user(conn, &initresp, &len); result = smtp_auth_login(conn, conn->user, &initresp, &len);
} }
else if(smtpc->authmechs & SASL_AUTH_PLAIN) { else if(smtpc->authmechs & SASL_AUTH_PLAIN) {
mech = "PLAIN"; mech = "PLAIN";
@ -684,7 +685,7 @@ static CURLcode smtp_state_authlogin_resp(struct connectdata *conn,
result = CURLE_LOGIN_DENIED; result = CURLE_LOGIN_DENIED;
} }
else { else {
result = smtp_auth_login_user(conn, &authuser, &len); result = smtp_auth_login(conn, conn->user, &authuser, &len);
if(!result) { if(!result) {
if(authuser) { if(authuser) {