aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_scanners/sophos.lua
diff options
context:
space:
mode:
authorCarsten Rosenberg <c.rosenberg@heinlein-support.de>2019-01-13 00:25:05 +0100
committerCarsten Rosenberg <c.rosenberg@heinlein-support.de>2019-01-13 00:25:05 +0100
commit2703711c00e1ab689e8fc1099abae15c21fb089a (patch)
tree4648b4032bd389dee851227e39469bfd630d83f5 /lualib/lua_scanners/sophos.lua
parent776a0273b5dc02498fcc24373bdb76ae608219fa (diff)
downloadrspamd-2703711c00e1ab689e8fc1099abae15c21fb089a.tar.gz
rspamd-2703711c00e1ab689e8fc1099abae15c21fb089a.zip
[Minor] lua_scanners - module_name, typos, logging
Diffstat (limited to 'lualib/lua_scanners/sophos.lua')
-rw-r--r--lualib/lua_scanners/sophos.lua47
1 files changed, 28 insertions, 19 deletions
diff --git a/lualib/lua_scanners/sophos.lua b/lualib/lua_scanners/sophos.lua
index b3eafc837..655cbc696 100644
--- a/lualib/lua_scanners/sophos.lua
+++ b/lualib/lua_scanners/sophos.lua
@@ -25,15 +25,16 @@ local upstream_list = require "rspamd_upstream_list"
local rspamd_logger = require "rspamd_logger"
local common = require "lua_scanners/common"
-local N = "sophos"
+local module_name = "sophos"
local default_message = '${SCANNER}: virus found: "${VIRUS}"'
local function sophos_config(opts)
local sophos_conf = {
- scan_mime_parts = true;
- scan_text_mime = false;
- scan_image_mime = false;
+ module_name = module_name,
+ scan_mime_parts = true,
+ scan_text_mime = false,
+ scan_image_mime = false,
default_port = 4010,
timeout = 15.0,
log_clean = false,
@@ -53,6 +54,14 @@ local function sophos_config(opts)
sophos_conf.prefix = 'rs_sp'
end
+ if not sophos_conf.log_prefix then
+ if sophos_conf.name:lower() == sophos_conf.type:lower() then
+ sophos_conf.log_prefix = sophos_conf.name
+ else
+ sophos_conf.log_prefix = sophos_conf.name .. ' (' .. sophos_conf.type .. ')'
+ end
+ end
+
if not sophos_conf['servers'] then
rspamd_logger.errx(rspamd_config, 'no servers defined')
@@ -64,7 +73,7 @@ local function sophos_config(opts)
sophos_conf.default_port)
if sophos_conf['upstreams'] then
- lua_util.add_debug_alias('antivirus', N)
+ lua_util.add_debug_alias('antivirus', sophos_conf.module_name)
return sophos_conf
end
@@ -97,7 +106,7 @@ local function sophos_check(task, content, digest, rule)
upstream = rule.upstreams:get_upstream_round_robin()
addr = upstream:get_addr()
- lua_util.debugm(N, task, '%s [%s]: retry IP: %s', rule['symbol'], rule['type'], addr)
+ lua_util.debugm(rule.module_name, task, '%s [%s]: retry IP: %s', rule['symbol'], rule['type'], addr)
tcp.request({
task = task,
@@ -114,19 +123,19 @@ local function sophos_check(task, content, digest, rule)
else
upstream:ok()
data = tostring(data)
- lua_util.debugm(N, task, '%s [%s]: got reply: %s', rule['symbol'], rule['type'], data)
+ lua_util.debugm(rule.module_name, task, '%s [%s]: got reply: %s', rule['symbol'], rule['type'], data)
local vname = string.match(data, 'VIRUS (%S+) ')
if vname then
- common.yield_result(task, rule, vname, N)
- common.save_av_cache(task, digest, rule, vname, N)
+ common.yield_result(task, rule, vname)
+ common.save_av_cache(task, digest, rule, vname)
else
if string.find(data, 'DONE OK') then
if rule['log_clean'] then
rspamd_logger.infox(task, '%s [%s]: message or mime_part is clean', rule['symbol'], rule['type'])
else
- lua_util.debugm(N, task, '%s [%s]: message or mime_part is clean', rule['symbol'], rule['type'])
+ lua_util.debugm(rule.module_name, task, '%s [%s]: message or mime_part is clean', rule['symbol'], rule['type'])
end
- common.save_av_cache(task, digest, rule, 'OK', N)
+ common.save_av_cache(task, digest, rule, 'OK')
-- not finished - continue
elseif string.find(data, 'ACC') or string.find(data, 'OK SSSP') then
conn:add_read(sophos_callback)
@@ -134,15 +143,15 @@ local function sophos_check(task, content, digest, rule)
elseif string.find(data, 'FAIL 0212') then
rspamd_logger.infox(task, 'Message is ENCRYPTED (0212 SOPHOS_SAVI_ERROR_FILE_ENCRYPTED): %s', data)
if rule['savdi_report_encrypted'] then
- common.yield_result(task, rule, "SAVDI_FILE_ENCRYPTED", N)
- common.save_av_cache(task, digest, rule, "SAVDI_FILE_ENCRYPTED", N)
+ common.yield_result(task, rule, "SAVDI_FILE_ENCRYPTED")
+ common.save_av_cache(task, digest, rule, "SAVDI_FILE_ENCRYPTED")
end
-- set pseudo virus if configured, else set fail since part was not scanned
elseif string.find(data, 'REJ 4') then
if rule['savdi_report_oversize'] then
rspamd_logger.infox(task, 'SAVDI: Message is OVERSIZED (SSSP reject code 4): %s', data)
- common.yield_result(task, rule, "SAVDI_FILE_OVERSIZED", N)
- common.save_av_cache(task, digest, rule, "SAVDI_FILE_OVERSIZED", N)
+ common.yield_result(task, rule, "SAVDI_FILE_OVERSIZED")
+ common.save_av_cache(task, digest, rule, "SAVDI_FILE_OVERSIZED")
else
rspamd_logger.errx(task, 'SAVDI: Message is OVERSIZED (SSSP reject code 4): %s', data)
task:insert_result(rule['symbol_fail'], 0.0, 'Message is OVERSIZED (SSSP reject code 4):' .. data)
@@ -170,8 +179,8 @@ local function sophos_check(task, content, digest, rule)
})
end
- if common.need_av_check(task, content, rule, N) then
- if common.check_av_cache(task, digest, rule, sophos_check_uncached, N) then
+ if common.need_av_check(task, content, rule) then
+ if common.check_av_cache(task, digest, rule, sophos_check_uncached) then
return
else
sophos_check_uncached()
@@ -184,5 +193,5 @@ return {
description = 'sophos antivirus',
configure = sophos_config,
check = sophos_check,
- name = 'sophos'
-} \ No newline at end of file
+ name = module_name
+}