aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_task.c16
-rw-r--r--src/main.h2
-rw-r--r--src/map.c5
-rw-r--r--src/plugins/lua/received_rbl.lua53
4 files changed, 72 insertions, 4 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 07edcb044..844229f9d 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -105,14 +105,26 @@ static int
lua_task_insert_result (lua_State *L)
{
struct worker_task *task = lua_check_task (L);
- const char *metric_name, *symbol_name;
+ const char *metric_name, *symbol_name, *param;
double flag;
+ GList *params = NULL;
+ int i, top;
if (task != NULL) {
metric_name = luaL_checkstring (L, 2);
symbol_name = luaL_checkstring (L, 3);
flag = luaL_checknumber (L, 4);
- insert_result (task, metric_name, symbol_name, flag, NULL);
+ top = lua_gettop (L);
+ /* Get additional options */
+ for (i = 5; i <= top; i ++) {
+ param = luaL_checkstring (L, i);
+ params = g_list_prepend (params, memory_pool_strdup (task->task_pool, param));
+ }
+
+ insert_result (task, metric_name, symbol_name, flag, params);
+ if (params != NULL) {
+ memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, params);
+ }
}
return 1;
}
diff --git a/src/main.h b/src/main.h
index 4c1ab8617..0590c8e5c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -19,7 +19,7 @@
#include "util.h"
/* Default values */
-#define FIXED_CONFIG_FILE CMAKE_PREFIX "/etc/rspamd.conf"
+#define FIXED_CONFIG_FILE ETC_PREFIX "/rspamd.conf"
/* Time in seconds to exit for old worker */
#define SOFT_SHUTDOWN_TIME 60
/* Default metric name */
diff --git a/src/map.c b/src/map.c
index d250970b1..f878e59b1 100644
--- a/src/map.c
+++ b/src/map.c
@@ -189,7 +189,7 @@ static int
read_chunk_header (u_char *buf, size_t len, struct http_map_data *data)
{
u_char chunkbuf[32], *p, *c;
- int skip;
+ int skip = 0;
p = chunkbuf;
c = buf;
@@ -280,6 +280,9 @@ read_http_common (struct rspamd_map *map, struct http_map_data *data, struct htt
memmove (buf, remain, rlen);
r = rlen;
}
+ if (r <= 0) {
+ return TRUE;
+ }
if (reply->parser_state == 6) {
if (reply->code != 200 && reply->code != 304) {
msg_err ("read_http: got error reply from server %s, %d", data->host, reply->code);
diff --git a/src/plugins/lua/received_rbl.lua b/src/plugins/lua/received_rbl.lua
new file mode 100644
index 000000000..bee027f50
--- /dev/null
+++ b/src/plugins/lua/received_rbl.lua
@@ -0,0 +1,53 @@
+-- This plugin is designed for testing received headers via rbl
+-- Configuration:
+-- .module 'received_rbl' {
+-- rbl = "insecure-bl.rambler.ru";
+-- rbl = "xbl.spamhaus.org";
+-- metric = "default";
+-- symbol = "RECEIVED_RBL";
+-- };
+
+
+metric = 'default'
+symbol = 'RECEIVED_RBL'
+rbls = {}
+
+function dns_cb(task, to_resolve, results, err)
+ if results then
+ local _,_,rbl = string.find(to_resolve, '%d+\.%d+\.%d+\.%d+\.(.+)')
+ task:insert_result(metric, symbol, 1, rbl)
+ end
+end
+
+function received_cb (task)
+ local recvh = task:get_received_headers()
+ for _,rh in ipairs(recvh) do
+ for k,v in pairs(rh) do
+ if k == 'real_ip' then
+ local _,_,o1,o2,o3,o4 = string.find(v, '(%d+)\.(%d+)\.(%d+)\.(%d+)')
+ for _,rbl in ipairs(rbls) do
+ rbl_str = o4 .. '.' .. o3 .. '.' .. o2 .. '.' .. o1 .. '.' .. rbl
+ task:resolve_dns_a(rbl_str, 'dns_cb')
+ end
+ end
+ end
+ end
+end
+
+-- Configuration
+local opts = rspamd_config:get_all_opt('received_rbl')
+if opts then
+ for n,v in pairs(opts) do
+ if n == 'rbl' then
+ table.insert(rbls, v)
+ elseif n == 'metric' then
+ metric = v
+ elseif n == 'symbol' then
+ symbol = v
+ end
+ end
+end
+
+-- Register symbol's callback
+local m = rspamd_config:get_metric(metric)
+m:register_symbol(symbol, 1.0, 'received_cb')