]> source.dussan.org Git - rspamd.git/commitdiff
Improve hostname processing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 Jan 2014 14:23:02 +0000 (14:23 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 Jan 2014 14:23:02 +0000 (14:23 +0000)
conf/lua/hfilter.lua
src/lua/lua_task.c

index 967953157f52ca9847a0a6ffb49aa639272113da..f0c4748a8bc9ca868bc6a0b9002758443a37a939 100644 (file)
@@ -134,12 +134,10 @@ local function check_host(task, host, symbol_suffix, eq_ip, eq_host)
     end
     if eq_host then
         eq_host = string.lower(eq_host)
-    else
-        eq_host = ''
     end
 
     if check_fqdn(host) then
-        if eq_host == '' or eq_host ~= host then
+        if not eq_host or (eq_host ~= 'unknown' or eq_host ~= host) then
             task:get_resolver():resolve_a(task:get_session(), task:get_mempool(), host, check_host_cb_a)
         end
     else
@@ -169,9 +167,6 @@ local function hfilter(task)
     
     --HOSTNAME--
     local hostname = task:get_hostname()
-        if hostname and ip and hostname == '[' .. ip .. ']' then
-            hostname = false
-        end
     
     --HELO--
     local helo = task:get_helo()
@@ -218,8 +213,9 @@ local function hfilter(task)
                 break
             end
         end
-    else
-        task:insert_result('HFILTER_HOSTNAME_NOPTR', 1.00)
+        if hostname == 'unknown' then
+               task:insert_result('HFILTER_HOSTNAME_NOPTR', 1.00)
+       end
     end
     
     --Insert weight's for HELO or HOSTNAME
index a9e0d543364edcd572b1e3a2125d0a7e394d6f86..73da200adb22779c5da02914903d671d4539beda 100644 (file)
@@ -1067,7 +1067,21 @@ lua_task_get_hostname (lua_State *L)
 
        if (task) {
                if (task->hostname != NULL) {
-                       lua_pushstring (L, (gchar *)task->hostname);
+                       /* Check whether it looks like an IP address */
+                       if (*task->hostname == '[') {
+                               /*
+                                * From the milter documentation:
+                                *  If the reverse lookup fails or if none of the IP
+                                *  addresses of the resolved host name matches the
+                                *  original IP address, hostname will contain the
+                                *  message sender's IP address enclosed in square
+                                *  brackets (e.g. `[a.b.c.d]')
+                                */
+                               lua_pushstring (L, "unknown");
+                       }
+                       else {
+                               lua_pushstring (L, task->hostname);
+                       }
                        return 1;
                }
        }