diff options
author | Andrew Lewis <nerf@judo.za.org> | 2020-10-12 15:20:14 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2020-10-12 15:20:14 +0200 |
commit | 211051d6bc542f0e30f6863695d1973e6fcf472f (patch) | |
tree | e83f0247a15e4062419be5443ce0c20f2762ff77 /src/plugins/lua/rbl.lua | |
parent | f1efd55e9d9afdc0bdee58c7b54dbff361e85363 (diff) | |
download | rspamd-211051d6bc542f0e30f6863695d1973e6fcf472f.tar.gz rspamd-211051d6bc542f0e30f6863695d1973e6fcf472f.zip |
[Feature] RBL: support use of multiple selectors
Diffstat (limited to 'src/plugins/lua/rbl.lua')
-rw-r--r-- | src/plugins/lua/rbl.lua | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 5bb175ff7..846a864a6 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -587,12 +587,14 @@ local function gen_rbl_callback(rule) end local function check_selector(task, requests_table, whitelist) - local res = rule.selector(task) + for selector_label, selector in pairs(rule.selectors) do + local res = selector(task) - if res then - for _,r in ipairs(res) do - add_dns_request(task, r, false, false, requests_table, - 'sel' .. rule.selector_id, whitelist) + if res then + for _,r in ipairs(res) do + add_dns_request(task, r, false, false, requests_table, + selector_label, whitelist) + end end end @@ -879,26 +881,33 @@ local function add_rbl(key, rbl, global_opts) end if rbl.selector then - if known_selectors[rbl.selector] then - lua_util.debugm(N, rspamd_config, 'reuse selector id %s', - known_selectors[rbl.selector].id) - rbl.selector = known_selectors[rbl.selector].selector - rbl.selector_id = known_selectors[rbl.selector].id - else - -- Create a new flattened closure - local sel = selectors.create_selector_closure(rspamd_config, rbl.selector, '', true) - if not sel then - rspamd_logger.errx('invalid selector for rbl rule %s: %s', key, rbl.selector) - return false - end + rbl.selectors = {} + if type(rbl.selector) ~= 'table' then + rbl.selector = {['selector'] = rbl.selector} + end - rbl.selector = sel - known_selectors[rbl.selector] = { - selector = sel, - id = #lua_util.keys(known_selectors) + 1, - } - rbl.selector_id = known_selectors[rbl.selector].id + for selector_label, selector in pairs(rbl.selector) do + if known_selectors[selector] then + lua_util.debugm(N, rspamd_config, 'reuse selector id %s', + known_selectors[selector].id) + rbl.selectors[selector_label] = known_selectors[selector].selector + else + -- Create a new flattened closure + local sel = selectors.create_selector_closure(rspamd_config, selector, '', true) + + if not sel then + rspamd_logger.errx('invalid selector for rbl rule %s: %s', key, selector) + return false + end + + rbl.selector = sel + known_selectors[selector] = { + selector = sel, + id = #lua_util.keys(known_selectors) + 1, + } + rbl.selectors[selector_label] = known_selectors[selector].selector + end end end @@ -1188,7 +1197,7 @@ local rule_schema_tbl = { return_codes = return_codes_schema:is_optional(), returnbits = return_bits_schema:is_optional(), returncodes = return_codes_schema:is_optional(), - selector = ts.string:is_optional(), + selector = ts.one_of{ts.string, ts.table}:is_optional(), symbol = ts.string:is_optional(), symbols_prefixes = ts.map_of(ts.string, ts.string):is_optional(), unknown = ts.boolean:is_optional(), |