commit 2703711: [Minor] lua_scanners - module_name, typos, logging

Carsten Rosenberg c.rosenberg at heinlein-support.de
Thu Jan 17 15:07:03 UTC 2019


Author: Carsten Rosenberg
Date: 2019-01-13 00:25:05 +0100
URL: https://github.com/rspamd/rspamd/commit/2703711c00e1ab689e8fc1099abae15c21fb089a

[Minor] lua_scanners - module_name, typos, logging

---
 lualib/lua_scanners/clamav.lua        | 43 +++++++++++++++++++-------------
 lualib/lua_scanners/dcc.lua           | 27 ++++++++++++--------
 lualib/lua_scanners/fprot.lua         | 33 +++++++++++++++---------
 lualib/lua_scanners/kaspersky_av.lua  | 37 ++++++++++++++++-----------
 lualib/lua_scanners/savapi.lua        | 41 ++++++++++++++++++------------
 lualib/lua_scanners/sophos.lua        | 47 +++++++++++++++++++++--------------
 src/plugins/lua/antivirus.lua         |  1 +
 src/plugins/lua/external_services.lua |  1 +
 8 files changed, 141 insertions(+), 89 deletions(-)

diff --git a/lualib/lua_scanners/clamav.lua b/lualib/lua_scanners/clamav.lua
index b7de739cd..9eb44e53a 100644
--- a/lualib/lua_scanners/clamav.lua
+++ b/lualib/lua_scanners/clamav.lua
@@ -26,15 +26,16 @@ local rspamd_util = require "rspamd_util"
 local rspamd_logger = require "rspamd_logger"
 local common = require "lua_scanners/common"
 
-local N = "clamav"
+local module_name = "clamav"
 
 local default_message = '${SCANNER}: virus found: "${VIRUS}"'
 
 local function clamav_config(opts)
   local clamav_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 = 3310,
     log_clean = false,
     timeout = 5.0, -- FIXME: this will break task_timeout!
@@ -52,6 +53,14 @@ local function clamav_config(opts)
     clamav_conf.prefix = 'rs_cl'
   end
 
+  if not clamav_conf.log_prefix then
+    if clamav_conf.name:lower() == clamav_conf.type:lower() then
+      clamav_conf.log_prefix = clamav_conf.name
+    else
+      clamav_conf.log_prefix = clamav_conf.name .. ' (' .. clamav_conf.type .. ')'
+    end
+  end
+
   if not clamav_conf['servers'] then
     rspamd_logger.errx(rspamd_config, 'no servers defined')
 
@@ -63,7 +72,7 @@ local function clamav_config(opts)
       clamav_conf.default_port)
 
   if clamav_conf['upstreams'] then
-    lua_util.add_debug_alias('antivirus', N)
+    lua_util.add_debug_alias('antivirus', clamav_conf.module_name)
     return clamav_conf
   end
 
@@ -96,7 +105,7 @@ local function clamav_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: retry IP: %s', rule.log_prefix, addr)
 
           tcp.request({
             task = task,
@@ -108,7 +117,7 @@ local function clamav_check(task, content, digest, rule)
             stop_pattern = '\0'
           })
         else
-          rspamd_logger.errx(task, '%s [%s]: failed to scan, maximum retransmits exceed', rule['symbol'], rule['type'])
+          rspamd_logger.errx(task, '%s: failed to scan, maximum retransmits exceed', rule.log_prefix)
           task:insert_result(rule['symbol_fail'], 0.0, 'failed to scan and retransmits exceed')
         end
 
@@ -116,26 +125,26 @@ local function clamav_check(task, content, digest, rule)
         upstream:ok()
         data = tostring(data)
         local cached
-        lua_util.debugm(N, task, '%s [%s]: got reply: %s', rule['symbol'], rule['type'], data)
+        lua_util.debugm(rule.module_name, task, '%s: got reply: %s', rule.log_prefix, data)
         if data == 'stream: OK' then
           cached = 'OK'
           if rule['log_clean'] then
-            rspamd_logger.infox(task, '%s [%s]: message or mime_part is clean', rule['symbol'], rule['type'])
+            rspamd_logger.infox(task, '%s: message or mime_part is clean', rule.log_prefix)
           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: message or mime_part is clean', rule.log_prefix)
           end
         else
           local vname = string.match(data, 'stream: (.+) FOUND')
           if vname then
-            common.yield_result(task, rule, vname, N)
+            common.yield_result(task, rule, vname)
             cached = vname
           else
-            rspamd_logger.errx(task, 'unhandled response: %s', data)
+            rspamd_logger.errx(task, '%s: unhandled response: %s', rule.log_prefix, data)
             task:insert_result(rule['symbol_fail'], 0.0, 'unhandled response')
           end
         end
         if cached then
-          common.save_av_cache(task, digest, rule, cached, N)
+          common.save_av_cache(task, digest, rule, cached)
         end
       end
     end
@@ -151,8 +160,8 @@ local function clamav_check(task, content, digest, rule)
     })
   end
 
-  if common.need_av_check(task, content, rule, N) then
-    if common.check_av_cache(task, digest, rule, clamav_check_uncached, N) then
+  if common.need_av_check(task, content, rule) then
+    if common.check_av_cache(task, digest, rule, clamav_check_uncached) then
       return
     else
       clamav_check_uncached()
@@ -165,5 +174,5 @@ return {
   description = 'clamav antivirus',
   configure = clamav_config,
   check = clamav_check,
-  name = 'clamav'
-}
\ No newline at end of file
+  name = module_name
+}
diff --git a/lualib/lua_scanners/dcc.lua b/lualib/lua_scanners/dcc.lua
index b6c3d552f..281672558 100644
--- a/lualib/lua_scanners/dcc.lua
+++ b/lualib/lua_scanners/dcc.lua
@@ -27,7 +27,7 @@ local rspamd_logger = require "rspamd_logger"
 local common = require "lua_scanners/common"
 local fun = require "fun"
 
-local N = 'dcc'
+local module_name = 'dcc'
 
 local function dcc_check(task, content, _, rule)
   local function dcc_check_uncached ()
@@ -95,7 +95,7 @@ local function dcc_check(task, content, _, rule)
           upstream = rule.upstreams:get_upstream_round_robin()
           addr = upstream:get_addr()
 
-          lua_util.debugm(N, task, '%s: retry IP: %s', rule.log_prefix, addr)
+          lua_util.debugm(rule.module_name, task, '%s: retry IP: %s', rule.log_prefix, addr)
 
           tcp.request({
             task = task,
@@ -117,7 +117,7 @@ local function dcc_check(task, content, _, rule)
         -- Parse the response
         if upstream then upstream:ok() end
         local _,_,result,disposition,header = tostring(data):find("(.-)\n(.-)\n(.-)\n")
-        lua_util.debugm(N, task, 'DCC result=%1 disposition=%2 header="%3"',
+        lua_util.debugm(rule.module_name, task, 'DCC result=%1 disposition=%2 header="%3"',
             result, disposition, header)
 
         if header then
@@ -137,7 +137,7 @@ local function dcc_check(task, content, _, rule)
               rspamd_logger.infox(task, '%s: clean, returned result A - info: %s',
                   rule.log_prefix, info)
             else
-              lua_util.debugm(N, task, '%s: returned result A - info: %s',
+              lua_util.debugm(rule.module_name, task, '%s: returned result A - info: %s',
                   rule.log_prefix, info)
 
               local opts = {}
@@ -202,11 +202,11 @@ local function dcc_check(task, content, _, rule)
             if rule.log_clean then
               rspamd_logger.infox(task, '%s: clean, returned result S - info: %s', rule.log_prefix, info)
             else
-              lua_util.debugm(N, task, '%s: returned result S - info: %s', rule.log_prefix, info)
+              lua_util.debugm(rule.module_name, task, '%s: returned result S - info: %s', rule.log_prefix, info)
             end
           else
             -- Unknown result
-            rspamd_logger.warnx(task, 'DCC result error: %1', result);
+            rspamd_logger.warnx(task, '%s: result error: %1', rule.log_prefix, result);
             task:insert_result(rule.symbol_fail,
                 0.0,
                 'error: ' .. result)
@@ -225,7 +225,7 @@ local function dcc_check(task, content, _, rule)
       callback = dcc_callback
     })
   end
-  if common.need_av_check(task, content, rule, N) then
+  if common.need_av_check(task, content, rule) then
     dcc_check_uncached()
   end
 end
@@ -233,6 +233,7 @@ end
 local function dcc_config(opts)
 
   local dcc_conf = {
+    module_name = module_name,
     default_port = 10045,
     timeout = 5.0,
     log_clean = false,
@@ -253,7 +254,11 @@ local function dcc_config(opts)
   dcc_conf = lua_util.override_defaults(dcc_conf, opts)
 
   if not dcc_conf.log_prefix then
-    dcc_conf.log_prefix = N
+    if dcc_conf.name:lower() == dcc_conf.type:lower() then
+      dcc_conf.log_prefix = dcc_conf.name
+    else
+      dcc_conf.log_prefix = dcc_conf.name .. ' (' .. dcc_conf.type .. ')'
+    end
   end
 
   if not dcc_conf.servers and dcc_conf.socket then
@@ -271,7 +276,7 @@ local function dcc_config(opts)
       dcc_conf.default_port)
 
   if dcc_conf.upstreams then
-    lua_util.add_debug_alias('external_services', N)
+    lua_util.add_debug_alias('external_services', dcc_conf.module_name)
     return dcc_conf
   end
 
@@ -285,5 +290,5 @@ return {
   description = 'dcc bulk scanner',
   configure = dcc_config,
   check = dcc_check,
-  name = 'dcc'
-}
\ No newline at end of file
+  name = module_name
+}
diff --git a/lualib/lua_scanners/fprot.lua b/lualib/lua_scanners/fprot.lua
index bfa0b4d33..d0736263e 100644
--- a/lualib/lua_scanners/fprot.lua
+++ b/lualib/lua_scanners/fprot.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 = "fprot"
+local module_name = "fprot"
 
 local default_message = '${SCANNER}: virus found: "${VIRUS}"'
 
 local function fprot_config(opts)
   local fprot_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 = 10200,
     timeout = 5.0, -- FIXME: this will break task_timeout!
     log_clean = false,
@@ -51,6 +52,14 @@ local function fprot_config(opts)
     fprot_conf.prefix = 'rs_fp'
   end
 
+  if not fprot_conf.log_prefix then
+    if fprot_conf.name:lower() == fprot_conf.type:lower() then
+      fprot_conf.log_prefix = fprot_conf.name
+    else
+      fprot_conf.log_prefix = fprot_conf.name .. ' (' .. fprot_conf.type .. ')'
+    end
+  end
+
   if not fprot_conf['servers'] then
     rspamd_logger.errx(rspamd_config, 'no servers defined')
 
@@ -62,7 +71,7 @@ local function fprot_config(opts)
       fprot_conf.default_port)
 
   if fprot_conf['upstreams'] then
-    lua_util.add_debug_alias('antivirus', N)
+    lua_util.add_debug_alias('antivirus', fprot_conf.module_name)
     return fprot_conf
   end
 
@@ -96,7 +105,7 @@ local function fprot_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,
@@ -133,12 +142,12 @@ local function fprot_check(task, content, digest, rule)
           if not vname then
             rspamd_logger.errx(task, 'Unhandled response: %s', data)
           else
-            common.yield_result(task, rule, vname, N)
+            common.yield_result(task, rule, vname)
             cached = vname
           end
         end
         if cached then
-          common.save_av_cache(task, digest, rule, cached, N)
+          common.save_av_cache(task, digest, rule, cached)
         end
       end
     end
@@ -154,8 +163,8 @@ local function fprot_check(task, content, digest, rule)
     })
   end
 
-  if common.need_av_check(task, content, rule, N) then
-    if common.check_av_cache(task, digest, rule, fprot_check_uncached, N) then
+  if common.need_av_check(task, content, rule) then
+    if common.check_av_cache(task, digest, rule, fprot_check_uncached) then
       return
     else
       fprot_check_uncached()
@@ -168,5 +177,5 @@ return {
   description = 'fprot antivirus',
   configure = fprot_config,
   check = fprot_check,
-  name = 'fprot'
-}
\ No newline at end of file
+  name = module_name
+}
diff --git a/lualib/lua_scanners/kaspersky_av.lua b/lualib/lua_scanners/kaspersky_av.lua
index 40cb6eb76..b9b439f05 100644
--- a/lualib/lua_scanners/kaspersky_av.lua
+++ b/lualib/lua_scanners/kaspersky_av.lua
@@ -26,15 +26,16 @@ local rspamd_util = require "rspamd_util"
 local rspamd_logger = require "rspamd_logger"
 local common = require "lua_scanners/common"
 
-local N = "kaspersky"
+local module_name = "kaspersky"
 
 local default_message = '${SCANNER}: virus found: "${VIRUS}"'
 
 local function kaspersky_config(opts)
   local kaspersky_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,
     product_id = 0,
     log_clean = false,
     timeout = 5.0,
@@ -48,6 +49,14 @@ local function kaspersky_config(opts)
 
   kaspersky_conf = lua_util.override_defaults(kaspersky_conf, opts)
 
+  if not kaspersky_conf.log_prefix then
+    if kaspersky_conf.name:lower() == kaspersky_conf.type:lower() then
+      kaspersky_conf.log_prefix = kaspersky_conf.name
+    else
+      kaspersky_conf.log_prefix = kaspersky_conf.name .. ' (' .. kaspersky_conf.type .. ')'
+    end
+  end
+
   if not kaspersky_conf['servers'] then
     rspamd_logger.errx(rspamd_config, 'no servers defined')
 
@@ -58,7 +67,7 @@ local function kaspersky_config(opts)
       kaspersky_conf['servers'], 0)
 
   if kaspersky_conf['upstreams'] then
-    lua_util.add_debug_alias('antivirus', N)
+    lua_util.add_debug_alias('antivirus', kaspersky_conf.module_name)
     return kaspersky_conf
   end
 
@@ -110,7 +119,7 @@ local function kaspersky_check(task, content, digest, rule)
           upstream = rule.upstreams:get_upstream_round_robin()
           addr = upstream:get_addr()
 
-          lua_util.debugm(N, task,
+          lua_util.debugm(rule.module_name, task,
               '%s [%s]: retry IP: %s', rule['symbol'], rule['type'], addr)
 
           tcp.request({
@@ -134,7 +143,7 @@ local function kaspersky_check(task, content, digest, rule)
         upstream:ok()
         data = tostring(data)
         local cached
-        lua_util.debugm(N, task, '%s [%s]: got reply: %s',
+        lua_util.debugm(rule.module_name, task, '%s [%s]: got reply: %s',
             rule['symbol'], rule['type'], data)
         if data == 'stream: OK' then
           cached = 'OK'
@@ -142,13 +151,13 @@ local function kaspersky_check(task, content, digest, rule)
             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',
+            lua_util.debugm(rule.module_name, task, '%s [%s]: message or mime_part is clean',
                 rule['symbol'], rule['type'])
           end
         else
           local vname = string.match(data, ': (.+) FOUND')
           if vname then
-            common.yield_result(task, rule, vname, N)
+            common.yield_result(task, rule, vname)
             cached = vname
           else
             rspamd_logger.errx(task, 'unhandled response: %s', data)
@@ -156,7 +165,7 @@ local function kaspersky_check(task, content, digest, rule)
           end
         end
         if cached then
-          common.save_av_cache(task, digest, rule, cached, N)
+          common.save_av_cache(task, digest, rule, cached)
         end
       end
     end
@@ -172,8 +181,8 @@ local function kaspersky_check(task, content, digest, rule)
     })
   end
 
-  if common.need_av_check(task, content, rule, N) then
-    if common.check_av_cache(task, digest, rule, kaspersky_check_uncached, N) then
+  if common.need_av_check(task, content, rule) then
+    if common.check_av_cache(task, digest, rule, kaspersky_check_uncached) then
       return
     else
       kaspersky_check_uncached()
@@ -186,5 +195,5 @@ return {
   description = 'kaspersky antivirus',
   configure = kaspersky_config,
   check = kaspersky_check,
-  name = 'kaspersky'
-}
\ No newline at end of file
+  name = module_name
+}
diff --git a/lualib/lua_scanners/savapi.lua b/lualib/lua_scanners/savapi.lua
index fab9de31b..d8ae8957b 100644
--- a/lualib/lua_scanners/savapi.lua
+++ b/lualib/lua_scanners/savapi.lua
@@ -26,15 +26,16 @@ local rspamd_util = require "rspamd_util"
 local rspamd_logger = require "rspamd_logger"
 local common = require "lua_scanners/common"
 
-local N = "savapi"
+local module_name = "savapi"
 
 local default_message = '${SCANNER}: virus found: "${VIRUS}"'
 
 local function savapi_config(opts)
   local savapi_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 = 4444, -- note: You must set ListenAddress in savapi.conf
     product_id = 0,
     log_clean = false,
@@ -54,6 +55,14 @@ local function savapi_config(opts)
     savapi_conf.prefix = 'rs_ap'
   end
 
+  if not savapi_conf.log_prefix then
+    if savapi_conf.name:lower() == savapi_conf.type:lower() then
+      savapi_conf.log_prefix = savapi_conf.name
+    else
+      savapi_conf.log_prefix = savapi_conf.name .. ' (' .. savapi_conf.type .. ')'
+    end
+  end
+
   if not savapi_conf['servers'] then
     rspamd_logger.errx(rspamd_config, 'no servers defined')
 
@@ -65,7 +74,7 @@ local function savapi_config(opts)
       savapi_conf.default_port)
 
   if savapi_conf['upstreams'] then
-    lua_util.add_debug_alias('antivirus', N)
+    lua_util.add_debug_alias('antivirus', savapi_conf.module_name)
     return savapi_conf
   end
 
@@ -112,15 +121,15 @@ local function savapi_check(task, content, digest, rule)
       for virus,_ in pairs(vnames) do
         table.insert(vnames_reordered, virus)
       end
-      lua_util.debugm(N, task, "%s: number of virus names found %s", rule['type'], #vnames_reordered)
+      lua_util.debugm(rule.module_name, task, "%s: number of virus names found %s", rule['type'], #vnames_reordered)
       if #vnames_reordered > 0 then
         local vname = {}
         for _,virus in ipairs(vnames_reordered) do
           table.insert(vname, virus)
         end
 
-        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)
       end
       if conn then
         conn:close()
@@ -129,7 +138,7 @@ local function savapi_check(task, content, digest, rule)
 
     local function savapi_scan2_cb(err, data, conn)
       local result = tostring(data)
-      lua_util.debugm(N, task, "%s: got reply: %s",
+      lua_util.debugm(rule.module_name, task, "%s: got reply: %s",
           rule['type'], result)
 
       -- Terminal response - clean
@@ -137,7 +146,7 @@ local function savapi_check(task, content, digest, rule)
         if rule['log_clean'] then
           rspamd_logger.infox(task, '%s: message or mime_part is clean', rule['type'])
         end
-        common.save_av_cache(task, digest, rule, 'OK', N)
+        common.save_av_cache(task, digest, rule, 'OK')
         conn:add_write(savapi_fin_cb, 'QUIT\n')
 
         -- Terminal response - infected
@@ -171,7 +180,7 @@ local function savapi_check(task, content, digest, rule)
     local function savapi_greet2_cb(err, data, conn)
       local result = tostring(data)
       if string.find(result, '100 PRODUCT') then
-        lua_util.debugm(N, task, "%s: scanning file: %s",
+        lua_util.debugm(rule.module_name, task, "%s: scanning file: %s",
             rule['type'], fname)
         conn:add_write(savapi_scan1_cb, {string.format('SCAN %s\n',
             fname)})
@@ -201,7 +210,7 @@ local function savapi_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,
@@ -236,8 +245,8 @@ local function savapi_check(task, content, digest, rule)
     })
   end
 
-  if common.need_av_check(task, content, rule, N) then
-    if common.check_av_cache(task, digest, rule, savapi_check_uncached, N) then
+  if common.need_av_check(task, content, rule) then
+    if common.check_av_cache(task, digest, rule, savapi_check_uncached) then
       return
     else
       savapi_check_uncached()
@@ -250,5 +259,5 @@ return {
   description = 'savapi avira antivirus',
   configure = savapi_config,
   check = savapi_check,
-  name = 'savapi'
-}
\ No newline at end of file
+  name = module_name
+}
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
+}
diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua
index 2f8f948ad..07dbba2f0 100644
--- a/src/plugins/lua/antivirus.lua
+++ b/src/plugins/lua/antivirus.lua
@@ -164,6 +164,7 @@ if opts and type(opts) == 'table' then
   for k, m in pairs(opts) do
     if type(m) == 'table' and m.servers then
       if not m.type then m.type = k end
+      if not m.name then m.name = k end
*** OUTPUT TRUNCATED, 15 LINES SKIPPED ***


More information about the Commits mailing list