changeset 22544:3b6fb61e5fb1

auth: Avoid DNS lookup for "host" if passdb returns also "hostip"
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 08 Sep 2017 11:01:20 +0300
parents 4dd4e41cd4a1
children 425ee3581927
files src/auth/auth-request.c
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-request.c	Tue Jul 25 10:39:43 2017 +0300
+++ b/src/auth/auth-request.c	Fri Sep 08 11:01:20 2017 +0300
@@ -2264,7 +2264,7 @@
 int auth_request_proxy_finish(struct auth_request *request,
 			      auth_request_proxy_cb_t *callback)
 {
-	const char *host;
+	const char *host, *hostip;
 	struct ip_addr ip;
 	bool proxy_host_is_self;
 
@@ -2291,8 +2291,18 @@
 		proxy_host_is_self =
 			auth_request_proxy_ip_is_self(request, &ip);
 	} else {
-		/* asynchronous host lookup */
-		return auth_request_proxy_host_lookup(request, host, callback);
+		hostip = auth_fields_find(request->extra_fields, "hostip");
+		if (hostip != NULL && net_addr2ip(hostip, &ip) < 0) {
+			auth_request_log_error(request, AUTH_SUBSYS_PROXY,
+				"Invalid hostip in passdb: %s", hostip);
+			return -1;
+		}
+		if (hostip == NULL) {
+			/* asynchronous host lookup */
+			return auth_request_proxy_host_lookup(request, host, callback);
+		}
+		proxy_host_is_self =
+			auth_request_proxy_ip_is_self(request, &ip);
 	}
 
 	auth_request_proxy_finish_ip(request, proxy_host_is_self);