diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-07-10 14:42:12 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-07-10 14:42:28 +0200 |
commit | 85d606bdbc00000f672e9a2c6613bbc34dadfc74 (patch) | |
tree | a4a073f723361c6b23ea1689bdc45e521f190bbd /src | |
parent | 81c4ddebc336c78e3a36ac7d865dc249f99a73be (diff) | |
download | rspamd-85d606bdbc00000f672e9a2c6613bbc34dadfc74.tar.gz rspamd-85d606bdbc00000f672e9a2c6613bbc34dadfc74.zip |
[Feature] Antivirus: ordered pattern matches
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/antivirus.lua | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index 0b9bf0b22..4802b239e 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -64,13 +64,24 @@ antivirus { end local function match_patterns(default_sym, found, patterns) - if not patterns then return default_sym end - for sym, pat in pairs(patterns) do - if pat:match(found) then - return sym + if type(patterns) ~= 'table' then return default_sym end + if not patterns[1] then + for sym, pat in pairs(patterns) do + if pat:match(found) then + return sym + end + end + return default_sym + else + for _, p in ipairs(patterns) do + for sym, pat in pairs(p) do + if pat:match(found) then + return sym + end + end end + return default_sym end - return default_sym end local function yield_result(task, rule, vname) @@ -749,10 +760,24 @@ local function add_antivirus_rule(sym, opts) return nil end - if opts['patterns'] then + if type(opts['patterns']) == 'table' then rule['patterns'] = {} - for k, v in pairs(opts['patterns']) do - rule['patterns'][k] = rspamd_regexp.create_cached(v) + if opts['patterns'][1] then + for i, p in ipairs(opts['patterns']) do + if type(p) == 'table' then + local new_set = {} + for k, v in pairs(p) do + new_set[k] = rspamd_regexp.create_cached(v) + end + rule['patterns'][i] = new_set + else + rule['patterns'][i] = {} + end + end + else + for k, v in pairs(opts['patterns']) do + rule['patterns'][k] = rspamd_regexp.create_cached(v) + end end end @@ -780,13 +805,27 @@ if opts and type(opts) == 'table' then name = m['symbol'], callback = cb, }) - if m['patterns'] then - for sym in pairs(m['patterns']) do - rspamd_config:register_symbol({ - type = 'virtual', - name = sym, - parent = id - }) + if type(m['patterns']) == 'table' then + if m['patterns'][1] then + for _, p in ipairs(m['patterns']) do + if type(p) == 'table' then + for sym in pairs(p) do + rspamd_config:register_symbol({ + type = 'virtual', + name = sym, + parent = id + }) + end + end + end + else + for sym in pairs(m['patterns']) do + rspamd_config:register_symbol({ + type = 'virtual', + name = sym, + parent = id + }) + end end end if m['score'] then |