On Tue, Mar 22, 2011 at 8:43 AM, Dan Fandrich <[email protected]>wrote:

> On Tue, Mar 22, 2011 at 08:22:49AM +0100, Patricia Muscalu wrote:
> > Thank you for your answers. Here is my attempt to expose SMTP
> authentication
> > methods in API
> [...]
> > +/* 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
>
> Since SMTP uses SASL for authentication, I suggest renaming these to
> CURL_SASL_AUTH_x so that they can be used for other protocols in the
> future.


I'm sending a new patch with the renamed auth flags.

Thank you,

Patricia


>


> >>> Dan
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette:  http://curl.haxx.se/mail/etiquette.html
>
From 485e3a52eac6ed43bd3ec2b55e794ee1ef7a9f42 Mon Sep 17 00:00:00 2001
From: Patricia Muscalu <[email protected]>
Date: Thu, 24 Mar 2011 09:31:53 +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..7e5d82c 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_SASL_AUTH_LOGIN         0x0001
+#define CURL_SASL_AUTH_PLAIN         0x0002
+#define CURL_SASL_AUTH_CRAM_MD5      0x0004
+#define CURL_SASL_AUTH_DIGEST_MD5    0x0008
+#define CURL_SASL_AUTH_GSSAPI        0x0010
+#define CURL_SASL_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..7dcbee1 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_SASL_AUTH_LOGIN;
       else if(wordlen == 5 && !memcmp(line, "PLAIN", 5))
-        smtpc->authmechs |= SMTP_AUTH_PLAIN;
+        smtpc->authmechs |= CURL_SASL_AUTH_PLAIN;
       else if(wordlen == 8 && !memcmp(line, "CRAM-MD5", 8))
-        smtpc->authmechs |= SMTP_AUTH_CRAM_MD5;
+        smtpc->authmechs |= CURL_SASL_AUTH_CRAM_MD5;
       else if(wordlen == 10 && !memcmp(line, "DIGEST-MD5", 10))
-        smtpc->authmechs |= SMTP_AUTH_DIGEST_MD5;
+        smtpc->authmechs |= CURL_SASL_AUTH_DIGEST_MD5;
       else if(wordlen == 6 && !memcmp(line, "GSSAPI", 6))
-        smtpc->authmechs |= SMTP_AUTH_GSSAPI;
+        smtpc->authmechs |= CURL_SASL_AUTH_GSSAPI;
       else if(wordlen == 8 && !memcmp(line, "EXTERNAL", 8))
-        smtpc->authmechs |= SMTP_AUTH_EXTERNAL;
+        smtpc->authmechs |= CURL_SASL_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_SASL_AUTH_CRAM_MD5) {
       mech = "CRAM-MD5";
       state1 = SMTP_AUTHCRAM;
     }
     else
 #endif
-    if(smtpc->authmechs & SMTP_AUTH_PLAIN) {
+    if(smtpc->authmechs & CURL_SASL_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_SASL_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..18e52f5 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_SASL_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

Reply via email to