From: Vsevolod Stakhov Date: Sun, 13 Feb 2011 23:49:59 +0000 (+0300) Subject: Fix bug with several metrics output. [1] X-Git-Tag: 0.3.7~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d479b7c8ed1ce247d7c8beebe8870e24a151b357;p=rspamd.git Fix bug with several metrics output. [1] Install surbl-whitelist. [1] [1] Reported by Victor Ustugov --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 78293ee92..749bbfe08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -779,6 +779,11 @@ IF(NOT EXISTS ${ETC_PREFIX}/rspamd/2tld.inc) INSTALL(FILES conf/2tld.inc DESTINATION etc/rspamd) ENDIF(NOT EXISTS ${ETC_PREFIX}/rspamd/2tld.inc) +INSTALL(FILES conf/surbl-whitelist.inc RENAME surbl-whitelist.inc DESTINATION etc/rspamd) +IF(NOT EXISTS ${ETC_PREFIX}/rspamd/surbl-whitelist.inc) + INSTALL(FILES conf/surbl-whitelist.inc DESTINATION etc/rspamd) +ENDIF(NOT EXISTS ${ETC_PREFIX}/rspamd/surbl-whitelist.inc) + INSTALL(FILES conf/rspamd.xml.sample DESTINATION etc/) # Lua plugins diff --git a/lib/librspamdclient.c b/lib/librspamdclient.c index 2bc45c888..ef4518e51 100644 --- a/lib/librspamdclient.c +++ b/lib/librspamdclient.c @@ -258,16 +258,17 @@ parse_rspamd_metric_line (struct rspamd_connection *conn, guint len, GError **er struct rspamd_metric *new; p = b; - c = b; + + while (g_ascii_isspace (*p)) { + p ++; + } + c = p; + while (p - b < remain) { switch (state) { case 0: /* Read metric's name */ - if (g_ascii_isspace (*p)) { - state = 99; - next_state = 0; - } - else if (*p == ';') { + if (*p == ';') { if (p - c <= 1) { /* Empty metric name */ goto err; diff --git a/src/filter.c b/src/filter.c index e1e5d06bc..1091de0ca 100644 --- a/src/filter.c +++ b/src/filter.c @@ -86,7 +86,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch if ((s = g_hash_table_lookup (metric_res->symbols, symbol)) != NULL) { if (s->options && opts && opts != s->options) { /* Append new options */ - s->options = g_list_concat (s->options, opts); + s->options = g_list_concat (s->options, g_list_copy(opts)); /* * Note that there is no need to add new destructor of GList as elements of appended * GList are used directly, so just free initial GList diff --git a/src/protocol.c b/src/protocol.c index 38d6d4423..e430fd03b 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -723,49 +723,63 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data } if (metric_name == NULL || metric_value == NULL) { m = g_hash_table_lookup (task->cfg->metrics, DEFAULT_METRIC); - default_required_score = m->required_score; - default_score = 0; + default_required_score = m->required_score; + default_score = 0; if (!check_metric_settings (task, m, &ms, &rs)) { ms = m->required_score; rs = m->reject_score; } if (task->proto == SPAMC_PROTO) { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: False ; 0 / %.2f" CRLF, ms); + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Spam: False ; 0 / %.2f" CRLF, ms); } else { if (task->proto_ver >= 11) { - if (!task->is_skipped) { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs); - } - else { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; Skip; 0 / %.2f / %.2f" CRLF, ms, rs); - } + if (!task->is_skipped) { + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, + rs); + } + else { + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: default; Skip; 0 / %.2f / %.2f" CRLF, ms, + rs); + } } else { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f" CRLF, ms); + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: default; False; 0 / %.2f" CRLF, ms); } - r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "Action: %s" CRLF, str_action_metric (METRIC_ACTION_NOACTION)); + r += rspamd_snprintf (outbuf + r, sizeof(outbuf) - r, + "Action: %s" CRLF, str_action_metric ( + METRIC_ACTION_NOACTION)); + } + if (!task->is_skipped) { + cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, + cd->log_size - cd->log_offset, + "(%s: F (no action): [0/%.2f/%.2f] [", "default", ms, rs); + } + else { + cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, + cd->log_size - cd->log_offset, "(%s: S: [0/%.2f/%.2f] [", + "default", ms, rs); } - if (!task->is_skipped) { - cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: F (no action): [0/%.2f/%.2f] [", "default", ms, rs); - } - else { - cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: S: [0/%.2f/%.2f] [", "default", ms, rs); - } } else { - /* XXX: dirty hack */ - if (strcmp (metric_res->metric->name, DEFAULT_METRIC) == 0) { - default_required_score = metric_res->metric->required_score; - default_score = metric_res->score; - } + /* XXX: dirty hack */ + if (strcmp (metric_res->metric->name, DEFAULT_METRIC) == 0) { + default_required_score = metric_res->metric->required_score; + default_score = metric_res->score; + } if (!check_metric_settings (task, metric_res->metric, &ms, &rs)) { ms = metric_res->metric->required_score; rs = metric_res->metric->reject_score; } - if (! check_metric_action_settings (task, metric_res->metric, metric_res->score, &action)) { - action = check_metric_action (metric_res->score, ms, metric_res->metric); + if (!check_metric_action_settings (task, metric_res->metric, + metric_res->score, &action)) { + action = check_metric_action (metric_res->score, ms, + metric_res->metric); } if (metric_res->score >= ms) { @@ -774,62 +788,79 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data if (task->proto == SPAMC_PROTO) { if (task->cmd != CMD_REPORT_IFSPAM || is_spam) { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: %s ; %.2f / %.2f" CRLF, (is_spam) ? "True" : "False", metric_res->score, ms); + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Spam: %s ; %.2f / %.2f" CRLF, (is_spam) ? "True" + : "False", metric_res->score, ms); } } else { if (task->proto_ver >= 11) { - if (!task->is_skipped) { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, - (gchar *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms, rs); - } - else { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; Skip; %.2f / %.2f / %.2f" CRLF, - (gchar *)metric_name, metric_res->score, ms, rs); - } + if (!task->is_skipped) { + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, + (gchar *) metric_name, + (is_spam) ? "True" : "False", metric_res->score, + ms, rs); + } + else { + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: %s; Skip; %.2f / %.2f / %.2f" CRLF, + (gchar *) metric_name, metric_res->score, ms, rs); + } } else { - r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f" CRLF, - (gchar *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms); + r = rspamd_snprintf (outbuf, sizeof(outbuf), + "Metric: %s; %s; %.2f / %.2f" CRLF, + (gchar *) metric_name, (is_spam) ? "True" : "False", + metric_res->score, ms); } - r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "Action: %s" CRLF, str_action_metric(action)); + r += rspamd_snprintf (outbuf + r, sizeof(outbuf) - r, + "Action: %s" CRLF, str_action_metric (action)); + } + if (!task->is_skipped) { + cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, + cd->log_size - cd->log_offset, + "(%s: %c (%s): [%.2f/%.2f/%.2f] [", (gchar *) metric_name, + is_spam ? 'T' : 'F', str_action_metric (action), + metric_res->score, ms, rs); + } + else { + cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, + cd->log_size - cd->log_offset, + "(%s: %c (default): [%.2f/%.2f/%.2f] [", + (gchar *) metric_name, 'S', metric_res->score, ms, rs); + } - if (!task->is_skipped) { - cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %c (%s): [%.2f/%.2f/%.2f] [", - (gchar *)metric_name, is_spam ? 'T' : 'F', str_action_metric (action), metric_res->score, ms, rs); - } - else { - cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %c (default): [%.2f/%.2f/%.2f] [", - (gchar *)metric_name, 'S', metric_res->score, ms, rs); - - } } if (task->cmd == CMD_PROCESS) { #ifndef GMIME24 g_mime_message_add_header (task->message, "X-Spam-Status", outbuf); #else - g_mime_object_append_header (GMIME_OBJECT (task->message), "X-Spam-Status", outbuf); + g_mime_object_append_header (GMIME_OBJECT (task->message), + "X-Spam-Status", outbuf); #endif } else { - if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) { + if (!rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE)) { cd->alive = FALSE; return; } if (metric_value != NULL) { - if (! show_metric_symbols (metric_res, cd)) { + if (!show_metric_symbols (metric_res, cd)) { cd->alive = FALSE; return; } } } #ifdef HAVE_CLOCK_GETTIME - cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %z, time: %s,", - task->msg->len, calculate_check_time (&task->tv, &task->ts, task->cfg->clock_res)); + cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, + cd->log_size - cd->log_offset, "]), len: %z, time: %s,", + task->msg->len, calculate_check_time (&task->tv, &task->ts, + task->cfg->clock_res)); #else cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %z, time: %s,", - task->msg->len, calculate_check_time (&task->tv, task->cfg->clock_res)); + task->msg->len, calculate_check_time (&task->tv, task->cfg->clock_res)); #endif }