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

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