aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lua/lua_tcp.c28
-rw-r--r--src/plugins/lua/greylist.lua7
-rw-r--r--src/plugins/lua/mx_check.lua12
3 files changed, 37 insertions, 10 deletions
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 391fb788a..a6cbf1f42 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -99,6 +99,7 @@ struct lua_tcp_cbdata {
guint16 port;
gboolean partial;
gboolean do_shutdown;
+ gboolean do_read;
gboolean connected;
};
@@ -288,15 +289,21 @@ call_finish_handler:
shutdown (cbd->fd, SHUT_WR);
}
- event_del (&cbd->ev);
+ if (cbd->do_read) {
+ event_del (&cbd->ev);
#ifdef EV_CLOSED
- event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST|EV_CLOSED,
- lua_tcp_handler, cbd);
+ event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST|EV_CLOSED,
+ lua_tcp_handler, cbd);
#else
- event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST, lua_tcp_handler, cbd);
+ event_set (&cbd->ev, cbd->fd, EV_READ|EV_PERSIST, lua_tcp_handler, cbd);
#endif
- event_base_set (cbd->ev_base, &cbd->ev);
- event_add (&cbd->ev, &cbd->tv);
+ event_base_set (cbd->ev_base, &cbd->ev);
+ event_add (&cbd->ev, &cbd->tv);
+ }
+ else {
+ lua_tcp_push_data (cbd, cbd->in->data, cbd->in->len);
+ REF_RELEASE (cbd);
+ }
}
static void
@@ -546,7 +553,7 @@ lua_tcp_request (lua_State *L)
struct iovec *iov = NULL;
guint niov = 0, total_out;
gdouble timeout = default_tcp_timeout;
- gboolean partial = FALSE, do_shutdown = FALSE;
+ gboolean partial = FALSE, do_shutdown = FALSE, do_read = TRUE;
if (lua_type (L, 1) == LUA_TTABLE) {
lua_pushstring (L, "host");
@@ -661,6 +668,13 @@ lua_tcp_request (lua_State *L)
}
lua_pop (L, 1);
+ lua_pushstring (L, "read");
+ lua_gettable (L, -2);
+ if (lua_type (L, -1) == LUA_TBOOLEAN) {
+ do_read = lua_toboolean (L, -1);
+ }
+ lua_pop (L, 1);
+
lua_pushstring (L, "on_connect");
lua_gettable (L, -2);
diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index 8bb101be0..5e0ce9ff1 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -255,6 +255,7 @@ local function greylist_set(task)
local is_whitelisted = task:get_mempool():get_variable("grey_whitelisted")
local do_greylisting = task:get_mempool():get_variable("grey_greylisted")
+ local do_greylisting_required = task:get_mempool():get_variable("grey_greylisted_required")
-- Third and second level domains whitelist
if not is_whitelisted and whitelist_domains_map then
@@ -269,7 +270,9 @@ local function greylist_set(task)
end
local action = task:get_metric_action('default')
- if action == 'no action' or action == 'reject' then return end
+ if action == 'no action' or action == 'reject' then
+ if not do_greylisting_required or do_greylisting_required ~= "1" then return end
+ end
local body_key = data_key(task)
local meta_key = envelope_key(task)
local upstream, ret, conn
@@ -312,7 +315,7 @@ local function greylist_set(task)
rspamd_logger.infox(task, 'got error while connecting to redis: %1', addr)
upstream:fail()
end
- elseif do_greylisting then
+ elseif do_greylisting or do_greylisting_required then
local t = tostring(math.floor(rspamd_util.get_time()))
local end_time = rspamd_util.time_to_string(t + settings['timeout'])
rspamd_logger.infox(task, 'greylisted until "%s", new record', end_time)
diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua
index bf38f63c6..be13a1322 100644
--- a/src/plugins/lua/mx_check.lua
+++ b/src/plugins/lua/mx_check.lua
@@ -28,6 +28,7 @@ local settings = {
symbol_good_mx = 'MX_GOOD',
expire = 86400, -- 1 day by default
expire_novalid = 7200, -- 2 hours by default for no valid mxes
+ greylist_invalid = false, -- Greylist first message with invalid MX (require greylist plugin)
key_prefix = 'rmx'
}
local redis_params
@@ -67,7 +68,16 @@ local function mx_check(task)
end
end
if not valid then
- task:insert_result(settings.symbol_bad_mx, 1.0)
+ -- Greylist message
+ if settings.greylist_invalid then
+ local grey_is_whitelisted = task:get_mempool():get_variable("grey_whitelisted")
+ if not grey_is_whitelisted then
+ task:get_mempool():set_variable("grey_greylisted_required", "1")
+ task:insert_result(settings.symbol_bad_mx, 1.0, "greylisted")
+ end
+ else
+ task:insert_result(settings.symbol_bad_mx, 1.0)
+ end
local ret,_,_ = rspamd_redis_make_request(task,
redis_params, -- connect params
key, -- hash key