]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: proxy: Use source_ip proxy field if it is returned from passdb.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 27 Feb 2018 21:56:20 +0000 (22:56 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 27 Feb 2018 22:16:27 +0000 (23:16 +0100)
Before, it was ignored. Now, it is used as the source IP for the outgoing LMTP
client connection.

src/lmtp/lmtp-proxy.c

index eef86be95a37423bccee3ec038ccd31740fc7ead..75556151e6112ac096ce9aa3e8c261e0d5c98122 100644 (file)
@@ -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);