[dovecot-cvs] dovecot/src/auth db-ldap.c,1.41.2.11,1.41.2.12

tss at dovecot.org tss at dovecot.org
Sat Nov 4 20:55:16 UTC 2006


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

Modified Files:
      Tag: branch_1_0
	db-ldap.c 
Log Message:
Fixes



Index: db-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.c,v
retrieving revision 1.41.2.11
retrieving revision 1.41.2.12
diff -u -d -r1.41.2.11 -r1.41.2.12
--- db-ldap.c	4 Nov 2006 20:09:54 -0000	1.41.2.11
+++ db-ldap.c	4 Nov 2006 20:55:14 -0000	1.41.2.12
@@ -147,24 +147,26 @@
 		return;
 	}
 
-	if (conn->last_auth_bind) {
-		/* switch back to the default dn before doing the search
-		   request. */
-		if (db_ldap_bind(conn) < 0) {
+	if (conn->connected) {
+		if (conn->last_auth_bind) {
+			/* switch back to the default dn before doing the
+			   search request. */
+			if (db_ldap_bind(conn) < 0) {
+				request->callback(conn, request, NULL);
+				return;
+			}
+		}
+
+		msgid = ldap_search(conn->ld, request->base, scope,
+				    request->filter, request->attributes, 0);
+		if (msgid == -1) {
+			i_error("LDAP: ldap_search() failed (filter %s): %s",
+				request->filter, ldap_get_error(conn));
 			request->callback(conn, request, NULL);
 			return;
 		}
 	}
 
-	msgid = ldap_search(conn->ld, request->base, scope,
-			    request->filter, request->attributes, 0);
-	if (msgid == -1) {
-		i_error("LDAP: ldap_search() failed (filter %s): %s",
-			request->filter, ldap_get_error(conn));
-		request->callback(conn, request, NULL);
-		return;
-	}
-
 	hash_insert(conn->requests, POINTER_CAST(msgid), request);
 }
 
@@ -320,10 +322,12 @@
 		return -1;
 	}
 
-	conn->connected = TRUE;
+	if (!conn->connected) {
+		conn->connected = TRUE;
 
-	/* in case there are requests waiting, retry them */
-	ldap_conn_retry_requests(conn);
+		/* in case there are requests waiting, retry them */
+		ldap_conn_retry_requests(conn);
+	}
 	return 0;
 }
 
@@ -342,7 +346,10 @@
 	}
 
 	ret = ldap_result2error(conn->ld, res, FALSE);
-	(void)db_ldap_connect_finish(conn, ret);
+	if (db_ldap_connect_finish(conn, ret) < 0) {
+		/* lost connection, close it */
+		ldap_conn_close(conn, TRUE);
+	}
 }
 
 static int db_ldap_bind(struct ldap_connection *conn)
@@ -350,8 +357,6 @@
 	struct ldap_request *ldap_request;
 	int msgid;
 
-	conn->connecting = TRUE;
-
 	ldap_request = i_new(struct ldap_request, 1);
 	ldap_request->callback = db_ldap_bind_callback;
 	ldap_request->context = conn;
@@ -364,6 +369,8 @@
 		i_free(ldap_request);
 		return -1;
 	}
+
+	conn->connecting = TRUE;
 	hash_insert(conn->requests, POINTER_CAST(msgid), ldap_request);
 
 	/* we're binding back to the original DN, not doing an



More information about the dovecot-cvs mailing list