]> git.kaiwu.me - nginx.git/commitdiff
create salt just before it will be used
authorIgor Sysoev <igor@sysoev.ru>
Fri, 14 Sep 2007 15:00:19 +0000 (15:00 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 14 Sep 2007 15:00:19 +0000 (15:00 +0000)
src/mail/ngx_mail_imap_handler.c
src/mail/ngx_mail_smtp_handler.c

index 97cd04f85ce037321a3d0a37ec29bfb03440010d..0c88d1a0777087a2d88373301d8edb90ac00cb79 100644 (file)
@@ -38,13 +38,6 @@ ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
 
     cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
 
-    if (cscf->imap_auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED) {
-        if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
-            ngx_mail_session_internal_server_error(s);
-            return;
-        }
-    }
-
     s->out.len = sizeof(imap_greeting) - 1;
     s->out.data = imap_greeting;
 
@@ -391,6 +384,12 @@ ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c)
             return NGX_MAIL_PARSE_INVALID_COMMAND;
         }
 
+        if (s->salt.data == NULL) {
+            if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
+                return NGX_ERROR;
+            }
+        }
+
         if (ngx_mail_auth_cram_md5_salt(s, c, "+ ", 2) == NGX_OK) {
             s->mail_state = ngx_imap_auth_cram_md5;
             return NGX_OK;
index 8eb28df2faf031cd2ed87844827b1221d465a7ea..9fad45958df038a0d2149e60c8b45d61f63846a2 100644 (file)
@@ -46,13 +46,6 @@ ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
 
     cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
 
-    if (cscf->smtp_auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED) {
-        if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
-            ngx_mail_session_internal_server_error(s);
-            return;
-        }
-    }
-
     timeout = cscf->smtp_greeting_delay ? cscf->smtp_greeting_delay:
                                           cscf->timeout;
     ngx_add_timer(c->read, timeout); 
@@ -422,6 +415,12 @@ ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
             return NGX_MAIL_PARSE_INVALID_COMMAND;
         }
 
+        if (s->salt.data == NULL) {
+            if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
+                return NGX_ERROR;
+            }
+        }
+
         if (ngx_mail_auth_cram_md5_salt(s, c, "334 ", 4) == NGX_OK) {
             s->mail_state = ngx_smtp_auth_cram_md5;
             return NGX_OK;