]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Some fixes to ids propagation
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Aug 2019 16:38:31 +0000 (17:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 20 Aug 2019 16:38:31 +0000 (17:38 +0100)
src/libserver/rspamd_symcache.c
src/lua/lua_config.c
src/plugins/surbl.c

index 900a1894c619bfe0b9bf063e7dcb91ed0f3796c4..69080eb18329d49114c06520ccf8e7d8262c722e 100644 (file)
@@ -542,6 +542,8 @@ rspamd_symcache_propagate_dep (struct rspamd_symcache *cache,
        const guint *ids;
        guint nids = 0;
 
+       msg_debug_cache ("check id propagation for dependency %s from %s",
+                       it->symbol, dit->symbol);
        ids = rspamd_symcache_get_allowed_settings_ids (cache, dit->symbol, &nids);
 
        /* TODO: merge? */
@@ -573,12 +575,15 @@ rspamd_symcache_process_dep (struct rspamd_symcache *cache,
        struct cache_dependency *rdep;
 
        if (dep->id >= 0) {
+               msg_debug_cache ("process real dependency %s on %s", it->symbol, dep->sym);
                dit = rspamd_symcache_find_filter (cache, dep->sym, true);
        }
 
        if (dep->vid >= 0) {
                /* Case of the virtual symbol that depends on another (maybe virtual) symbol */
                vdit = rspamd_symcache_find_filter (cache, dep->sym, false);
+               msg_debug_cache ("process virtual dependency %s(%d) on %s(%d)", it->symbol,
+                               dep->vid, vdit->symbol, vdit->id);
        }
        else {
                vdit = dit;
@@ -686,7 +691,8 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache)
                else {
                        msg_debug_cache ("delayed between %s(%d:%d) -> %s", ddep->from,
                                        it->id, vit->id, ddep->to);
-                       rspamd_symcache_add_dependency (cache, it->id, ddep->to, vit->id);
+                       rspamd_symcache_add_dependency (cache, it->id, ddep->to, vit != it ?
+                                                                                                                                        vit->id : -1);
                }
 
                cur = g_list_next (cur);
@@ -730,6 +736,14 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache)
                }
        }
 
+       /* Special case for virtual symbols */
+       PTR_ARRAY_FOREACH (cache->virtual, i, it) {
+
+               PTR_ARRAY_FOREACH (it->deps, j, dep) {
+                       rspamd_symcache_process_dep (cache, it, dep);
+               }
+       }
+
        g_ptr_array_sort_with_data (cache->prefilters_empty, prefilters_cmp, cache);
        g_ptr_array_sort_with_data (cache->prefilters, prefilters_cmp, cache);
        g_ptr_array_sort_with_data (cache->postfilters, postfilters_cmp, cache);
@@ -2485,7 +2499,7 @@ rspamd_symcache_add_dependency (struct rspamd_symcache *cache,
 
        g_assert (id_from >= 0 && id_from < (gint)cache->items_by_id->len);
 
-       source = g_ptr_array_index (cache->items_by_id, id_from);
+       source = (struct rspamd_symcache_item *)g_ptr_array_index (cache->items_by_id, id_from);
        dep = rspamd_mempool_alloc (cache->static_pool, sizeof (*dep));
        dep->id = id_from;
        dep->sym = rspamd_mempool_strdup (cache->static_pool, to);
@@ -2494,11 +2508,13 @@ rspamd_symcache_add_dependency (struct rspamd_symcache *cache,
        dep->vid = -1;
        g_ptr_array_add (source->deps, dep);
 
-       if (id_from != virtual_id_from) {
+       if (virtual_id_from >= 0) {
+               g_assert (virtual_id_from < (gint)cache->virtual->len);
                /* We need that for settings id propagation */
-               vsource = g_ptr_array_index (cache->items_by_id, virtual_id_from);
+               vsource = (struct rspamd_symcache_item *)
+                               g_ptr_array_index (cache->virtual, virtual_id_from);
                dep = rspamd_mempool_alloc (cache->static_pool, sizeof (*dep));
-               dep->vid = id_from;
+               dep->vid = virtual_id_from;
                dep->id = -1;
                dep->sym = rspamd_mempool_strdup (cache->static_pool, to);
                /* Will be filled later */
index 9b8c084c0aa102ed89a8c788f8568ed6c2b0f1e1..5c914af79123db507524f9262a556eaf2a118d51 100644 (file)
@@ -1524,6 +1524,17 @@ rspamd_register_symbol_fromlua (lua_State *L,
                ids = rspamd_process_id_list (allowed_ids, &nids);
 
                if (nids > 0) {
+                       GString *dbg = g_string_new ("");
+
+                       for (guint i = 0; i < nids; i ++) {
+                               rspamd_printf_gstring (dbg, "%ud,", ids[i]);
+                       }
+
+                       dbg->len --;
+
+                       msg_debug_config ("allowed ids for %s are: %v", name, dbg);
+                       g_string_free (dbg, TRUE);
+
                        rspamd_symcache_set_allowed_settings_ids (cfg->cache, name,
                                        ids, nids);
 
@@ -1535,6 +1546,17 @@ rspamd_register_symbol_fromlua (lua_State *L,
                ids = rspamd_process_id_list (forbidden_ids, &nids);
 
                if (nids > 0) {
+                       GString *dbg = g_string_new ("");
+
+                       for (guint i = 0; i < nids; i ++) {
+                               rspamd_printf_gstring (dbg, "%ud,", ids[i]);
+                       }
+
+                       dbg->len --;
+
+                       msg_debug_config ("forbidden ids for %s are: %v", name, dbg);
+                       g_string_free (dbg, TRUE);
+
                        rspamd_symcache_set_forbidden_settings_ids (cfg->cache, name,
                                        ids, nids);
 
@@ -2207,7 +2229,7 @@ lua_config_register_dependency (lua_State * L)
                if (child_id > 0 && parent != NULL) {
 
                        rspamd_symcache_add_dependency (cfg->cache, child_id, parent,
-                                       child_id);
+                                       -1);
                }
        }
        else {
index 7da36f4832aecdb8580aa4f83d723caaa383422d..0d03f95167817b01aa97451e17045898cfdc3149 100644 (file)
@@ -868,7 +868,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                                1,
                                1);
                rspamd_symcache_add_dependency (cfg->cache, cb_id,
-                               SURBL_REDIRECTOR_CALLBACK, cb_id);
+                               SURBL_REDIRECTOR_CALLBACK, -1);
                /* Failure symbol */
                g_string_append (sym, "_FAIL");
                rspamd_symcache_add_symbol (cfg->cache, sym->str,
@@ -1205,7 +1205,7 @@ surbl_module_config (struct rspamd_config *cfg)
 
                if (cur_suffix->options & SURBL_OPTION_CHECKDKIM) {
                        rspamd_symcache_add_dependency (cfg->cache,
-                                       cur_suffix->callback_id, "DKIM_TRACE", cur_suffix->callback_id);
+                                       cur_suffix->callback_id, "DKIM_TRACE", -1);
                }
 
                cur_opt = g_list_next (cur_opt);