aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-14 09:30:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-14 09:30:08 +0100
commit639c67dbd85d566d04c87a2f6ec59fd9b5ffe54a (patch)
tree246f12e74d8020008026bdffed1399dc95987850 /src
parent9ee06af6e58a973d58bb5f749eed6b97dc3fe989 (diff)
downloadrspamd-639c67dbd85d566d04c87a2f6ec59fd9b5ffe54a.tar.gz
rspamd-639c67dbd85d566d04c87a2f6ec59fd9b5ffe54a.zip
[Fix] Fix parsing IPv6 nameservers in resolv.conf
Diffstat (limited to 'src')
-rw-r--r--src/libserver/dns.c5
-rw-r--r--src/libutil/upstream.c44
-rw-r--r--src/libutil/upstream.h10
-rw-r--r--src/plugins/surbl.c3
4 files changed, 51 insertions, 11 deletions
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 21a15297c..d2629fd21 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -240,8 +240,9 @@ rspamd_dns_resolv_conf_on_server (struct rdns_resolver *resolver,
{
struct rspamd_dns_resolver *dns_resolver = ud;
- return rspamd_upstreams_add_upstream (dns_resolver->ups,
- name, port, NULL);
+ return rspamd_upstreams_add_upstream (dns_resolver->ups, name, port,
+ RSPAMD_UPSTREAM_PARSE_NAMESERVER,
+ NULL);
}
struct rspamd_dns_resolver *
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 907024579..ac15780ad 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -563,20 +563,50 @@ rspamd_upstream_name (struct upstream *up)
}
gboolean
-rspamd_upstreams_add_upstream (struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data)
+rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str,
+ guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+ void *data)
{
struct upstream *up;
GPtrArray *addrs = NULL;
guint i;
rspamd_inet_addr_t *addr;
+ gboolean ret = FALSE;
up = g_slice_alloc0 (sizeof (*up));
- if (!rspamd_parse_host_port_priority (str, &addrs,
- &up->weight,
- &up->name, def_port, ups->ctx->pool)) {
+ switch (parse_type) {
+ case RSPAMD_UPSTREAM_PARSE_DEFAULT:
+ ret = rspamd_parse_host_port_priority (str, &addrs,
+ &up->weight,
+ &up->name, def_port, ups->ctx->pool);
+ break;
+ case RSPAMD_UPSTREAM_PARSE_NAMESERVER:
+ addrs = g_ptr_array_sized_new (1);
+
+ ret = rspamd_parse_inet_address (&addr, str, strlen (str));
+
+ if (ret) {
+ if (rspamd_inet_address_get_port (addr) == 0) {
+ rspamd_inet_address_set_port (addr, def_port);
+ }
+
+ g_ptr_array_add (addrs, addr);
+ rspamd_mempool_add_destructor (ups->ctx->pool,
+ (rspamd_mempool_destruct_t)rspamd_inet_address_free,
+ addr);
+ rspamd_mempool_add_destructor (ups->ctx->pool,
+ (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard,
+ addrs);
+ }
+ else {
+ g_ptr_array_free (addrs, TRUE);
+ }
+
+ break;
+ }
+ if (!ret) {
g_slice_free1 (sizeof (*up), up);
return FALSE;
}
@@ -691,7 +721,9 @@ rspamd_upstreams_parse_line (struct upstream_list *ups,
tmp = g_malloc (len + 1);
rspamd_strlcpy (tmp, p, len + 1);
- if (rspamd_upstreams_add_upstream (ups, tmp, def_port, data)) {
+ if (rspamd_upstreams_add_upstream (ups, tmp, def_port,
+ RSPAMD_UPSTREAM_PARSE_DEFAULT,
+ data)) {
ret = TRUE;
}
diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h
index ddc480afe..84e75288d 100644
--- a/src/libutil/upstream.h
+++ b/src/libutil/upstream.h
@@ -110,6 +110,11 @@ gsize rspamd_upstreams_count (struct upstream_list *ups);
*/
gsize rspamd_upstreams_alive (struct upstream_list *ups);
+enum rspamd_upstream_parse_type {
+ RSPAMD_UPSTREAM_PARSE_DEFAULT = 0,
+ RSPAMD_UPSTREAM_PARSE_NAMESERVER,
+};
+
/**
* Add upstream from the string
* @param ups upstream list
@@ -118,8 +123,9 @@ gsize rspamd_upstreams_alive (struct upstream_list *ups);
* @param data optional userdata
* @return TRUE if upstream has been added
*/
-gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data);
+gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str,
+ guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+ void *data);
/**
* Add multiple upstreams from comma, semicolon or space separated line
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 78422461a..486b48388 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -768,7 +768,8 @@ surbl_module_config (struct rspamd_config *cfg)
{
redir_val = ucl_obj_tostring (cur);
if (rspamd_upstreams_add_upstream (surbl_module_ctx->redirectors,
- redir_val, 80, NULL)) {
+ redir_val, 80, RSPAMD_UPSTREAM_PARSE_DEFAULT,
+ NULL)) {
surbl_module_ctx->use_redirector = TRUE;
}
}