diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-28 21:11:41 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-28 21:11:41 +0000 |
commit | 5c222722ab5ebe57374218cdbd97aa678dad26e8 (patch) | |
tree | 8557967332f14efe6a4dc48464de06b0cd8a07d7 | |
parent | 4e9e25230c63574c9a37c4d621a3a5c215d94e2e (diff) | |
download | rspamd-5c222722ab5ebe57374218cdbd97aa678dad26e8.tar.gz rspamd-5c222722ab5ebe57374218cdbd97aa678dad26e8.zip |
[Minor] Another try to deal with symbols from settings
Need to handle allowed ids as well
-rw-r--r-- | src/plugins/lua/settings.lua | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 8dfd91c10..993d2a8e9 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -395,7 +395,7 @@ local function check_settings(task) end -- Process settings based on their priority -local function process_settings_table(tbl, allow_ids, mempool) +local function process_settings_table(tbl, allow_ids, mempool, is_static) local get_priority = function(elt) local pri_tonum = function(p) if p then @@ -968,22 +968,26 @@ local function process_settings_table(tbl, allow_ids, mempool) name, elt.id, out.id) end - if elt.apply and elt.apply.symbols then - -- Register virtual symbols - for k,v in pairs(elt.apply.symbols) do - local rtb = { - type = 'virtual', - parent = module_sym_id, - } - if type(k) == 'number' and type(v) == 'string' then - rtb.name = v - elseif type(k) == 'string' then - rtb.name = k - end - if out.id then - rtb.allowed_ids = tostring(elt.id) + if not is_static then + -- If we apply that from map + -- In fact, it is useless and evil but who cares... + if elt.apply and elt.apply.symbols then + -- Register virtual symbols + for k,v in pairs(elt.apply.symbols) do + local rtb = { + type = 'virtual', + parent = module_sym_id, + } + if type(k) == 'number' and type(v) == 'string' then + rtb.name = v + elseif type(k) == 'string' then + rtb.name = k + end + if out.id then + rtb.allowed_ids = tostring(elt.id) + end + rspamd_config:register_symbol(rtb) end - rspamd_config:register_symbol(rtb) end end else @@ -1180,8 +1184,37 @@ if set_section and set_section[1] and type(set_section[1]) == "string" then end elseif set_section and type(set_section) == "table" then settings_map_pool = rspamd_mempool.create() + -- We need to check this table and register static symbols first + -- Postponed settings init is needed to ensure that all symbols have been + -- registered BEFORE settings plugin. Otherwise, we can have inconsistent settings expressions + fun.each(function(_, elt) + if elt.apply and elt.apply.symbols then + -- Register virtual symbols + for k,v in pairs(elt.apply.symbols) do + local rtb = { + type = 'virtual', + parent = module_sym_id, + } + if type(k) == 'number' and type(v) == 'string' then + rtb.name = v + elseif type(k) == 'string' then + rtb.name = k + end + rspamd_config:register_symbol(rtb) + end + end + end, + -- Include only settings, exclude all maps + fun.filter( + function(_, elt) + if type(elt) == "table" then + return true + end + return false + end, set_section) + ) rspamd_config:add_post_init(function () - process_settings_table(set_section, true, settings_map_pool) + process_settings_table(set_section, true, settings_map_pool, true) end) end |