commit 55e758f: [Minor] Use standard utility to get check_local/authed

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Sep 4 16:14:05 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-09-04 16:33:12 +0100
URL: https://github.com/rspamd/rspamd/commit/55e758f714ced82a4a15b974f9154838938a2449 (HEAD -> master)

[Minor] Use standard utility to get check_local/authed

---
 src/plugins/lua/asn.lua           |  6 ++++++
 src/plugins/lua/greylist.lua      |  6 ++++++
 src/plugins/lua/hfilter.lua       | 22 ++++------------------
 src/plugins/lua/once_received.lua | 23 +++++------------------
 src/plugins/lua/spamtrap.lua      | 22 +++++-----------------
 src/plugins/lua/whitelist.lua     | 22 ++++------------------
 6 files changed, 30 insertions(+), 71 deletions(-)

diff --git a/src/plugins/lua/asn.lua b/src/plugins/lua/asn.lua
index 4c7d73dba..f641ac53c 100644
--- a/src/plugins/lua/asn.lua
+++ b/src/plugins/lua/asn.lua
@@ -110,6 +110,12 @@ local configure_asn_module = function()
       options[k] = v
     end
   end
+
+  local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+      false, true)
+  options.check_local = auth_and_local_conf[1]
+  options.check_authed = auth_and_local_conf[2]
+
   if options['provider_type'] == 'rspamd' then
     if not options['provider_info'] and options['provider_info']['ip4'] and
         options['provider_info']['ip6'] then
diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index 152788175..807859bff 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -83,6 +83,7 @@ local settings = {
 local rspamd_logger = require "rspamd_logger"
 local rspamd_util = require "rspamd_util"
 local lua_redis = require "lua_redis"
+local lua_util = require "lua_util"
 local fun = require "fun"
 local hash = require "rspamd_cryptobox_hash"
 local rspamd_lua_utils = require "lua_util"
@@ -464,6 +465,11 @@ if opts then
     end
   end
 
+  local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+      false, false)
+  settings.check_local = auth_and_local_conf[1]
+  settings.check_authed = auth_and_local_conf[2]
+
   if settings['greylist_min_score'] then
     settings['greylist_min_score'] = tonumber(settings['greylist_min_score'])
   else
diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua
index 962b302ba..9179f63b8 100644
--- a/src/plugins/lua/hfilter.lua
+++ b/src/plugins/lua/hfilter.lua
@@ -568,24 +568,10 @@ local symbols_from = {
   "HFILTER_FROM_BOUNCE"
 }
 
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
-
-if not try_opts(N) then try_opts('options') end
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 local opts = rspamd_config:get_all_opt('hfilter')
 if opts then
diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua
index 4f1e67c72..11e880cc5 100644
--- a/src/plugins/lua/once_received.lua
+++ b/src/plugins/lua/once_received.lua
@@ -31,6 +31,7 @@ local good_hosts = {}
 local whitelist = nil
 
 local rspamd_logger = require "rspamd_logger"
+local lua_util = require "lua_util"
 local fun = require "fun"
 local N = 'once_received'
 
@@ -156,24 +157,10 @@ local function check_quantity_received (task)
   end
 end
 
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
-
-if not try_opts(N) then try_opts('options') end
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 -- Configuration
 local opts = rspamd_config:get_all_opt(N)
diff --git a/src/plugins/lua/spamtrap.lua b/src/plugins/lua/spamtrap.lua
index fbe748db2..0b7a5bd9f 100644
--- a/src/plugins/lua/spamtrap.lua
+++ b/src/plugins/lua/spamtrap.lua
@@ -135,22 +135,6 @@ local function spamtrap_cb(task)
 end
 
 -- Module setup
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
 
 local opts = rspamd_config:get_all_opt('spamtrap')
 if not (opts and type(opts) == 'table') then
@@ -158,7 +142,11 @@ if not (opts and type(opts) == 'table') then
   return
 end
 
-if not try_opts(M) then try_opts('options') end
+
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, 'spamtrap',
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 if opts then
   for k,v in pairs(opts) do
diff --git a/src/plugins/lua/whitelist.lua b/src/plugins/lua/whitelist.lua
index ab04577b0..24b154c94 100644
--- a/src/plugins/lua/whitelist.lua
+++ b/src/plugins/lua/whitelist.lua
@@ -322,24 +322,10 @@ local configure_whitelist_module = function()
       options[k] = v
     end
 
-    local function try_opts(where)
-      local ret = false
-      local test_opts = rspamd_config:get_all_opt(where)
-      if type(test_opts) == 'table' then
-        if type(test_opts.check_local) == 'boolean' then
-          options.check_local = test_opts.check_local
-          ret = true
-        end
-        if type(test_opts.check_authed) == 'boolean' then
-          options.check_authed = test_opts.check_authed
-          ret = true
-        end
-      end
-
-      return ret
-    end
-
-    if not try_opts(N) then try_opts('options') end
+    local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+        false, false)
+    options.check_local = auth_and_local_conf[1]
+    options.check_authed = auth_and_local_conf[2]
   else
     rspamd_logger.infox(rspamd_config, 'Module is unconfigured')
     return


More information about the Commits mailing list