diff -Naur nginx-0.5.35.orig/src/mail/ngx_mail_proxy_module.c nginx-0.5.35.new/src/mail/ngx_mail_proxy_module.c --- nginx-0.5.35.orig/src/mail/ngx_mail_proxy_module.c 2007-11-07 09:24:55.000000000 -0500 +++ nginx-0.5.35.new/src/mail/ngx_mail_proxy_module.c 2008-03-23 16:03:18.000000000 -0400 @@ -17,6 +17,7 @@ ngx_flag_t xclient; size_t buffer_size; ngx_msec_t timeout; + ngx_array_t xclient_capabilities; } ngx_mail_proxy_conf_t; @@ -73,10 +74,27 @@ offsetof(ngx_mail_proxy_conf_t, xclient), NULL }, + { ngx_string("xclient_capabilities"), + NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, + ngx_mail_capabilities, + NGX_MAIL_SRV_CONF_OFFSET, + offsetof(ngx_mail_proxy_conf_t, xclient_capabilities), + NULL }, + ngx_null_command }; +static ngx_str_t ngx_mail_xclient_default_capabilities[] = { + ngx_string("PROTO"), + ngx_string("HELO"), + ngx_string("ADDR"), + ngx_string("LOGIN"), + ngx_string("NAME"), + ngx_null_string +}; + + static ngx_mail_module_t ngx_mail_proxy_module_ctx = { NULL, /* protocol */ @@ -467,6 +485,8 @@ ngx_mail_session_t *s; ngx_mail_proxy_conf_t *pcf; ngx_mail_core_srv_conf_t *cscf; + ngx_uint_t i; + ngx_str_t *xc; ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy smtp auth handler"); @@ -539,20 +559,38 @@ return; } - if (s->smtp_helo.len) { - line.len = ngx_sprintf(line.data, - "XCLIENT PROTO=%sSMTP HELO=%V ADDR=%V LOGIN=%V " - "NAME=[UNAVAILABLE]" CRLF, - (s->esmtp ? "E" : ""), &s->smtp_helo, - &s->connection->addr_text, &s->login) - - line.data; - } else { - line.len = ngx_sprintf(line.data, - "XCLIENT PROTO=SMTP ADDR=%V LOGIN=%V " - "NAME=[UNAVAILABLE]" CRLF, - &s->connection->addr_text, &s->login) - - line.data; + line.len = ngx_sprintf(line.data, "XCLIENT") - line.data; + pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); + xc = pcf->xclient_capabilities.elts; + for (i = 0; i < pcf->xclient_capabilities.nelts; i++) { + if (ngx_strcmp(xc[i].data, "PROTO") == 0) + { + line.len = ngx_sprintf(line.data + line.len, + " PROTO=%sSMTP", (s->esmtp ? "E" : "")) + - line.data; + } else if (ngx_strcmp(xc[i].data, "HELO") == 0 && s->smtp_helo.len) + { + line.len = ngx_sprintf(line.data + line.len, + " HELO=%V", &s->smtp_helo) + - line.data; + } else if (ngx_strcmp(xc[i].data, "ADDR") == 0) + { + line.len = ngx_sprintf(line.data + line.len, + " ADDR=%V", &s->connection->addr_text) + - line.data; + } else if (ngx_strcmp(xc[i].data, "LOGIN") == 0) + { + line.len = ngx_sprintf(line.data + line.len, + " LOGIN=%V", &s->login) + - line.data; + } else if (ngx_strcmp(xc[i].data, "NAME") == 0) + { + line.len = ngx_sprintf(line.data + line.len, + " NAME=[UNAVAILABLE]") + - line.data; + } } + line.len = ngx_sprintf(line.data + line.len, CRLF) - line.data; s->mail_state = ngx_smtp_xclient; break; @@ -977,6 +1015,12 @@ pcf->buffer_size = NGX_CONF_UNSET_SIZE; pcf->timeout = NGX_CONF_UNSET_MSEC; + if (ngx_array_init(&pcf->xclient_capabilities, cf->pool, 4, sizeof(ngx_str_t)) + != NGX_OK) + { + return NULL; + } + return pcf; } @@ -987,6 +1031,8 @@ ngx_mail_proxy_conf_t *prev = parent; ngx_mail_proxy_conf_t *conf = child; + ngx_str_t *c, *d; + ngx_conf_merge_value(conf->enable, prev->enable, 0); ngx_conf_merge_value(conf->pass_error_message, prev->pass_error_message, 0); ngx_conf_merge_value(conf->xclient, prev->xclient, 1); @@ -994,5 +1040,21 @@ (size_t) ngx_pagesize); ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 24 * 60 * 60000); + if (conf->xclient_capabilities.nelts == 0) { + conf->xclient_capabilities = prev->xclient_capabilities; + } + + if (conf->xclient_capabilities.nelts == 0) { + + for (d = ngx_mail_xclient_default_capabilities; d->len; d++) { + c = ngx_array_push(&conf->xclient_capabilities); + if (c == NULL) { + return NGX_CONF_ERROR; + } + + *c = *d; + } + } + return NGX_CONF_OK; }