]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix groups override when defining symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Feb 2018 15:54:38 +0000 (15:54 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Feb 2018 15:54:38 +0000 (15:54 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_utils.c
src/lua/lua_config.c
src/plugins/lua/ip_score.lua

index cb433b6d57f2f40ce64de545d9574cc4ae470810..2a6c29955c3cae3c073aceb8804bccc4c7f6b43b 100644 (file)
@@ -103,6 +103,7 @@ struct rspamd_symbols_group {
 
 #define RSPAMD_SYMBOL_FLAG_IGNORE (1 << 1)
 #define RSPAMD_SYMBOL_FLAG_ONEPARAM (1 << 2)
+#define RSPAMD_SYMBOL_FLAG_UNGROUPPED (1 << 3)
 
 /**
  * Symbol definition
index d3e27755e23501d40be69e3c084bb4a8fb4e4c71..36af1926a29256f7d5952fa53e738d578d510dfd 100644 (file)
@@ -1449,6 +1449,7 @@ rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol,
        /* Search for symbol group */
        if (group == NULL) {
                group = "ungrouped";
+               sym_def->flags |= RSPAMD_SYMBOL_FLAG_UNGROUPPED;
        }
 
        sym_group = g_hash_table_lookup (cfg->groups, group);
@@ -1471,10 +1472,25 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
        struct rspamd_symbol *sym_def;
        g_assert (cfg != NULL);
        g_assert (symbol != NULL);
+       struct rspamd_symbols_group *sym_group;
 
        sym_def = g_hash_table_lookup (cfg->symbols, symbol);
 
        if (sym_def != NULL) {
+               if (sym_def->flags & RSPAMD_SYMBOL_FLAG_UNGROUPPED && group != NULL) {
+                       /* Non-empty group has a priority over non-groupped one */
+                       sym_group = g_hash_table_lookup (cfg->groups, group);
+
+                       if (sym_group == NULL) {
+                               /* Create new group */
+                               sym_group = rspamd_config_new_group (cfg, group);
+                       }
+
+                       sym_def->gr = sym_group;
+                       g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def);
+                       sym_def->flags &= ~(RSPAMD_SYMBOL_FLAG_UNGROUPPED);
+               }
+
                if (sym_def->priority > priority) {
                        msg_debug_config ("symbol %s has been already registered with "
                                        "priority %ud, do not override (new priority: %ud)",
@@ -1511,6 +1527,24 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
 
                        sym_def->priority = priority;
 
+                       /* We also check group information in this case */
+                       if (group != NULL && sym_def->gr != NULL &&
+                                       strcmp (group, sym_def->gr->name) != 0) {
+                               msg_debug_config ("move symbol %s from group %s to %s",
+                                               sym_def->gr->name, group);
+
+                               g_hash_table_remove (sym_def->gr->symbols, sym_def->name);
+                               sym_group = g_hash_table_lookup (cfg->groups, group);
+
+                               if (sym_group == NULL) {
+                                       /* Create new group */
+                                       sym_group = rspamd_config_new_group (cfg, group);
+                               }
+
+                               sym_def->gr = sym_group;
+                               g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def);
+                       }
+
                        return TRUE;
                }
        }
index cd33b219eb936b7db65575771f0ca6a2a3b11000..ab99d2e70a8fe220ecde1dc71f118b4c9ec1eeb3 100644 (file)
@@ -1526,7 +1526,8 @@ lua_config_register_symbol (lua_State * L)
                        }
 
                        rspamd_config_add_symbol (cfg, name,
-                                       score, description, group, flags, (guint) priority, nshots);
+                                       score, description, group, flags,
+                                       (guint) priority, nshots);
                }
        }
        else {
index 0e9d8920e907b3178344707d78d95581722dd378..118d7d81125dcfd6f1883e8a0834adc28db2916f 100644 (file)
@@ -388,6 +388,8 @@ if redis_params then
   rspamd_config:register_symbol({
     name = options['symbol'],
     callback = ip_score_check,
+    group = 'reputation',
+    score = '2.0'
   })
 else
   rspamd_lua_utils.disable_module(N, "redis")