]> git.kaiwu.me - nginx.git/commitdiff
do not resolve SMTP clients by default
authorIgor Sysoev <igor@sysoev.ru>
Sat, 16 Feb 2008 13:46:33 +0000 (13:46 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 16 Feb 2008 13:46:33 +0000 (13:46 +0000)
src/mail/ngx_mail_core_module.c
src/mail/ngx_mail_smtp_handler.c
src/mail/ngx_mail_smtp_module.c

index ad785fd99450e3c88819203719ba675c2ec00fc9..91b425f7f2a4587c322cddaf391ca9ae54663c95 100644 (file)
@@ -154,13 +154,14 @@ ngx_mail_core_create_srv_conf(ngx_conf_t *cf)
      * set by ngx_pcalloc():
      *
      *     cscf->protocol = NULL;
-     *     cscf->resolver = NULL;
      */
 
     cscf->timeout = NGX_CONF_UNSET_MSEC;
     cscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
     cscf->so_keepalive = NGX_CONF_UNSET;
 
+    cscf->resolver = NGX_CONF_UNSET_PTR;
+
     cscf->file_name = cf->conf_file->file.name.data;
     cscf->line = cf->conf_file->line;
 
@@ -207,9 +208,7 @@ ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
         return NGX_CONF_ERROR;
     }
 
-    if (conf->resolver == NULL) {
-        conf->resolver = prev->resolver;
-    }
+    ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL);
 
     return NGX_CONF_OK;
 }
@@ -423,6 +422,11 @@ ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
+    if (ngx_strcmp(value[1].data, "off") == 0) {
+        cscf->resolver = NULL;
+        return NGX_CONF_OK;
+    }
+
     ngx_memzero(&u, sizeof(ngx_url_t));
 
     u.host = value[1];
@@ -435,7 +439,7 @@ ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     cscf->resolver = ngx_resolver_create(&u.addrs[0], cf->cycle->new_log);
     if (cscf->resolver == NULL) {
-        return NGX_OK;
+        return NGX_CONF_OK;
     }
 
     return NGX_CONF_OK;
index 2d7c24f5657a9d3dc8c611c938d0875560794e18..6e944738f97b8f09c6cf6d84b8b476ed3d66b47f 100644 (file)
@@ -54,10 +54,16 @@ ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
     ngx_resolver_ctx_t        *ctx;
     ngx_mail_core_srv_conf_t  *cscf;
 
-    c->log->action = "in resolving client address";
-
     cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
 
+    if (cscf->resolver == NULL) {
+        s->host = smtp_unavailable;
+        ngx_mail_smtp_greeting(s, c);
+        return;
+    }
+
+    c->log->action = "in resolving client address";
+
     ctx = ngx_resolve_start(cscf->resolver, NULL);
     if (ctx == NULL) {
         ngx_mail_close_connection(c);
index 71ba3fd9afb3d5c9d70b2ffa0c67ed34144dd946..5f5ac0567ef28d4004fb1d20ae99353d484af4e8 100644 (file)
@@ -158,15 +158,6 @@ ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
 
     cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module);
 
-    if (cscf->protocol->type == NGX_MAIL_SMTP_PROTOCOL
-        && cscf->resolver == NULL)
-    {
-        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
-                      "undefined resolver for server in %s:%ui",
-                      cscf->file_name, cscf->line);
-        return NGX_CONF_ERROR;
-    }
-
     size = sizeof("220  ESMTP ready" CRLF) - 1 + cscf->server_name.len;
 
     p = ngx_palloc(cf->pool, size);