aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lua/lua_config.c7
-rw-r--r--src/plugins/lua/dcc.lua5
-rw-r--r--src/plugins/lua/dmarc.lua33
-rw-r--r--src/plugins/lua/emails.lua19
-rw-r--r--src/plugins/lua/forged_recipients.lua130
-rw-r--r--src/plugins/lua/ip_score.lua5
-rw-r--r--src/plugins/lua/maillist.lua13
-rw-r--r--src/plugins/lua/mime_types.lua26
-rw-r--r--src/plugins/lua/multimap.lua14
-rw-r--r--src/plugins/lua/once_received.lua19
-rw-r--r--src/plugins/lua/phishing.lua14
-rw-r--r--src/plugins/lua/ratelimit.lua6
-rw-r--r--src/plugins/lua/rbl.lua20
-rw-r--r--src/plugins/lua/spamassassin.lua6
-rw-r--r--src/plugins/lua/trie.lua37
-rw-r--r--src/plugins/lua/whitelist.lua7
16 files changed, 231 insertions, 130 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index a974a7f52..0737584c5 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -968,6 +968,9 @@ lua_parse_symbol_type (const gchar *str)
else if (strcmp (str, "normal") == 0) {
ret = SYMBOL_TYPE_NORMAL;
}
+ else {
+ msg_warn ("bad type: %s", str);
+ }
}
return ret;
@@ -1019,10 +1022,10 @@ lua_config_register_symbol (lua_State * L)
type = lua_parse_symbol_type (type_str);
- if (!name && type != SYMBOL_TYPE_CALLBACK) {
+ if (!name && !(type & SYMBOL_TYPE_CALLBACK)) {
return luaL_error (L, "no symbol name but type is not callback");
}
- else if (type != SYMBOL_TYPE_VIRTUAL && cbref == -1) {
+ else if (!(type & SYMBOL_TYPE_VIRTUAL) && cbref == -1) {
return luaL_error (L, "no callback for symbol %s", name);
}
diff --git a/src/plugins/lua/dcc.lua b/src/plugins/lua/dcc.lua
index 9dc7a8ea9..216139fab 100644
--- a/src/plugins/lua/dcc.lua
+++ b/src/plugins/lua/dcc.lua
@@ -116,7 +116,10 @@ end
-- Configuration
if opts and opts['host'] then
- rspamd_config:register_symbol(symbol_bulk, 1.0, check_dcc)
+ rspamd_config:register_symbol({
+ name = symbol_bulk,
+ callback = check_dcc
+ })
rspamd_config:set_metric_symbol({
group = 'dcc',
score = 2.0,
diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua
index fd0e9912a..924b02017 100644
--- a/src/plugins/lua/dmarc.lua
+++ b/src/plugins/lua/dmarc.lua
@@ -306,12 +306,33 @@ if dkim_opts then
check_mopt('dkim_allow_symbol', 'symbol_allow')
end
-local id = rspamd_config:register_callback_symbol('DMARC_CALLBACK', 1.0,
- dmarc_callback)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_ALLOW', -1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_REJECT', 1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_QUARANTINE', 1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_SOFTFAIL', 1, id)
+local id = rspamd_config:register_symbol({
+ name = 'DMARC_CALLBACK',
+ type = 'callback',
+ callback = dmarc_callback
+})
+rspamd_config:register_symbol({
+ name = 'DMARC_POLICY_ALLOW',
+ flags = 'nice',
+ parent = id,
+ type = 'virtual'
+})
+rspamd_config:register_symbol({
+ name = 'DMARC_POLICY_REJECT',
+ parent = id,
+ type = 'virtual'
+})
+rspamd_config:register_symbol({
+ name = 'DMARC_POLICY_QUARANTINE',
+ parent = id,
+ type = 'virtual'
+})
+rspamd_config:register_symbol({
+ name = 'DMARC_POLICY_SOFTFAIL',
+ parent = id,
+ type = 'virtual'
+})
+
rspamd_config:register_dependency(id, symbols['spf_allow_symbol'])
rspamd_config:register_dependency(id, symbols['dkim_allow_symbol'])
diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua
index 621bc6a01..32dc00103 100644
--- a/src/plugins/lua/emails.lua
+++ b/src/plugins/lua/emails.lua
@@ -38,10 +38,10 @@ local function check_email_rule(task, rule, addr)
else
to_resolve = string.format('%s.%s.%s', addr:get_user(), addr:get_host(), rule['dnsbl'])
end
-
+
task:get_resolver():resolve_a({
- task=task,
- name = to_resolve,
+ task=task,
+ name = to_resolve,
callback = emails_dns_cb})
elseif rule['map'] then
if rule['domain_only'] then
@@ -74,7 +74,7 @@ local function check_emails(task)
check_email_rule(task, rule, addr)
end
checked[to_check] = true
- end
+ end
end
end
end
@@ -102,8 +102,15 @@ end
if table.maxn(rules) > 0 then
-- add fake symbol to check all maps inside a single callback
- local id = rspamd_config:register_callback_symbol(1.0, check_emails)
+ local id = rspamd_config:register_symbol({
+ type = 'callback',
+ callback = check_emails
+ })
for _,rule in ipairs(rules) do
- rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
+ rspamd_config:register_symbol({
+ name = rule['symbol'],
+ type = 'virtual',
+ parent = id
+ })
end
end
diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua
index 533626748..a9347a685 100644
--- a/src/plugins/lua/forged_recipients.lua
+++ b/src/plugins/lua/forged_recipients.lua
@@ -22,74 +22,76 @@ local symbol_rcpt = 'FORGED_RECIPIENTS'
local symbol_sender = 'FORGED_SENDER'
local function check_forged_headers(task)
- local smtp_rcpt = task:get_recipients(1)
- local res = false
- local score = 1.0
+ local smtp_rcpt = task:get_recipients(1)
+ local res = false
+ local score = 1.0
- if smtp_rcpt then
- local mime_rcpt = task:get_recipients(2)
- local count = 0
- if mime_rcpt then
- count = table.maxn(mime_rcpt)
- end
- if count > 0 and count < table.maxn(smtp_rcpt) then
- task:insert_result(symbol_rcpt, 1)
- elseif count > 0 then
- -- Find pair for each smtp recipient recipient in To or Cc headers
- for _,sr in ipairs(smtp_rcpt) do
- if mime_rcpt then
- for _,mr in ipairs(mime_rcpt) do
- if mr['addr'] and sr['addr'] and
- string.lower(mr['addr']) == string.lower(sr['addr']) then
- res = true
- break
- elseif mr['user'] and sr['user'] and
- string.lower(mr['user']) == string.lower(sr['user']) then
- -- If we have the same username but for another domain, then
- -- lower the overall score
- score = score / 2
- end
- end
- end
- if not res then
- task:insert_result(symbol_rcpt, score)
- break
- end
- end
- end
- end
- -- Check sender
- local smtp_from = task:get_from(1)
- if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then
- local mime_from = task:get_from(2)
- if not mime_from or not mime_from[1] or
- not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
- task:insert_result(symbol_sender, 1)
- end
- end
-end
-
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
- if rspamd_config:get_api_version() >= 1 then
- rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string')
- rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string')
- end
+ if smtp_rcpt then
+ local mime_rcpt = task:get_recipients(2)
+ local count = 0
+ if mime_rcpt then
+ count = table.maxn(mime_rcpt)
+ end
+ if count > 0 and count < table.maxn(smtp_rcpt) then
+ task:insert_result(symbol_rcpt, 1)
+ elseif count > 0 then
+ -- Find pair for each smtp recipient recipient in To or Cc headers
+ for _,sr in ipairs(smtp_rcpt) do
+ if mime_rcpt then
+ for _,mr in ipairs(mime_rcpt) do
+ if mr['addr'] and sr['addr'] and
+ string.lower(mr['addr']) == string.lower(sr['addr']) then
+ res = true
+ break
+ elseif mr['user'] and sr['user'] and
+ string.lower(mr['user']) == string.lower(sr['user']) then
+ -- If we have the same username but for another domain, then
+ -- lower the overall score
+ score = score / 2
+ end
+ end
+ end
+ if not res then
+ task:insert_result(symbol_rcpt, score)
+ break
+ end
+ end
+ end
+ end
+ -- Check sender
+ local smtp_from = task:get_from(1)
+ if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then
+ local mime_from = task:get_from(2)
+ if not mime_from or not mime_from[1] or
+ not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
+ task:insert_result(symbol_sender, 1)
+ end
+ end
end
-- Configuration
local opts = rspamd_config:get_all_opt('forged_recipients')
if opts then
- if opts['symbol_rcpt'] or opts['symbol_sender'] then
- local id = rspamd_config:register_callback_symbol(1.0,
- check_forged_headers)
- if opts['symbol_rcpt'] then
- symbol_rcpt = opts['symbol_rcpt']
- rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, id)
- end
- if opts['symbol_sender'] then
- symbol_sender = opts['symbol_sender']
- rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id)
- end
- end
+ if opts['symbol_rcpt'] or opts['symbol_sender'] then
+ local id = rspamd_config:register_symbol({
+ callback = check_forged_headers,
+ type = 'callback',
+ })
+ if opts['symbol_rcpt'] then
+ symbol_rcpt = opts['symbol_rcpt']
+ rspamd_config:register_symbol({
+ name = symbol_rcpt,
+ type = 'virtual',
+ parent = id,
+ })
+ end
+ if opts['symbol_sender'] then
+ symbol_sender = opts['symbol_sender']
+ rspamd_config:register_symbol({
+ name = symbol_sender,
+ type = 'virtual',
+ parent = id,
+ })
+ end
+ end
end
diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua
index c18e11e0a..7d12f1a5e 100644
--- a/src/plugins/lua/ip_score.lua
+++ b/src/plugins/lua/ip_score.lua
@@ -355,6 +355,9 @@ if upstreams then
if options['asn_provider'] then
rspamd_config:register_pre_filter(asn_check)
end
- rspamd_config:register_symbol(options['symbol'], 1.0, ip_score_check)
+ rspamd_config:register_symbol({
+ name = options['symbol'],
+ callback = ip_score_check
+ })
rspamd_config:register_post_filter(ip_score_set)
end
diff --git a/src/plugins/lua/maillist.lua b/src/plugins/lua/maillist.lua
index 5f683a003..42cdc9176 100644
--- a/src/plugins/lua/maillist.lua
+++ b/src/plugins/lua/maillist.lua
@@ -267,16 +267,15 @@ local function check_maillist(task)
task:insert_result(symbol, 0.5, 'generic')
end
end
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
- if rspamd_config:get_api_version() >= 1 then
- rspamd_config:register_module_option('maillist', 'symbol', 'string')
- end
-end
+
+
-- Configuration
local opts = rspamd_config:get_all_opt('maillist')if opts then
if opts['symbol'] then
symbol = opts['symbol']
- rspamd_config:register_symbol(symbol, 1.0, check_maillist)
+ rspamd_config:register_symbol({
+ name = symbol,
+ callback = check_maillist
+ })
end
end
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua
index 2c168393b..f51e20cb7 100644
--- a/src/plugins/lua/mime_types.lua
+++ b/src/plugins/lua/mime_types.lua
@@ -115,10 +115,26 @@ if opts then
description = 'mime types map'
})
end
- local id = rspamd_config:register_callback_symbol(1.0, check_mime_type)
- rspamd_config:register_virtual_symbol(settings['symbol_unknown'], 1.0, id)
- rspamd_config:register_virtual_symbol(settings['symbol_bad'], 1.0, id)
- rspamd_config:register_virtual_symbol(settings['symbol_good'], 1.0, id)
- rspamd_config:register_virtual_symbol(settings['symbol_attachment'], 1.0, id)
+ local id = rspamd_config:register_symbol({
+ callback = check_mime_type,
+ type = 'callback'
+ })
+
+ rspamd_config:register_symbol({
+ type = 'virtual',
+ name = settings['symbol_unknown'],
+ parent = id
+ })
+ rspamd_config:register_symbol({
+ type = 'virtual',
+ name = settings['symbol_good'],
+ flags = 'nice',
+ parent = id
+ })
+ rspamd_config:register_symbol({
+ type = 'virtual',
+ name = settings['symbol_attachment'],
+ parent = id
+ })
end
end
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index d89b90aab..9f0d92849 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -482,10 +482,18 @@ if opts and type(opts) == 'table' then
end
-- add fake symbol to check all maps inside a single callback
if _.any(function(r) return not r['prefilter'] end, rules) then
- local id = rspamd_config:register_callback_symbol_priority(1.0, -1,
- multimap_filter_callback)
+ local id = rspamd_config:register_symbol({
+ type = 'callback',
+ priority = -1,
+ callback = multimap_filter_callback,
+ flags = 'empty'
+ })
for i,rule in ipairs(rules) do
- rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
+ rspamd_config:register_symbol({
+ type = 'virtual',
+ name = rule['symbol'],
+ parent = id,
+ })
end
end
diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua
index d192c0b79..274504cf2 100644
--- a/src/plugins/lua/once_received.lua
+++ b/src/plugins/lua/once_received.lua
@@ -144,7 +144,11 @@ if opts then
if opts['symbol'] then
local symbol = opts['symbol']
- local id = rspamd_config:register_symbol(symbol, 1.0, check_quantity_received)
+ local id = rspamd_config:register_symbol({
+ name = symbol,
+ callback = check_quantity_received,
+ type = 'callback',
+ })
for n,v in pairs(opts) do
if n == 'symbol_strict' then
@@ -167,7 +171,16 @@ if opts then
whitelist = rspamd_config:add_radix_map (v, 'once received whitelist')
end
end
- rspamd_config:register_virtual_symbol(symbol_rdns, 1.0, id)
- rspamd_config:register_virtual_symbol(symbol_strict, 1.0, id)
+
+ rspamd_config:register_symbol({
+ name = symbol_rdns,
+ type = 'virtual',
+ parent = id
+ })
+ rspamd_config:register_symbol({
+ name = symbol_strict,
+ type = 'virtual',
+ parent = id
+ })
end
end
diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua
index d2b85dac5..338d16fdd 100644
--- a/src/plugins/lua/phishing.lua
+++ b/src/plugins/lua/phishing.lua
@@ -108,21 +108,15 @@ local function phishing_map(mapname, phishmap)
end
end
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
- if rspamd_config:get_api_version() >= 1 then
- rspamd_config:register_module_option('phishing', 'symbol', 'string')
- rspamd_config:register_module_option('phishing', 'domains', 'map')
- rspamd_config:register_module_option('phishing', 'strict_domains', 'string')
- rspamd_config:register_module_option('phishing', 'redirector_domains', 'string')
- end
-end
if opts then
if opts['symbol'] then
symbol = opts['symbol']
-- Register symbol's callback
- rspamd_config:register_symbol(symbol, 1.0, phishing_cb)
+ rspamd_config:register_symbol({
+ name = symbol,
+ callback = phishing_cb
+ })
end
if opts['domains'] and type(opt['domains']) == 'string' then
domains = rspamd_config:add_hash_map (opts['domains'])
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index a6328eb4d..2604423e8 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -435,7 +435,11 @@ if opts then
if not ratelimit_symbol then
rspamd_config:register_pre_filter(rate_test)
else
- rspamd_config:register_symbol(ratelimit_symbol, 1.0, rate_test)
+ rspamd_config:register_symbol({
+ name = ratelimit_symbol,
+ callback = rate_test,
+ flags = 'empty'
+ })
end
rspamd_config:register_post_filter(rate_set)
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua
index 45880d5a3..91e20dc5b 100644
--- a/src/plugins/lua/rbl.lua
+++ b/src/plugins/lua/rbl.lua
@@ -363,7 +363,11 @@ local white_symbols = {}
local black_symbols = {}
local need_dkim = false
-local id = rspamd_config:register_callback_symbol_priority(1.0, 0, rbl_cb)
+local id = rspamd_config:register_symbol({
+ type = 'callback',
+ callback = rbl_cb,
+ flags = 'empty,nice'
+})
for key,rbl in pairs(opts['rbls']) do
for default, default_v in pairs(default_defaults) do
@@ -374,7 +378,12 @@ for key,rbl in pairs(opts['rbls']) do
if type(rbl['returncodes']) == 'table' then
for s,_ in pairs(rbl['returncodes']) do
if type(rspamd_config.get_api_version) ~= 'nil' then
- rspamd_config:register_virtual_symbol(s, 1, id)
+ rspamd_config:register_symbol({
+ name = s,
+ parent = id,
+ type = 'virtual'
+ })
+
if rbl['dkim'] then
need_dkim = true
end
@@ -411,7 +420,12 @@ for key,rbl in pairs(opts['rbls']) do
rbl['symbol'] = key
end
if type(rspamd_config.get_api_version) ~= 'nil' and rbl['symbol'] then
- rspamd_config:register_virtual_symbol(rbl['symbol'], 1, id)
+ rspamd_config:register_symbol({
+ name = rbl['symbol'],
+ parent = id,
+ type = 'virtual'
+ })
+
if rbl['dkim'] then
need_dkim = true
end
diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index e025714ce..f90a838c3 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -1419,7 +1419,11 @@ local function post_process()
one_shot = true })
scores_added[k] = 1
end
- rspamd_config:register_symbol(k, calculate_score(k, r), meta_cb)
+ rspamd_config:register_symbol({
+ name = k,
+ weight = calculate_score(k, r),
+ callback = meta_cb
+ })
r['expression'] = expression
if not atoms[k] then
atoms[k] = meta_cb
diff --git a/src/plugins/lua/trie.lua b/src/plugins/lua/trie.lua
index 7295c907f..4a1fdfd4e 100644
--- a/src/plugins/lua/trie.lua
+++ b/src/plugins/lua/trie.lua
@@ -27,13 +27,13 @@ local raw_trie
local mime_patterns = {}
local raw_patterns = {}
--- here we store params for each pattern, so for each i = 1..n patterns[i]
+-- here we store params for each pattern, so for each i = 1..n patterns[i]
-- should have corresponding params[i]
local mime_params = {}
local raw_params = {}
local function tries_callback(task)
-
+
local matched = {}
local function gen_trie_cb(raw)
@@ -43,11 +43,11 @@ local function tries_callback(task)
patterns = raw_patterns
params = raw_params
end
-
+
return function (idx, pos)
local param = params[idx]
local pattern = patterns[idx]
-
+
if param['multi'] or not matched[pattern] then
rspamd_logger.debugx(task, "<%1> matched pattern %2 at pos %3",
task:get_message_id(), pattern, pos)
@@ -58,7 +58,7 @@ local function tries_callback(task)
end
end
end
-
+
if mime_trie then
mime_trie:search_mime(task, gen_trie_cb(false))
end
@@ -71,7 +71,7 @@ local function process_single_pattern(pat, symbol, cf)
if pat then
local multi = false
if cf['multi'] then multi = true end
-
+
if cf['raw'] then
table.insert(raw_patterns, pat)
table.insert(raw_params, {symbol=symbol, multi=multi})
@@ -84,7 +84,7 @@ end
local function process_trie_file(symbol, cf)
file = io.open(cf['file'])
-
+
if not file then
rspamd_logger.errx(rspamd_config, 'Cannot open trie file %1', cf['file'])
else
@@ -102,15 +102,15 @@ end
local function process_trie_conf(symbol, cf)
local raw = false
-
+
if type(cf) ~= 'table' then
rspamd_logger.errx(rspamd_config, 'invalid value for symbol %1: "%2", expected table',
symbol, cf)
return
end
-
+
if cf['raw'] then raw = true end
-
+
if cf['file'] then
process_trie_file(symbol, cf)
elseif cf['patterns'] then
@@ -125,7 +125,7 @@ if opts then
for sym, opt in pairs(opts) do
process_trie_conf(sym, opt)
end
-
+
if #raw_patterns > 0 then
raw_trie = rspamd_trie.create(raw_patterns)
rspamd_logger.infox(rspamd_config, 'registered raw search trie from %1 patterns', #raw_patterns)
@@ -135,17 +135,24 @@ if opts then
mime_trie = rspamd_trie.create(mime_patterns)
rspamd_logger.infox(rspamd_config, 'registered mime search trie from %1 patterns', #mime_patterns)
end
-
+
local id = -1
if mime_trie or raw_trie then
- id = rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback)
+ id = rspamd_config:register_symbol({
+ type = 'callback',
+ callback = tries_callback
+ })
else
rspamd_logger.errx(rspamd_config, 'no tries defined')
end
-
+
if id ~= -1 then
for sym, opt in pairs(opts) do
- rspamd_config:register_virtual_symbol(sym, 1.0, id)
+ rspamd_config:register_symbol({
+ name = sym,
+ type = 'virtual',
+ parent = id
+ })
end
end
end
diff --git a/src/plugins/lua/whitelist.lua b/src/plugins/lua/whitelist.lua
index 202d85465..8c4f4cbcc 100644
--- a/src/plugins/lua/whitelist.lua
+++ b/src/plugins/lua/whitelist.lua
@@ -180,8 +180,11 @@ local configure_whitelist_module = function()
return
end
- local id = rspamd_config:register_symbol(symbol, -1.0,
- gen_whitelist_cb(symbol, rule))
+ local id = rspamd_config:register_symbol({
+ name = symbol,
+ flags = 'nice,empty',
+ callback = gen_whitelist_cb(symbol, rule)
+ })
if rule['valid_spf'] then
rspamd_config:register_dependency(id, options['spf_allow_symbol'])