aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-25 19:40:16 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-25 19:40:16 +0000
commit80bb5413db189bee40e39b6572110af565339e03 (patch)
tree5f6e84100feaaa0af729bd899b4f43b57386b029 /src/libutil/addr.c
parenta0b5db928fa1e0a6653d97569ee0485093ac6d72 (diff)
downloadrspamd-80bb5413db189bee40e39b6572110af565339e03.tar.gz
rspamd-80bb5413db189bee40e39b6572110af565339e03.zip
[Fix] Fix listen socket parsing
Issue: #3254
Diffstat (limited to 'src/libutil/addr.c')
-rw-r--r--src/libutil/addr.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index 1beeb421e..52c0dbf97 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -1345,6 +1345,7 @@ rspamd_parse_host_port_priority (const gchar *str,
guint *priority,
gchar **name_ptr,
guint default_port,
+ gboolean allow_listen,
rspamd_mempool_t *pool)
{
gchar portbuf[8];
@@ -1352,6 +1353,7 @@ rspamd_parse_host_port_priority (const gchar *str,
gsize namelen;
rspamd_inet_addr_t *cur_addr = NULL;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
+ union sa_union su;
/*
* In this function, we can have several possibilities:
@@ -1361,19 +1363,62 @@ rspamd_parse_host_port_priority (const gchar *str,
* 4) ip|host[:port[:priority]]
*/
- if (str[0] == '*') {
- if (!rspamd_check_port_priority (str + 1, default_port, priority,
+ if (allow_listen && str[0] == '*') {
+ bool v4_any = true, v6_any = true;
+
+ p = &str[1];
+
+ if (g_ascii_strncasecmp (p, "v4", 2) == 0) {
+ p += 2;
+ name = "*v4";
+ v6_any = false;
+ }
+ else if (g_ascii_strncasecmp (p, "v6", 2) == 0) {
+ p += 2;
+ name = "*v6";
+ v4_any = false;
+ }
+ else {
+ name = "*";
+ }
+
+ if (!rspamd_check_port_priority (p, default_port, priority,
portbuf, sizeof (portbuf), pool)) {
return ret;
}
- if (rspamd_resolve_addrs (str, 0, addrs, portbuf, AI_PASSIVE, pool)
- == RSPAMD_PARSE_ADDR_FAIL) {
- return ret;
+ if (*addrs == NULL) {
+ *addrs = g_ptr_array_new_full (1,
+ (GDestroyNotify) rspamd_inet_address_free);
+
+ if (pool != NULL) {
+ rspamd_mempool_add_destructor (pool,
+ rspamd_ptr_array_free_hard, *addrs);
+ }
+ }
+
+ if (v4_any) {
+ cur_addr = rspamd_inet_addr_create (AF_INET, pool);
+ rspamd_parse_inet_address_ip4 ("0.0.0.0",
+ sizeof ("0.0.0.0") - 1, &su.s4.sin_addr);
+ memcpy (&cur_addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr,
+ sizeof (struct in_addr));
+ rspamd_inet_address_set_port (cur_addr,
+ strtoul (portbuf, NULL, 10));
+ g_ptr_array_add (*addrs, cur_addr);
+ }
+ if (v6_any) {
+ cur_addr = rspamd_inet_addr_create (AF_INET6, pool);
+ rspamd_parse_inet_address_ip6 ("::",
+ sizeof ("::") - 1, &su.s6.sin6_addr);
+ memcpy (&cur_addr->u.in.addr.s6.sin6_addr, &su.s6.sin6_addr,
+ sizeof (struct in6_addr));
+ rspamd_inet_address_set_port (cur_addr,
+ strtoul (portbuf, NULL, 10));
+ g_ptr_array_add (*addrs, cur_addr);
}
- name = "*";
- namelen = 1;
+ namelen = strlen (name);
ret = RSPAMD_PARSE_ADDR_NUMERIC; /* No resolution here */
}
else if (str[0] == '[') {