From 94edb9f04b2144be4a78556653451456738ba767 Mon Sep 17 00:00:00 2001 From: "cebka@lenovo-laptop" Date: Wed, 17 Feb 2010 18:57:05 +0300 Subject: [PATCH] * Add ability to add custom messages to rspamd output * Add messages from spf checks --- src/main.h | 1 + src/plugins/fuzzy_check.c | 8 ++------ src/plugins/spf.c | 3 +++ src/protocol.c | 22 +++++++++++++++++++++- src/spf.c | 6 ++++++ src/worker.c | 3 +++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main.h b/src/main.h index a7cab8676..cffb215d5 100644 --- a/src/main.h +++ b/src/main.h @@ -199,6 +199,7 @@ struct worker_task { GList *urls; /**< list of parsed urls */ GHashTable *results; /**< hash table of metric_result indexed by * metric's name */ + GList *messages; /**< list of messages that would be reported */ GHashTable *re_cache; /**< cache for matched or not matched regexps */ struct config_file *cfg; /**< pointer to config object */ struct save_point save; /**< save point for delayed processing */ diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 987a2cb40..40b1aaa79 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -490,7 +490,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c { char *arg, out_buf[BUFSIZ], *err_str; uint32_t size; - int r, value, *sargs; + int r, value = 1, *sargs; /* Process size */ arg = args[0]; @@ -510,11 +510,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c } /* Process value */ arg = args[1]; - if (!arg || *arg == '\0') { - msg_info ("empty value, assume it 1"); - value = 1; - } - else { + if (arg && *arg != '\0') { value = strtol (arg, &err_str, 10); } diff --git a/src/plugins/spf.c b/src/plugins/spf.c index ae762f12a..57a6f4407 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -155,13 +155,16 @@ spf_plugin_callback (struct spf_record *record, struct worker_task *task) switch (addr->mech) { case SPF_FAIL: insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_fail, 1, g_list_prepend (NULL, addr->spf_string)); + task->messages = g_list_prepend (task->messages, "(SPF): spf fail"); break; case SPF_SOFT_FAIL: case SPF_NEUTRAL: insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_softfail, 1, g_list_prepend (NULL, addr->spf_string)); + task->messages = g_list_prepend (task->messages, "(SPF): spf softfail"); break; default: insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_allow, 1, g_list_prepend (NULL, addr->spf_string)); + task->messages = g_list_prepend (task->messages, "(SPF): spf allow"); break; } /* Stop parsing */ diff --git a/src/protocol.c b/src/protocol.c index 134820cab..e07640807 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -547,6 +547,7 @@ show_metric_symbols (struct metric_result *metric_res, struct metric_callback_da } } + static void show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data) { @@ -652,6 +653,22 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data (long int)task->msg->len, calculate_check_time (&task->ts, task->cfg->clock_res)); } +static void +show_messages (struct worker_task *task) +{ + int r = 0; + char outbuf[OUTBUFSIZ]; + GList *cur; + + cur = task->messages; + while (cur) { + r += snprintf (outbuf + r, sizeof (outbuf) - r, "Message: %s" CRLF, (char *)cur->data); + cur = g_list_next (cur); + } + + rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE); +} + static int write_check_reply (struct worker_task *task) { @@ -694,6 +711,8 @@ write_check_reply (struct worker_task *task) /* Write result for each metric separately */ g_hash_table_foreach (task->results, show_metric_result, &cd); + /* Messages */ + show_messages (task); /* URL stat */ show_url_header (task); } @@ -748,7 +767,8 @@ write_process_reply (struct worker_task *task) /* Write result for each metric separately */ g_hash_table_foreach (task->results, show_metric_result, &cd); - /* URL stat */ + /* Messages */ + show_messages (task); } write_hashes_to_log (task, logbuf, cd.log_offset, cd.log_size); msg_info ("%s", logbuf); diff --git a/src/spf.c b/src/spf.c index d9f64310d..50ad3176e 100644 --- a/src/spf.c +++ b/src/spf.c @@ -887,6 +887,12 @@ parse_spf_record (struct worker_task *task, struct spf_record *rec) begin += sizeof (SPF_INCLUDE) - 1; res = parse_spf_include (task, begin, rec, new); } + else if (strncmp (begin, SPF_IP6, sizeof (SPF_IP4) - 1) == 0) { + begin += sizeof (SPF_IP6) - 1; + msg_info ("ignoring ip6 spf command as IPv6 is not supported: %s", begin); + new = NULL; + res = TRUE; + } else { msg_info ("bad spf command: %s", begin); } diff --git a/src/worker.c b/src/worker.c index 92c80bc32..0f1be1047 100644 --- a/src/worker.c +++ b/src/worker.c @@ -214,6 +214,9 @@ free_task (struct worker_task *task, gboolean is_soft) if (task->urls) { g_list_free (task->urls); } + if (task->messages) { + g_list_free (task->messages); + } memory_pool_delete (task->task_pool); if (task->dispatcher) { if (is_soft) { -- 2.39.5