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

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