Blame SOURCES/autofs-5.1.1-move-query-dn-calculation-from-do_bind-to-do_connect.patch

306fa1
autofs-5.1.1 - move query dn calculation from do_bind() to do_connect()
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
In the ldap lookup module the do_reconnect() call doesn't distinguish
306fa1
between no entry found and service unavailable.
306fa1
306fa1
If service unavailable gets returned from a master map read it results
306fa1
in autofs not updating the mounts. A notfound return doesn't because it
306fa1
indicates the map doesn't exist so updating the mounts isn't a problem
306fa1
as it can be when the source is unavailable.
306fa1
306fa1
Start the update of do_reconnect() by moving the query dn calculation
306fa1
from do_bind() to do_connect().
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG             |    1 
306fa1
 modules/lookup_ldap.c |   81 ++++++++++++++++++++++++++++++--------------------
306fa1
 2 files changed, 51 insertions(+), 31 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -172,6 +172,7 @@
306fa1
 - init qdn before use in get_query_dn().
306fa1
 - fix left mount count return from umount_multi_triggers().
306fa1
 - fix return handling in sss lookup module.
306fa1
+- move query dn calculation from do_bind() to do_connect().
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/modules/lookup_ldap.c
306fa1
+++ autofs-5.0.7/modules/lookup_ldap.c
306fa1
@@ -574,7 +574,7 @@ static int find_query_dn(unsigned logopt
306fa1
 static int do_bind(unsigned logopt, LDAP *ldap, const char *uri, struct lookup_context *ctxt)
306fa1
 {
306fa1
 	char *host = NULL, *nhost;
306fa1
-	int rv, need_base = 1;
306fa1
+	int rv;
306fa1
 
306fa1
 #ifdef WITH_SASL
306fa1
 	debug(logopt, MODPREFIX "auth_required: %d, sasl_mech %s",
306fa1
@@ -610,6 +610,7 @@ static int do_bind(unsigned logopt, LDAP
306fa1
 	}
306fa1
 	ldap_memfree(host);
306fa1
 
306fa1
+	uris_mutex_lock(ctxt);
306fa1
 	if (!ctxt->cur_host) {
306fa1
 		ctxt->cur_host = nhost;
306fa1
 		if (!(ctxt->format & MAP_FLAG_FORMAT_AMD)) {
306fa1
@@ -618,43 +619,21 @@ static int do_bind(unsigned logopt, LDAP
306fa1
 		}
306fa1
 	} else {
306fa1
 		/* If connection host has changed update */
306fa1
-		if (strcmp(ctxt->cur_host, nhost)) {
306fa1
+		if (!strcmp(ctxt->cur_host, nhost))
306fa1
+			free(nhost);
306fa1
+		else {
306fa1
 			free(ctxt->cur_host);
306fa1
 			ctxt->cur_host = nhost;
306fa1
-		} else {
306fa1
-			free(nhost);
306fa1
-			need_base = 0;
306fa1
-		}
306fa1
-	}
306fa1
-
306fa1
-	if (ctxt->schema && ctxt->qdn && !need_base)
306fa1
-		return 1;
306fa1
-
306fa1
-	/*
306fa1
-	 * If the schema isn't defined in the configuration then check for
306fa1
-	 * presence of a map dn with a the common schema. Then calculate the
306fa1
-	 * base dn for searches.
306fa1
-	 */
306fa1
-	if (!ctxt->schema) {
306fa1
-		if (!find_query_dn(logopt, ldap, ctxt)) {
306fa1
-			warn(logopt,
306fa1
-			      MODPREFIX "failed to find valid query dn");
306fa1
-			return 0;
306fa1
-		}
306fa1
-	} else if (!(ctxt->format & MAP_FLAG_FORMAT_AMD)) {
306fa1
-		const char *class = ctxt->schema->map_class;
306fa1
-		const char *key = ctxt->schema->map_attr;
306fa1
-		if (!get_query_dn(logopt, ldap, ctxt, class, key)) {
306fa1
-			error(logopt, MODPREFIX "failed to get query dn");
306fa1
-			return 0;
306fa1
 		}
306fa1
 	}
306fa1
+	uris_mutex_unlock(ctxt);
306fa1
 
306fa1
 	return 1;
306fa1
 }
306fa1
 
306fa1
 static LDAP *do_connect(unsigned logopt, const char *uri, struct lookup_context *ctxt)
306fa1
 {
306fa1
+	char *cur_host = NULL;
306fa1
 	LDAP *ldap;
306fa1
 
306fa1
 #ifdef WITH_SASL
306fa1
@@ -665,13 +644,53 @@ static LDAP *do_connect(unsigned logopt,
306fa1
 #endif
306fa1
 
306fa1
 	ldap = init_ldap_connection(logopt, uri, ctxt);
306fa1
-	if (ldap) {
306fa1
-		if (!do_bind(logopt, ldap, uri, ctxt)) {
306fa1
+	if (!ldap)
306fa1
+		goto out;
306fa1
+
306fa1
+	uris_mutex_lock(ctxt);
306fa1
+	if (ctxt->cur_host)
306fa1
+		cur_host = ctxt->cur_host;
306fa1
+	uris_mutex_unlock(ctxt);
306fa1
+
306fa1
+	if (!do_bind(logopt, ldap, uri, ctxt)) {
306fa1
+		unbind_ldap_connection(logopt, ldap, ctxt);
306fa1
+		ldap = NULL;
306fa1
+		goto out;
306fa1
+	}
306fa1
+
306fa1
+	/* If the lookup schema and the query dn are set and the
306fa1
+	 * ldap host hasn't changed return.
306fa1
+	 */
306fa1
+	uris_mutex_lock(ctxt);
306fa1
+	if (ctxt->schema && ctxt->qdn && (cur_host == ctxt->cur_host)) {
306fa1
+		uris_mutex_unlock(ctxt);
306fa1
+		return ldap;
306fa1
+	}
306fa1
+	uris_mutex_unlock(ctxt);
306fa1
+
306fa1
+	/*
306fa1
+	 * If the schema isn't defined in the configuration then check for
306fa1
+	 * presence of a map dn with a the common schema. Then calculate the
306fa1
+	 * base dn for searches.
306fa1
+	 */
306fa1
+	if (!ctxt->schema) {
306fa1
+		if (!find_query_dn(logopt, ldap, ctxt)) {
306fa1
 			unbind_ldap_connection(logopt, ldap, ctxt);
306fa1
 			ldap = NULL;
306fa1
+			warn(logopt,
306fa1
+			      MODPREFIX "failed to find valid query dn");
306fa1
+			goto out;
306fa1
+		}
306fa1
+	} else if (!(ctxt->format & MAP_FLAG_FORMAT_AMD)) {
306fa1
+		const char *class = ctxt->schema->map_class;
306fa1
+		const char *key = ctxt->schema->map_attr;
306fa1
+		if (!get_query_dn(logopt, ldap, ctxt, class, key)) {
306fa1
+			unbind_ldap_connection(logopt, ldap, ctxt);
306fa1
+			ldap = NULL;
306fa1
+			error(logopt, MODPREFIX "failed to get query dn");
306fa1
 		}
306fa1
 	}
306fa1
-
306fa1
+out:
306fa1
 	return ldap;
306fa1
 }
306fa1