Blame SOURCES/autofs-5.1.1-fix-return-handling-of-do_reconnect-in-ldap-module.patch

4d476f
autofs-5.1.1 - fix return handling of do_reconnect() in ldap module
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
Finally make do_reconnect() return a status instead of an LDAP handle
4d476f
and pass back the LDAP handle via a function parameter.
4d476f
4d476f
Signed-off-by: Ian Kent <raven@themaw.net>
4d476f
---
4d476f
 CHANGELOG             |    1 
4d476f
 modules/lookup_ldap.c |   78 ++++++++++++++++++++++++++++----------------------
4d476f
 2 files changed, 46 insertions(+), 33 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/CHANGELOG
4d476f
+++ autofs-5.0.7/CHANGELOG
4d476f
@@ -177,6 +177,7 @@
4d476f
 - make connect_to_server() return a status.
4d476f
 - make find_dc_server() return a status.
4d476f
 - make find_server() return a status.
4d476f
+- fix return handling of do_reconnect() in ldap module.
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
@@ -961,31 +961,33 @@ static int find_server(unsigned logopt,
4d476f
 	return ret;
4d476f
 }
4d476f
 
4d476f
-static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
4d476f
+static int do_reconnect(unsigned logopt,
4d476f
+			LDAP **ldap, struct lookup_context *ctxt)
4d476f
 {
4d476f
-	LDAP *ldap = NULL;
4d476f
-	int ret;
4d476f
+	int ret = NSS_STATUS_UNAVAIL;
4d476f
+	int dcrv = NSS_STATUS_SUCCESS;
4d476f
+	int rv = NSS_STATUS_SUCCESS;
4d476f
 
4d476f
 	if (ctxt->server || !ctxt->uris) {
4d476f
-		ret = do_connect(logopt, &ldap, ctxt->server, ctxt);
4d476f
+		ret = do_connect(logopt, ldap, ctxt->server, ctxt);
4d476f
 #ifdef WITH_SASL
4d476f
 		/* Dispose of the sasl authentication connection and try again. */
4d476f
-		if (ret != NSS_STATUS_SUCCESS &&
4d476f
-		    ctxt->auth_required & LDAP_NEED_AUTH) {
4d476f
+		if (ctxt->auth_required & LDAP_NEED_AUTH &&
4d476f
+		    ret != NSS_STATUS_SUCCESS && ret != NSS_STATUS_NOTFOUND) {
4d476f
 			ldapinit_mutex_lock();
4d476f
 			autofs_sasl_dispose(ctxt);
4d476f
 			ldapinit_mutex_unlock();
4d476f
-			ret = connect_to_server(logopt, &ldap,
4d476f
+			ret = connect_to_server(logopt, ldap,
4d476f
 						ctxt->server, ctxt);
4d476f
 		}
4d476f
 #endif
4d476f
-		return ldap;
4d476f
+		return ret;
4d476f
 	}
4d476f
 
4d476f
 	if (ctxt->dclist) {
4d476f
-		ret = find_dc_server(logopt, &ldap, ctxt->dclist->uri, ctxt);
4d476f
-		if (ret == NSS_STATUS_SUCCESS)
4d476f
-			return ldap;
4d476f
+		dcrv = find_dc_server(logopt, ldap, ctxt->dclist->uri, ctxt);
4d476f
+		if (dcrv == NSS_STATUS_SUCCESS)
4d476f
+			return dcrv;
4d476f
 	}
4d476f
 
4d476f
 	uris_mutex_lock(ctxt);
4d476f
@@ -1004,22 +1006,22 @@ static LDAP *do_reconnect(unsigned logop
4d476f
 	if (!ctxt->uri)
4d476f
 		goto find_server;
4d476f
 
4d476f
-	ret = do_connect(logopt, &ldap, ctxt->uri->uri, ctxt);
4d476f
+	rv = do_connect(logopt, ldap, ctxt->uri->uri, ctxt);
4d476f
 #ifdef WITH_SASL
4d476f
 	/*
4d476f
 	 * Dispose of the sasl authentication connection and try the
4d476f
 	 * current server again before trying other servers in the list.
4d476f
 	 */
4d476f
-	if (ret != NSS_STATUS_SUCCESS &&
4d476f
-	    ctxt->auth_required & LDAP_NEED_AUTH) {
4d476f
+	if (ctxt->auth_required & LDAP_NEED_AUTH &&
4d476f
+	    rv != NSS_STATUS_SUCCESS && rv != NSS_STATUS_NOTFOUND) {
4d476f
 		ldapinit_mutex_lock();
4d476f
 		autofs_sasl_dispose(ctxt);
4d476f
 		ldapinit_mutex_unlock();
4d476f
-		ret = connect_to_server(logopt, &ldap, ctxt->uri->uri, ctxt);
4d476f
+		rv = connect_to_server(logopt, ldap, ctxt->uri->uri, ctxt);
4d476f
 	}
4d476f
 #endif
4d476f
-	if (ldap)
4d476f
-		return ldap;
4d476f
+	if (rv == NSS_STATUS_SUCCESS)
4d476f
+		return rv;
4d476f
 
4d476f
 	/* Failed to connect, try to find a new server */
4d476f
 
4d476f
@@ -1031,11 +1033,16 @@ find_server:
4d476f
 #endif
4d476f
 
4d476f
 	/* Current server failed, try the rest or dc connection */
4d476f
-	ret = find_server(logopt, &ldap, ctxt);
4d476f
-	if (ret != NSS_STATUS_SUCCESS)
4d476f
+	ret = find_server(logopt, ldap, ctxt);
4d476f
+	if (ret != NSS_STATUS_SUCCESS) {
4d476f
+		if (ret == NSS_STATUS_NOTFOUND ||
4d476f
+		    dcrv == NSS_STATUS_NOTFOUND ||
4d476f
+		    rv == NSS_STATUS_NOTFOUND)
4d476f
+			ret = NSS_STATUS_NOTFOUND;
4d476f
 		error(logopt, MODPREFIX "failed to find available server");
4d476f
+	}
4d476f
 
4d476f
-	return ldap;
4d476f
+	return ret;
4d476f
 }
4d476f
 
4d476f
 int get_property(unsigned logopt, xmlNodePtr node, const char *prop, char **value)
4d476f
@@ -1841,12 +1848,12 @@ int lookup_read_master(struct master *ma
4d476f
 	char **values = NULL;
4d476f
 	char *attrs[3];
4d476f
 	int scope = LDAP_SCOPE_SUBTREE;
4d476f
-	LDAP *ldap;
4d476f
+	LDAP *ldap = NULL;
4d476f
 
4d476f
 	/* Initialize the LDAP context. */
4d476f
-	ldap = do_reconnect(logopt, ctxt);
4d476f
-	if (!ldap)
4d476f
-		return NSS_STATUS_UNAVAIL;
4d476f
+	rv = do_reconnect(logopt, &ldap, ctxt);
4d476f
+	if (rv)
4d476f
+		return rv;
4d476f
 
4d476f
 	class = ctxt->schema->entry_class;
4d476f
 	entry = ctxt->schema->entry_attr;
4d476f
@@ -2754,9 +2761,10 @@ static int read_one_map(struct autofs_po
4d476f
 	sp.age = age;
4d476f
 
4d476f
 	/* Initialize the LDAP context. */
4d476f
-	sp.ldap = do_reconnect(ap->logopt, ctxt);
4d476f
-	if (!sp.ldap)
4d476f
-		return NSS_STATUS_UNAVAIL;
4d476f
+	sp.ldap = NULL;
4d476f
+	rv = do_reconnect(ap->logopt, &sp.ldap, ctxt);
4d476f
+	if (rv)
4d476f
+		return rv;
4d476f
 
4d476f
 	class = ctxt->schema->entry_class;
4d476f
 	entry = ctxt->schema->entry_attr;
4d476f
@@ -2908,7 +2916,7 @@ static int lookup_one(struct autofs_poin
4d476f
 	struct berval **bvValues;
4d476f
 	char *attrs[3];
4d476f
 	int scope = LDAP_SCOPE_SUBTREE;
4d476f
-	LDAP *ldap;
4d476f
+	LDAP *ldap = NULL;
4d476f
 	struct mapent *we;
4d476f
 	unsigned int wild = 0;
4d476f
 	int ret = CHE_MISSING;
4d476f
@@ -2921,9 +2929,11 @@ static int lookup_one(struct autofs_poin
4d476f
 	}
4d476f
 
4d476f
 	/* Initialize the LDAP context. */
4d476f
-	ldap = do_reconnect(ap->logopt, ctxt);
4d476f
-	if (!ldap)
4d476f
+	rv = do_reconnect(ap->logopt, &ldap, ctxt);
4d476f
+	if (rv == NSS_STATUS_UNAVAIL)
4d476f
 		return CHE_UNAVAIL;
4d476f
+	if (rv == NSS_STATUS_NOTFOUND)
4d476f
+		return ret;
4d476f
 
4d476f
 	class = ctxt->schema->entry_class;
4d476f
 	entry = ctxt->schema->entry_attr;
4d476f
@@ -3252,7 +3262,7 @@ static int lookup_one_amd(struct autofs_
4d476f
 			  struct lookup_context *ctxt)
4d476f
 {
4d476f
 	struct mapent_cache *mc = source->mc;
4d476f
-	LDAP *ldap;
4d476f
+	LDAP *ldap = NULL;
4d476f
 	LDAPMessage *result = NULL, *e;
4d476f
 	char *query;
4d476f
 	int scope = LDAP_SCOPE_SUBTREE;
4d476f
@@ -3271,9 +3281,11 @@ static int lookup_one_amd(struct autofs_
4d476f
 	}
4d476f
 
4d476f
 	/* Initialize the LDAP context. */
4d476f
-	ldap = do_reconnect(ap->logopt, ctxt);
4d476f
-	if (!ldap)
4d476f
+	rv = do_reconnect(ap->logopt, &ldap, ctxt);
4d476f
+	if (rv == NSS_STATUS_UNAVAIL)
4d476f
 		return CHE_UNAVAIL;
4d476f
+	if (rv == NSS_STATUS_NOTFOUND)
4d476f
+		return ret;
4d476f
 
4d476f
 	map = ctxt->schema->map_attr;
4d476f
 	class = ctxt->schema->entry_class;