]> git.kaiwu.me - nginx.git/commitdiff
r2496, r2749 merge:
authorIgor Sysoev <igor@sysoev.ru>
Mon, 18 May 2009 15:58:46 +0000 (15:58 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 18 May 2009 15:58:46 +0000 (15:58 +0000)
compatibility with Microsoft's
    AUTH LOGIN [base64 encoded user name ]
patch by Maxim Dounin

src/mail/ngx_mail.h
src/mail/ngx_mail_auth_http_module.c
src/mail/ngx_mail_handler.c
src/mail/ngx_mail_imap_handler.c
src/mail/ngx_mail_parse.c
src/mail/ngx_mail_pop3_handler.c
src/mail/ngx_mail_smtp_handler.c

index 1efff5b515ccf8724baf75efada7ad533e1971bf..4e6453270fa0d9059c8e4ad47b39af35aa45fc31 100644 (file)
@@ -164,7 +164,7 @@ typedef struct {
     unsigned                no_sync_literal:1;
     unsigned                starttls:1;
     unsigned                esmtp:1;
-    unsigned                auth_method:2;
+    unsigned                auth_method:3;
     unsigned                auth_wait:1;
 
     ngx_str_t               login;
@@ -243,10 +243,11 @@ typedef struct {
 #define NGX_SMTP_STARTTLS      13
 
 
-#define NGX_MAIL_AUTH_PLAIN     0
-#define NGX_MAIL_AUTH_LOGIN     1
-#define NGX_MAIL_AUTH_APOP      2
-#define NGX_MAIL_AUTH_CRAM_MD5  3
+#define NGX_MAIL_AUTH_PLAIN             0
+#define NGX_MAIL_AUTH_LOGIN             1
+#define NGX_MAIL_AUTH_LOGIN_USERNAME    2
+#define NGX_MAIL_AUTH_APOP              3
+#define NGX_MAIL_AUTH_CRAM_MD5          4
 
 
 #define NGX_MAIL_AUTH_PLAIN_ENABLED     0x0002
@@ -329,7 +330,7 @@ ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
     ngx_uint_t n);
 ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
-    ngx_connection_t *c);
+    ngx_connection_t *c, ngx_uint_t n);
 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
     ngx_connection_t *c);
 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
index 17e7861c06ba29a5c736db8ccb68a54fe1539f5e..cee5faafc0af264bf25856b41e600d63e70e2527 100644 (file)
@@ -138,6 +138,7 @@ ngx_module_t  ngx_mail_auth_http_module = {
 
 
 static ngx_str_t   ngx_mail_auth_http_method[] = {
+    ngx_string("plain"),
     ngx_string("plain"),
     ngx_string("plain"),
     ngx_string("apop"),
index 0cb67a237c8ac0a1746a22055fe1bfc60623384b..6b514972db6186fb92df09b4bb6ffc7af8cc2c67 100644 (file)
@@ -335,21 +335,22 @@ ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
 
 
 ngx_int_t
-ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c)
+ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c,
+    ngx_uint_t n)
 {
     ngx_str_t  *arg;
 
     arg = s->args.elts;
 
     ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
-                   "mail auth login username: \"%V\"", &arg[0]);
+                   "mail auth login username: \"%V\"", &arg[n]);
 
-    s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len));
+    s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[n].len));
     if (s->login.data == NULL){
         return NGX_ERROR;
     }
 
-    if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) {
+    if (ngx_decode_base64(&s->login, &arg[n]) != NGX_OK) {
         ngx_log_error(NGX_LOG_INFO, c->log, 0,
             "client sent invalid base64 encoding in AUTH LOGIN command");
         return NGX_MAIL_PARSE_INVALID_COMMAND;
index 62ba17da846535a2e1d20b17dd3f7b0a937e0d1e..e176469fe43174a94148873985442959cc62d21c 100644 (file)
@@ -205,7 +205,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
             break;
 
         case ngx_imap_auth_login_username:
-            rc = ngx_mail_auth_login_username(s, c);
+            rc = ngx_mail_auth_login_username(s, c, 0);
 
             tag = 0;
             s->out.len = sizeof(imap_password) - 1;
@@ -370,6 +370,14 @@ ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c)
 
         return NGX_OK;
 
+    case NGX_MAIL_AUTH_LOGIN_USERNAME:
+
+        s->out.len = sizeof(imap_password) - 1;
+        s->out.data = imap_password;
+        s->mail_state = ngx_imap_auth_login_password;
+
+        return ngx_mail_auth_login_username(s, c, 1);
+
     case NGX_MAIL_AUTH_PLAIN:
 
         s->out.len = sizeof(imap_plain_next) - 1;
index e558d2f48abed2263d946fa446ae217d97dcc621..693abfdc31d3aac63f72f817d000b8272343421c 100644 (file)
@@ -848,6 +848,10 @@ ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c)
                 return NGX_MAIL_AUTH_LOGIN;
             }
 
+            if (s->args.nelts == 2) {
+                return NGX_MAIL_AUTH_LOGIN_USERNAME;
+            }
+
             return NGX_MAIL_PARSE_INVALID_COMMAND;
         }
 
index c486fbebd5556ca1a16b867e8c9487a4da838930..668f0525b27b3e8488b8019efafa8f6a30689214 100644 (file)
@@ -226,7 +226,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *rev)
             break;
 
         case ngx_pop3_auth_login_username:
-            rc = ngx_mail_auth_login_username(s, c);
+            rc = ngx_mail_auth_login_username(s, c, 0);
 
             s->out.len = sizeof(pop3_password) - 1;
             s->out.data = pop3_password;
@@ -474,6 +474,14 @@ ngx_mail_pop3_auth(ngx_mail_session_t *s, ngx_connection_t *c)
 
         return NGX_OK;
 
+    case NGX_MAIL_AUTH_LOGIN_USERNAME:
+
+        s->out.len = sizeof(pop3_password) - 1;
+        s->out.data = pop3_password;
+        s->mail_state = ngx_pop3_auth_login_password;
+
+        return ngx_mail_auth_login_username(s, c, 1);
+
     case NGX_MAIL_AUTH_PLAIN:
 
         s->out.len = sizeof(pop3_next) - 1;
index 307ec697d6375a0ae1b2870ba8e685857ca0a5c8..f4cb69fb1d74cd219bc3f72cdb19979199795606 100644 (file)
@@ -452,7 +452,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
             break;
 
         case ngx_smtp_auth_login_username:
-            rc = ngx_mail_auth_login_username(s, c);
+            rc = ngx_mail_auth_login_username(s, c, 0);
 
             s->out.len = sizeof(smtp_password) - 1;
             s->out.data = smtp_password;
@@ -596,6 +596,14 @@ ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
 
         return NGX_OK;
 
+    case NGX_MAIL_AUTH_LOGIN_USERNAME:
+
+        s->out.len = sizeof(smtp_password) - 1;
+        s->out.data = smtp_password;
+        s->mail_state = ngx_smtp_auth_login_password;
+
+        return ngx_mail_auth_login_username(s, c, 1);
+
     case NGX_MAIL_AUTH_PLAIN:
 
         s->out.len = sizeof(smtp_next) - 1;