commit d75fdb4: [Minor] Reputation: Support compatible whitelist definition
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Nov 9 11:56:10 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-11-09 11:54:11 +0000
URL: https://github.com/rspamd/rspamd/commit/d75fdb486e4025e5396f915154f861b55923f6d0
[Minor] Reputation: Support compatible whitelist definition
Issue: #3545
---
src/plugins/lua/reputation.lua | 40 ++++++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua
index aa3215b57..0f6bed93b 100644
--- a/src/plugins/lua/reputation.lua
+++ b/src/plugins/lua/reputation.lua
@@ -248,7 +248,7 @@ local dkim_selector = {
dependencies = {"DKIM_TRACE"},
filter = dkim_reputation_filter, -- used to get scores
postfilter = dkim_reputation_postfilter, -- used to adjust DKIM scores
- idempotent = dkim_reputation_idempotent -- used to set scores
+ idempotent = dkim_reputation_idempotent, -- used to set scores
}
-- URL Selector functions
@@ -523,7 +523,7 @@ local ip_selector = {
--dependencies = {"ASN"}, -- ASN is a prefilter now...
init = ip_reputation_init,
filter = ip_reputation_filter, -- used to get scores
- idempotent = ip_reputation_idempotent -- used to set scores
+ idempotent = ip_reputation_idempotent, -- used to set scores
}
-- SPF Selector functions
@@ -584,7 +584,7 @@ local spf_selector = {
},
dependencies = {"R_SPF_ALLOW"},
filter = spf_reputation_filter, -- used to get scores
- idempotent = spf_reputation_idempotent -- used to set scores
+ idempotent = spf_reputation_idempotent, -- used to set scores
}
-- Generic selector based on lua_selectors framework
@@ -680,7 +680,7 @@ local generic_selector = {
inbound = ts.boolean,
selector = ts.string,
delimiter = ts.string,
- whitelist = ts.string:is_optional(),
+ whitelist = ts.one_of(lua_maps.map_schema, lua_maps_exprs.schema):is_optional(),
},
config = {
lower_bound = 10, -- minimum number of messages to be scored
@@ -1122,8 +1122,36 @@ local function parse_rule(name, tbl)
rule.config = lua_util.override_defaults(rule.config, tbl)
if rule.config.whitelist then
- rule.config.whitelist_map = lua_maps_exprs.create(rspamd_config,
- rule.config.whitelist, N)
+ if lua_maps_exprs.schema(rule.config.whitelist) then
+ rule.config.whitelist_map = lua_maps_exprs.create(rspamd_config,
+ rule.config.whitelist, N)
+ elseif lua_maps.map_schema(rule.config.whitelist) then
+ local map = lua_maps.map_add_from_ucl(rule.config.whitelist,
+ 'radix',
+ sel_type .. ' reputation whitelist')
+
+ if not map then
+ rspamd_logger.errx(rspamd_config, "cannot parse whitelist map config for %s: (%s)",
+ sel_type,
+ rule.config.whitelist)
+ return
+ end
+
+ rule.config.whitelist_map = {
+ process = function(_, task)
+ -- Hack: we assume that it is an ip whitelist :(
+ local ip = task:get_from_ip()
+
+ if ip and map:get_key(ip) then return true end
+ return false
+ end
+ }
+ else
+ rspamd_logger.errx(rspamd_config, "cannot parse whitelist map config for %s: (%s)",
+ sel_type,
+ rule.config.whitelist)
+ return
+ end
end
local symbol = rule.selector.config.symbol or name
More information about the Commits
mailing list