]> source.dussan.org Git - rspamd.git/commitdiff
* Write symbols weights to rspamc output
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Sat, 31 Jul 2010 14:59:40 +0000 (18:59 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Sat, 31 Jul 2010 14:59:40 +0000 (18:59 +0400)
* Improve logic of selecting rspamc version
* Do not try to parse broken DNS replies
* Add 'raw' flag to FROM_EXCESS_BASE64 rule (requested by citrin)

conf/lua/regexp/headers.lua
perl/lib/Mail/Rspamd/Client.pm
rspamc.pl.in
src/dns.c
src/main.h
src/protocol.c
src/protocol.h

index d296b365394587050d33825bec9dd96471cd0a51..4c415a2f37489b58555f0ed6660b28d2c6ae9ad4 100644 (file)
@@ -77,7 +77,7 @@ reconf['TRACKER_ID'] = '/^[a-z0-9]{6,24}[-_a-z0-9]{2,36}[a-z0-9]{6,24}\\s*\\z/is
 -- Regexp that checks that from header is encoded with base64 (search in raw headers)
 local from_encoded_b64 = 'From=/\\=\\?\\S+\\?B\\?/iX'
 -- From contains only 7bit characters (parsed headers are used)
-local from_needs_mime = 'From=/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f-\\xff]/H'
+local from_needs_mime = 'From=/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f-\\xff]/Hr'
 -- Final rule
 reconf['FROM_EXCESS_BASE64'] = string.format('%s & !%s', from_encoded_b64, from_needs_mime)
 
index 789b3187d95bd6aa0fb5c1f0ddafa1159a1732fe..4af7a02d908f26278e63c74a1417337626beb6bc 100644 (file)
@@ -35,7 +35,7 @@ $VERSION = "1.02";
 
 my $EOL = "\015\012";
 my $BLANK = $EOL x 2;
-my $PROTOVERSION = 'RSPAMC/1.0';
+my $PROTOVERSION = 'RSPAMC/1.2';
 
 =head1 PUBLIC METHODS
 
@@ -953,14 +953,16 @@ sub _do_rspamc_command {
        }
        else {
                foreach my $line (@lines) {
-                       if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+)!) {
+                       if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+) (/ (\S+))?!) {
                                $metrics{$1} = {
                                        isspam => $2,
                                        score => $3 + 0,
                                        threshold => $4 + 0,
+                                       reject_score => $6,
                                        symbols => [],
                                        urls => [],
                                        messages => [],
+                                       action => 'no action',
                                };
                                $cur_metric = $1;
                        }
index b2f6162d809289c92d0dbf3ca1eb00fd71eddef5..8d69e341aa27e742085f30d470cd1c12b1c54fdf 100755 (executable)
@@ -288,6 +288,7 @@ if ($cmd =~ /(SYMBOLS|PROCESS|CHECK|URLS|EMAILS)/i) {
 elsif ($cmd =~ /(STAT|LEARN|SHUTDOWN|RELOAD|UPTIME|COUNTERS|FUZZY_ADD|FUZZY_DEL|WEIGHTS)/i) {
     $cfg{'command'} = $1;
     $cfg{'control'} = 1;
+       $cfg{'hosts'} = ['localhost:11334'];
 }
 else {
     die "unknown command $cmd";
index 5197aae66d0311b126ed99bd4e50b94e0c64c318..c50b9f3883cf7ae141204ee28ea85ef00c83d2e3 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -771,7 +771,7 @@ dns_parse_rr (guint8 *in, union rspamd_reply_element *elt, guint8 **pos, struct
                msg_info ("bad RR name");
                return -1;
        }
-       if (p - *pos >= *remain - sizeof (guint16) * 5) {
+       if (p - *pos >= *remain - sizeof (guint16) * 5 || *remain <= 0) {
                msg_info ("stripped dns reply");
                return -1;
        }
index e35a7eea30e584db7db12551b7615536d900410a..697c63f472299af81419b26cd322123360dbd282 100644 (file)
@@ -173,7 +173,7 @@ struct worker_task {
        } state;                                                                                                        /**< current session state                                                      */
        size_t content_length;                                                                          /**< length of user's input                                                     */
        enum rspamd_protocol proto;                                                                     /**< protocol (rspamc or spamc)                                         */
-       const char *proto_ver;                                                                          /**< protocol version                                                           */
+       guint proto_ver;                                                                                        /**< protocol version                                                           */
        enum rspamd_command cmd;                                                                        /**< command                                                                            */
        struct custom_command *custom_cmd;                                                      /**< custom command if any                                                      */      
        int sock;                                                                                                       /**< socket descriptor                                                          */
index cb79b258ceab80d5050c8e37e6ecb1f0736cd24e..297aaa9226fbcf6a96cac1d03e136e2cacd14186 100644 (file)
@@ -92,6 +92,20 @@ static GList                   *custom_commands = NULL;
 /* For default metric, dirty hack, but much faster than hash lookup */
 static double default_score, default_required_score;
 
+G_INLINE_FUNC const char *
+rspamc_proto_str (guint ver)
+{
+       if (ver >= 12) {
+               return "1.2";
+       }
+       else if (ver >= 11) {
+               return "1.1";
+       }
+       else {
+               return "1.0";
+       }
+}
+
 static char                    *
 separate_command (f_str_t * in, char c)
 {
@@ -120,7 +134,7 @@ parse_command (struct worker_task *task, f_str_t * line)
        struct custom_command          *cmd;
        GList                          *cur;
 
-       task->proto_ver = RSPAMC_PROTO_1_1;
+       task->proto_ver = 11;
        token = separate_command (line, ' ');
        if (line == NULL || token == NULL) {
                debug_task ("bad command");
@@ -202,12 +216,15 @@ parse_command (struct worker_task *task, f_str_t * line)
 
        if (g_ascii_strncasecmp (line->begin, RSPAMC_GREETING, sizeof (RSPAMC_GREETING) - 1) == 0) {
                task->proto = RSPAMC_PROTO;
-               task->proto_ver = RSPAMC_PROTO_1_0;
+               task->proto_ver = 10;
                if (*(line->begin + sizeof (RSPAMC_GREETING) - 1) == '/') {
                        /* Extract protocol version */
                        token = line->begin + sizeof (RSPAMC_GREETING);
                        if (strncmp (token, RSPAMC_PROTO_1_1, sizeof (RSPAMC_PROTO_1_1) - 1) == 0) {
-                               task->proto_ver = RSPAMC_PROTO_1_1;
+                               task->proto_ver = 11;
+                       }
+                       else if (strncmp (token, RSPAMC_PROTO_1_2, sizeof (RSPAMC_PROTO_1_2) - 1) == 0) {
+                               task->proto_ver = 12;
                        }
                }
        }
@@ -529,7 +546,12 @@ metric_symbols_callback (gpointer key, gpointer value, void *user_data)
        }
 
        if (s->options) {
-               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (char *)key);
+               if (task->proto_ver >= 12) {
+                       r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f); ", (char *)key, s->score);
+               }
+               else {
+                       r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s; ", (char *)key);
+               }
                cur = s->options;
                while (cur) {
                        if (g_list_next (cur)) {
@@ -547,7 +569,12 @@ metric_symbols_callback (gpointer key, gpointer value, void *user_data)
                }
        }
        else {
-               r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (char *)key);
+               if (task->proto_ver >= 12) {
+                       r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s(%.2f)" CRLF, (char *)key, s->score);
+               }
+               else {
+                       r = rspamd_snprintf (outbuf, OUTBUFSIZ, "Symbol: %s" CRLF, (char *)key);
+               }
        }
        cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "%s,", (char *)key);
 
@@ -670,7 +697,7 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: False ; 0 / %.2f" CRLF, ms);
                }
                else {
-                       if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
+                       if (task->proto_ver >= 11) {
                 if (!task->is_skipped) {
                                    r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs);
                 }
@@ -709,7 +736,7 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "Spam: %s ; %.2f / %.2f" CRLF, (is_spam) ? "True" : "False", metric_res->score, ms);
                }
                else {
-                       if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
+                       if (task->proto_ver >= 11) {
                 if (!task->is_skipped) {
                                    r = rspamd_snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, 
                                                (char *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms, rs);
@@ -793,7 +820,7 @@ write_check_reply (struct worker_task *task)
        struct metric_callback_data     cd;
 
        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER,
-                                       task->proto_ver, "OK");
+                               rspamc_proto_str (task->proto_ver), "OK");
        if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, TRUE, FALSE)) {
                return FALSE;
        }
@@ -882,7 +909,7 @@ write_process_reply (struct worker_task *task)
 
        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF "Content-Length: %zd" CRLF CRLF, 
                        (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, 
-                       task->proto_ver, "OK", task->msg->len);
+                       rspamc_proto_str (task->proto_ver), "OK", task->msg->len);
 
        cd.task = task;
        cd.log_buf = logbuf;
@@ -970,12 +997,12 @@ write_reply (struct worker_task *task)
                /* Write error message and error code to reply */
                if (task->proto == SPAMC_PROTO) {
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF CRLF, 
-                                       SPAMD_REPLY_BANNER, task->proto_ver, task->error_code, SPAMD_ERROR);
+                                       SPAMD_REPLY_BANNER, rspamc_proto_str (task->proto_ver), task->error_code, SPAMD_ERROR);
                        debug_task ("writing error: %s", outbuf);
                }
                else {
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s %d %s" CRLF "%s: %s" CRLF CRLF, 
-                                       RSPAMD_REPLY_BANNER, task->proto_ver, task->error_code, SPAMD_ERROR, ERROR_HEADER, task->last_error);
+                                       RSPAMD_REPLY_BANNER, rspamc_proto_str (task->proto_ver), task->error_code, SPAMD_ERROR, ERROR_HEADER, task->last_error);
                        debug_task ("writing error: %s", outbuf);
                }
                /* Write to bufferevent error message */
@@ -994,12 +1021,12 @@ write_reply (struct worker_task *task)
                        break;
                case CMD_SKIP:
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 %s" CRLF, 
-                                       (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, task->proto_ver, SPAMD_OK);
+                                       (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, rspamc_proto_str (task->proto_ver), SPAMD_OK);
                        return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE);
                        break;
                case CMD_PING:
                        r = rspamd_snprintf (outbuf, sizeof (outbuf), "%s/%s 0 PONG" CRLF, 
-                                       (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, task->proto_ver);
+                                       (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, rspamc_proto_str (task->proto_ver));
                        return rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE);
                        break;
                case CMD_OTHER:
index d45e5c5553f2b275fc3a21e3ace4f2c212711e5e..c216259f61c89e758fc95f0f5d181f7790a37e31 100644 (file)
@@ -15,6 +15,7 @@
 
 #define RSPAMC_PROTO_1_0 "1.0"
 #define RSPAMC_PROTO_1_1 "1.1"
+#define RSPAMC_PROTO_1_2 "1.2"
 
 /*
  * Reply messages