[dovecot-cvs] dovecot/src/auth db-ldap.c, 1.41.2.16, 1.41.2.17 passdb-ldap.c, 1.44.2.11, 1.44.2.12

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


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

Modified Files:
      Tag: branch_1_0
	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.41.2.16
retrieving revision 1.41.2.17
diff -u -d -r1.41.2.16 -r1.41.2.17
--- db-ldap.c	16 Jan 2007 13:25:38 -0000	1.41.2.16
+++ db-ldap.c	19 Jan 2007 15:18:20 -0000	1.41.2.17
@@ -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. */
@@ -289,7 +307,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
@@ -299,14 +320,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));
@@ -314,12 +329,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
@@ -389,6 +414,7 @@
 {
 	int ret;
 
+	conn->binding = FALSE;
 	conn->connecting = FALSE;
 	i_free(ldap_request);
 
@@ -409,6 +435,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;
@@ -422,6 +450,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
@@ -451,6 +480,7 @@
 
 	if (conn->connected || conn->connecting)
 		return 0;
+	i_assert(!conn->binding);
 
 	if (conn->ld == NULL) {
 		if (conn->set.uris != NULL) {
@@ -561,6 +591,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.44.2.11
retrieving revision 1.44.2.12
diff -u -d -r1.44.2.11 -r1.44.2.12
--- passdb-ldap.c	12 Nov 2006 13:07:40 -0000	1.44.2.11
+++ passdb-ldap.c	19 Jan 2007 15:18:20 -0000	1.44.2.12
@@ -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