]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add symbols for explicit enabling
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 14:49:10 +0000 (15:49 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jun 2019 14:49:10 +0000 (15:49 +0100)
src/libserver/rspamd_symcache.c
src/libserver/rspamd_symcache.h
src/lua/lua_config.c

index fd9db9126f675d6e3752de2a695a7653c1356c11..ac0b8dded7505ed2b90c237d6407b900070205b7 100644 (file)
@@ -1423,10 +1423,18 @@ rspamd_symcache_check_id_list (const struct rspamd_symcache_id_list *ls, guint32
        return FALSE;
 }
 
-static gboolean
+gboolean
 rspamd_symcache_is_item_allowed (struct rspamd_task *task,
                                                                 struct rspamd_symcache_item *item)
 {
+       /* Static checks */
+       if (!item->enabled ||
+               (RSPAMD_TASK_IS_EMPTY (task) && !(item->type & SYMBOL_TYPE_EMPTY)) ||
+               (item->type & SYMBOL_TYPE_MIME_ONLY && !RSPAMD_TASK_IS_MIME(task))) {
+               return FALSE;
+       }
+
+       /* Settings checks */
        if (task->settings_elt != 0) {
                guint32 id = task->settings_elt->id;
 
@@ -1458,6 +1466,11 @@ rspamd_symcache_is_item_allowed (struct rspamd_task *task,
                                        id);
                }
        }
+       else if (item->type & SYMBOL_TYPE_EXPLICIT_ENABLE) {
+               msg_debug_cache_task ("deny execution of %s as it must be explicitly enabled",
+                               item->symbol);
+               return FALSE;
+       }
 
        /* Allow all symbols with no settings id */
        return TRUE;
@@ -1501,10 +1514,7 @@ rspamd_symcache_check_symbol (struct rspamd_task *task,
        /* Check has been started */
        SET_START_BIT (checkpoint, dyn_item);
 
-       if (!item->enabled || /* Static flag */
-               !rspamd_symcache_is_item_allowed (task, item) || /* Dynamic id */
-               (RSPAMD_TASK_IS_EMPTY (task) && !(item->type & SYMBOL_TYPE_EMPTY)) ||
-               (item->type & SYMBOL_TYPE_MIME_ONLY && !RSPAMD_TASK_IS_MIME(task))) {
+       if (!rspamd_symcache_is_item_allowed (task, item)) {
                msg_debug_cache_task ("disable execution of symbol %s", item->symbol);
                check = FALSE;
        }
index a440a542bed06a551a157616ad2b880f3a9beb85..fcf3d1c7752b2b7542873c4a708e52b8bfebc48f 100644 (file)
@@ -51,7 +51,8 @@ enum rspamd_symbol_type {
        SYMBOL_TYPE_MIME_ONLY = (1u << 15u), /* Symbol is mime only */
        SYMBOL_TYPE_EXPLICIT_DISABLE = (1u << 16u), /* Symbol should be disabled explicitly only */
        SYMBOL_TYPE_IGNORE_PASSTHROUGH = (1u << 17u), /* Symbol ignores passthrough result */
-       SYMBOL_TYPE_USE_CORO = (1u << 18u), /* Symbol uses lua coroutines */
+       SYMBOL_TYPE_EXPLICIT_ENABLE = (1u << 18u), /* Symbol should be enabled explicitly only */
+       SYMBOL_TYPE_USE_CORO = (1u << 19u), /* Symbol uses lua coroutines */
 };
 
 /**
@@ -480,4 +481,13 @@ const guint32* rspamd_symcache_get_forbidden_settings_ids (struct rspamd_symcach
 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
+ * @param task
+ * @param item
+ * @return
+ */
+gboolean rspamd_symcache_is_item_allowed (struct rspamd_task *task,
+                                                                                 struct rspamd_symcache_item *item);
+
 #endif
index e54ecce424840d2305ded2e44aac0dbcde639074..802fab1a63fd711edd298b7f64ea524d176a44c7 100644 (file)
@@ -1607,6 +1607,9 @@ lua_parse_symbol_flags (const gchar *str)
                if (strstr (str, "explicit_disable") != NULL) {
                        ret |= SYMBOL_TYPE_EXPLICIT_DISABLE;
                }
+               if (strstr (str, "explicit_enable") != NULL) {
+                       ret |= SYMBOL_TYPE_EXPLICIT_ENABLE;
+               }
                if (strstr (str, "coro") != NULL) {
                        ret |= SYMBOL_TYPE_USE_CORO;
                }
@@ -1687,6 +1690,11 @@ lua_push_symbol_flags (lua_State *L, guint flags)
                lua_rawseti (L, -2, i++);
        }
 
+       if (flags & SYMBOL_TYPE_EXPLICIT_ENABLE) {
+               lua_pushstring (L, "explicit_enable");
+               lua_rawseti (L, -2, i++);
+       }
+
        if (flags & SYMBOL_TYPE_IGNORE_PASSTHROUGH) {
                lua_pushstring (L, "ignore_passthrough");
                lua_rawseti (L, -2, i++);