aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-16 18:24:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-16 18:24:13 +0100
commit6ead92784f0e5852410140feb220d60ec7970dee (patch)
treea8776224824c75f5028ee145475633b01c87745f
parent3aa4d38cf467c95b571d6c79ca2dad2e058e098d (diff)
downloadrspamd-6ead92784f0e5852410140feb220d60ec7970dee.tar.gz
rspamd-6ead92784f0e5852410140feb220d60ec7970dee.zip
[Fix] Allow to enable or add new actions via settings
-rw-r--r--src/lua/lua_task.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 316e91bdd..afc741af9 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -5067,8 +5067,45 @@ lua_task_set_settings (lua_State *L)
}
if (!found) {
- msg_warn_task ("cannot set custom score %.2f for unknown action %s",
- act_score, act_name);
+
+ if (!isnan (act_score)) {
+ struct rspamd_action *new_act;
+
+ HASH_FIND_PTR (task->cfg->actions, act_name, new_act);
+
+ if (new_act == NULL) {
+ /* New action! */
+ msg_info_task ("added new action %s with threshold %.2f "
+ "due to settings",
+ act_name,
+ act_score);
+ new_act = rspamd_mempool_alloc0 (task->task_pool,
+ sizeof (*new_act));
+ new_act->name = rspamd_mempool_strdup (task->task_pool, act_name);
+ new_act->action_type = METRIC_ACTION_CUSTOM;
+ new_act->threshold = act_score;
+ }
+ else {
+ /* A disabled action that is enabled */
+ msg_info_task ("enabled disabled action %s with threshold %.2f "
+ "due to settings",
+ act_name,
+ act_score);
+ }
+
+ /* Insert it to the mres structure */
+ gsize new_actions_cnt = mres->nactions + 1;
+ struct rspamd_action_result *old_actions = mres->actions_limits;
+
+ mres->actions_limits = rspamd_mempool_alloc (task->task_pool,
+ sizeof (struct rspamd_action_result) * new_actions_cnt);
+ memcpy (mres->actions_limits, old_actions,
+ sizeof (struct rspamd_action_result) * mres->nactions);
+ mres->actions_limits[mres->nactions].action = new_act;
+ mres->actions_limits[mres->nactions].cur_limit = act_score;
+ mres->nactions ++;
+ }
+ /* Disabled/missing action is disabled one more time, not an error */
}
else {
if (isnan (act_score)) {