From 6bc88cf287a9af5a194ae6087a3c633dde41a265 Mon Sep 17 00:00:00 2001 From: Christian Roessner Date: Wed, 1 Mar 2017 14:10:28 +0100 Subject: [PATCH] [Minor] Chose correct virus name from returned string --- src/plugins/lua/antivirus.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index c7664f6d1..d848d789b 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -231,11 +231,16 @@ local function need_av_check(task, rule) end local function check_av_cache(task, rule, fn) + local key = task:get_digest() + local function redis_av_cb(err, data) if data and type(data) == 'string' then -- Cached if data ~= 'OK' then + rspamd_logger.debugm(N, task, 'got cached result for %s: %s', key, data) yield_result(task, rule, data) + else + rspamd_logger.debugm(N, task, 'got cached result for %s: %s', key, data) end else if err then @@ -246,7 +251,7 @@ local function check_av_cache(task, rule, fn) end if redis_params then - local key = task:get_digest() + if redis_params['prefix'] then key = redis_params['prefix'] .. key end @@ -274,6 +279,8 @@ local function save_av_cache(task, rule, to_save) if err then rspamd_logger.errx(task, 'failed to save virus cache for %s -> "%s": %s', to_save, key, err) + else + rspamd_logger.debugm(N, task, 'saved cached result for %s: %s', key, to_save) end end @@ -522,10 +529,7 @@ local function savapi_check(task, rule) elseif string.find(result, '310') then -- infected message rspamd_logger.debugm(N, task, 'infected message') - local parts = rspamd_str_split(result, ' ') - local message = parts[2] - -- A message: ; ; - local vname = rspamd_str_split(message, ';')[1] + local vname = rspamd_str_split(result, ' ')[4] rspamd_logger.infox(task, 'SAVAPI: virus found: %s', vname) yield_result(task, rule, vname) save_av_cache(task, rule, vname) @@ -677,11 +681,20 @@ if opts and type(opts) == 'table' then if not cb then rspamd_logger.errx(rspamd_config, 'cannot add rule: "' .. k .. '"') else - rspamd_config:register_symbol({ + local id = rspamd_config:register_symbol({ type = 'normal', 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 + }) + end + end if m['score'] then -- Register metric symbol local description = 'antivirus symbol' -- 2.39.5