]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Support definition of ungrouped symbol in conf file, use group info from lua...
authorssturges <ststurge@cisco.com>
Tue, 25 Jan 2022 18:37:10 +0000 (13:37 -0500)
committerssturges <ststurge@cisco.com>
Tue, 25 Jan 2022 18:37:10 +0000 (13:37 -0500)
src/libserver/cfg_utils.c
src/lua/lua_config.c

index 44cdbc84fde3e496af059467afc5ec0a7ffa0de1..4deae950e9918a8c44823e1610755cd85e58d2b1 100644 (file)
@@ -1630,8 +1630,9 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                                        sym_group = rspamd_config_new_group (cfg, group);
                                }
 
-                               if (!sym_def->gr) {
+                               if ((!sym_def->gr) || (sym_def->flags & RSPAMD_SYMBOL_FLAG_UNGROUPPED)) {
                                        sym_def->gr = sym_group;
+                                       sym_def->flags &= ~RSPAMD_SYMBOL_FLAG_UNGROUPPED;
                                }
 
                                g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def);
index 8b0a4a46cd1755c9b87454011d0df1aa8e66bc99..d66af2d0c88c16cb5fe8a7eefb6a147a3eeed556 100644 (file)
@@ -2873,6 +2873,41 @@ lua_config_newindex (lua_State *L)
                                        lua_pop (L, 1);
                                }
                        }
+                       else
+                       {
+                               /* Fill in missing fields from lua defintion if they are not set */
+                               if (sym->description == NULL) {
+                                       lua_pushstring (L, "description");
+                                       lua_gettable (L, -2);
+
+                                       if (lua_type (L, -1) == LUA_TSTRING) {
+                                               description = lua_tostring (L, -1);
+                                       }
+                                       lua_pop (L, 1);
+
+                                       if (description) {
+                                               sym->description = rspamd_mempool_strdup (cfg->cfg_pool, description);
+                                       }
+                               }
+
+                               /* If ungrouped and there is a group defined in lua, change the primary group
+                                * Otherwise, add to the list of groups for this symbol. */
+                               lua_pushstring (L, "group");
+                               lua_gettable (L, -2);
+                               if (lua_type (L, -1) == LUA_TSTRING) {
+                                       group = lua_tostring (L, -1);
+                               }
+                               lua_pop (L, 1);
+                               if (group) {
+                                       if (sym->flags & RSPAMD_SYMBOL_FLAG_UNGROUPPED)
+                                       {
+                                               /* Unset the "ungrouped" group */
+                                               sym->gr = NULL;
+                                       }
+                                       /* Add the group */
+                                       rspamd_config_add_symbol_group (cfg, name, group);
+                               }
+                       }
 
                        /* Remove table from stack */
                        lua_pop (L, 1);