]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix some issues
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Jan 2019 17:25:56 +0000 (17:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Jan 2019 17:25:56 +0000 (17:25 +0000)
src/libmime/filter.c
src/libserver/cfg_utils.c
src/libserver/dns.c
src/libutil/uthash_strcase.h
src/lua/lua_task.c

index 46a0e5b927fc6bafe8f47743ca3372a3eb70280e..ea9b500c991a79e8670cec8c9f9ab8cd4a8e15e1 100644 (file)
@@ -499,7 +499,7 @@ rspamd_check_action_metric (struct rspamd_task *task)
 
        /* We are not certain about the results during processing */
        if (mres->passthrough_result == NULL) {
-               for (i = 0; i < mres->nactions; i++) {
+               for (i = mres->nactions - 1; i >= 0; i--) {
                        action_lim = &mres->actions_limits[i];
                        sc = action_lim->cur_limit;
 
@@ -517,7 +517,7 @@ rspamd_check_action_metric (struct rspamd_task *task)
                        }
                }
 
-               if (set_action && selected_action == NULL) {
+               if (selected_action == NULL) {
                        selected_action = noaction->action;
                }
        }
index 26bf4e4b01744fd44eeaaa59147eab3722e6f5d1..d4b4e9075f7df549a8aea2c0a68cd17273fb8821 100644 (file)
@@ -153,7 +153,8 @@ rspamd_config_new (enum rspamd_config_init_flags flags)
                        action->flags |= RSPAMD_ACTION_HAM;
                }
 
-               HASH_ADD_STR (cfg->actions, name, action);
+               HASH_ADD_KEYPTR (hh, cfg->actions,
+                               action->name, strlen (action->name), action);
        }
 
        /* Disable timeout */
@@ -1952,8 +1953,6 @@ rspamd_config_action_from_ucl (struct rspamd_config *cfg,
                act->action_type = METRIC_ACTION_CUSTOM;
        }
 
-       rspamd_actions_sort (cfg);
-
        return TRUE;
 }
 
@@ -1963,6 +1962,7 @@ rspamd_config_set_action_score (struct rspamd_config *cfg,
                const ucl_object_t *obj)
 {
        struct rspamd_action *act;
+       enum rspamd_action_type std_act;
        const ucl_object_t *elt;
        guint priority = ucl_object_get_priority (obj), obj_type;
 
@@ -1979,6 +1979,17 @@ rspamd_config_set_action_score (struct rspamd_config *cfg,
                }
        }
 
+       /* Here are dragons:
+        * We have `canonical` name for actions, such as `soft reject` and
+        * configuration names for actions (used to be more convenient), such
+        * as `soft_reject`. Unfortunately, we must have heuristic for this
+        * variance of names.
+        */
+
+       if (rspamd_action_from_str (action_name, (gint *)&std_act)) {
+               action_name = rspamd_action_to_str (std_act);
+       }
+
        HASH_FIND_STR (cfg->actions, action_name, act);
 
        if (act) {
@@ -1992,7 +2003,12 @@ rspamd_config_set_action_score (struct rspamd_config *cfg,
                                        act->priority,
                                        priority,
                                        act->threshold);
-                       return rspamd_config_action_from_ucl (cfg, act, obj, priority);
+                       if (rspamd_config_action_from_ucl (cfg, act, obj, priority)) {
+                               rspamd_actions_sort (cfg);
+                       }
+                       else {
+                               return FALSE;
+                       }
                }
                else {
                        msg_info_config ("action %s has been already registered with "
@@ -2008,7 +2024,9 @@ rspamd_config_set_action_score (struct rspamd_config *cfg,
                act->name = rspamd_mempool_strdup (cfg->cfg_pool, action_name);
 
                if (rspamd_config_action_from_ucl (cfg, act, obj, priority)) {
-                       HASH_ADD_STR (cfg->actions, name, act);
+                       HASH_ADD_KEYPTR (hh, cfg->actions,
+                                       act->name, strlen (act->name), act);
+                       rspamd_actions_sort (cfg);
                }
                else {
                        return FALSE;
index 17b84884afd2b21bde1a7a2251a95ae5eb007b06..7ad266c2f76e7133dfe565aa84457ce86489f4ba 100644 (file)
@@ -20,7 +20,6 @@
 #include "dns.h"
 #include "rspamd.h"
 #include "utlist.h"
-#include "uthash.h"
 #include "rdns_event.h"
 #include "unix-std.h"
 
index 77c807630450fd1afa5fbddca1b747a0bde2dfd5..fba97d9b17d732cca8778404be2c91358121a8d0 100644 (file)
@@ -16,6 +16,9 @@
 #ifndef UTHASH_STRCASE_H_
 #define UTHASH_STRCASE_H_
 
+#ifdef UTHASH_H
+#error Invalid include order: uthash is already included
+#endif
 
 /* Utils for uthash tuning */
 #ifndef HASH_CASELESS
index 5728b3342b01ab7a9fa0e7d4aba0947891c5466b..e8746f2bdc70a8fd4ccafabbeb7ba691ffdb79de 100644 (file)
@@ -1673,6 +1673,12 @@ lua_task_set_pre_result (lua_State * L)
                }
 
                if (action == NULL) {
+                       struct rspamd_action *tmp;
+
+                       HASH_ITER (hh, task->cfg->actions, action, tmp) {
+                               msg_err ("known action: %s = %f", action->name, action->threshold);
+                       }
+
                        return luaL_error (L, "unknown action %s", lua_tostring (L, 2));
                }