/* for AUTH PLAIN (without initial response) responses */ static CURLcode smtp_state_authplain_resp(struct connectdata *conn, int smtpcode, smtpstate instate) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; size_t l; char * plainauth; (void)instate; /* no use for this yet */ if(smtpcode != 334) { failf(data, "Access denied: %d", smtpcode); result = CURLE_LOGIN_DENIED; } else { l = smtp_auth_plain_data(conn, &plainauth); if(!l) result = CURLE_OUT_OF_MEMORY; else { result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", plainauth); free(plainauth); if(!result) state(conn, SMTP_AUTH); } } return result; }
static CURLcode smtp_authenticate(struct connectdata *conn) { CURLcode result = CURLE_OK; struct smtp_conn *smtpc = &conn->proto.smtpc; char * initresp; const char * mech; size_t l; smtpstate state1; smtpstate state2; if(!conn->bits.user_passwd) state(conn, SMTP_STOP); /* End of connect phase. */ else { initresp = (char *) NULL; l = 1; /* Check supported authentication mechanisms by decreasing order of preference. */ mech = (const char *) NULL; /* Avoid compiler warnings. */ state1 = SMTP_STOP; state2 = SMTP_STOP; #ifndef CURL_DISABLE_CRYPTO_AUTH if(smtpc->authmechs & SMTP_AUTH_CRAM_MD5) { mech = "CRAM-MD5"; state1 = SMTP_AUTHCRAM; } else #endif if(smtpc->authmechs & SMTP_AUTH_PLAIN) { mech = "PLAIN"; state1 = SMTP_AUTHPLAIN; state2 = SMTP_AUTH; l = smtp_auth_plain_data(conn, &initresp); } else if(smtpc->authmechs & SMTP_AUTH_LOGIN) { mech = "LOGIN"; state1 = SMTP_AUTHLOGIN; state2 = SMTP_AUTHPASSWD; l = smtp_auth_login_user(conn, &initresp); } else result = CURLE_LOGIN_DENIED; /* Other mechanisms not supported. */ if(!result) { if(!l) result = CURLE_OUT_OF_MEMORY; else if(initresp && l + strlen(mech) <= 512 - 8) { /* AUTH <mech> ...<crlf> */ result = Curl_pp_sendf(&smtpc->pp, "AUTH %s %s", mech, initresp); free(initresp); if(!result) state(conn, state2); } else { Curl_safefree(initresp); result = Curl_pp_sendf(&smtpc->pp, "AUTH %s", mech); if(!result) state(conn, state1); } } } return result; }
static CURLcode smtp_authenticate(struct connectdata *conn) { CURLcode result = CURLE_OK; struct smtp_conn *smtpc = &conn->proto.smtpc; char *initresp = NULL; const char *mech = NULL; size_t len = 0; smtpstate state1 = SMTP_STOP; smtpstate state2 = SMTP_STOP; /* Check we have a username and password to authenticate with and end the connect phase if we don't. */ if(!conn->bits.user_passwd) { state(conn, SMTP_STOP); return result; } /* Check supported authentication mechanisms by decreasing order of security. */ #ifndef CURL_DISABLE_CRYPTO_AUTH if(smtpc->authmechs & SMTP_AUTH_CRAM_MD5) { mech = "CRAM-MD5"; state1 = SMTP_AUTHCRAM; smtpc->authused = SMTP_AUTH_CRAM_MD5; } else #endif #ifdef USE_NTLM if(smtpc->authmechs & SMTP_AUTH_NTLM) { mech = "NTLM"; state1 = SMTP_AUTHNTLM; state2 = SMTP_AUTHNTLM_TYPE2MSG; smtpc->authused = SMTP_AUTH_NTLM; result = smtp_auth_ntlm_type1_message(conn, &initresp, &len); } else #endif if(smtpc->authmechs & SMTP_AUTH_LOGIN) { mech = "LOGIN"; state1 = SMTP_AUTHLOGIN; state2 = SMTP_AUTHPASSWD; smtpc->authused = SMTP_AUTH_LOGIN; result = smtp_auth_login_user(conn, &initresp, &len); } else if(smtpc->authmechs & SMTP_AUTH_PLAIN) { mech = "PLAIN"; state1 = SMTP_AUTHPLAIN; state2 = SMTP_AUTH; smtpc->authused = SMTP_AUTH_PLAIN; result = smtp_auth_plain_data(conn, &initresp, &len); } else { infof(conn->data, "No known auth mechanisms supported!\n"); result = CURLE_LOGIN_DENIED; /* Other mechanisms not supported. */ } if(!result) { if(initresp && strlen(mech) + len <= 512 - 8) { /* AUTH <mech> ...<crlf> */ result = Curl_pp_sendf(&smtpc->pp, "AUTH %s %s", mech, initresp); if(!result) state(conn, state2); } else { result = Curl_pp_sendf(&smtpc->pp, "AUTH %s", mech); if(!result) state(conn, state1); } Curl_safefree(initresp); } return result; }