dovecot-2.0: auth: If initial binding to LDAP server hangs, dete...

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 4 17:53:07 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/cef23de90ff1
changeset: 12710:cef23de90ff1
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 04 17:53:05 2011 +0300
description:
auth: If initial binding to LDAP server hangs, detect it and abort.

diffstat:

 src/auth/db-ldap.c |  23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diffs (61 lines):

diff -r 0ce50c22f84c -r cef23de90ff1 src/auth/db-ldap.c
--- a/src/auth/db-ldap.c	Sun Apr 03 06:42:48 2011 +0300
+++ b/src/auth/db-ldap.c	Mon Apr 04 17:53:05 2011 +0300
@@ -456,6 +456,8 @@
 		return -1;
 	}
 
+	if (conn->to != NULL)
+		timeout_remove(&conn->to);
 	conn->conn_state = LDAP_CONN_STATE_BOUND_DEFAULT;
 	while (db_ldap_request_queue_next(conn))
 		;
@@ -693,6 +695,14 @@
 }
 #endif
 
+static void ldap_connection_timeout(struct ldap_connection *conn)
+{
+	i_assert(conn->conn_state == LDAP_CONN_STATE_BINDING);
+
+	i_error("LDAP: Initial binding to LDAP server timed out");
+	db_ldap_conn_close(conn);
+}
+
 static int db_ldap_bind(struct ldap_connection *conn)
 {
 	int msgid;
@@ -714,6 +724,11 @@
 
 	conn->conn_state = LDAP_CONN_STATE_BINDING;
 	conn->default_bind_msgid = msgid;
+
+	if (conn->to != NULL)
+		timeout_remove(&conn->to);
+	conn->to = timeout_add(DB_LDAP_REQUEST_LOST_TIMEOUT_SECS*1000,
+			       ldap_connection_timeout, conn);
 	return 0;
 }
 
@@ -928,6 +943,9 @@
 	conn->conn_state = LDAP_CONN_STATE_DISCONNECTED;
 	conn->default_bind_msgid = -1;
 
+	if (conn->to != NULL)
+		timeout_remove(&conn->to);
+
 	if (conn->pending_count != 0) {
 		requests = array_idx(&conn->request_array, 0);
 		for (i = 0; i < conn->pending_count; i++) {
@@ -951,10 +969,7 @@
 		io_remove_closed(&conn->io);
 	}
 
-	if (aqueue_count(conn->request_queue) == 0) {
-		if (conn->to != NULL)
-			timeout_remove(&conn->to);
-	} else if (conn->to == NULL) {
+	if (aqueue_count(conn->request_queue) > 0) {
 		conn->to = timeout_add(DB_LDAP_REQUEST_DISCONNECT_TIMEOUT_SECS *
 				       1000/2, db_ldap_disconnect_timeout, conn);
 	}


More information about the dovecot-cvs mailing list