From: Vsevolod Stakhov Date: Mon, 28 Dec 2020 21:11:41 +0000 (+0000) Subject: [Minor] Another try to deal with symbols from settings X-Git-Tag: 2.7~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c222722ab5ebe57374218cdbd97aa678dad26e8;p=rspamd.git [Minor] Another try to deal with symbols from settings Need to handle allowed ids as well --- 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