[dovecot-cvs] dovecot/src/auth db-ldap.c, 1.60, 1.61 passdb-ldap.c, 1.56, 1.57

tss at dovecot.org tss at dovecot.org
Fri Jan 19 15:18:26 UTC 2007


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv27244

Modified Files:
	db-ldap.c passdb-ldap.c 
Log Message:
Do ldap_bind() only when there are no requests waiting, and don't do
anything until ldap_bind() has finished. This fixes several problems with
auth_bind=yes.



Index: db-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- db-ldap.c	16 Jan 2007 13:25:40 -0000	1.60
+++ db-ldap.c	19 Jan 2007 15:18:24 -0000	1.61
@@ -149,8 +149,6 @@
 void db_ldap_add_delayed_request(struct ldap_connection *conn,
 				 struct ldap_request *request)
 {
-	i_assert(!conn->connected);
-
 	request->next = NULL;
 
 	if (conn->delayed_requests_head == NULL)
@@ -160,6 +158,26 @@
 	conn->delayed_requests_tail = request;
 }
 
+static void db_ldap_handle_next_delayed_request(struct ldap_connection *conn)
+{
+	struct ldap_request *request;
+
+	if (conn->delayed_requests_head == NULL)
+		return;
+
+	request = conn->delayed_requests_head;
+	conn->delayed_requests_head = request->next;
+	if (conn->delayed_requests_head == NULL)
+		conn->delayed_requests_tail = NULL;
+
+	conn->retrying = TRUE;
+	if (request->filter == NULL)
+		request->callback(conn, request, NULL);
+	else
+		db_ldap_search(conn, request, conn->set.ldap_scope);
+	conn->retrying = FALSE;
+}
+
 void db_ldap_search(struct ldap_connection *conn, struct ldap_request *request,
 		    int scope)
 {
@@ -170,7 +188,7 @@
 		return;
 	}
 
-	if (conn->connected) {
+	if (conn->connected && !conn->binding) {
 		if (conn->last_auth_bind) {
 			/* switch back to the default dn before doing the
 			   search request. */
@@ -288,7 +306,10 @@
 	LDAPMessage *res;
 	int ret, msgid;
 
-	while (conn->ld != NULL) {
+	for (;;) {
+		if (conn->ld == NULL)
+			return;
+
 		memset(&timeout, 0, sizeof(timeout));
 		ret = ldap_result(conn->ld, LDAP_RES_ANY, 1, &timeout, &res);
 #ifdef OPENLDAP_ASYNC_WORKAROUND
@@ -298,14 +319,8 @@
 					  &timeout, &res);
 		}
 #endif
-		if (ret <= 0) {
-			if (ret < 0) {
-				i_error("LDAP: ldap_result() failed: %s",
-					ldap_get_error(conn));
-				ldap_conn_reconnect(conn);
-			}
-			return;
-		}
+		if (ret <= 0)
+			break;
 
 		msgid = ldap_msgid(res);
 		request = hash_lookup(conn->requests, POINTER_CAST(msgid));
@@ -313,12 +328,22 @@
 			i_error("LDAP: Reply with unknown msgid %d",
 				msgid);
 		} else {
+			i_info("remove: %u", msgid);
 			hash_remove(conn->requests, POINTER_CAST(msgid));
 			request->callback(conn, request, res);
 		}
 
 		ldap_msgfree(res);
 	}
+
+	if (ret < 0) {
+		i_error("LDAP: ldap_result() failed: %s",
+			ldap_get_error(conn));
+		ldap_conn_reconnect(conn);
+	} else {
+		if (!conn->binding)
+			db_ldap_handle_next_delayed_request(conn);
+	}
 }
 
 #ifdef HAVE_LDAP_SASL
@@ -388,6 +413,7 @@
 {
 	int ret;
 
+	conn->binding = FALSE;
 	conn->connecting = FALSE;
 	i_free(ldap_request);
 
@@ -408,6 +434,8 @@
 	struct ldap_request *ldap_request;
 	int msgid;
 
+	i_assert(!conn->binding);
+
 	ldap_request = i_new(struct ldap_request, 1);
 	ldap_request->callback = db_ldap_bind_callback;
 	ldap_request->context = conn;
@@ -421,6 +449,7 @@
 	}
 
 	conn->connecting = TRUE;
+	conn->binding = TRUE;
 	hash_insert(conn->requests, POINTER_CAST(msgid), ldap_request);
 
 	/* we're binding back to the original DN, not doing an
@@ -450,6 +479,7 @@
 
 	if (conn->connected || conn->connecting)
 		return 0;
+	i_assert(!conn->binding);
 
 	if (conn->ld == NULL) {
 		if (conn->set.uris != NULL) {
@@ -560,6 +590,7 @@
 	}
 
 	conn->connected = FALSE;
+	conn->binding = FALSE;
 
 	if (conn->io != NULL)
 		io_remove(&conn->io);

Index: passdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-ldap.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- passdb-ldap.c	12 Nov 2006 13:07:43 -0000	1.56
+++ passdb-ldap.c	19 Jan 2007 15:18:24 -0000	1.57
@@ -258,10 +258,11 @@
 		return;
 	}
 
-	if (conn->connected) {
+	if (conn->connected && hash_size(conn->requests) == 0) {
 		/* switch back to the default dn before doing the next search
 		   request */
 		conn->last_auth_bind = TRUE;
+		i_assert(!conn->binding);
 
 		/* the DN is kept in base variable, a bit ugly.. */
 		msgid = ldap_bind(conn->ld, ldap_request->base,
@@ -276,6 +277,8 @@
 					     auth_request);
 			return;
 		}
+
+		conn->binding = TRUE;
 		hash_insert(conn->requests, POINTER_CAST(msgid), ldap_request);
 
 		auth_request_log_debug(auth_request, "ldap", "bind: dn=%s",
@@ -298,6 +301,7 @@
 	enum passdb_result passdb_result;
 	int ret;
 
+	conn->binding = FALSE;
 	passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
 
 	if (res != NULL) {



More information about the dovecot-cvs mailing list