aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-29 12:27:41 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-29 12:27:41 +0000
commitbb5e5fb4149df13488fa04623a50eca3ada13f7e (patch)
tree7410848ae7e4f2fb2f482743b258cae69f5b87f1 /src/libmime
parentb1c259630635d5cf262cc942e1faada1616da36f (diff)
downloadrspamd-bb5e5fb4149df13488fa04623a50eca3ada13f7e.tar.gz
rspamd-bb5e5fb4149df13488fa04623a50eca3ada13f7e.zip
[Rework] Allow to set a different behaviour for actions from settings
Issue: #4025
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/message.c3
-rw-r--r--src/libmime/scan_result.c48
-rw-r--r--src/libmime/scan_result.h13
3 files changed, 51 insertions, 13 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 1676e4218..ec49b3b5e 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -862,7 +862,8 @@ rspamd_message_process_text_part_maybe (struct rspamd_task *task,
rspamd_add_passthrough_result (task, action,
RSPAMD_PASSTHROUGH_CRITICAL,
- score, "Gtube pattern", "GTUBE", 0, NULL);
+ score, "Gtube pattern",
+ "GTUBE", 0, NULL);
}
rspamd_task_insert_result (task, GTUBE_SYMBOL, 0, NULL);
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index 16ec9b0c5..37244f60f 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -91,15 +91,15 @@ rspamd_create_metric_result (struct rspamd_task *task,
if (task->cfg) {
struct rspamd_action *act, *tmp;
- metric_res->actions_limits = rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct rspamd_action_result) * HASH_COUNT (task->cfg->actions));
+ metric_res->actions_config = rspamd_mempool_alloc0 (task->task_pool,
+ sizeof (struct rspamd_action_config) * HASH_COUNT (task->cfg->actions));
i = 0;
HASH_ITER (hh, task->cfg->actions, act, tmp) {
if (!(act->flags & RSPAMD_ACTION_NO_THRESHOLD)) {
- metric_res->actions_limits[i].cur_limit = act->threshold;
+ metric_res->actions_config[i].cur_limit = act->threshold;
}
- metric_res->actions_limits[i].action = act;
+ metric_res->actions_config[i].action = act;
i ++;
}
@@ -122,9 +122,14 @@ rspamd_pr_sort (const struct rspamd_passthrough_result *pra,
return prb->priority - pra->priority;
}
-void
-rspamd_add_passthrough_result (struct rspamd_task *task, struct rspamd_action *action, guint priority,
- double target_score, const gchar *message, const gchar *module, guint flags,
+bool
+rspamd_add_passthrough_result (struct rspamd_task *task,
+ struct rspamd_action *action,
+ guint priority,
+ double target_score,
+ const gchar *message,
+ const gchar *module,
+ uint flags,
struct rspamd_scan_result *scan_result)
{
struct rspamd_passthrough_result *pr;
@@ -133,6 +138,29 @@ rspamd_add_passthrough_result (struct rspamd_task *task, struct rspamd_action *a
scan_result = task->result;
}
+ /* Find the speicific action config */
+ struct rspamd_action_config *action_config = NULL;
+
+ for (unsigned int i = 0; i < HASH_COUNT (task->cfg->actions); i ++) {
+ struct rspamd_action_config *cur = &scan_result->actions_config[i];
+
+ /* We assume that all action pointers are static */
+ if (cur->action == action) {
+ action_config = cur;
+ break;
+ }
+ }
+
+ if (action_config && (action_config->flags & RSPAMD_ACTION_RESULT_DISABLED)) {
+ msg_info_task ("<%s>: NOT set pre-result to '%s' %s(%.2f): '%s' from %s(%d); action is disabled",
+ MESSAGE_FIELD_CHECK (task, message_id), action->name,
+ flags & RSPAMD_PASSTHROUGH_LEAST ? "*least " : "",
+ target_score,
+ message, module, priority);
+
+ return false;
+ }
+
pr = rspamd_mempool_alloc (task->task_pool, sizeof (*pr));
pr->action = action;
pr->priority = priority;
@@ -160,6 +188,8 @@ rspamd_add_passthrough_result (struct rspamd_task *task, struct rspamd_action *a
}
scan_result->nresults ++;
+
+ return true;
}
static inline gdouble
@@ -777,7 +807,7 @@ rspamd_check_action_metric (struct rspamd_task *task,
struct rspamd_passthrough_result **ppr,
struct rspamd_scan_result *scan_result)
{
- struct rspamd_action_result *action_lim,
+ struct rspamd_action_config *action_lim,
*noaction = NULL;
struct rspamd_action *selected_action = NULL, *least_action = NULL;
struct rspamd_passthrough_result *pr, *sel_pr = NULL;
@@ -850,7 +880,7 @@ rspamd_check_action_metric (struct rspamd_task *task,
* Select result by score
*/
for (i = scan_result->nactions - 1; i >= 0; i--) {
- action_lim = &scan_result->actions_limits[i];
+ action_lim = &scan_result->actions_config[i];
sc = action_lim->cur_limit;
if (action_lim->action->action_type == METRIC_ACTION_NOACTION) {
diff --git a/src/libmime/scan_result.h b/src/libmime/scan_result.h
index c8bacf3e8..2f982fd1b 100644
--- a/src/libmime/scan_result.h
+++ b/src/libmime/scan_result.h
@@ -66,8 +66,15 @@ struct rspamd_passthrough_result {
struct rspamd_passthrough_result *prev, *next;
};
-struct rspamd_action_result {
+
+enum rspamd_action_config_flags {
+ RSPAMD_ACTION_RESULT_DEFAULT = 0,
+ RSPAMD_ACTION_RESULT_NO_THRESHOLD = (1u << 0u),
+ RSPAMD_ACTION_RESULT_DISABLED = (1u << 1u),
+};
+struct rspamd_action_config {
gdouble cur_limit;
+ int flags;
struct rspamd_action *action;
};
@@ -83,7 +90,7 @@ struct rspamd_scan_result {
double negative_score;
struct kh_rspamd_symbols_hash_s *symbols; /**< symbols of metric */
struct kh_rspamd_symbols_group_hash_s *sym_groups; /**< groups of symbols */
- struct rspamd_action_result *actions_limits;
+ struct rspamd_action_config *actions_config;
const gchar *name; /**< for named results, NULL is the default result */
struct rspamd_task *task; /**< back reference */
gint symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */
@@ -121,7 +128,7 @@ struct rspamd_scan_result *rspamd_find_metric_result (struct rspamd_task *task,
* @param message
* @param module
*/
-void rspamd_add_passthrough_result (struct rspamd_task *task,
+bool rspamd_add_passthrough_result (struct rspamd_task *task,
struct rspamd_action *action, guint priority,
double target_score, const gchar *message,
const gchar *module, guint flags,