commit 04127ef: [Fix] Distinguish remote and local addrs parsing

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Sep 28 12:42:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-28 13:37:22 +0100
URL: https://github.com/rspamd/rspamd/commit/04127efebacaaa088668198cdbe52f933367b731 (HEAD -> master)

[Fix] Distinguish remote and local addrs parsing

---
 src/client/rspamc.c         |  3 ++-
 src/controller.c            |  6 +++--
 src/libmime/message.c       |  3 ++-
 src/libmime/mime_headers.c  | 17 +++++++++----
 src/libserver/cfg_rcl.c     |  6 +++--
 src/libserver/dns.c         |  3 ++-
 src/libserver/protocol.c    |  3 ++-
 src/libutil/addr.c          | 61 +++++++++++++++++++++++++++++----------------
 src/libutil/addr.h          | 16 +++++++++---
 src/libutil/map.c           |  3 ++-
 src/libutil/upstream.c      |  3 ++-
 src/lua/lua_http.c          |  3 ++-
 src/lua/lua_ip.c            |  6 +++--
 src/lua/lua_redis.c         |  6 +++--
 src/lua/lua_task.c          |  3 ++-
 src/lua/lua_tcp.c           |  6 +++--
 src/lua/lua_udp.c           |  3 ++-
 src/ragel/smtp_ip_parser.rl |  3 ++-
 src/rspamadm/control.c      |  3 ++-
 src/rspamd.c                |  3 ++-
 test/rspamd_upstream_test.c |  6 +++--
 21 files changed, 113 insertions(+), 53 deletions(-)

diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 3f637cda0..075f0a487 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -564,7 +564,8 @@ add_options (GQueue *opts)
 	if (ip != NULL) {
 		rspamd_inet_addr_t *addr = NULL;
 
-		if (!rspamd_parse_inet_address (&addr, ip, strlen (ip))) {
+		if (!rspamd_parse_inet_address (&addr, ip, strlen (ip),
+				RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			/* Try to resolve */
 			struct addrinfo hints, *res, *cur;
 			gint r;
diff --git a/src/controller.c b/src/controller.c
index 474e7ec92..27c6d18cc 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -434,7 +434,8 @@ rspamd_controller_check_forwarded (struct rspamd_controller_session *session,
 			comma = hdr->begin;
 		}
 		if (rspamd_parse_inet_address (&addr, comma,
-				(hdr->begin + hdr->len) - comma)) {
+				(hdr->begin + hdr->len) - comma,
+				RSPAMD_INET_ADDRESS_PARSE_NO_UNIX)) {
 			/* We have addr now, so check if it is still trusted */
 			if (ctx->secure_map &&
 					rspamd_match_radix_map_addr (ctx->secure_map, addr) != NULL) {
@@ -463,7 +464,8 @@ rspamd_controller_check_forwarded (struct rspamd_controller_session *session,
 		hdr = rspamd_http_message_find_header (msg, alt_hdr_name);
 
 		if (hdr) {
-			if (rspamd_parse_inet_address (&addr, hdr->begin, hdr->len)) {
+			if (rspamd_parse_inet_address (&addr, hdr->begin, hdr->len,
+					RSPAMD_INET_ADDRESS_PARSE_NO_UNIX)) {
 				/* We have addr now, so check if it is still trusted */
 				if (ctx->secure_map &&
 						rspamd_match_radix_map_addr (ctx->secure_map, addr) != NULL) {
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 9e9d27d8a..4169ca0b5 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -1287,7 +1287,8 @@ rspamd_message_parse (struct rspamd_task *task)
 		if (recv->real_ip) {
 			if (!rspamd_parse_inet_address (&task->from_addr,
 					recv->real_ip,
-					strlen (recv->real_ip))) {
+					strlen (recv->real_ip),
+					RSPAMD_INET_ADDRESS_PARSE_NO_UNIX)) {
 				msg_warn_task ("cannot get IP from received header: '%s'",
 						recv->real_ip);
 				task->from_addr = NULL;
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index a93a4ffd0..e83debc43 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -32,6 +32,9 @@ struct rspamd_mime_headers_table {
 	ref_entry_t ref;
 };
 
+#define RSPAMD_INET_ADDRESS_PARSE_RECEIVED \
+	(RSPAMD_INET_ADDRESS_PARSE_REMOTE|RSPAMD_INET_ADDRESS_PARSE_NO_UNIX)
+
 static void
 rspamd_mime_header_check_special (struct rspamd_task *task,
 		struct rspamd_mime_header *rh)
@@ -1320,7 +1323,8 @@ rspamd_smtp_received_process_host_tcpinfo (struct rspamd_task *task,
 		if (brace_pos) {
 			addr = rspamd_parse_inet_address_pool (data + 1,
 					brace_pos - data - 1,
-					task->task_pool);
+					task->task_pool,
+					RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
 
 			if (addr) {
 				rh->addr = addr;
@@ -1334,7 +1338,7 @@ rspamd_smtp_received_process_host_tcpinfo (struct rspamd_task *task,
 		if (g_ascii_isxdigit (data[0])) {
 			/* Try to parse IP address */
 			addr = rspamd_parse_inet_address_pool (data,
-					len, task->task_pool);
+					len, task->task_pool, RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
 			if (addr) {
 				rh->addr = addr;
 				rh->real_ip = rspamd_mempool_strdup (task->task_pool,
@@ -1355,7 +1359,8 @@ rspamd_smtp_received_process_host_tcpinfo (struct rspamd_task *task,
 				if (ebrace_pos) {
 					addr = rspamd_parse_inet_address_pool (obrace_pos + 1,
 							ebrace_pos - obrace_pos - 1,
-							task->task_pool);
+							task->task_pool,
+							RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
 
 					if (addr) {
 						rh->addr = addr;
@@ -1420,7 +1425,8 @@ rspamd_smtp_received_process_from (struct rspamd_task *task,
 				if (brace_pos) {
 					addr = rspamd_parse_inet_address_pool (rpart->data + 1,
 							brace_pos - rpart->data - 1,
-							task->task_pool);
+							task->task_pool,
+							RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
 
 					if (addr) {
 						seen_ip_in_data = TRUE;
@@ -1434,7 +1440,8 @@ rspamd_smtp_received_process_from (struct rspamd_task *task,
 				/* Try to parse IP address */
 				rspamd_inet_addr_t *addr;
 				addr = rspamd_parse_inet_address_pool (rpart->data,
-						rpart->dlen, task->task_pool);
+						rpart->dlen, task->task_pool,
+						RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
 				if (addr) {
 					seen_ip_in_data = TRUE;
 					rh->addr = addr;
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index b219e1af8..cdf3d9b5b 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -3254,13 +3254,15 @@ rspamd_rcl_parse_struct_addr (rspamd_mempool_t *pool,
 	struct rspamd_rcl_struct_parser *pd = ud;
 	rspamd_inet_addr_t **target;
 	const gchar *val;
+	gsize size;
 
 	target = (rspamd_inet_addr_t **)(((gchar *)pd->user_struct) + pd->offset);
 
 	if (ucl_object_type (obj) == UCL_STRING) {
-		val = ucl_object_tostring (obj);
+		val = ucl_object_tolstring (obj, &size);
 
-		if (!rspamd_parse_inet_address (target, val, strlen (val))) {
+		if (!rspamd_parse_inet_address (target, val, size,
+				RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			g_set_error (err,
 				CFG_RCL_ERROR,
 				EINVAL,
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index f6e533523..08454c656 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -300,7 +300,8 @@ rspamd_dns_resolv_conf_on_server (struct rdns_resolver *resolver,
 	msg_info_config ("parsed nameserver %s from resolv.conf", name);
 
 	/* Try to open a connection */
-	if (!rspamd_parse_inet_address (&addr, name, strlen (name))) {
+	if (!rspamd_parse_inet_address (&addr, name, strlen (name),
+			RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		msg_warn_config ("cannot parse nameserver address %s", name);
 
 		return FALSE;
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 469b834dc..da02eb61b 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -545,7 +545,8 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
 			case 'I':
 				IF_HEADER (IP_ADDR_HEADER) {
 					if (!rspamd_parse_inet_address (&task->from_addr,
-							hv_tok->begin, hv_tok->len)) {
+							hv_tok->begin, hv_tok->len,
+							RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 						msg_err_protocol ("bad ip header: '%T'", hv_tok);
 					}
 					else {
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index 7ab5e11ee..f6aed8bf4 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -315,8 +315,10 @@ out:
 }
 
 static gboolean
-rspamd_parse_unix_path (rspamd_inet_addr_t **target, const char *src,
-						rspamd_mempool_t *pool)
+rspamd_parse_unix_path (rspamd_inet_addr_t **target,
+						const char *src, gsize len,
+						rspamd_mempool_t *pool,
+						enum rspamd_inet_address_parse_flags how)
 {
 	gchar **tokens, **cur_tok, *p, *pwbuf;
 	glong pwlen;
@@ -325,19 +327,29 @@ rspamd_parse_unix_path (rspamd_inet_addr_t **target, const char *src,
 	rspamd_inet_addr_t *addr;
 	bool has_group = false;
 
-	tokens = g_strsplit_set (src, " ,", -1);
 	addr = rspamd_inet_addr_create (AF_UNIX, pool);
 
-	rspamd_strlcpy (addr->u.un->addr.sun_path, tokens[0],
-			sizeof (addr->u.un->addr.sun_path));
-	#if defined(FREEBSD) || defined(__APPLE__)
-	addr->u.un->addr.sun_len = SUN_LEN (&addr->u.un->addr);
-	#endif
-
 	addr->u.un->mode = 00644;
 	addr->u.un->owner = (uid_t)-1;
 	addr->u.un->group = (gid_t)-1;
 
+	if (!(how & RSPAMD_INET_ADDRESS_PARSE_REMOTE)) {
+		tokens = rspamd_string_len_split (src, len, " ,", -1, pool);
+
+		if (tokens[0] == NULL) {
+			return FALSE;
+		}
+	}
+	else {
+		rspamd_strlcpy (addr->u.un->addr.sun_path, src,
+				MIN (len + 1, sizeof (addr->u.un->addr.sun_path)));
+#if defined(FREEBSD) || defined(__APPLE__)
+		addr->u.un->addr.sun_len = SUN_LEN (&addr->u.un->addr);
+#endif
+		return TRUE;
+	}
+
+	/* Skip for remote */
 	cur_tok = &tokens[1];
 #ifdef _SC_GETPW_R_SIZE_MAX
 	pwlen = sysconf (_SC_GETPW_R_SIZE_MAX);
@@ -679,12 +691,13 @@ static gboolean
 rspamd_parse_inet_address_common (rspamd_inet_addr_t **target,
 								  const char *src,
 								  gsize srclen,
-								  rspamd_mempool_t *pool)
+								  rspamd_mempool_t *pool,
+								  enum rspamd_inet_address_parse_flags how)
 {
 	gboolean ret = FALSE;
 	rspamd_inet_addr_t *addr = NULL;
 	union sa_inet su;
-	const char *end;
+	const char *end = NULL;
 	char ipbuf[INET6_ADDRSTRLEN + 1];
 	guint iplen;
 	gulong portnum;
@@ -698,8 +711,9 @@ rspamd_parse_inet_address_common (rspamd_inet_addr_t **target,
 
 	rspamd_ip_check_ipv6 ();
 
-	if (src[0] == '/' || src[0] == '.') {
-		return rspamd_parse_unix_path (target, src, pool);
+	if (!(how & RSPAMD_INET_ADDRESS_PARSE_NO_UNIX) &&
+		(src[0] == '/' || src[0] == '.')) {
+		return rspamd_parse_unix_path (target, src, srclen, pool, how);
 	}
 
 	if (src[0] == '[') {
@@ -726,7 +740,7 @@ rspamd_parse_inet_address_common (rspamd_inet_addr_t **target,
 			ret = TRUE;
 		}
 
-		if (ret && end[1] == ':') {
+		if (!(how & RSPAMD_INET_ADDRESS_PARSE_NO_PORT) && ret && end[1] == ':') {
 			/* Port part */
 			rspamd_strtoul (end + 1, srclen - iplen - 3, &portnum);
 			rspamd_inet_address_set_port (addr, portnum);
@@ -734,7 +748,8 @@ rspamd_parse_inet_address_common (rspamd_inet_addr_t **target,
 	}
 	else {
 
-		if ((end = memchr (src, ':', srclen)) != NULL) {
+		if (!(how & RSPAMD_INET_ADDRESS_PARSE_NO_PORT) &&
+			(end = memchr (src, ':', srclen)) != NULL) {
 			/* This is either port number and ipv4 addr or ipv6 addr */
 			/* Search for another semicolon */
 			if (memchr (end + 1, ':', srclen - (end - src + 1)) &&
@@ -789,19 +804,21 @@ rspamd_parse_inet_address_common (rspamd_inet_addr_t **target,
 gboolean
 rspamd_parse_inet_address (rspamd_inet_addr_t **target,
 						   const char *src,
-						   gsize srclen)
+						   gsize srclen,
+						   enum rspamd_inet_address_parse_flags how)
 {
-	return rspamd_parse_inet_address_common (target, src, srclen, NULL);
+	return rspamd_parse_inet_address_common (target, src, srclen, NULL, how);
 }
 
 rspamd_inet_addr_t *
 rspamd_parse_inet_address_pool (const char *src,
 								gsize srclen,
-								rspamd_mempool_t *pool)
+								rspamd_mempool_t *pool,
+								enum rspamd_inet_address_parse_flags how)
 {
 	rspamd_inet_addr_t *ret = NULL;
 
-	if (!rspamd_parse_inet_address_common (&ret, src, srclen, pool)) {
+	if (!rspamd_parse_inet_address_common (&ret, src, srclen, pool, how)) {
 		return NULL;
 	}
 
@@ -1224,7 +1241,8 @@ rspamd_resolve_addrs (const char *begin, size_t len, GPtrArray **addrs,
 
 	rspamd_ip_check_ipv6 ();
 
-	if (rspamd_parse_inet_address (&cur_addr, begin, len)) {
+	if (rspamd_parse_inet_address (&cur_addr,
+			begin, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		if (*addrs == NULL) {
 			*addrs = g_ptr_array_new_full (1,
 					(GDestroyNotify) rspamd_inet_address_free);
@@ -1387,7 +1405,8 @@ rspamd_parse_host_port_priority (const gchar *str,
 			}
 		}
 
-		if (!rspamd_parse_inet_address (&cur_addr, str, strlen (str))) {
+		if (!rspamd_parse_inet_address (&cur_addr,
+				str, strlen (str), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			msg_err_pool_check ("cannot parse unix socket definition %s: %s",
 					str,
 					strerror (errno));
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index 06413a51a..6a33ad7ec 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -86,6 +86,13 @@ rspamd_inet_addr_t *rspamd_inet_address_from_rnds (
 gboolean rspamd_parse_inet_address_ip6 (const guchar *text, gsize len,
 										gpointer target);
 
+enum rspamd_inet_address_parse_flags {
+	RSPAMD_INET_ADDRESS_PARSE_DEFAULT = 0,
+	RSPAMD_INET_ADDRESS_PARSE_REMOTE = 1u << 0u,
+	RSPAMD_INET_ADDRESS_PARSE_NO_UNIX = 1u << 1u,
+	RSPAMD_INET_ADDRESS_PARSE_NO_PORT = 1u << 2u,
+};
+
 /**
  * Parse string with ipv4 address of length `len` to `target` which should be
  * at least sizeof (in4_addr_t)
@@ -105,7 +112,8 @@ gboolean rspamd_parse_inet_address_ip4 (const guchar *text, gsize len,
  * @return
  */
 gboolean rspamd_parse_inet_address_ip (const char *src,
-									   gsize srclen, rspamd_inet_addr_t *target);
+									   gsize srclen,
+									   rspamd_inet_addr_t *target);
 
 /**
  * Try to parse address from string
@@ -115,7 +123,8 @@ gboolean rspamd_parse_inet_address_ip (const char *src,
  */
 gboolean rspamd_parse_inet_address (rspamd_inet_addr_t **target,
 									const char *src,
-									gsize srclen);
+									gsize srclen,
+									enum rspamd_inet_address_parse_flags how);
 
 /**
  * Use memory pool allocated inet address
@@ -126,7 +135,8 @@ gboolean rspamd_parse_inet_address (rspamd_inet_addr_t **target,
  */
 rspamd_inet_addr_t *rspamd_parse_inet_address_pool (const char *src,
 													gsize srclen,
-													rspamd_mempool_t *pool);
+													rspamd_mempool_t *pool,
+													enum rspamd_inet_address_parse_flags how);
 
 /**
  * Returns string representation of inet address
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 19612f8ff..4f0e2354c 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -1469,7 +1469,8 @@ check:
 	/* Try address */
 	rspamd_inet_addr_t *addr = NULL;
 
-	if (rspamd_parse_inet_address (&addr, data->host, strlen (data->host))) {
+	if (rspamd_parse_inet_address (&addr, data->host,
+			strlen (data->host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		rspamd_inet_address_set_port (addr, cbd->data->port);
 		g_ptr_array_add (cbd->addrs, (void *)addr);
 		cbd->conn = rspamd_http_connection_new_client (
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 0637a0ac1..e2bfd94d9 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -788,7 +788,8 @@ rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str,
 		break;
 	case RSPAMD_UPSTREAM_PARSE_NAMESERVER:
 		addrs = g_ptr_array_sized_new (1);
-		if (rspamd_parse_inet_address (&addr, str, strlen (str))) {
+		if (rspamd_parse_inet_address (&addr, str, strlen (str),
+				RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			if (ups->ctx) {
 				upstream->name = rspamd_mempool_strdup (ups->ctx->pool, str);
 			}
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index ec42ab39e..d73bd7281 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -984,7 +984,8 @@ lua_http_request (lua_State *L)
 		cbd->session = session;
 	}
 
-	if (rspamd_parse_inet_address (&cbd->addr, msg->host->str, msg->host->len)) {
+	if (rspamd_parse_inet_address (&cbd->addr,
+			msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		/* Host is numeric IP, no need to resolve */
 		gboolean ret;
 
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index 8318125ba..f873c4515 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -375,7 +375,8 @@ lua_ip_from_string (lua_State *L)
 	if (ip_str) {
 		ip = lua_ip_new (L, NULL);
 
-		if (!rspamd_parse_inet_address (&ip->addr, ip_str, len)) {
+		if (!rspamd_parse_inet_address (&ip->addr,
+				ip_str, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			msg_warn ("cannot parse ip: %*s", (gint) len, ip_str);
 			ip->addr = NULL;
 		}
@@ -560,7 +561,8 @@ rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str)
 	else {
 		ip = g_malloc0 (sizeof (struct rspamd_lua_ip));
 
-		if (rspamd_parse_inet_address (&ip->addr, ip_str, strlen (ip_str))) {
+		if (rspamd_parse_inet_address (&ip->addr,
+				ip_str, strlen (ip_str), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 
 			pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
 			rspamd_lua_setclass (L, "rspamd{ip}", -1);
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index 279f84ffa..32fa55476 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -896,7 +896,8 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref, gboolean is_asy
 		else if (lua_type (L, -1) == LUA_TSTRING) {
 			host = lua_tostring (L, -1);
 
-			if (rspamd_parse_inet_address (&ip, host, strlen (host))) {
+			if (rspamd_parse_inet_address (&ip,
+					host, strlen (host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 				addr = g_alloca (sizeof (*addr));
 				addr->addr = ip;
 
@@ -1165,7 +1166,8 @@ lua_redis_make_request_sync (lua_State *L)
 		}
 		else if (lua_type (L, -1) == LUA_TSTRING) {
 			host = lua_tostring (L, -1);
-			if (rspamd_parse_inet_address (&ip, host, strlen (host))) {
+			if (rspamd_parse_inet_address (&ip,
+					host, strlen (host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 				addr = g_alloca (sizeof (*addr));
 				addr->addr = ip;
 
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index af1a12fae..2ec6dc29b 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -3867,7 +3867,8 @@ lua_task_set_from_ip (lua_State *L)
 	else {
 		if (!rspamd_parse_inet_address (&addr,
 				ip_str,
-				len)) {
+				len,
+				RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			msg_warn_task ("cannot get IP from received header: '%s'",
 					ip_str);
 		}
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 18c022c38..379d3d807 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1760,7 +1760,8 @@ lua_tcp_request (lua_State *L)
 		}
 	}
 
-	if (rspamd_parse_inet_address (&cbd->addr, host, strlen (host))) {
+	if (rspamd_parse_inet_address (&cbd->addr,
+			host, strlen (host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		rspamd_inet_address_set_port (cbd->addr, port);
 		/* Host is numeric IP, no need to resolve */
 		lua_tcp_register_watcher (cbd);
@@ -1942,7 +1943,8 @@ lua_tcp_connect_sync (lua_State *L)
 		}
 	}
 
-	if (rspamd_parse_inet_address (&cbd->addr, host, strlen (host))) {
+	if (rspamd_parse_inet_address (&cbd->addr,
+			host, strlen (host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		rspamd_inet_address_set_port (cbd->addr, (guint16)port);
 		/* Host is numeric IP, no need to resolve */
 		if (!lua_tcp_make_connection (cbd)) {
diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c
index 966ce9788..b72108c34 100644
--- a/src/lua/lua_udp.c
+++ b/src/lua/lua_udp.c
@@ -373,7 +373,8 @@ lua_udp_sendto (lua_State *L) {
 		if (lua_type (L, -1) == LUA_TSTRING) {
 			host = luaL_checkstring (L, -1);
 
-			if (rspamd_parse_inet_address (&addr, host, strlen (host))) {
+			if (rspamd_parse_inet_address (&addr,
+					host, strlen (host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 				if (port != 0) {
 					rspamd_inet_address_set_port (addr, port);
 				}
diff --git a/src/ragel/smtp_ip_parser.rl b/src/ragel/smtp_ip_parser.rl
index 36d9746a5..617f731f2 100644
--- a/src/ragel/smtp_ip_parser.rl
+++ b/src/ragel/smtp_ip_parser.rl
@@ -48,7 +48,8 @@ rspamd_parse_smtp_ip (const char *data, size_t len, rspamd_mempool_t *pool)
   %% write exec;
 
   if (ip_start && ip_end && ip_end > ip_start) {
-    return rspamd_parse_inet_address_pool (ip_start, ip_end - ip_start, pool);
+    return rspamd_parse_inet_address_pool (ip_start, ip_end - ip_start, pool,
+    		RSPAMD_INET_ADDRESS_PARSE_NO_UNIX|RSPAMD_INET_ADDRESS_PARSE_REMOTE);
   }
 
   return NULL;
diff --git a/src/rspamadm/control.c b/src/rspamadm/control.c
index e605ecb0a..a089b70f7 100644
--- a/src/rspamadm/control.c
+++ b/src/rspamadm/control.c
@@ -223,7 +223,8 @@ rspamadm_control (gint argc, gchar **argv, const struct rspamadm_command *_cmd)
 		exit (1);
 	}
 
-	if (!rspamd_parse_inet_address (&addr, control_path, strlen (control_path))) {
+	if (!rspamd_parse_inet_address (&addr,
+			control_path, strlen (control_path), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 		rspamd_fprintf (stderr, "bad control path: %s\n", control_path);
 		exit (1);
 	}
diff --git a/src/rspamd.c b/src/rspamd.c
index aa8a6235b..95cc2bd6b 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -1323,7 +1323,8 @@ main (gint argc, gchar **argv, gchar **env)
 	if (rspamd_main->cfg->control_socket_path) {
 		if (!rspamd_parse_inet_address (&control_addr,
 				rspamd_main->cfg->control_socket_path,
-				strlen (rspamd_main->cfg->control_socket_path))) {
+				strlen (rspamd_main->cfg->control_socket_path),
+				RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
 			msg_err_main ("cannot parse inet address %s",
 					rspamd_main->cfg->control_socket_path);
 		}
diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c
index 12e478793..bbe47fc04 100644
--- a/test/rspamd_upstream_test.c
+++ b/test/rspamd_upstream_test.c
@@ -83,9 +83,11 @@ rspamd_upstream_test_func (void)
 			RSPAMD_UPSTREAM_PARSE_DEFAULT,
 			NULL));
 	up = rspamd_upstream_get (nls, RSPAMD_UPSTREAM_RANDOM, NULL, 0);
-	rspamd_parse_inet_address (&paddr, "127.0.0.2", strlen ("127.0.0.2"));
+	rspamd_parse_inet_address (&paddr, "127.0.0.2", strlen ("127.0.0.2"),
+			RSPAMD_INET_ADDRESS_PARSE_DEFAULT);
 	g_assert (rspamd_upstream_add_addr (up, paddr));
-	rspamd_parse_inet_address (&paddr, "::1", strlen ("::1"));
+	rspamd_parse_inet_address (&paddr, "::1", strlen ("::1"),
+			RSPAMD_INET_ADDRESS_PARSE_DEFAULT);
 	g_assert (rspamd_upstream_add_addr (up, paddr));
 	/* Rewind to start */
 	addr = rspamd_upstream_addr_next (up);


More information about the Commits mailing list