dovecot-1.0: If proxy points to the same host/port/user combinat...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Oct 28 02:54:33 EEST 2007
details: http://hg.dovecot.org/dovecot-1.0/rev/8c43fe6f89bc
changeset: 5435:8c43fe6f89bc
user: Timo Sirainen <tss at iki.fi>
date: Sun Oct 28 02:54:30 2007 +0300
description:
If proxy points to the same host/port/user combination as we currently have,
don't create an infinite connection loop.
diffstat:
4 files changed, 26 insertions(+), 3 deletions(-)
src/imap-login/client-authenticate.c | 5 +++--
src/login-common/login-proxy.c | 16 ++++++++++++++++
src/login-common/login-proxy.h | 5 +++++
src/pop3-login/client-authenticate.c | 3 ++-
diffs (76 lines):
diff -r 5ca293be0ca2 -r 8c43fe6f89bc src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c Sat Oct 27 22:38:02 2007 +0300
+++ b/src/imap-login/client-authenticate.c Sun Oct 28 02:54:30 2007 +0300
@@ -107,7 +107,8 @@ static bool client_handle_args(struct im
if (destuser == NULL)
destuser = client->common.virtual_user;
- if (proxy) {
+ if (proxy &&
+ !login_proxy_is_ourself(&client->common, host, port, destuser)) {
/* we want to proxy the connection to another server.
don't do this unless authentication succeeded. with
master user proxying we can get FAIL with proxy still set.
@@ -120,7 +121,7 @@ static bool client_handle_args(struct im
return TRUE;
}
- if (host != NULL) {
+ if (!proxy && host != NULL) {
/* IMAP referral
[nologin] referral host=.. [port=..] [destuser=..]
diff -r 5ca293be0ca2 -r 8c43fe6f89bc src/login-common/login-proxy.c
--- a/src/login-common/login-proxy.c Sat Oct 27 22:38:02 2007 +0300
+++ b/src/login-common/login-proxy.c Sun Oct 28 02:54:30 2007 +0300
@@ -227,6 +227,22 @@ void login_proxy_free(struct login_proxy
main_listen_start();
}
+bool login_proxy_is_ourself(struct client *client, const char *host,
+ unsigned int port, const char *destuser)
+{
+ struct ip_addr ip;
+
+ if (port != client->local_port)
+ return FALSE;
+
+ if (net_addr2ip(host, &ip) < 0)
+ return FALSE;
+ if (!net_ip_compare(&ip, &client->local_ip))
+ return FALSE;
+
+ return strcmp(client->virtual_user, destuser) == 0;
+}
+
const char *login_proxy_get_host(struct login_proxy *proxy)
{
return proxy->host;
diff -r 5ca293be0ca2 -r 8c43fe6f89bc src/login-common/login-proxy.h
--- a/src/login-common/login-proxy.h Sat Oct 27 22:38:02 2007 +0300
+++ b/src/login-common/login-proxy.h Sun Oct 28 02:54:30 2007 +0300
@@ -15,6 +15,11 @@ login_proxy_new(struct client *client, c
/* Free the proxy. This should be called if authentication fails. */
void login_proxy_free(struct login_proxy *proxy);
+/* Return TRUE if host/port/destuser combination points to same as current
+ connection. */
+bool login_proxy_is_ourself(struct client *client, const char *host,
+ unsigned int port, const char *destuser);
+
/* Detach proxy from client. This is done after the authentication is
successful and all that is left is the dummy proxying. */
void login_proxy_detach(struct login_proxy *proxy, struct istream *client_input,
diff -r 5ca293be0ca2 -r 8c43fe6f89bc src/pop3-login/client-authenticate.c
--- a/src/pop3-login/client-authenticate.c Sat Oct 27 22:38:02 2007 +0300
+++ b/src/pop3-login/client-authenticate.c Sun Oct 28 02:54:30 2007 +0300
@@ -114,7 +114,8 @@ static bool client_handle_args(struct po
if (destuser == NULL)
destuser = client->common.virtual_user;
- if (proxy) {
+ if (proxy &&
+ !login_proxy_is_ourself(&client->common, host, port, destuser)) {
/* we want to proxy the connection to another server.
don't do this unless authentication succeeded. with
master user proxying we can get FAIL with proxy still set.
More information about the dovecot-cvs
mailing list