]> git.kaiwu.me - nginx.git/commitdiff
compatibility with Microsoft's
authorIgor Sysoev <igor@sysoev.ru>
Mon, 9 Feb 2009 12:03:55 +0000 (12:03 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 9 Feb 2009 12:03:55 +0000 (12:03 +0000)
    AUTH LOGIN [base64 encoded user name ]
patch by Maxim Dounin

src/mail/ngx_mail.h
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 4052efea7d35ab8466c148946350981192d46cde..f813911c617002f291c26c2721f557c50e875645 100644 (file)
@@ -258,11 +258,12 @@ 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_NONE      4
+#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_NONE              5
 
 
 #define NGX_MAIL_AUTH_PLAIN_ENABLED     0x0002
@@ -346,7 +347,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 e86877f1a42a655297c67628fda987f18e954d3a..0863d6dfeb9fade7da0831c9341522b1a12b78bb 100644 (file)
@@ -356,21 +356,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_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len));
+    s->login.data = ngx_pnalloc(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 780c38fbb2bb5133b082eb89bcb2c4e190180722..a2e032efff3bcfceef1bc79b13c108bdef8963c9 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 a2d3f48ad51d594a090825370ecd40c51d484f06..67f4d5edf6d2fa4af4d1edba59d96f468f1ec94d 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 c763f04ff163061fe829ef227f642f9dbe679b67..aed66291975a3b2b4c9d5468ecffb150be1990e1 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 a88a82cd44afcc847af3537b13e67bc9a1c48af4..a0ad37f175a06bea52e7aba770d8bda4746b1a5c 100644 (file)
@@ -462,7 +462,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;
@@ -611,6 +611,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;