From: Vsevolod Stakhov Date: Tue, 2 Oct 2018 11:55:55 +0000 (+0100) Subject: [Minor] Unify check_auth/check_local options X-Git-Tag: 1.8.1~106 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4c9f6b21186be5c87785d5f6c91fb26cb8300b5b;p=rspamd.git [Minor] Unify check_auth/check_local options --- diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 67aa8eb8e..f728fb5ec 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -320,15 +320,26 @@ dkim_module_config (struct rspamd_config *cfg) lua_pop (cfg->lua_state, 1); /* Remove global function */ dkim_module_ctx->whitelist_ip = NULL; - if ((value = - rspamd_config_get_module_opt (cfg, "dkim", "check_local")) != NULL) { + value = rspamd_config_get_module_opt (cfg, "dkim", "check_local"); + + if (value == NULL) { + rspamd_config_get_module_opt (cfg, "options", "check_local"); + } + + if (value != NULL) { dkim_module_ctx->check_local = ucl_object_toboolean (value); } else { dkim_module_ctx->check_local = FALSE; } - if ((value = - rspamd_config_get_module_opt (cfg, "dkim", "check_authed")) != NULL) { + + value = rspamd_config_get_module_opt (cfg, "dkim", "check_authed"); + + if (value == NULL) { + rspamd_config_get_module_opt (cfg, "options", "check_authed"); + } + + if (value != NULL) { dkim_module_ctx->check_authed = ucl_object_toboolean (value); } else { diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index 38f54f1f8..69e210e47 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -561,17 +561,26 @@ local function dmarc_callback(task) forced = true}) end -local opts = rspamd_config:get_all_opt('options') -if type(opts) == 'table' then - if type(opts['check_local']) == 'boolean' then - check_local = opts['check_local'] - end - if type(opts['check_authed']) == 'boolean' then - check_authed = opts['check_authed'] +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 -opts = rspamd_config:get_all_opt('dmarc') +if not try_opts(N) then try_opts('options') end + +local opts = rspamd_config:get_all_opt('dmarc') if not opts or type(opts) ~= 'table' then return end diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua index b63483f41..334378ba4 100644 --- a/src/plugins/lua/hfilter.lua +++ b/src/plugins/lua/hfilter.lua @@ -569,17 +569,26 @@ local symbols_from = { "HFILTER_FROM_BOUNCE" } -local opts = rspamd_config:get_all_opt('options') -if type(opts) == 'table' then - if type(opts['check_local']) == 'boolean' then - check_local = opts['check_local'] - end - if type(opts['check_authed']) == 'boolean' then - check_authed = opts['check_authed'] +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 -opts = rspamd_config:get_all_opt('hfilter') +if not try_opts(N) then try_opts('options') end + +local opts = rspamd_config:get_all_opt('hfilter') if opts then for k,v in pairs(opts) do config[k] = v diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index 47b000b8b..d3aec2264 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -356,18 +356,29 @@ local ip_score_check = function(task) end end - --- Configuration options -local configure_ip_score_module = function() - local opts = rspamd_config:get_all_opt(N) +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_authed']) == 'boolean' then - check_authed = opts['check_authed'] - end 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 + +-- Configuration options +local configure_ip_score_module = function() + local opts = rspamd_config:get_all_opt(N) + if not opts then return end for k,v in pairs(opts) do options[k] = v diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua index b09a87dbe..c8c47ddb1 100644 --- a/src/plugins/lua/once_received.lua +++ b/src/plugins/lua/once_received.lua @@ -32,6 +32,7 @@ local whitelist = nil local rspamd_logger = require "rspamd_logger" local fun = require "fun" +local N = 'once_received' local check_local = false local check_authed = false @@ -152,17 +153,27 @@ local function check_quantity_received (task) end end -local opts = rspamd_config:get_all_opt('options') -if type(opts) == 'table' then - if type(opts['check_local']) == 'boolean' then - check_local = opts['check_local'] - end - if type(opts['check_authed']) == 'boolean' then - check_authed = opts['check_authed'] +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 + -- Configuration -opts = rspamd_config:get_all_opt('once_received') +local opts = rspamd_config:get_all_opt(N) if opts then if opts['symbol'] then symbol = opts['symbol'] diff --git a/src/plugins/lua/spamtrap.lua b/src/plugins/lua/spamtrap.lua index cf0b89957..f1582f8ce 100644 --- a/src/plugins/lua/spamtrap.lua +++ b/src/plugins/lua/spamtrap.lua @@ -31,10 +31,11 @@ local settings = { fuzzy_flag = 1, fuzzy_weight = 10.0, key_prefix = 'sptr_', - check_authed = true, - check_local = true, } +local check_authed = true +local check_local = true + local function spamtrap_cb(task) local rcpts = task:get_recipients('smtp') local authed_user = task:get_user() @@ -42,8 +43,8 @@ local function spamtrap_cb(task) local called_for_domain = false local target - if ((not settings['check_authed'] and authed_user) or - (not settings['check_local'] and ip_addr and ip_addr:is_local())) then + if ((not check_authed and authed_user) or + (not check_local and ip_addr and ip_addr:is_local())) then rspamd_logger.infox(task, "skip spamtrap checks for local networks or authenticated user"); return end @@ -141,6 +142,26 @@ if not (opts and type(opts) == 'table') then rspamd_logger.infox(rspamd_config, 'module is unconfigured') return 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(M) then try_opts('options') end + if opts then for k,v in pairs(opts) do settings[k] = v diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 5ec5bfcfc..46160878f 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -206,15 +206,26 @@ spf_module_config (struct rspamd_config *cfg) spf_module_ctx->whitelist_ip = NULL; - if ((value = - rspamd_config_get_module_opt (cfg, "options", "check_local")) != NULL) { + value = rspamd_config_get_module_opt (cfg, "spf", "check_local"); + + if (value == NULL) { + rspamd_config_get_module_opt (cfg, "options", "check_local"); + } + + if (value != NULL) { spf_module_ctx->check_local = ucl_obj_toboolean (value); } else { spf_module_ctx->check_local = FALSE; } - if ((value = - rspamd_config_get_module_opt (cfg, "options", "check_authed")) != NULL) { + + value = rspamd_config_get_module_opt (cfg, "spf", "check_authed"); + + if (value == NULL) { + rspamd_config_get_module_opt (cfg, "options", "check_authed"); + } + + if (value != NULL) { spf_module_ctx->check_authed = ucl_obj_toboolean (value); } else {