diff src/imap/ngx_imap_auth_http_module.c @ 567:1af2fcb3be8a release-0.3.5

nginx-0.3.5-RELEASE import *) Bugfix: the segmentation fault may occurred if the IMAP/POP3 login was changed by authorization server; the bug had appeared in 0.2.2. *) Bugfix: the accept mutex did not work and all connections were handled by one process; the bug had appeared in 0.3.3. *) Bugfix: the timeout did not work if the "rtsig" method and the "timer_resolution" directive were used.
author Igor Sysoev <igor@sysoev.ru>
date Fri, 21 Oct 2005 19:12:18 +0000
parents c1f965ef9718
children 58475592100c
line wrap: on
line diff
--- a/src/imap/ngx_imap_auth_http_module.c
+++ b/src/imap/ngx_imap_auth_http_module.c
@@ -44,6 +44,7 @@ struct ngx_imap_auth_http_ctx_s {
     ngx_str_t                       addr;
     ngx_str_t                       port;
     ngx_str_t                       err;
+    ngx_str_t                       errmsg;
 
     time_t                          sleep;
 
@@ -459,6 +460,9 @@ ngx_imap_auth_http_process_headers(ngx_i
                     continue;
                 }
 
+                ctx->errmsg.len = len;
+                ctx->errmsg.data = ctx->header_start;
+
                 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
                     size = sizeof("-ERR") - 1 + len + sizeof(CRLF) - 1;
 
@@ -486,6 +490,7 @@ ngx_imap_auth_http_process_headers(ngx_i
                 }
 
                 *p++ = ' ';
+
                 p = ngx_cpymem(p, ctx->header_start, len);
                 *p++ = CR; *p++ = LF;
 
@@ -519,7 +524,16 @@ ngx_imap_auth_http_process_headers(ngx_i
                                    sizeof("Auth-User") - 1) == 0)
             {
                 s->login.len = ctx->header_end - ctx->header_start;
-                s->login.data = ctx->header_start;
+
+                s->login.data = ngx_palloc(s->connection->pool, s->login.len);
+                if (s->login.data == NULL) {
+                    ngx_close_connection(ctx->peer.connection);
+                    ngx_destroy_pool(ctx->pool);
+                    ngx_imap_session_internal_server_error(s);
+                    return;
+                }
+
+                ngx_memcpy(s->login.data, ctx->header_start, s->login.len);
 
                 continue;
             }
@@ -550,14 +564,14 @@ ngx_imap_auth_http_process_headers(ngx_i
             ngx_close_connection(ctx->peer.connection);
 
             if (ctx->err.len) {
+                ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
+                              "client login failed: \"%V\"", &ctx->errmsg);
+
                 s->out = ctx->err;
                 timer = ctx->sleep;
 
                 ngx_destroy_pool(ctx->pool);
 
-                ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
-                              "client login failed");
-
                 if (timer == 0) {
                     s->quit = 1;
                     ngx_imap_send(s->connection->write);