dovecot: If LDAP server disconnects the connection and we haven'...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Dec 28 19:14:40 EET 2007
details: http://hg.dovecot.org/dovecot/rev/ae0556fb268d
changeset: 7045:ae0556fb268d
user: Timo Sirainen <tss at iki.fi>
date: Fri Dec 28 19:14:36 2007 +0200
description:
If LDAP server disconnects the connection and we haven't sent requests for a
minute, disconnect silently and don't reconnect until the next auth request
comes.
diffstat:
3 files changed, 22 insertions(+), 3 deletions(-)
src/auth/db-ldap.c | 22 +++++++++++++++++++---
src/auth/db-ldap.h | 1 +
src/auth/passdb-ldap.c | 2 ++
diffs (93 lines):
diff -r b7f037c8ff57 -r ae0556fb268d src/auth/db-ldap.c
--- a/src/auth/db-ldap.c Fri Dec 28 00:50:48 2007 +0200
+++ b/src/auth/db-ldap.c Fri Dec 28 19:14:36 2007 +0200
@@ -41,6 +41,10 @@
#ifndef LDAP_OPT_SUCCESS
# define LDAP_OPT_SUCCESS LDAP_SUCCESS
#endif
+
+/* If server disconnects us, don't reconnect if no requests have been sent
+ for this many seconds. */
+#define LDAP_IDLE_RECONNECT_SECS 60
struct db_ldap_result_iterate_context {
struct ldap_connection *conn;
@@ -277,6 +281,7 @@ void db_ldap_search(struct ldap_connecti
hash_insert(conn->requests, POINTER_CAST(msgid), request);
else
db_ldap_add_delayed_request(conn, request);
+ conn->last_request_stamp = ioloop_time;
}
static void ldap_conn_retry_requests(struct ldap_connection *conn)
@@ -395,12 +400,21 @@ static void ldap_input(struct ldap_conne
ldap_msgfree(res);
}
- if (ret < 0) {
+ if (ret == 0) {
+ if (!conn->binding)
+ db_ldap_handle_next_delayed_request(conn);
+ } else if (ldap_get_errno(conn) != LDAP_SERVER_DOWN) {
i_error("LDAP: ldap_result() failed: %s", ldap_get_error(conn));
ldap_conn_reconnect(conn);
+ } else if (hash_count(conn->requests) > 0 ||
+ ioloop_time - conn->last_request_stamp <
+ LDAP_IDLE_RECONNECT_SECS) {
+ i_error("LDAP: Connection lost to LDAP server, reconnecting");
+ ldap_conn_reconnect(conn);
} else {
- if (!conn->binding)
- db_ldap_handle_next_delayed_request(conn);
+ /* server probably disconnected an idle connection. don't
+ reconnect until the next request comes. */
+ ldap_conn_close(conn, TRUE);
}
}
@@ -516,6 +530,7 @@ static int db_ldap_bind(struct ldap_conn
/* we're binding back to the original DN, not doing an
authentication bind */
conn->last_auth_bind = FALSE;
+ conn->last_request_stamp = ioloop_time;
return 0;
}
@@ -547,6 +562,7 @@ int db_ldap_connect(struct ldap_connecti
return 0;
i_assert(!conn->binding);
+ conn->last_request_stamp = ioloop_time;
if (conn->ld == NULL) {
if (conn->set.uris != NULL) {
#ifdef LDAP_HAVE_INITIALIZE
diff -r b7f037c8ff57 -r ae0556fb268d src/auth/db-ldap.h
--- a/src/auth/db-ldap.h Fri Dec 28 00:50:48 2007 +0200
+++ b/src/auth/db-ldap.h Fri Dec 28 19:14:36 2007 +0200
@@ -62,6 +62,7 @@ struct ldap_connection {
struct hash_table *requests;
struct ldap_request *delayed_requests_head, *delayed_requests_tail;
+ time_t last_request_stamp;
char **pass_attr_names, **user_attr_names;
struct hash_table *pass_attr_map, *user_attr_map;
diff -r b7f037c8ff57 -r ae0556fb268d src/auth/passdb-ldap.c
--- a/src/auth/passdb-ldap.c Fri Dec 28 00:50:48 2007 +0200
+++ b/src/auth/passdb-ldap.c Fri Dec 28 19:14:36 2007 +0200
@@ -4,6 +4,7 @@
#ifdef PASSDB_LDAP
+#include "ioloop.h"
#include "hash.h"
#include "str.h"
#include "var-expand.h"
@@ -203,6 +204,7 @@ static void authbind_start(struct ldap_c
}
conn->binding = TRUE;
+ conn->last_request_stamp = ioloop_time;
hash_insert(conn->requests, POINTER_CAST(msgid), ldap_request);
auth_request_log_debug(auth_request, "ldap", "bind: dn=%s",
More information about the dovecot-cvs
mailing list