dovecot-1.2: login proxy: Added client_proxy passdb extra field ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 12 21:32:26 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/e3ccd235a7e5
changeset: 9306:e3ccd235a7e5
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 12 14:32:17 2009 -0400
description:
login proxy: Added client_proxy passdb extra field to specify proxy's connect timeout.

diffstat:

8 files changed, 44 insertions(+), 8 deletions(-)
src/imap-login/client-authenticate.c |    5 ++++-
src/imap-login/imap-proxy.c          |    4 +++-
src/imap-login/imap-proxy.h          |    3 ++-
src/login-common/login-proxy.c       |   19 +++++++++++++++++++
src/login-common/login-proxy.h       |    9 +++++++--
src/pop3-login/client-authenticate.c |    5 ++++-
src/pop3-login/pop3-proxy.c          |    4 +++-
src/pop3-login/pop3-proxy.h          |    3 ++-

diffs (211 lines):

diff -r b7dbcf86086b -r e3ccd235a7e5 src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/imap-login/client-authenticate.c	Wed Aug 12 14:32:17 2009 -0400
@@ -128,6 +128,7 @@ static bool client_handle_args(struct im
 	enum login_proxy_ssl_flags ssl_flags = 0;
 	string_t *reply;
 	unsigned int port = 143;
+	unsigned int proxy_timeout_msecs = 0;
 	bool proxy = FALSE, temp = FALSE, nologin = !success;
 	bool authz_failure = FALSE;
 
@@ -161,6 +162,8 @@ static bool client_handle_args(struct im
 			destuser = value;
 		else if (strcmp(key, "pass") == 0)
 			pass = value;
+		else if (strcmp(key, "proxy_timeout") == 0)
+			proxy_timeout_msecs = 1000*atoi(value);
 		else if (strcmp(key, "master") == 0)
 			master_user = value;
 		else if (strcmp(key, "ssl") == 0) {
@@ -191,7 +194,7 @@ static bool client_handle_args(struct im
 		if (!success)
 			return FALSE;
 		if (imap_proxy_new(client, host, port, destuser, master_user,
-				   pass, ssl_flags) < 0)
+				   pass, ssl_flags, proxy_timeout_msecs) < 0)
 			client_auth_failed(client, TRUE);
 		return TRUE;
 	}
diff -r b7dbcf86086b -r e3ccd235a7e5 src/imap-login/imap-proxy.c
--- a/src/imap-login/imap-proxy.c	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/imap-login/imap-proxy.c	Wed Aug 12 14:32:17 2009 -0400
@@ -400,7 +400,8 @@ static void proxy_input(struct imap_clie
 
 int imap_proxy_new(struct imap_client *client, const char *host,
 		   unsigned int port, const char *user, const char *master_user,
-		   const char *password, enum login_proxy_ssl_flags ssl_flags)
+		   const char *password, enum login_proxy_ssl_flags ssl_flags,
+		   unsigned int connect_timeout_msecs)
 {
 	i_assert(user != NULL);
 	i_assert(!client->destroyed);
@@ -426,6 +427,7 @@ int imap_proxy_new(struct imap_client *c
 	}
 
 	client->proxy = login_proxy_new(&client->common, host, port, ssl_flags,
+					connect_timeout_msecs,
 					proxy_input, client);
 	if (client->proxy == NULL) {
 		client_send_tagline(client, PROXY_FAILURE_MSG);
diff -r b7dbcf86086b -r e3ccd235a7e5 src/imap-login/imap-proxy.h
--- a/src/imap-login/imap-proxy.h	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/imap-login/imap-proxy.h	Wed Aug 12 14:32:17 2009 -0400
@@ -5,6 +5,7 @@
 
 int imap_proxy_new(struct imap_client *client, const char *hosts,
 		   unsigned int port, const char *user, const char *master_user,
-		   const char *password, enum login_proxy_ssl_flags ssl_flags);
+		   const char *password, enum login_proxy_ssl_flags ssl_flags,
+		   unsigned int connect_timeout_msecs);
 
 #endif
diff -r b7dbcf86086b -r e3ccd235a7e5 src/login-common/login-proxy.c
--- a/src/login-common/login-proxy.c	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/login-common/login-proxy.c	Wed Aug 12 14:32:17 2009 -0400
@@ -24,6 +24,8 @@ struct login_proxy {
 	struct ip_addr ip;
 	struct ssl_proxy *ssl_proxy;
 
+	struct timeout *to;
+
 	char *host, *user;
 	unsigned int port;
 	enum login_proxy_ssl_flags ssl_flags;
@@ -138,6 +140,9 @@ static void proxy_wait_connect(struct lo
                 login_proxy_free(&proxy);
 		return;
 	}
+
+	if (proxy->to != NULL)
+		timeout_remove(&proxy->to);
 
 	if ((proxy->ssl_flags & PROXY_SSL_FLAG_YES) != 0 &&
 	    (proxy->ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
@@ -151,10 +156,17 @@ static void proxy_wait_connect(struct lo
 	}
 }
 
+static void proxy_connect_timeout(struct login_proxy *proxy)
+{
+	i_error("proxy: connect(%s, %u) timed out", proxy->host, proxy->port);
+	login_proxy_free(&proxy);
+}
+
 #undef login_proxy_new
 struct login_proxy *
 login_proxy_new(struct client *client, const char *host, unsigned int port,
 		enum login_proxy_ssl_flags ssl_flags,
+		unsigned int connect_timeout_msecs,
 		proxy_callback_t *callback, void *context)
 {
 	struct login_proxy *proxy;
@@ -188,6 +200,10 @@ login_proxy_new(struct client *client, c
 
 	proxy->server_fd = fd;
 	proxy->server_io = io_add(fd, IO_WRITE, proxy_wait_connect, proxy);
+	if (connect_timeout_msecs != 0) {
+		proxy->to = timeout_add(connect_timeout_msecs,
+					proxy_connect_timeout, proxy);
+	}
 
 	proxy->callback = callback;
 	proxy->context = context;
@@ -207,6 +223,9 @@ void login_proxy_free(struct login_proxy
 	if (proxy->destroying)
 		return;
 	proxy->destroying = TRUE;
+
+	if (proxy->to != NULL)
+		timeout_remove(&proxy->to);
 
 	if (proxy->server_io != NULL)
 		io_remove(&proxy->server_io);
diff -r b7dbcf86086b -r e3ccd235a7e5 src/login-common/login-proxy.h
--- a/src/login-common/login-proxy.h	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/login-common/login-proxy.h	Wed Aug 12 14:32:17 2009 -0400
@@ -20,15 +20,20 @@ struct login_proxy *
 struct login_proxy *
 login_proxy_new(struct client *client, const char *host, unsigned int port,
 		enum login_proxy_ssl_flags ssl_flags,
+		unsigned int connect_timeout_msecs,
 		proxy_callback_t *callback, void *context);
 #ifdef CONTEXT_TYPE_SAFETY
-#  define login_proxy_new(client, host, port, ssl_flags, callback, context) \
+#  define login_proxy_new(client, host, port, ssl_flags, \
+			  connect_timeout_msecs, callback, context) \
 	({(void)(1 ? 0 : callback(context)); \
 	  login_proxy_new(client, host, port, ssl_flags, \
+	  	connect_timeout_msecs, \
 		(proxy_callback_t *)callback, context); })
 #else
-#  define login_proxy_new(client, host, port, ssl_flags, callback, context) \
+#  define login_proxy_new(client, host, port, ssl_flags, \
+			  connect_timeout_msecs, callback, context) \
 	  login_proxy_new(client, host, port, ssl_flags, \
+	  	connect_timeout_msecs, \
 		(proxy_callback_t *)callback, context)
 #endif
 /* Free the proxy. This should be called if authentication fails. */
diff -r b7dbcf86086b -r e3ccd235a7e5 src/pop3-login/client-authenticate.c
--- a/src/pop3-login/client-authenticate.c	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/pop3-login/client-authenticate.c	Wed Aug 12 14:32:17 2009 -0400
@@ -130,6 +130,7 @@ static bool client_handle_args(struct po
 	enum login_proxy_ssl_flags ssl_flags = 0;
 	string_t *reply;
 	unsigned int port = 110;
+	unsigned int proxy_timeout_msecs = 0;
 	bool proxy = FALSE, temp = FALSE, nologin = !success;
 
 	*nodelay_r = FALSE;
@@ -160,6 +161,8 @@ static bool client_handle_args(struct po
 			destuser = value;
 		else if (strcmp(key, "pass") == 0)
 			pass = value;
+		else if (strcmp(key, "proxy_timeout") == 0)
+			proxy_timeout_msecs = 1000*atoi(value);
 		else if (strcmp(key, "master") == 0)
 			master_user = value;
 		else if (strcmp(key, "ssl") == 0) {
@@ -190,7 +193,7 @@ static bool client_handle_args(struct po
 		if (!success)
 			return FALSE;
 		if (pop3_proxy_new(client, host, port, destuser, master_user,
-				   pass, ssl_flags) < 0)
+				   pass, ssl_flags, proxy_timeout_msecs) < 0)
 			client_auth_failed(client, TRUE);
 		return TRUE;
 	}
diff -r b7dbcf86086b -r e3ccd235a7e5 src/pop3-login/pop3-proxy.c
--- a/src/pop3-login/pop3-proxy.c	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/pop3-login/pop3-proxy.c	Wed Aug 12 14:32:17 2009 -0400
@@ -259,7 +259,8 @@ static void proxy_input(struct pop3_clie
 
 int pop3_proxy_new(struct pop3_client *client, const char *host,
 		   unsigned int port, const char *user, const char *master_user,
-		   const char *password, enum login_proxy_ssl_flags ssl_flags)
+		   const char *password, enum login_proxy_ssl_flags ssl_flags,
+		   unsigned int connect_timeout_msecs)
 {
 	i_assert(user != NULL);
 	i_assert(!client->destroyed);
@@ -285,6 +286,7 @@ int pop3_proxy_new(struct pop3_client *c
 	}
 
 	client->proxy = login_proxy_new(&client->common, host, port, ssl_flags,
+					connect_timeout_msecs,
 					proxy_input, client);
 	if (client->proxy == NULL) {
 		client_send_line(client, PROXY_FAILURE_MSG);
diff -r b7dbcf86086b -r e3ccd235a7e5 src/pop3-login/pop3-proxy.h
--- a/src/pop3-login/pop3-proxy.h	Tue Aug 11 17:38:06 2009 -0400
+++ b/src/pop3-login/pop3-proxy.h	Wed Aug 12 14:32:17 2009 -0400
@@ -5,6 +5,7 @@
 
 int pop3_proxy_new(struct pop3_client *client, const char *host,
 		   unsigned int port, const char *user, const char *master_user,
-		   const char *password, enum login_proxy_ssl_flags ssl_flags);
+		   const char *password, enum login_proxy_ssl_flags ssl_flags,
+		   unsigned int connect_timeout_msecs);
 
 #endif


More information about the dovecot-cvs mailing list