changeset 18358:804dc641f448

auth ldap: Call ldap_init*() already at db_ldap_init(). ldap_init*() doesn't start connecting yet, but this way we can verify that all the settings are correct.
author Timo Sirainen <tss@iki.fi>
date Mon, 16 Mar 2015 23:14:49 +0200
parents b3fd99432298
children ec2e7ae958c5
files src/auth/db-ldap.c
diffstat 1 files changed, 28 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/db-ldap.c	Mon Mar 16 23:03:10 2015 +0200
+++ b/src/auth/db-ldap.c	Mon Mar 16 23:14:49 2015 +0200
@@ -1114,6 +1114,30 @@
 	db_ldap_set_tls_options(conn);
 }
 
+static void db_ldap_init_ld(struct ldap_connection *conn)
+{
+	int ret;
+
+	if (conn->set.uris != NULL) {
+#ifdef LDAP_HAVE_INITIALIZE
+		ret = ldap_initialize(&conn->ld, conn->set.uris);
+		if (ret != LDAP_SUCCESS) {
+			i_fatal("LDAP: ldap_initialize() failed with uris %s: %s",
+				conn->set.uris, ldap_err2string(ret));
+		}
+#else
+		i_unreached(); /* already checked at init */
+#endif
+	} else {
+		conn->ld = ldap_init(conn->set.hosts, LDAP_PORT);
+		if (conn->ld == NULL) {
+			i_fatal("LDAP: ldap_init() failed with hosts: %s",
+				conn->set.hosts);
+		}
+	}
+	db_ldap_set_options(conn);
+}
+
 int db_ldap_connect(struct ldap_connection *conn)
 {
 	bool debug = atoi(conn->set.debug_level) > 0;
@@ -1128,27 +1152,8 @@
 			memset(&start, 0, sizeof(start));
 	}
 	i_assert(conn->pending_count == 0);
-	if (conn->ld == NULL) {
-		if (conn->set.uris != NULL) {
-#ifdef LDAP_HAVE_INITIALIZE
-			ret = ldap_initialize(&conn->ld, conn->set.uris);
-			if (ret != LDAP_SUCCESS) {
-				i_fatal("LDAP: ldap_initialize() failed with uris %s: %s",
-					conn->set.uris, ldap_err2string(ret));
-				conn->ld = NULL;
-			}
-#else
-			i_unreached(); /* already checked at init */
-#endif
-		} else {
-			conn->ld = ldap_init(conn->set.hosts, LDAP_PORT);
-			if (conn->ld == NULL) {
-				i_fatal("LDAP: ldap_init() failed with hosts: %s",
-					conn->set.hosts);
-			}
-		}
-		db_ldap_set_options(conn);
-	}
+	if (conn->ld == NULL)
+		db_ldap_init_ld(conn);
 
 	if (conn->set.tls) {
 #ifdef LDAP_HAVE_START_TLS_S
@@ -1827,6 +1832,8 @@
 
 	conn->next = ldap_connections;
         ldap_connections = conn;
+
+	db_ldap_init_ld(conn);
 	return conn;
 }