From 4bec789c788a6a3829620bf06b431effd3ec157d Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Tue, 27 Feb 2018 22:56:20 +0100 Subject: [PATCH] lmtp: proxy: Use source_ip proxy field if it is returned from passdb. Before, it was ignored. Now, it is used as the source IP for the outgoing LMTP client connection. --- src/lmtp/lmtp-proxy.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index eef86be95a..75556151e6 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -32,7 +32,7 @@ struct lmtp_proxy_rcpt_settings { enum smtp_protocol protocol; const char *host; - struct ip_addr hostip; + struct ip_addr hostip, source_ip; in_port_t port; unsigned int timeout_msecs; struct smtp_params_rcpt params; @@ -191,7 +191,8 @@ lmtp_proxy_get_connection(struct lmtp_proxy *proxy, if (conn->set.protocol == set->protocol && conn->set.port == set->port && - strcmp(conn->set.host, host) == 0) + strcmp(conn->set.host, host) == 0 && + net_ip_compare(&conn->set.source_ip, &set->source_ip)) return conn; } @@ -201,11 +202,13 @@ lmtp_proxy_get_connection(struct lmtp_proxy *proxy, conn->set.hostip = set->hostip; conn->host = i_strdup(host); conn->set.host = conn->host; + conn->set.source_ip = set->source_ip; conn->set.port = set->port; conn->set.timeout_msecs = set->timeout_msecs; array_append(&proxy->connections, &conn, 1); i_zero(&lmtp_set); + lmtp_set.my_ip = conn->set.source_ip; lmtp_set.peer_trusted = TRUE; lmtp_conn = smtp_client_connection_create(proxy->lmtp_client, @@ -303,6 +306,11 @@ lmtp_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, i_error("proxy: Invalid hostip %s", value); return FALSE; } + } else if (strcmp(key, "source_ip") == 0) { + if (net_addr2ip(value, &set->source_ip) < 0) { + i_error("proxy: Invalid source_ip %s", value); + return FALSE; + } } else if (strcmp(key, "port") == 0) { if (net_str2port(value, &set->port) < 0) { i_error("proxy: Invalid port number %s", value);