]> source.dussan.org Git - rspamd.git/commitdiff
Fix PTR requests handling.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 19 Feb 2014 18:41:19 +0000 (18:41 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 19 Feb 2014 18:41:19 +0000 (18:41 +0000)
src/lua/lua_dns.c
src/rdns
src/smtp_proxy.c

index b3d8f768f241bf172f19e3f48bb2d99c4520fa7d..c53688ef5a8afec707866602301dbb9eb1de96b4 100644 (file)
@@ -178,7 +178,6 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol
        struct rspamd_async_session                                     *session, **psession;
        memory_pool_t                                                           *pool, **ppool;
        const gchar                                                                     *to_resolve;
-       struct in_addr                                                           ina;
        struct lua_dns_cbdata                                           *cbdata;
 
        /* Check arguments */
@@ -191,17 +190,23 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol
        to_resolve = luaL_checkstring (L, 4);
 
        if (pool != NULL && session != NULL && to_resolve != NULL && lua_isfunction (L, 5)) {
-               if (type == DNS_REQUEST_PTR) {
-                       if (inet_aton (to_resolve, &ina) == 0) {
+               cbdata = memory_pool_alloc (pool, sizeof (struct lua_dns_cbdata));
+               cbdata->L = L;
+               cbdata->resolver = resolver;
+               if (type != DNS_REQUEST_PTR) {
+                       cbdata->to_resolve = memory_pool_strdup (pool, to_resolve);
+               }
+               else {
+                       char *ptr_str;
+                       ptr_str = rdns_generate_ptr_from_str (to_resolve);
+                       if (ptr_str == NULL) {
                                msg_err ("wrong resolve string to PTR request: %s", to_resolve);
                                lua_pushnil (L);
                                return 1;
                        }
+                       cbdata->to_resolve = memory_pool_strdup (pool, ptr_str);
+                       free (ptr_str);
                }
-               cbdata = memory_pool_alloc (pool, sizeof (struct lua_dns_cbdata));
-               cbdata->L = L;
-               cbdata->resolver = resolver;
-               cbdata->to_resolve = memory_pool_strdup (pool, to_resolve);
                lua_pushvalue (L, 5);
                cbdata->cbref = luaL_ref (L, LUA_REGISTRYINDEX);
 
@@ -211,13 +216,7 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol
                else {
                        cbdata->user_str = NULL;
                }
-
-               if (type == DNS_REQUEST_PTR) {
-                       make_dns_request (resolver, session, pool, lua_dns_callback, cbdata, type, &ina);
-               }
-               else {
-                       make_dns_request (resolver, session, pool, lua_dns_callback, cbdata, type, to_resolve);
-               }
+               make_dns_request (resolver, session, pool, lua_dns_callback, cbdata, type, to_resolve);
                lua_pushboolean (L, TRUE);
        }
        else {
index 4a9991016a7f820620817f9d3359810fd02ec5ea..cddc17d60ccf3516516e73f4e5cab151277fafbb 160000 (submodule)
--- a/src/rdns
+++ b/src/rdns
@@ -1 +1 @@
-Subproject commit 4a9991016a7f820620817f9d3359810fd02ec5ea
+Subproject commit cddc17d60ccf3516516e73f4e5cab151277fafbb
index c75cb530d41dab5a82ee0b46d855c7057d96e80a..24d78ef4f7ab461ca13bbbbc721e13ac519578ae 100644 (file)
@@ -108,6 +108,7 @@ struct smtp_proxy_session {
        enum rspamd_smtp_proxy_state state;
        struct rspamd_worker *worker;
        struct in_addr client_addr;
+       gchar *ptr_str;
        gchar *hostname;
        gchar *error;
        gchar *temp_name;
@@ -233,6 +234,9 @@ free_smtp_proxy_session (gpointer arg)
                if (session->proxy) {
                        rspamd_proxy_close (session->proxy);
                }
+               if (session->ptr_str) {
+                       free (session->ptr_str);
+               }
                if (session->upstream_sock != -1) {
                        event_del (&session->upstream_ev);
                        close (session->upstream_sock);
@@ -930,6 +934,7 @@ accept_socket (gint fd, short what, void *arg)
        session->resolver = ctx->resolver;
        session->ev_base = ctx->ev_base;
        session->upstream_sock = -1;
+       session->ptr_str = rdns_generate_ptr_from_str (inet_ntoa (su.s4.sin_addr));
        worker->srv->stat->connections_count++;
 
        /* Resolve client's addr */
@@ -937,7 +942,7 @@ accept_socket (gint fd, short what, void *arg)
        session->s = new_async_session (session->pool, NULL, NULL, free_smtp_proxy_session, session);
        session->state = SMTP_PROXY_STATE_RESOLVE_REVERSE;
        if (! make_dns_request (session->resolver, session->s, session->pool,
-                       smtp_dns_cb, session, DNS_REQUEST_PTR, &session->client_addr)) {
+                       smtp_dns_cb, session, DNS_REQUEST_PTR, session->ptr_str)) {
                msg_err ("cannot resolve %s", inet_ntoa (session->client_addr));
                g_slice_free1 (sizeof (struct smtp_proxy_session), session);
                close (nfd);