2004-12-07 [colin] 0.9.13cvs2
authorColin Leroy <colin@colino.net>
Tue, 7 Dec 2004 07:56:45 +0000 (07:56 +0000)
committerColin Leroy <colin@colino.net>
Tue, 7 Dec 2004 07:56:45 +0000 (07:56 +0000)
* AUTHORS
* src/prefs_account.c
* src/common/smtp.c
* src/common/smtp.h
Add SMTP PLAIN authentication. Patch by
George Michaelson <ggm@apnic.net>

AUTHORS
ChangeLog.claws
PATCHSETS
configure.ac
src/common/smtp.c
src/common/smtp.h
src/prefs_account.c

diff --git a/AUTHORS b/AUTHORS
index 5d2ad214b05f4385c1dc2c8c15f26fe516893a9b..d2ba9014c88dced3658efc2f14f3872974017739 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -210,3 +210,4 @@ contributors (beside the above; based on Changelog)
        Reza Pakdel
        Stephan Sachse
        Thomas Gilgin
+       George Michaelson
index 71ba874a865a38e3576ea8b3f1fbbb895392325a..98ac64f674e8ae9b7009ac0c34db35f2e1e62f54 100644 (file)
@@ -1,3 +1,12 @@
+2004-12-07 [colin]     0.9.13cvs2
+
+       * AUTHORS
+       * src/prefs_account.c
+       * src/common/smtp.c
+       * src/common/smtp.h
+               Add SMTP PLAIN authentication. Patch by 
+               George Michaelson <ggm@apnic.net>
+
 2004-12-07 [thorsten]  0.9.13cvs1
 
        * src/procmime.c
index 9b24398db02b33db5945ce45a37781d0d15fead6..4ea28815270812103f83b3ef903f9a8d67b7eeaa 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.33 -r 1.34 INSTALL; cvs diff -u -r 1.39 -r 1.40 README.claws; cvs diff -u -r 1.71 -r 1.72 po/es.po; cvs diff -u -r 1.50 -r 1.51 po/fr.po; cvs diff -u -r 1.37 -r 1.38 po/it.po; cvs diff -u -r 1.23 -r 1.24 po/ja.po; cvs diff -u -r 1.52 -r 1.53 po/pt_BR.po; cvs diff -u -r 1.10 -r 1.11 po/zh_CN.po; ) > 0.9.12cvs186.patchset
 ( cvs diff -u -r 1.462 -r 1.463 src/compose.c; ) > 0.9.12cvs187.patchset
 ( cvs diff -u -r 1.97 -r 1.98 src/procmime.c; ) > 0.9.13cvs1.patchset
+( cvs diff -u -r 1.122 -r 1.123 AUTHORS; cvs diff -u -r 1.122 -r 1.123 src/prefs_account.c; cvs diff -u -r 1.19 -r 1.20 src/common/smtp.c; cvs diff -u -r 1.9 -r 1.10 src/common/smtp.h; ) > 0.9.13cvs2.patchset
index 550a5b34fac5f42dac1408dc835d896a5ea2d0df..b40d67c8b29aac138617bf7c0e464cb51f0f193c 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=13
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=1
+EXTRA_VERSION=2
 EXTRA_RELEASE=
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
index 5d1f722464dd87f7044e4447ff1afe99282ff4e7..d65477a807fc0eb7063085ce222b2fd44b9e9fa6 100644 (file)
@@ -40,6 +40,7 @@ static gint smtp_auth(SMTPSession *session);
 static gint smtp_starttls(SMTPSession *session);
 static gint smtp_auth_cram_md5(SMTPSession *session);
 static gint smtp_auth_login(SMTPSession *session);
+static gint smtp_auth_plain(SMTPSession *session);
 
 static gint smtp_ehlo(SMTPSession *session);
 static gint smtp_ehlo_recv(SMTPSession *session, const gchar *msg);
@@ -161,6 +162,10 @@ static gint smtp_auth(SMTPSession *session)
                 (session->forced_auth_type == 0 &&
                  (session->avail_auth_type & SMTPAUTH_LOGIN) != 0))
                smtp_auth_login(session);
+       else if (session->forced_auth_type == SMTPAUTH_PLAIN ||
+                (session->forced_auth_type == 0 &&
+                 (session->avail_auth_type & SMTPAUTH_PLAIN) != 0))
+               smtp_auth_plain(session);
        else {
                log_warning(_("SMTP AUTH not available\n"));
                return SM_AUTHFAIL;
@@ -282,6 +287,8 @@ static gint smtp_ehlo_recv(SMTPSession *session, const gchar *msg)
                if (*p == '-' || *p == ' ') p++;
                if (g_strncasecmp(p, "AUTH", 4) == 0) {
                        p += 5;
+                       if (strcasestr(p, "PLAIN"))
+                               session->avail_auth_type |= SMTPAUTH_PLAIN;
                        if (strcasestr(p, "LOGIN"))
                                session->avail_auth_type |= SMTPAUTH_LOGIN;
                        if (strcasestr(p, "CRAM-MD5"))
@@ -325,6 +332,58 @@ static gint smtp_auth_cram_md5(SMTPSession *session)
        return SM_OK;
 }
 
+static gint smtp_auth_plain(SMTPSession *session)
+{
+       gchar buf[MSGBUFSIZE];
+
+       /* 
+        * +1      +1      +1
+        * \0<user>\0<pass>\0 
+        */
+       int b64len = (1 + strlen(session->user) + 1 + strlen(session->pass) + 1);
+       gchar *b64buf = g_malloc(b64len);
+
+       /* use the char *ptr to walk the base64 string with embedded \0 */
+       char  *a = b64buf;
+       int  b64cnt = 0;
+
+       session->state = SMTP_AUTH_PLAIN;
+       session->auth_type = SMTPAUTH_PLAIN;
+
+       memset(buf, 0, sizeof buf);
+
+       /*
+        * have to construct the string bit by bit. sprintf can't do it in one.
+        * first field is null, so string is \0<user>\0<password>
+        */
+       *a = 0;
+       a++;
+
+       g_snprintf (a, b64len - 1, "%s", session->user);
+
+       b64cnt = strlen(session->user)+1;
+       a += b64cnt;
+
+       g_snprintf (a, b64len - b64cnt - 1, "%s", session->pass);
+       b64cnt += strlen(session->pass) + 1;    
+
+       /*
+        * reuse the char *ptr to offset into the textbuf to meld
+        * the plaintext ESMTP message and the base64 string value
+        */
+       strcpy(buf, "AUTH PLAIN ");
+       a = buf + strlen(buf);
+       base64_encode(a, b64buf, b64cnt);
+
+       session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf);
+
+       log_print("ESMTP> [AUTH PLAIN]\n");
+
+       g_free(b64buf);
+
+       return SM_OK;
+}
+
 static gint smtp_auth_login(SMTPSession *session)
 {
        session->state = SMTP_AUTH;
@@ -439,6 +498,7 @@ static gint smtp_session_recv_msg(Session *session, const gchar *msg)
        case SMTP_EHLO:
        case SMTP_STARTTLS:
        case SMTP_AUTH:
+       case SMTP_AUTH_PLAIN:
        case SMTP_AUTH_LOGIN_USER:
        case SMTP_AUTH_LOGIN_PASS:
        case SMTP_AUTH_CRAM_MD5:
@@ -554,6 +614,7 @@ static gint smtp_session_recv_msg(Session *session, const gchar *msg)
        case SMTP_AUTH_LOGIN_USER:
                smtp_auth_login_user_recv(smtp_session, msg);
                break;
+       case SMTP_AUTH_PLAIN:
        case SMTP_AUTH_LOGIN_PASS:
        case SMTP_AUTH_CRAM_MD5:
                smtp_from(smtp_session);
index b813ae68cf366b9edaef343c8c4e62b322b4fe62..5ca3d39c4d0c3629b7f25c995baa3127e51716a4 100644 (file)
@@ -54,7 +54,8 @@ typedef enum
        SMTPAUTH_LOGIN      = 1 << 0,
        SMTPAUTH_CRAM_MD5   = 1 << 1,
        SMTPAUTH_DIGEST_MD5 = 1 << 2,
-       SMTPAUTH_TLS_AVAILABLE = 1 << 3
+       SMTPAUTH_TLS_AVAILABLE = 1 << 3,
+       SMTPAUTH_PLAIN      = 1 << 4
 } SMTPAuthType;
 
 typedef enum
@@ -69,6 +70,7 @@ typedef enum
        SMTP_AUTH_LOGIN_USER,
        SMTP_AUTH_LOGIN_PASS,
        SMTP_AUTH_CRAM_MD5,
+       SMTP_AUTH_PLAIN,
        SMTP_RCPT,
        SMTP_DATA,
        SMTP_SEND_DATA,
index e681363e4d9d1a6b1b6d4b38b068697e5bae7d5d..f0a11c966e0ace7f626695469a7c8b02d6781b23 100644 (file)
@@ -1584,6 +1584,7 @@ static void prefs_account_send_create(void)
        optmenu_menu = gtk_menu_new ();
 
        MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
+       MENUITEM_ADD (optmenu_menu, menuitem, "PLAIN", SMTPAUTH_PLAIN);
        MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", SMTPAUTH_LOGIN);
        MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
        MENUITEM_ADD (optmenu_menu, menuitem, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);