--- ORIG/dovecot-1.2.10/src/login-common/login-proxy.c	2010-01-24 23:14:17.000000000 +0000
+++ dovecot-1.2.10/src/login-common/login-proxy.c	2010-03-12 04:45:29.000000000 +0000
@@ -194,18 +194,36 @@
 {
 	struct login_proxy *proxy;
 	struct login_proxy_record *rec;
-	struct ip_addr ip;
-	int fd;
+	struct ip_addr ip, *ip_list;
+	char *host_ip;
+	int fd, ret;
+	unsigned int ip_count;
 
 	if (host == NULL) {
 		i_error("proxy(%s): host not given", client->virtual_user);
 		return NULL;
 	}
 
-	if (net_addr2ip(host, &ip) < 0) {
-		i_error("proxy(%s): %s is not a valid IP",
+	host_ip = t_strdup(host);
+	ret = net_gethostbyname(host, &ip_list, &ip_count);
+	if (ret != 0) {
+		i_error("proxy(%s): cannot resolve %s. "
+			"If name resolution is working outside dovecot, it may be a chroot issue. "
+			"See LoginProcess on wiki, and login_dir & login_chroot in config.",
+			client->virtual_user, host);
+		return NULL;
+	} else if (ip_count < 1) {
+		i_error("proxy(%s): succesfully resolved host %s, got no IPs.",
 			client->virtual_user, host);
 		return NULL;
+	} else {
+		host_ip = t_strdup(net_ip2addr(&ip_list[0]));
+	}
+
+	if (net_addr2ip(host_ip, &ip) < 0) {
+		i_error("proxy(%s): %s is not a valid IP",
+			client->virtual_user, host_ip);
+		return NULL;
 	}
 
 	rec = login_proxy_state_get(proxy_state, &ip, port);
@@ -218,13 +236,13 @@
 	fd = net_connect_ip(&ip, port, NULL);
 	if (fd < 0) {
 		i_error("proxy(%s): connect(%s, %u) failed: %m",
-			client->virtual_user, host, port);
+			client->virtual_user, host_ip, port);
 		return NULL;
 	}
 
 	proxy = i_new(struct login_proxy, 1);
 	proxy->created = ioloop_timeval;
-	proxy->host = i_strdup(host);
+	proxy->host = i_strdup(host_ip);
 	proxy->user = i_strdup(client->virtual_user);
 	proxy->port = port;
 	proxy->ssl_flags = ssl_flags;
