dovecot-2.2: lmtp proxy: Send client's IP/port to destination se...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 23 11:59:23 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/1bc56eec3f8e
changeset: 14151:1bc56eec3f8e
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 23 11:59:10 2012 +0200
description:
lmtp proxy: Send client's IP/port to destination server via XCLIENT if possible.

diffstat:

 src/lmtp/commands.c   |  18 ++++++++++++------
 src/lmtp/lmtp-proxy.c |  26 ++++++++++++++++----------
 src/lmtp/lmtp-proxy.h |  13 +++++++++++--
 3 files changed, 39 insertions(+), 18 deletions(-)

diffs (170 lines):

diff -r 3144001fae84 -r 1bc56eec3f8e src/lmtp/commands.c
--- a/src/lmtp/commands.c	Thu Feb 23 11:58:35 2012 +0200
+++ b/src/lmtp/commands.c	Thu Feb 23 11:59:10 2012 +0200
@@ -150,7 +150,7 @@
 }
 
 static bool
-client_proxy_rcpt_parse_fields(struct lmtp_proxy_settings *set,
+client_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set,
 			       const char *const *args, const char **address)
 {
 	const char *p, *key, *value;
@@ -203,7 +203,7 @@
 
 static bool
 client_proxy_is_ourself(const struct client *client,
-			const struct lmtp_proxy_settings *set)
+			const struct lmtp_proxy_rcpt_settings *set)
 {
 	struct ip_addr ip;
 
@@ -237,7 +237,7 @@
 			      const char *username, const char *detail)
 {
 	struct auth_master_connection *auth_conn;
-	struct lmtp_proxy_settings set;
+	struct lmtp_proxy_rcpt_settings set;
 	struct auth_user_info info;
 	struct mail_storage_service_input input;
 	const char *args, *const *fields, *errstr, *orig_username = username;
@@ -304,9 +304,15 @@
 		return TRUE;
 	}
 	if (client->proxy == NULL) {
-		client->proxy = lmtp_proxy_init(client->set->hostname,
-						dns_client_socket_path,
-						client->output);
+		struct lmtp_proxy_settings proxy_set;
+
+		memset(&proxy_set, 0, sizeof(proxy_set));
+		proxy_set.my_hostname = client->set->hostname;
+		proxy_set.dns_client_socket_path = dns_client_socket_path;
+		proxy_set.source_ip = client->remote_ip;
+		proxy_set.source_port = client->remote_port;
+
+		client->proxy = lmtp_proxy_init(&proxy_set, client->output);
 		if (client->state.mail_body_8bitmime)
 			args = " BODY=8BITMIME";
 		else if (client->state.mail_body_7bit)
diff -r 3144001fae84 -r 1bc56eec3f8e src/lmtp/lmtp-proxy.c
--- a/src/lmtp/lmtp-proxy.c	Thu Feb 23 11:58:35 2012 +0200
+++ b/src/lmtp/lmtp-proxy.c	Thu Feb 23 11:59:10 2012 +0200
@@ -21,7 +21,7 @@
 
 struct lmtp_proxy_connection {
 	struct lmtp_proxy *proxy;
-	struct lmtp_proxy_settings set;
+	struct lmtp_proxy_rcpt_settings set;
 
 	struct lmtp_client *client;
 	struct istream *data_input;
@@ -33,8 +33,8 @@
 
 struct lmtp_proxy {
 	pool_t pool;
-	const char *mail_from, *my_hostname;
-	const char *dns_client_socket_path;
+	const char *mail_from;
+	struct lmtp_proxy_settings set;
 
 	ARRAY_DEFINE(connections, struct lmtp_proxy_connection *);
 	ARRAY_DEFINE(rcpt_to, struct lmtp_proxy_recipient *);
@@ -55,7 +55,7 @@
 static void lmtp_conn_finish(void *context);
 
 struct lmtp_proxy *
-lmtp_proxy_init(const char *my_hostname, const char *dns_client_socket_path,
+lmtp_proxy_init(const struct lmtp_proxy_settings *set,
 		struct ostream *client_output)
 {
 	struct lmtp_proxy *proxy;
@@ -66,9 +66,12 @@
 	pool = pool_alloconly_create("lmtp proxy", 1024);
 	proxy = p_new(pool, struct lmtp_proxy, 1);
 	proxy->pool = pool;
-	proxy->my_hostname = p_strdup(pool, my_hostname);
 	proxy->client_output = client_output;
-	proxy->dns_client_socket_path = p_strdup(pool, dns_client_socket_path);
+	proxy->set.my_hostname = p_strdup(pool, set->my_hostname);
+	proxy->set.dns_client_socket_path =
+		p_strdup(pool, set->dns_client_socket_path);
+	proxy->set.source_ip = set->source_ip;
+	proxy->set.source_port = set->source_port;
 	i_array_init(&proxy->rcpt_to, 32);
 	i_array_init(&proxy->connections, 32);
 	return proxy;
@@ -110,7 +113,7 @@
 
 static struct lmtp_proxy_connection *
 lmtp_proxy_get_connection(struct lmtp_proxy *proxy,
-			  const struct lmtp_proxy_settings *set)
+			  const struct lmtp_proxy_rcpt_settings *set)
 {
 	struct lmtp_proxy_connection *const *conns, *conn;
 	struct lmtp_client_settings client_set;
@@ -127,8 +130,10 @@
 
 	memset(&client_set, 0, sizeof(client_set));
 	client_set.mail_from = proxy->mail_from;
-	client_set.my_hostname = proxy->my_hostname;
-	client_set.dns_client_socket_path = proxy->dns_client_socket_path;
+	client_set.my_hostname = proxy->set.my_hostname;
+	client_set.dns_client_socket_path = proxy->set.dns_client_socket_path;
+	client_set.source_ip = proxy->set.source_ip;
+	client_set.source_port = proxy->set.source_port;
 
 	conn = p_new(proxy->pool, struct lmtp_proxy_connection, 1);
 	conn->proxy = proxy;
@@ -236,7 +241,7 @@
 }
 
 int lmtp_proxy_add_rcpt(struct lmtp_proxy *proxy, const char *address,
-			const struct lmtp_proxy_settings *set)
+			const struct lmtp_proxy_rcpt_settings *set)
 {
 	struct lmtp_proxy_connection *conn;
 	struct lmtp_proxy_recipient *rcpt;
@@ -294,4 +299,5 @@
 		lmtp_client_send(conn->client, conn->data_input);
 		lmtp_client_send_more(conn->client);
 	}
+	lmtp_proxy_try_finish(proxy);
 }
diff -r 3144001fae84 -r 1bc56eec3f8e src/lmtp/lmtp-proxy.h
--- a/src/lmtp/lmtp-proxy.h	Thu Feb 23 11:58:35 2012 +0200
+++ b/src/lmtp/lmtp-proxy.h	Thu Feb 23 11:59:10 2012 +0200
@@ -5,6 +5,15 @@
 #include "lmtp-client.h"
 
 struct lmtp_proxy_settings {
+	const char *my_hostname;
+	const char *dns_client_socket_path;
+
+	/* the original client's IP/port that connected to the proxy */
+	struct ip_addr source_ip;
+	unsigned int source_port;
+};
+
+struct lmtp_proxy_rcpt_settings {
 	const char *host;
 	unsigned int port;
 	unsigned int timeout_msecs;
@@ -14,7 +23,7 @@
 typedef void lmtp_proxy_finish_callback_t(void *context);
 
 struct lmtp_proxy *
-lmtp_proxy_init(const char *my_hostname, const char *dns_client_socket_path,
+lmtp_proxy_init(const struct lmtp_proxy_settings *set,
 		struct ostream *client_output);
 void lmtp_proxy_deinit(struct lmtp_proxy **proxy);
 
@@ -23,7 +32,7 @@
 /* Add a new recipient. Returns -1 if we already know that the destination
    host can't be reached. */
 int lmtp_proxy_add_rcpt(struct lmtp_proxy *proxy, const char *address,
-			const struct lmtp_proxy_settings *set);
+			const struct lmtp_proxy_rcpt_settings *set);
 /* Start proxying */
 void lmtp_proxy_start(struct lmtp_proxy *proxy, struct istream *data_input,
 		      const char *header,


More information about the dovecot-cvs mailing list