commit 5c22272: [Minor] Another try to deal with symbols from settings

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Dec 28 21:14:07 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-12-28 21:11:41 +0000
URL: https://github.com/rspamd/rspamd/commit/5c222722ab5ebe57374218cdbd97aa678dad26e8 (HEAD -> master)

[Minor] Another try to deal with symbols from settings
Need to handle allowed ids as well

---
 src/plugins/lua/settings.lua | 67 +++++++++++++++++++++++++++++++++-----------
 1 file 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
 


More information about the Commits mailing list