]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Implement checks for symbols against allowed ids
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 15:11:52 +0000 (16:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 15:11:52 +0000 (16:11 +0100)
src/libmime/filter.c
src/libserver/rspamd_symcache.c
src/libserver/rspamd_symcache.h

index 3550370eda3e3bc46d2ddee2ef7d2ea9f3138256..39d073b051d263ed6dd485a9f12e00d2525d1d4c 100644 (file)
@@ -208,6 +208,13 @@ insert_metric_result (struct rspamd_task *task,
                }
        }
        else {
+               if (sdef->cache_item) {
+                       /* Check if we can insert this symbol at all */
+                       if (!rspamd_symcache_is_item_allowed (task, sdef->cache_item)) {
+                               return NULL;
+                       }
+               }
+
                final_score = (*sdef->weight_ptr) * weight;
 
                PTR_ARRAY_FOREACH (sdef->groups, i, gr) {
@@ -434,8 +441,8 @@ rspamd_task_insert_result_full (struct rspamd_task *task,
                        flags);
 
        /* Process cache item */
-       if (task->cfg->cache) {
-               rspamd_symcache_inc_frequency (task->cfg->cache, symbol);
+       if (task->cfg->cache && s->sym) {
+               rspamd_symcache_inc_frequency (task->cfg->cache, s->sym->cache_item);
        }
 
        return s;
index ac0b8dded7505ed2b90c237d6407b900070205b7..1ae279e73ec77a7c2f11d03c717e1b4f7c9e41f9 100644 (file)
@@ -2281,14 +2281,8 @@ rspamd_symcache_start_refresh (struct rspamd_symcache *cache,
 
 void
 rspamd_symcache_inc_frequency (struct rspamd_symcache *cache,
-                                                          const gchar *symbol)
+                                                          struct rspamd_symcache_item *item)
 {
-       struct rspamd_symcache_item *item;
-
-       g_assert (cache != NULL);
-
-       item = g_hash_table_lookup (cache->items_by_symbol, symbol);
-
        if (item != NULL) {
                g_atomic_int_inc (&item->st->hits);
        }
@@ -2604,28 +2598,37 @@ rspamd_symcache_is_symbol_enabled (struct rspamd_task *task,
                item = rspamd_symcache_find_filter (cache, symbol, true);
 
                if (item) {
-                       dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
-                       if (CHECK_START_BIT (checkpoint, dyn_item)) {
+
+                       if (!rspamd_symcache_is_item_allowed (task, item)) {
                                ret = FALSE;
                        }
                        else {
-                               if (item->specific.normal.condition_cb != -1) {
-                                       /* We also executes condition callback to check if we need this symbol */
-                                       L = task->cfg->lua_state;
-                                       lua_rawgeti (L, LUA_REGISTRYINDEX,
-                                                       item->specific.normal.condition_cb);
-                                       ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
-                                       rspamd_lua_setclass (L, "rspamd{task}", -1);
-                                       *ptask = task;
-
-                                       if (lua_pcall (L, 1, 1, 0) != 0) {
-                                               msg_info_task ("call to condition for %s failed: %s",
-                                                               item->symbol, lua_tostring (L, -1));
-                                               lua_pop (L, 1);
-                                       }
-                                       else {
-                                               ret = lua_toboolean (L, -1);
-                                               lua_pop (L, 1);
+                               dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
+                               if (CHECK_START_BIT (checkpoint, dyn_item)) {
+                                       ret = FALSE;
+                               }
+                               else {
+                                       if (item->specific.normal.condition_cb != -1) {
+                                               /*
+                                                * We also executes condition callback to check
+                                                * if we need this symbol
+                                                */
+                                               L = task->cfg->lua_state;
+                                               lua_rawgeti (L, LUA_REGISTRYINDEX,
+                                                               item->specific.normal.condition_cb);
+                                               ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
+                                               rspamd_lua_setclass (L, "rspamd{task}", -1);
+                                               *ptask = task;
+
+                                               if (lua_pcall (L, 1, 1, 0) != 0) {
+                                                       msg_info_task ("call to condition for %s failed: %s",
+                                                                       item->symbol, lua_tostring (L, -1));
+                                                       lua_pop (L, 1);
+                                               }
+                                               else {
+                                                       ret = lua_toboolean (L, -1);
+                                                       lua_pop (L, 1);
+                                               }
                                        }
                                }
                        }
index fcf3d1c7752b2b7542873c4a708e52b8bfebc48f..b063109a4db98c65e57ab6b14730400197da64d8 100644 (file)
@@ -207,7 +207,7 @@ void rspamd_symcache_start_refresh (struct rspamd_symcache *cache,
  * @param symbol
  */
 void rspamd_symcache_inc_frequency (struct rspamd_symcache *cache,
-                                                                       const gchar *symbol);
+                                                                       struct rspamd_symcache_item *item);
 
 /**
  * Add dependency relation between two symbols identified by id (source) and
@@ -482,7 +482,8 @@ void rspamd_symcache_process_settings_elt (struct rspamd_symcache *cache,
                                                                                   struct rspamd_config_settings_elt *elt);
 
 /**
- * Check if a symbol is allowed for execution/insertion
+ * Check if a symbol is allowed for execution/insertion, this does not involve
+ * condition scripts to be checked (so it is intended to be fast).
  * @param task
  * @param item
  * @return