aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-14 18:46:50 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-14 18:46:50 +0400
commit9ebf3a1a948f328543101ff1d2ab0f7521de8963 (patch)
treea944ec5e2951314c7fda39ba2628a7fff63ce165
parentd16336b4929ac76a1661b9c7dafd28568e6e0859 (diff)
downloadrspamd-9ebf3a1a948f328543101ff1d2ab0f7521de8963.tar.gz
rspamd-9ebf3a1a948f328543101ff1d2ab0f7521de8963.zip
* Fix getting of message headers from lua plugins
* Fix forged recipients plugin
-rw-r--r--src/lua/lua_message.c22
-rw-r--r--src/message.c9
-rw-r--r--src/plugins/lua/forged_recipients.lua31
-rw-r--r--src/spf.c74
4 files changed, 81 insertions, 55 deletions
diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c
index a6a12213a..98a4ae6ed 100644
--- a/src/lua/lua_message.c
+++ b/src/lua/lua_message.c
@@ -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);
diff --git a/src/message.c b/src/message.c
index 4bfaf093a..5cdd24768 100644
--- a/src/message.c
+++ b/src/message.c
@@ -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;
}
diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua
index b3aa2f577..d3463daae 100644
--- a/src/plugins/lua/forged_recipients.lua
+++ b/src/plugins/lua/forged_recipients.lua
@@ -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
diff --git a/src/spf.c b/src/spf.c
index b4736e3ce..695eaaea4 100644
--- a/src/spf.c
+++ b/src/spf.c
@@ -41,6 +41,10 @@
#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