From 136e1e02a3c4f5fb7b7e96e2bc88ac7d5fe9f779 Mon Sep 17 00:00:00 2001 From: hiro Date: Mon, 14 Mar 2005 09:47:36 +0000 Subject: implemented PLAIN authentication method for SMTP AUTH. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@166 ee746299-78ed-0310-b773-934348b2243d --- src/prefs_account.c | 10 +++++++--- src/smtp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/smtp.h | 6 ++++-- 3 files changed, 61 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/prefs_account.c b/src/prefs_account.c index 29159fc9..c8a790d9 100644 --- a/src/prefs_account.c +++ b/src/prefs_account.c @@ -1237,6 +1237,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); @@ -2130,15 +2131,18 @@ static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam) GtkWidget *menuitem; switch (type) { - case SMTPAUTH_LOGIN: + case SMTPAUTH_PLAIN: gtk_option_menu_set_history(optmenu, 1); break; - case SMTPAUTH_CRAM_MD5: + case SMTPAUTH_LOGIN: gtk_option_menu_set_history(optmenu, 2); break; - case SMTPAUTH_DIGEST_MD5: + case SMTPAUTH_CRAM_MD5: gtk_option_menu_set_history(optmenu, 3); break; + case SMTPAUTH_DIGEST_MD5: + gtk_option_menu_set_history(optmenu, 4); + break; case 0: default: gtk_option_menu_set_history(optmenu, 0); diff --git a/src/smtp.c b/src/smtp.c index 3ee43c3b..1c872b8c 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,6 +38,7 @@ static gint smtp_from(SMTPSession *session); static gint smtp_auth(SMTPSession *session); static gint smtp_starttls(SMTPSession *session); static gint smtp_auth_cram_md5(SMTPSession *session); +static gint smtp_auth_plain(SMTPSession *session); static gint smtp_auth_login(SMTPSession *session); static gint smtp_ehlo(SMTPSession *session); @@ -143,6 +144,10 @@ static gint smtp_auth(SMTPSession *session) (session->forced_auth_type == 0 && (session->avail_auth_type & SMTPAUTH_CRAM_MD5) != 0)) smtp_auth_cram_md5(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 if (session->forced_auth_type == SMTPAUTH_LOGIN || (session->forced_auth_type == 0 && (session->avail_auth_type & SMTPAUTH_LOGIN) != 0)) @@ -266,8 +271,10 @@ static gint smtp_ehlo_recv(SMTPSession *session, const gchar *msg) const gchar *p = msg; p += 3; if (*p == '-' || *p == ' ') p++; - if (g_strncasecmp(p, "AUTH", 4) == 0) { + if (g_strncasecmp(p, "AUTH", 4) == 0 && p[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")) @@ -307,6 +314,45 @@ static gint smtp_auth_cram_md5(SMTPSession *session) return SM_OK; } +static gint smtp_auth_plain(SMTPSession *session) +{ + gchar *authstr; + gint authlen; + gchar *outbuf; + gchar *p; + + session->state = SMTP_AUTH_PLAIN; + session->auth_type = SMTPAUTH_PLAIN; + + /* + * construct the string: \0\0\0 + */ + + authlen = 1 + strlen(session->user) + 1 + strlen(session->pass) + 1; + authstr = g_malloc(authlen); + + p = authstr; + + *p++ = '\0'; + strcpy(p, session->user); + p += strlen(p) + 1; + strcpy(p, session->pass); + + outbuf = g_malloc(sizeof("AUTH PLAIN ") + authlen * 2 + 1); + + strcpy(outbuf, "AUTH PLAIN "); + p = outbuf + strlen(outbuf); + base64_encode(p, authstr, authlen); + + session_send_msg(SESSION(session), SESSION_MSG_NORMAL, outbuf); + log_print("ESMTP> AUTH PLAIN ********\n"); + + g_free(outbuf); + g_free(authstr); + + return SM_OK; +} + static gint smtp_auth_login(SMTPSession *session) { session->state = SMTP_AUTH; @@ -421,6 +467,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: @@ -522,6 +569,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/smtp.h b/src/smtp.h index 19629333..445bba69 100644 --- a/src/smtp.h +++ b/src/smtp.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2003 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +53,8 @@ typedef enum { SMTPAUTH_LOGIN = 1 << 0, SMTPAUTH_CRAM_MD5 = 1 << 1, - SMTPAUTH_DIGEST_MD5 = 1 << 2 + SMTPAUTH_DIGEST_MD5 = 1 << 2, + SMTPAUTH_PLAIN = 1 << 3 } SMTPAuthType; typedef enum @@ -65,6 +66,7 @@ typedef enum SMTP_STARTTLS, SMTP_FROM, SMTP_AUTH, + SMTP_AUTH_PLAIN, SMTP_AUTH_LOGIN_USER, SMTP_AUTH_LOGIN_PASS, SMTP_AUTH_CRAM_MD5, -- cgit v1.2.3