From: Colin Leroy Date: Tue, 7 Dec 2004 07:56:45 +0000 (+0000) Subject: 2004-12-07 [colin] 0.9.13cvs2 X-Git-Tag: rel_1_0_0~52 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=3f2f00e466970fac207659577e5d1f8f59354adc 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 --- diff --git a/AUTHORS b/AUTHORS index 5d2ad214b..d2ba9014c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -210,3 +210,4 @@ contributors (beside the above; based on Changelog) Reza Pakdel Stephan Sachse Thomas Gilgin + George Michaelson diff --git a/ChangeLog.claws b/ChangeLog.claws index 71ba874a8..98ac64f67 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -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 + 2004-12-07 [thorsten] 0.9.13cvs1 * src/procmime.c diff --git a/PATCHSETS b/PATCHSETS index 9b24398db..4ea288152 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -171,3 +171,4 @@ ( 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 diff --git a/configure.ac b/configure.ac index 550a5b34f..b40d67c8b 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/common/smtp.c b/src/common/smtp.c index 5d1f72246..d65477a80 100644 --- a/src/common/smtp.c +++ b/src/common/smtp.c @@ -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\0\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\0 + */ + *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); diff --git a/src/common/smtp.h b/src/common/smtp.h index b813ae68c..5ca3d39c4 100644 --- a/src/common/smtp.h +++ b/src/common/smtp.h @@ -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, diff --git a/src/prefs_account.c b/src/prefs_account.c index e681363e4..f0a11c966 100644 --- a/src/prefs_account.c +++ b/src/prefs_account.c @@ -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);