diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-27 12:24:28 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-27 12:24:28 +0100 |
commit | f8ffbf44bf786b5d072d0c4d91f18a20a7583699 (patch) | |
tree | 493ccca2a655d3f2b3d25916de08f794fc2b5448 /src/plugins/lua/rbl.lua | |
parent | 466de60fc320c8f54fd34871097a8d81df520c2d (diff) | |
download | rspamd-f8ffbf44bf786b5d072d0c4d91f18a20a7583699.tar.gz rspamd-f8ffbf44bf786b5d072d0c4d91f18a20a7583699.zip |
[Fix] Rbl: Fix received positioned checks
Diffstat (limited to 'src/plugins/lua/rbl.lua')
-rw-r--r-- | src/plugins/lua/rbl.lua | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index f1c20fa13..f73cd4371 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -136,28 +136,27 @@ local function ip_to_rbl(ip) end local function gen_check_rcvd_conditions(rbl, received_total) - local min_pos = tonumber(rbl['received_min_pos']) - local max_pos = tonumber(rbl['received_max_pos']) - local match_flags = rbl['received_flags'] - local nmatch_flags = rbl['received_nflags'] + local min_pos = tonumber(rbl.received_min_pos) + local max_pos = tonumber(rbl.received_max_pos) + local match_flags = rbl.received_flags + local nmatch_flags = rbl.received_nflags + local function basic_received_check(rh) - if not (rh['real_ip'] and rh['real_ip']:is_valid()) then return false end - if ((rh['real_ip']:get_version() == 6 and rbl['ipv6']) or - (rh['real_ip']:get_version() == 4 and rbl['ipv4'])) and - ((rbl['exclude_private_ips'] and not rh['real_ip']:is_local()) or - not rbl['exclude_private_ips']) and ((rbl['exclude_local_ips'] and - not is_excluded_ip(rh['real_ip'])) or not rbl['exclude_local_ips']) then + if not (rh.real_ip and rh.real_ip:is_valid()) then return false end + if ((rh.real_ip:get_version() == 6 and rbl.ipv6) or + (rh.real_ip:get_version() == 4 and rbl.ipv4)) and + ((rbl.exclude_private_ips and not rh.real_ip:is_local()) or + not rbl.exclude_private_ips) and ((rbl.exclude_local_ips and + not is_excluded_ip(rh.real_ip)) or not rbl.exclude_local_ips) then return true else return false end end - if not (max_pos or min_pos or match_flags or nmatch_flags) then - return basic_received_check - end - return function(rh, pos) - if not basic_received_check() then return false end - local got_flags = rh['flags'] or E + + local function positioned_received_check(rh, pos) + if not rh or not basic_received_check(rh) then return false end + local got_flags = rh.flags or E if min_pos then if min_pos < 0 then if min_pos == -1 then @@ -165,7 +164,7 @@ local function gen_check_rcvd_conditions(rbl, received_total) return false end else - if pos <= (received_total - (min_pos*-1)) then + if pos <= (received_total - math.abs(min_pos)) then return false end end @@ -175,7 +174,7 @@ local function gen_check_rcvd_conditions(rbl, received_total) end if max_pos then if max_pos < -1 then - if (received_total - (max_pos*-1)) >= pos then + if (received_total - math.abs(max_pos)) >= pos then return false end elseif max_pos > 0 then @@ -200,6 +199,13 @@ local function gen_check_rcvd_conditions(rbl, received_total) end return true end + + + if not (max_pos or min_pos or match_flags or nmatch_flags) then + return basic_received_check + else + return positioned_received_check + end end local function rbl_dns_process(task, rbl, to_resolve, results, err, resolve_table_elt) |