From fe260b75e74fed56573d133dd64d2424660743cb Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Fri, 28 Mar 2014 18:21:27 +0000 Subject: [PATCH] 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 --- lib/smtp.c | 23 ++++++++++++++--------- lib/smtp.h | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/smtp.c b/lib/smtp.c index 616481d8b4..cc1f2ad56b 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * 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; struct smtp_conn *smtpc = &conn->proto.smtpc; - smtpc->authmechs = 0; /* No known authentication mechanisms yet */ - smtpc->authused = 0; /* Clear the authentication mechanism used - for esmtp connections */ - smtpc->tls_supported = FALSE; /* Clear the TLS capability */ + smtpc->authmechs = 0; /* No known authentication mechanisms yet */ + smtpc->authused = 0; /* Clear the authentication mechanism used + for esmtp connections */ + smtpc->tls_supported = FALSE; /* Clear the TLS capability */ + smtpc->auth_supported = FALSE; /* Clear the AUTH capability */ /* Send the EHLO command */ 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) { CURLcode result = CURLE_OK; + struct smtp_conn *smtpc = &conn->proto.smtpc; const char *mech = NULL; char *initresp = 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) { + /* Check we have a username and password to authenticate with, and the + server supports authentiation, and end the connect phase if not */ + if(!conn->bits.user_passwd || !smtpc->auth_supported) { state(conn, SMTP_STOP); 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)) smtpc->size_supported = TRUE; - /* Do we have the authentication mechanism list? */ + /* Does the server support authentication? */ else if(len >= 5 && !memcmp(line, "AUTH ", 5)) { + smtpc->auth_supported = TRUE; + + /* Advance past the AUTH keyword */ line += 5; len -= 5; diff --git a/lib/smtp.h b/lib/smtp.h index a14c378225..017b943362 100644 --- a/lib/smtp.h +++ b/lib/smtp.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2009 - 2013, Daniel Stenberg, , et al. + * Copyright (C) 2009 - 2014, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * 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 size_supported; /* If server supports SIZE extension according to RFC 1870 */ + bool auth_supported; /* AUTH capability supported by server */ }; extern const struct Curl_handler Curl_handler_smtp;