]> source.dussan.org Git - rspamd.git/commitdiff
* Fix getting of message headers from lua plugins
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 14 Oct 2009 14:46:50 +0000 (18:46 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 14 Oct 2009 14:46:50 +0000 (18:46 +0400)
* Fix forged recipients plugin

src/lua/lua_message.c
src/message.c
src/plugins/lua/forged_recipients.lua
src/spf.c

index a6a12213a295593cbd5a71e136bb90c2c0d6dd99..98a4ae6ede48231640f1e049118365cfe7dff5cd 100644 (file)
@@ -97,16 +97,16 @@ lua_check_message (lua_State * L)
 /*** Message interface ***/
 
 LUA_GMIME_BRIDGE_GET (message, get_subject, Message)
-       LUA_GMIME_BRIDGE_SET (message, set_subject, Message)
-       LUA_GMIME_BRIDGE_GET (message, get_message_id, Message)
-       LUA_GMIME_BRIDGE_SET (message, set_message_id, Message)
-       LUA_GMIME_BRIDGE_GET (message, get_sender, Message)
-       LUA_GMIME_BRIDGE_SET (message, set_sender, Message)
-       LUA_GMIME_BRIDGE_GET (message, get_reply_to, Message)
-       LUA_GMIME_BRIDGE_SET (message, set_reply_to, Message)
-
-  static int
-                                  lua_message_get_header (lua_State * L)
+LUA_GMIME_BRIDGE_SET (message, set_subject, Message)
+LUA_GMIME_BRIDGE_GET (message, get_message_id, Message)
+LUA_GMIME_BRIDGE_SET (message, set_message_id, Message)
+LUA_GMIME_BRIDGE_GET (message, get_sender, Message)
+LUA_GMIME_BRIDGE_SET (message, set_sender, Message)
+LUA_GMIME_BRIDGE_GET (message, get_reply_to, Message)
+LUA_GMIME_BRIDGE_SET (message, set_reply_to, Message)
+
+static int
+lua_message_get_header (lua_State * L)
 {
        const char                     *headern;
        GMimeMessage                   *obj = lua_check_message (L);
@@ -126,7 +126,7 @@ LUA_GMIME_BRIDGE_GET (message, get_subject, Message)
                                        g_free (cur->data);
                                        cur = g_list_next (cur);
                                }
-                               g_free (res);
+                               g_list_free (res);
                        }
                        else {
                                lua_pushnil (L);
index 4bfaf093a60506eb106b9ac0cbf8d5fc718ca1bd..5cdd247680044da51590900c8fc040a30022bed1 100644 (file)
@@ -1177,13 +1177,14 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const char *fi
                                break;
                        case FUNC_IA:
                                ia_list = (*(fieldfunc[i].rcptfunc)) (message, field);
-                               gret = g_list_alloc ();
                                ia = ia_list;
 #ifndef GMIME24
                                while (ia && ia->address) {
 
                                        ia_string = internet_address_to_string ((InternetAddress *) ia->address, FALSE);
-                                       memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string);
+                                       if (pool != NULL) {
+                                               memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string);
+                                       }
                                        gret = g_list_prepend (gret, ia_string);
                                        ia = ia->next;
                                }
@@ -1191,7 +1192,9 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const char *fi
                                i = internet_address_list_length (ia);
                                while (i > 0) {
                                        ia_string = internet_address_to_string (internet_address_list_get_address (ia, i), FALSE);
-                                       memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string);
+                                       if (pool != NULL) {
+                                               memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string);
+                                       }
                                        gret = g_list_prepend (gret, ia_string);
                                        --i;
                                }
index b3aa2f5774a9adbb5cdd3c97759b125e71165fda..d3463daae02069f51e5eb7cefcd54b25124059f1 100644 (file)
@@ -9,26 +9,37 @@ function check_forged_headers(task)
        local msg = task:get_message()
        local smtp_rcpt = task:get_recipients()
        local res = false
-
+       
        if smtp_rcpt then
                local mime_rcpt = msg:get_header('To')
                local mime_cc = msg:get_header('Cc')
+               local count = 0
+               if mime_rcpt then
+                       count = table.maxn(mime_rcpt)
+               end
+               if mime_cc then
+                       count = count + table.maxn(mime_cc)
+               end
                -- Check recipients count
-               if table.maxn(mime_rcpt) + table.maxn(mime_cc) <= table.maxn(smtp_rcpt) then
+               if count <= table.maxn(smtp_rcpt) then
                        task:insert_result(metric, symbol_rcpt, 1)
                else
                        -- Find pair for each smtp recipient recipient in To or Cc headers
                        for _,sr in ipairs(smtp_rcpt) do
-                               for _,mr in ipairs(mime_rcpt) do
-                                       if string.find(mr, sr) then
-                                               res = true
-                                               break
+                               if mime_rcpt then
+                                       for _,mr in ipairs(mime_rcpt) do
+                                               if string.find(mr, sr) then
+                                                       res = true
+                                                       break
+                                               end
                                        end
                                end
-                               for _,mr in ipairs(mime_cc) do
-                                       if string.find(mr, sr) then
-                                               res = true
-                                               break
+                               if mime_cc then
+                                       for _,mr in ipairs(mime_cc) do
+                                               if string.find(mr, sr) then
+                                                       res = true
+                                                       break
+                                               end
                                        end
                                end
 
index b4736e3ceefcca211b3d77526e62a7a626802f39..695eaaea46d6700a027f30cccd8fb7555961c32c 100644 (file)
--- a/src/spf.c
+++ b/src/spf.c
 #define SPF_REDIRECT "redirect"
 #define SPF_EXP "exp"
 
+/** SPF limits for avoiding abuse **/
+#define SPF_MAX_NESTING 5
+#define SPF_MAX_DNS_REQUESTS 10
+
 /**
  * State machine for SPF record:
  *
@@ -91,37 +95,8 @@ check_spf_mech (const char *elt, gboolean *need_shift)
 }
 
 static gboolean
-parse_spf_a (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
-{
-       struct spf_dns_cb *cb;
-}
-
-static gboolean
-parse_spf_ptr (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
-{
-       struct spf_dns_cb *cb;
-
-}
-
-static gboolean
-parse_spf_mx (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+parse_spf_ipmask (const char *begin, struct spf_addr *addr)
 {
-       struct spf_dns_cb *cb;
-
-}
-
-static gboolean
-parse_spf_all (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
-{
-       /* All is 0/0 */
-       addr->addr = 0;
-       addr->mask = 0;
-}
-
-static gboolean
-parse_spf_ip4 (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
-{
-       /* ip4:addr[/mask] */
        const char *pos;
        char ip_buf[sizeof ("255.255.255.255")], mask_buf[3], *p;
        int state = 0, dots = 0;
@@ -194,8 +169,45 @@ parse_spf_ip4 (struct worker_task *task, const char *begin, struct spf_record *r
        else {
                addr->mask = 32;
        }
-       
+
        return TRUE;
+
+}
+
+static gboolean
+parse_spf_a (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+{
+       struct spf_dns_cb *cb;
+}
+
+static gboolean
+parse_spf_ptr (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+{
+       struct spf_dns_cb *cb;
+
+}
+
+static gboolean
+parse_spf_mx (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+{
+       struct spf_dns_cb *cb;
+
+}
+
+static gboolean
+parse_spf_all (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+{
+       /* All is 0/0 */
+       addr->addr = 0;
+       addr->mask = 0;
+}
+
+static gboolean
+parse_spf_ip4 (struct worker_task *task, const char *begin, struct spf_record *rec, struct spf_addr *addr)
+{
+       /* ip4:addr[/mask] */
+
+       return parse_spf_ipmask (begin, addr);
 }
 
 static gboolean