Hi again, Thank you for your answers. Here is my attempt to expose SMTP authentication methods in API (just following the instructions from http://curl.haxx.se/mail/lib-2010-10/0078.html)
Thanks, Patricia On Fri, Mar 18, 2011 at 1:41 PM, Daniel Stenberg <[email protected]> wrote: > On Fri, 18 Mar 2011, Ben Noordhuis wrote: > > Is it on the libucurl's TODO list to expose SMTP authentication methods in >>> the future release(s)? >>> >> >> It's not on the official TODO list so far. >> > > The official TODO is not very important anyway. That file just lists ideas > and things we might consider doing one day. > > Things get implemented when a developer somewhere writes up the necessary > code and sends in a patch to the list. That developer can by anyone. We're > entirelly driven by volunteers unless you can find someone who pays (a > developer) for the particular features you want. > > So, there's nothing magic in the TODO. It's just a list of things that may > or may not be implemented some day. We frequently add things to curl that > never were in the TODO. > > -- > > / daniel.haxx.se > > ------------------------------------------------------------------- > List admin: http://cool.haxx.se/list/listinfo/curl-library > Etiquette: http://curl.haxx.se/mail/etiquette.html >
From 2eb62c7fd66b6afc5457c20223aff1f49d57288d Mon Sep 17 00:00:00 2001 From: Patricia Muscalu <[email protected]> Date: Mon, 21 Mar 2011 23:12:30 +0100 Subject: [PATCH] Expose SMTP authentication methods --- include/curl/curl.h | 12 ++++++++++++ lib/smtp.c | 22 +++++++++++++--------- lib/smtp.h | 8 -------- lib/url.c | 14 ++++++++++++++ lib/urldata.h | 2 ++ 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/include/curl/curl.h b/include/curl/curl.h index 73713dd..65f19a4 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -606,6 +606,14 @@ typedef enum { #define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ #define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY +/* SMTP authentication mechanism flags. */ +#define CURL_SMTP_AUTH_LOGIN 0x0001 +#define CURL_SMTP_AUTH_PLAIN 0x0002 +#define CURL_SMTP_AUTH_CRAM_MD5 0x0004 +#define CURL_SMTP_AUTH_DIGEST_MD5 0x0008 +#define CURL_SMTP_AUTH_GSSAPI 0x0010 +#define CURL_SMTP_AUTH_EXTERNAL 0x0020 + #define CURL_ERROR_SIZE 256 struct curl_khkey { @@ -1458,6 +1466,10 @@ typedef enum { /* Set authentication type for authenticated TLS */ CINIT(TLSAUTH_TYPE, OBJECTPOINT, 206), + /* Set this to a bitmask value to enable particular SMTP authentication + methods */ + CINIT(SMTPAUTH, LONG, 207), + CURLOPT_LASTENTRY /* the last unused */ } CURLoption; diff --git a/lib/smtp.c b/lib/smtp.c index 3b21796..5051a3c 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -258,17 +258,17 @@ static int smtp_endofresp(struct pingpong *pp, int *resp) wordlen++; if(wordlen == 5 && !memcmp(line, "LOGIN", 5)) - smtpc->authmechs |= SMTP_AUTH_LOGIN; + smtpc->authmechs |= CURL_SMTP_AUTH_LOGIN; else if(wordlen == 5 && !memcmp(line, "PLAIN", 5)) - smtpc->authmechs |= SMTP_AUTH_PLAIN; + smtpc->authmechs |= CURL_SMTP_AUTH_PLAIN; else if(wordlen == 8 && !memcmp(line, "CRAM-MD5", 8)) - smtpc->authmechs |= SMTP_AUTH_CRAM_MD5; + smtpc->authmechs |= CURL_SMTP_AUTH_CRAM_MD5; else if(wordlen == 10 && !memcmp(line, "DIGEST-MD5", 10)) - smtpc->authmechs |= SMTP_AUTH_DIGEST_MD5; + smtpc->authmechs |= CURL_SMTP_AUTH_DIGEST_MD5; else if(wordlen == 6 && !memcmp(line, "GSSAPI", 6)) - smtpc->authmechs |= SMTP_AUTH_GSSAPI; + smtpc->authmechs |= CURL_SMTP_AUTH_GSSAPI; else if(wordlen == 8 && !memcmp(line, "EXTERNAL", 8)) - smtpc->authmechs |= SMTP_AUTH_EXTERNAL; + smtpc->authmechs |= CURL_SMTP_AUTH_EXTERNAL; line += wordlen; len -= wordlen; @@ -381,6 +381,7 @@ static CURLcode smtp_authenticate(struct connectdata *conn) { CURLcode result = CURLE_OK; struct smtp_conn *smtpc = &conn->proto.smtpc; + struct UserDefined *set = &conn->data->set; char * initresp; const char * mech; size_t l; @@ -399,20 +400,23 @@ static CURLcode smtp_authenticate(struct connectdata *conn) state1 = SMTP_STOP; state2 = SMTP_STOP; + /* mask authmechs */ + smtpc->authmechs &= set->smtpauthmask; + #ifndef CURL_DISABLE_CRYPTO_AUTH - if(smtpc->authmechs & SMTP_AUTH_CRAM_MD5) { + if(smtpc->authmechs & CURL_SMTP_AUTH_CRAM_MD5) { mech = "CRAM-MD5"; state1 = SMTP_AUTHCRAM; } else #endif - if(smtpc->authmechs & SMTP_AUTH_PLAIN) { + if(smtpc->authmechs & CURL_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) { + else if(smtpc->authmechs & CURL_SMTP_AUTH_LOGIN) { mech = "LOGIN"; state1 = SMTP_AUTHLOGIN; state2 = SMTP_AUTHPASSWD; diff --git a/lib/smtp.h b/lib/smtp.h index 0f52714..525eb6e 100644 --- a/lib/smtp.h +++ b/lib/smtp.h @@ -61,14 +61,6 @@ struct smtp_conn { bool ssldone; /* is connect() over SSL done? only relevant in multi mode */ }; -/* Authentication mechanism flags. */ -#define SMTP_AUTH_LOGIN 0x0001 -#define SMTP_AUTH_PLAIN 0x0002 -#define SMTP_AUTH_CRAM_MD5 0x0004 -#define SMTP_AUTH_DIGEST_MD5 0x0008 -#define SMTP_AUTH_GSSAPI 0x0010 -#define SMTP_AUTH_EXTERNAL 0x0020 - extern const struct Curl_handler Curl_handler_smtp; extern const struct Curl_handler Curl_handler_smtps; diff --git a/lib/url.c b/lib/url.c index 47ac725..8919cfc 100644 --- a/lib/url.c +++ b/lib/url.c @@ -744,6 +744,8 @@ CURLcode Curl_init_userdefined(struct UserDefined *set) set->httpauth = CURLAUTH_BASIC; /* defaults to basic */ set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */ + set->smtpauthmask = ~0; /* turn on all authentication methods */ + /* make libcurl quiet by default: */ set->hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ @@ -1471,6 +1473,18 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, #endif /* CURL_DISABLE_HTTP */ + case CURLOPT_SMTPAUTH: + { + long auth = va_arg(param, long); + + data->set.smtpauthmask &= auth; + +#ifdef CURL_DISABLE_CRYPTO_AUTH + data->set.smtpauthmask &= ~CURL_SMTP_AUTH_CRAM_MD5; +#endif + } + break; + case CURLOPT_CUSTOMREQUEST: /* * Set a custom string to use as request diff --git a/lib/urldata.h b/lib/urldata.h index 7588ced..dd4550b 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1490,6 +1490,8 @@ struct UserDefined { long socks5_gssapi_nec; /* flag to support nec socks5 server */ #endif struct curl_slist *mail_rcpt; /* linked list of mail recipients */ + unsigned int smtpauthmask; /* bitmask set to the SMTP authentication methods + (with CURLOPT_SMTPAUTH) */ /* Common RTSP header options */ Curl_RtspReq rtspreq; /* RTSP request type */ long rtspversion; /* like httpversion, for RTSP */ -- 1.7.1
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
