smtp: Fixed login denied when server doesn't support AUTH capability

Specifying user credentials when the SMTP server doesn't support
authentication would cause curl to display "No known authentication
mechanisms supported!" and return CURLE_LOGIN_DENIED.

Reported-by: Tom Sparrow
Bug: http://curl.haxx.se/mail/lib-2014-03/0173.html
This commit is contained in:
Steve Holme 2014-03-28 18:21:27 +00:00
parent 2dc63c72dc
commit fe260b75e7
2 changed files with 16 additions and 10 deletions

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -349,10 +349,11 @@ static CURLcode smtp_perform_ehlo(struct connectdata *conn)
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct smtp_conn *smtpc = &conn->proto.smtpc; struct smtp_conn *smtpc = &conn->proto.smtpc;
smtpc->authmechs = 0; /* No known authentication mechanisms yet */ smtpc->authmechs = 0; /* No known authentication mechanisms yet */
smtpc->authused = 0; /* Clear the authentication mechanism used smtpc->authused = 0; /* Clear the authentication mechanism used
for esmtp connections */ for esmtp connections */
smtpc->tls_supported = FALSE; /* Clear the TLS capability */ smtpc->tls_supported = FALSE; /* Clear the TLS capability */
smtpc->auth_supported = FALSE; /* Clear the AUTH capability */
/* Send the EHLO command */ /* Send the EHLO command */
result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", smtpc->domain); result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", smtpc->domain);
@ -475,15 +476,16 @@ static CURLcode smtp_perform_auth(struct connectdata *conn,
static CURLcode smtp_perform_authentication(struct connectdata *conn) static CURLcode smtp_perform_authentication(struct connectdata *conn)
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct smtp_conn *smtpc = &conn->proto.smtpc;
const char *mech = NULL; const char *mech = NULL;
char *initresp = NULL; char *initresp = NULL;
size_t len = 0; size_t len = 0;
smtpstate state1 = SMTP_STOP; smtpstate state1 = SMTP_STOP;
smtpstate state2 = SMTP_STOP; smtpstate state2 = SMTP_STOP;
/* Check we have a username and password to authenticate with and end the /* Check we have a username and password to authenticate with, and the
connect phase if we don't */ server supports authentiation, and end the connect phase if not */
if(!conn->bits.user_passwd) { if(!conn->bits.user_passwd || !smtpc->auth_supported) {
state(conn, SMTP_STOP); state(conn, SMTP_STOP);
return result; return result;
@ -739,8 +741,11 @@ static CURLcode smtp_state_ehlo_resp(struct connectdata *conn, int smtpcode,
else if(len >= 4 && !memcmp(line, "SIZE", 4)) else if(len >= 4 && !memcmp(line, "SIZE", 4))
smtpc->size_supported = TRUE; smtpc->size_supported = TRUE;
/* Do we have the authentication mechanism list? */ /* Does the server support authentication? */
else if(len >= 5 && !memcmp(line, "AUTH ", 5)) { else if(len >= 5 && !memcmp(line, "AUTH ", 5)) {
smtpc->auth_supported = TRUE;
/* Advance past the AUTH keyword */
line += 5; line += 5;
len -= 5; len -= 5;

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2009 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2009 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -82,6 +82,7 @@ struct smtp_conn {
bool tls_supported; /* StartTLS capability supported by server */ bool tls_supported; /* StartTLS capability supported by server */
bool size_supported; /* If server supports SIZE extension according to bool size_supported; /* If server supports SIZE extension according to
RFC 1870 */ RFC 1870 */
bool auth_supported; /* AUTH capability supported by server */
}; };
extern const struct Curl_handler Curl_handler_smtp; extern const struct Curl_handler Curl_handler_smtp;