* Add ability to resolve ip in once_received plugin to avoid temporary DNS fails of SMTP resolving
}
static void
-make_ptr_req (struct rspamd_dns_request *req, struct in_addr addr)
+make_ptr_req (struct rspamd_dns_request *req, struct in_addr *addr)
{
gchar ipbuf[sizeof("255.255.255.255.in-addr.arpa")];
- guint32 a = ntohl (addr.s_addr), r;
- guint16 *p;
+ guint32 r;
+ guint16 *p;
+ guint8 *addr_p = (guint8 *)&addr->s_addr;
r = rspamd_snprintf (ipbuf, sizeof(ipbuf), "%d.%d.%d.%d.in-addr.arpa",
- (gint)(guint8)((a ) & 0xff),
- (gint)(guint8)((a>>8 ) & 0xff),
- (gint)(guint8)((a>>16) & 0xff),
- (gint)(guint8)((a>>24) & 0xff));
-
+ addr_p[3], addr_p[2], addr_p[1], addr_p[0]);
allocate_packet (req, r);
make_dns_header (req);
format_dns_name (req, ipbuf, r);
{
va_list args;
struct rspamd_dns_request *req;
- struct in_addr addr;
+ struct in_addr *addr;
const gchar *name, *service, *proto;
gint r;
struct dns_header *header;
va_start (args, type);
switch (type) {
case DNS_REQUEST_PTR:
- addr = va_arg (args, struct in_addr);
+ addr = va_arg (args, struct in_addr *);
make_ptr_req (req, addr);
break;
case DNS_REQUEST_MX:
msg_info ("invalid parameters passed to function");
return 0;
}
- if (make_dns_request (task->resolver, task->s, task->task_pool, lua_dns_callback, (void *)cd, DNS_REQUEST_PTR, ina)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ lua_dns_callback, (void *)cd, DNS_REQUEST_PTR, ina)) {
task->dns_requests ++;
task->save.saved++;
}
local bad_hosts = {}
local good_hosts = {}
+function recv_dns_cb(task, to_resolve, results, err)
+ if not results then
+ task:insert_result(symbol_strict, 1)
+ else
+ rspamd_logger.info(string.format('SMTP resolver failed to resolve: %s is %s', to_resolve, results[1]))
+ local i = true
+ for _,h in ipairs(bad_hosts) do
+ if string.find(results[1], h) then
+ -- Check for good hostname
+ if good_hosts then
+ for _,gh in ipairs(good_hosts) do
+ if string.find(results[1], gh) then
+ i = false
+ break
+ end
+ end
+ end
+ if i then
+ task:insert_result(symbol_strict, 1, h)
+ return
+ end
+ end
+ end
+ end
+end
+
function check_quantity_received (task)
local recvh = task:get_received_headers()
if table.maxn(recvh) <= 1 then
end
-- Unresolved host
if not r['real_hostname'] or string.lower(r['real_hostname']) == 'unknown' or string.match(r['real_hostname'], '^%d+%.%d+%.%d+%.%d+$') then
- task:insert_result(symbol_strict, 1)
+ if r['real_ip'] then
+ -- Try to resolve it again
+ task:resolve_dns_ptr(r['real_ip'], 'recv_dns_cb')
+ else
+ task:insert_result(symbol_strict, 1)
+ end
return
end
rspamd_config:register_virtual_symbol(symbol_strict, 1.0)
end
elseif n == 'bad_host' then
- bad_hosts = v
+ if type(v) == 'string' then
+ bad_hosts[1] = v
+ else
+ bad_hosts = v
+ end
elseif n == 'good_host' then
- good_hosts = v
+ if type(v) == 'string' then
+ good_hosts[1] = v
+ else
+ good_hosts = v
+ end
end
end
/* Set up async session */
session->s = new_async_session (session->pool, free_smtp_session, session);
session->state = SMTP_STATE_RESOLVE_REVERSE;
- if (! make_dns_request (session->resolver, session->s, session->pool, smtp_dns_cb, session, DNS_REQUEST_PTR, session->client_addr)) {
+ if (! make_dns_request (session->resolver, session->s, session->pool,
+ smtp_dns_cb, session, DNS_REQUEST_PTR, &session->client_addr)) {
msg_err ("cannot resolve %s", inet_ntoa (session->client_addr));
g_free (session);
close (nfd);