Esempio n. 1
0
void
ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
{
    struct sockaddr_in        *sin;
    ngx_resolver_ctx_t        *ctx;
    ngx_mail_core_srv_conf_t  *cscf;

    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;
    }

    if (c->sockaddr->sa_family != AF_INET) {
        s->host = smtp_tempunavail;
        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);
        return;
    }

    /* AF_INET only */

    sin = (struct sockaddr_in *) c->sockaddr;

    ctx->addr = sin->sin_addr.s_addr;
    ctx->handler = ngx_mail_smtp_resolve_addr_handler;
    ctx->data = s;
    ctx->timeout = cscf->resolver_timeout;

    if (ngx_resolve_addr(ctx) != NGX_OK) {
        ngx_mail_close_connection(c);
    }
}
Esempio n. 2
0
void
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;

    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;
    }

#if (NGX_HAVE_UNIX_DOMAIN)
    if (c->sockaddr->sa_family == AF_UNIX) {
        s->host = smtp_tempunavail;
        ngx_mail_smtp_greeting(s, c);
        return;
    }
#endif

    c->log->action = "in resolving client address";

    ctx = ngx_resolve_start(cscf->resolver, NULL);
    if (ctx == NULL) {
        ngx_mail_close_connection(c);
        return;
    }

    ctx->addr.sockaddr = c->sockaddr;
    ctx->addr.socklen = c->socklen;
    ctx->handler = ngx_mail_smtp_resolve_addr_handler;
    ctx->data = s;
    ctx->timeout = cscf->resolver_timeout;

    if (ngx_resolve_addr(ctx) != NGX_OK) {
        ngx_mail_close_connection(c);
    }
}
static ngx_int_t resolver_handler(ngx_http_request_t * r) {
    ngx_http_rdns_loc_conf_t * loc_cf = ngx_http_get_module_loc_conf(r, ngx_http_rdns_module);
    ngx_http_core_loc_conf_t * core_loc_cf;
    ngx_resolver_ctx_t * rctx;
    ngx_http_rdns_ctx_t * ctx = ngx_http_get_module_ctx(r, ngx_http_rdns_module);
    ngx_http_rdns_common_conf_t * cconf;

#if (OLD_RESOLVER_API)
    struct sockaddr_in * sin = (struct sockaddr_in *) r->connection->sockaddr;
#endif

    if (loc_cf == NULL) {
        return NGX_DECLINED;
    }

    cconf = rdns_get_common_conf(ctx, loc_cf);
    if (cconf == NULL) {
        return NGX_DECLINED;
    }

    if (cconf->enabled) {
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                "rdns: resolver handler");

        if ((ctx != NULL) && ctx->resolved) {
            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "rdns: resolver handler: already resolved");
            return NGX_DECLINED;
        } else if (ctx == NULL) {
            /* Context needed because of ctx->resolved flag */
            ctx = create_context(r);
            if (ctx == NULL) {
                ngx_log_debug0(NGX_LOG_ERR, r->connection->log, 0,
                        "rdns: resolver handler: unable to create request context");
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }

            ctx->conf_source = NGX_HTTP_RDNS_CONF_CONF;
            ctx->resolved = 0;
        }

        if (loc_cf == NULL) {
            ngx_log_debug0(NGX_LOG_ERR, r->connection->log, 0,
                    "rdns: resolver handler: failed to get rdns location config");
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

        core_loc_cf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
        if (core_loc_cf == NULL) {
            ngx_log_debug0(NGX_LOG_ERR, r->connection->log, 0,
                    "rdns: resolver handler: failed to get core location config");
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

        rctx = ngx_resolve_start(core_loc_cf->resolver, NULL);
        if (rctx == NULL) {
            ngx_log_debug0(NGX_LOG_ERR, r->connection->log, 0,
                    "rdns: resolver handler: unable to create resolver context");
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

        if (rctx == NGX_NO_RESOLVER) {
            ngx_log_debug0(NGX_LOG_ERR, r->connection->log, 0,
                    "rdns: resolver handler: core resolver is not defined");
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

#if (OLD_RESOLVER_API)
        rctx->addr = sin->sin_addr.s_addr;
        rctx->type = NGX_RESOLVE_PTR;
#else
        rctx->addr.sockaddr = r->connection->sockaddr;
        rctx->addr.socklen = r->connection->socklen;
#endif

        rctx->handler = rdns_handler;
        rctx->data = r;
        rctx->timeout = core_loc_cf->resolver_timeout;

        if (ngx_resolve_addr(rctx) != NGX_OK) {
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
        }

        return NGX_DONE;
    } else {
        return NGX_DECLINED;
    }
}