IMAP proxy problems

Igor Sysoev is at rambler-co.ru
Thu Aug 16 22:22:03 MSD 2007


On Thu, Aug 16, 2007 at 06:26:34PM +0200, Attila Nagy wrote:

> I'm trying to set up nginx (stable and devel, both without success) as 
> an IMAP proxy to an Exchange server.
> 
> The config is:
> daemon off;
> error_log  /var/log/nginx-error.log debug;
> events {
>    worker_connections  1024;
> }
> mail {
>    auth_http  127.0.0.1:9000/cgi-bin/auth;
>    imap_capabilities  "IMAP4rev1"  "UIDPLUS";
> 
>    server {
>        listen     143;
>        protocol   imap;
>        proxy      on;
>    }
> }
> 
> I give back on TCP/9000 the following:
> HTTP/1.0 200 OK
> Auth-Status: OK
> Auth-Server: 127.0.0.1
> Auth-Port: 1433
> (this is just a test on a forwarded port)
> 
> What I get in the log:
> 2007/08/16 16:06:43 [info] 38634#0: *6 client  connected to
> 2007/08/16 16:06:48 [error] 38634#0: *6 upstream sent invalid response: 
> "LOGIN BAD Protocol Error: "Unknown command found"." while reading 
> response from upstream, client: , server: , login: "", upstream:
> 
> If I trace nginx, I see the following IO:
> 38634 nginx    GIO   fd 8 read 103 bytes
>       "* OK Microsoft Exchange Server 2003 IMAP4rev1 server version 
> 6.5.7638.\
>        1 (MAILSRV) ready.\r
>       "
> 38634 nginx    RET   recvfrom 103/0x67
> 38634 nginx    CALL  sendto(0x8,0x3f1140,0xb,0,0,0)
> 38634 nginx    GIO   fd 8 wrote 11 bytes
>       "LOGIN {6}\r
>       "
> 38634 nginx    RET   sendto 11/0xb
> 38634 nginx    CALL  kevent(0x7,0x40c000,0,0x414000,0x200,0x7fdffffe3b0)
> 38634 nginx    RET   kevent 2
> 38634 nginx    CALL  gettimeofday(0x7fdffffe250,0)
> 38634 nginx    RET   gettimeofday 0
> 38634 nginx    CALL  recvfrom(0x8,0x47c000,0x2000,0,0,0)
> 38634 nginx    GIO   fd 8 read 38 bytes
>       "+ Ready for additional command text.\r
>       "
> 38634 nginx    RET   recvfrom 38/0x26
> 38634 nginx    CALL  sendto(0x8,0x3f1170,0x6,0,0,0)
> 38634 nginx    GIO   fd 8 wrote 6 bytes
>       " {8}\r
>       "
> 38634 nginx    RET   sendto 6
> 38634 nginx    CALL  kevent(0x7,0x40c000,0,0x414000,0x200,0x7fdffffe3b0)
> 38634 nginx    RET   kevent 2
> 38634 nginx    CALL  gettimeofday(0x7fdffffe250,0)
> 38634 nginx    RET   gettimeofday 0
> 38634 nginx    CALL  recvfrom(0x8,0x47c000,0x2000,0,0,0)
> 38634 nginx    GIO   fd 8 read 52 bytes
>       "LOGIN BAD Protocol Error: "Unknown command found".\r
>       "
> 
> The OS is FreeBSD/sparc64, version 6-STABLE, nginx linked statically (if 
> that counts).

Try the attached patch.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/ngx_http_script.c
===================================================================
--- src/http/ngx_http_script.c	(revision 724)
+++ src/http/ngx_http_script.c	(working copy)
@@ -1191,7 +1191,7 @@
 
     if (value && !value->not_found) {
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
-                       "http script var: \"%V\"", value);
+                       "http script var: \"%v\"", value);
 
         *e->sp = *value;
         e->sp++;
Index: src/http/modules/ngx_http_limit_zone_module.c
===================================================================
--- src/http/modules/ngx_http_limit_zone_module.c	(revision 724)
+++ src/http/modules/ngx_http_limit_zone_module.c	(working copy)
@@ -141,7 +141,7 @@
     if (len > 255) {
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                       "the value of the \"%V\" variable "
-                      "is more than 255 bytes: \"%V\"",
+                      "is more than 255 bytes: \"%v\"",
                       &ctx->var, vv);
         return NGX_DECLINED;
     }
Index: src/http/modules/ngx_http_geo_module.c
===================================================================
--- src/http/modules/ngx_http_geo_module.c	(revision 724)
+++ src/http/modules/ngx_http_geo_module.c	(working copy)
@@ -86,7 +86,7 @@
     *v = *vv;
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http geo: %V %V", &r->connection->addr_text, v);
+                   "http geo: %V %v", &r->connection->addr_text, v);
 
     return NGX_OK;
 }
@@ -100,8 +100,8 @@
     ngx_conf_t                save;
     ngx_pool_t               *pool;
     ngx_radix_tree_t         *tree;
+    ngx_http_variable_t      *var;
     ngx_http_geo_conf_ctx_t   ctx;
-    ngx_http_variable_t  *var;
 
     value = cf->args->elts;
 
@@ -285,9 +285,8 @@
                     ngx_radix32tree_find(ctx->tree, cidrin.addr & cidrin.mask);
 
         ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
-                           "duplicate parameter \"%V\", value: \"%V\", "
-                           "old value: \"%V\"",
-                           &value[0], var, old);
+                "duplicate parameter \"%V\", value: \"%v\", old value: \"%v\"",
+                &value[0], var, old);
 
         rc = ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask);
 
Index: src/http/modules/ngx_http_map_module.c
===================================================================
--- src/http/modules/ngx_http_map_module.c	(revision 724)
+++ src/http/modules/ngx_http_map_module.c	(working copy)
@@ -151,7 +151,7 @@
     }
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http map: \"%V\" \"%V\"", vv, v);
+                   "http map: \"%v\" \"%v\"", vv, v);
 
     return NGX_OK;
 }
Index: src/core/ngx_string.c
===================================================================
--- src/core/ngx_string.c	(revision 724)
+++ src/core/ngx_string.c	(working copy)
@@ -59,8 +59,9 @@
  *    %P                        ngx_pid_t
  *    %M                        ngx_msec_t
  *    %r                        rlim_t
- *    %p                        pointer
- *    %V                        pointer to ngx_str_t
+ *    %p                        void *
+ *    %V                        ngx_str_t *
+ *    %v                        ngx_variable_value_t *
  *    %s                        null-terminated string
  *    %Z                        '\0'
  *    %N                        '\n'
@@ -117,7 +118,8 @@
     uint64_t               ui64;
     ngx_msec_t             ms;
     ngx_uint_t             width, sign, hexadecimal, max_width;
-    ngx_variable_value_t  *v;
+    ngx_str_t             *v;
+    ngx_variable_value_t  *vv;
     static u_char          hex[] = "0123456789abcdef";
     static u_char          HEX[] = "0123456789ABCDEF";
 
@@ -188,7 +190,7 @@
             switch (*fmt) {
 
             case 'V':
-                v = va_arg(args, ngx_variable_value_t *);
+                v = va_arg(args, ngx_str_t *);
 
                 len = v->len;
                 len = (buf + len < last) ? len : (size_t) (last - buf);
@@ -198,6 +200,17 @@
 
                 continue;
 
+            case 'v':
+                vv = va_arg(args, ngx_variable_value_t *);
+
+                len = vv->len;
+                len = (buf + len < last) ? len : (size_t) (last - buf);
+
+                buf = ngx_cpymem(buf, vv->data, len);
+                fmt++;
+
+                continue;
+
             case 's':
                 p = va_arg(args, u_char *);
 


More information about the nginx mailing list