From: Vsevolod Stakhov Date: Wed, 22 Jan 2014 14:23:02 +0000 (+0000) Subject: Improve hostname processing. X-Git-Tag: 0.6.8~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a10555e79913dfef6785e79001b4c1ccfc0ad957;p=rspamd.git Improve hostname processing. --- diff --git a/conf/lua/hfilter.lua b/conf/lua/hfilter.lua index 967953157..f0c4748a8 100644 --- a/conf/lua/hfilter.lua +++ b/conf/lua/hfilter.lua @@ -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 diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e653e25d1..6b74bade0 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1070,7 +1070,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; } }