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.
diff --git a/src/imap/ngx_imap_auth_http_module.c b/src/imap/ngx_imap_auth_http_module.c
index bc98dc8..4b8584d 100644
--- a/src/imap/ngx_imap_auth_http_module.c
+++ b/src/imap/ngx_imap_auth_http_module.c
@@ -44,6 +44,7 @@
     ngx_str_t                       addr;
     ngx_str_t                       port;
     ngx_str_t                       err;
+    ngx_str_t                       errmsg;
 
     time_t                          sleep;
 
@@ -459,6 +460,9 @@
                     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 @@
                 }
 
                 *p++ = ' ';
+
                 p = ngx_cpymem(p, ctx->header_start, len);
                 *p++ = CR; *p++ = LF;
 
@@ -519,7 +524,16 @@
                                    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_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);
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index 4fe1248..b8c5bfc 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -767,9 +767,9 @@
 static u_char *
 ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len)
 {
-    u_char                 *p;
-    ngx_imap_session_t     *s;
-    ngx_imap_log_ctx_t     *ctx;
+    u_char              *p;
+    ngx_imap_session_t  *s;
+    ngx_imap_log_ctx_t  *ctx;
 
     if (log->action) {
         p = ngx_snprintf(buf, len, " while %s", log->action);