Blame SOURCES/autofs-5.1.1-make-do_connect-return-a-status.patch

306fa1
autofs-5.1.1 - make do_connect() return a status
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
The next step in the update of do_reconnect() is to make do_connect()
306fa1
return a status instead of an LDAP handle and pass back the LDAP handle
306fa1
via a function parameter.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG             |    1 
306fa1
 modules/lookup_ldap.c |   60 ++++++++++++++++++++++++++++++--------------------
306fa1
 2 files changed, 38 insertions(+), 23 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -173,6 +173,7 @@
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
+- make do_connect() return a status.
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
@@ -631,10 +631,14 @@ static int do_bind(unsigned logopt, LDAP
306fa1
 	return 1;
306fa1
 }
306fa1
 
306fa1
-static LDAP *do_connect(unsigned logopt, const char *uri, struct lookup_context *ctxt)
306fa1
+static int do_connect(unsigned logopt, LDAP **ldap,
306fa1
+		      const char *uri, struct lookup_context *ctxt)
306fa1
 {
306fa1
 	char *cur_host = NULL;
306fa1
-	LDAP *ldap;
306fa1
+	LDAP *handle;
306fa1
+	int ret = NSS_STATUS_SUCCESS;
306fa1
+
306fa1
+	*ldap = NULL;
306fa1
 
306fa1
 #ifdef WITH_SASL
306fa1
 	if (ctxt->extern_cert && ctxt->extern_key) {
306fa1
@@ -643,18 +647,20 @@ static LDAP *do_connect(unsigned logopt,
306fa1
 	}
306fa1
 #endif
306fa1
 
306fa1
-	ldap = init_ldap_connection(logopt, uri, ctxt);
306fa1
-	if (!ldap)
306fa1
+	handle = init_ldap_connection(logopt, uri, ctxt);
306fa1
+	if (!handle) {
306fa1
+		ret = NSS_STATUS_UNAVAIL;
306fa1
 		goto out;
306fa1
+	}
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
+	if (!do_bind(logopt, handle, uri, ctxt)) {
306fa1
+		unbind_ldap_connection(logopt, handle, ctxt);
306fa1
+		ret = NSS_STATUS_UNAVAIL;
306fa1
 		goto out;
306fa1
 	}
306fa1
 
306fa1
@@ -664,7 +670,8 @@ static LDAP *do_connect(unsigned logopt,
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
+		*ldap = handle;
306fa1
+		goto out;
306fa1
 	}
306fa1
 	uris_mutex_unlock(ctxt);
306fa1
 
306fa1
@@ -674,9 +681,9 @@ static LDAP *do_connect(unsigned logopt,
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
+		if (!find_query_dn(logopt, handle, ctxt)) {
306fa1
+			unbind_ldap_connection(logopt, handle, ctxt);
306fa1
+			ret = NSS_STATUS_NOTFOUND;
306fa1
 			warn(logopt,
306fa1
 			      MODPREFIX "failed to find valid query dn");
306fa1
 			goto out;
306fa1
@@ -684,14 +691,17 @@ static LDAP *do_connect(unsigned logopt,
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
+		if (!get_query_dn(logopt, handle, ctxt, class, key)) {
306fa1
+			unbind_ldap_connection(logopt, handle, ctxt);
306fa1
+			ret = NSS_STATUS_NOTFOUND;
306fa1
 			error(logopt, MODPREFIX "failed to get query dn");
306fa1
+			goto out;
306fa1
 		}
306fa1
 	}
306fa1
+
306fa1
+	*ldap = handle;
306fa1
 out:
306fa1
-	return ldap;
306fa1
+	return ret;
306fa1
 }
306fa1
 
306fa1
 static unsigned long get_amd_timestamp(struct lookup_context *ctxt)
306fa1
@@ -706,8 +716,8 @@ static unsigned long get_amd_timestamp(s
306fa1
 	unsigned long timestamp = 0;
306fa1
 	int rv, l, ql;
306fa1
 
306fa1
-	ldap = do_connect(LOGOPT_ANY, ctxt->server, ctxt);
306fa1
-	if (!ldap)
306fa1
+	rv = do_connect(LOGOPT_ANY, &ldap, ctxt->server, ctxt);
306fa1
+	if (rv != NSS_STATUS_SUCCESS)
306fa1
 		return 0;
306fa1
 
306fa1
 	map = amd_timestamp.map_attr;
306fa1
@@ -817,9 +827,10 @@ next:
306fa1
 static LDAP *connect_to_server(unsigned logopt, const char *uri, struct lookup_context *ctxt)
306fa1
 {
306fa1
 	LDAP *ldap;
306fa1
+	int ret;
306fa1
 
306fa1
-	ldap = do_connect(logopt, uri, ctxt);
306fa1
-	if (!ldap) {
306fa1
+	ret = do_connect(logopt, &ldap, uri, ctxt);
306fa1
+	if (ret != NSS_STATUS_SUCCESS) {
306fa1
 		warn(logopt,
306fa1
 		     MODPREFIX "couldn't connect to server %s",
306fa1
 		     uri ? uri : "default");
306fa1
@@ -940,12 +951,14 @@ static LDAP *find_server(unsigned logopt
306fa1
 static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
306fa1
 {
306fa1
 	LDAP *ldap = NULL;
306fa1
+	int ret;
306fa1
 
306fa1
 	if (ctxt->server || !ctxt->uris) {
306fa1
-		ldap = do_connect(logopt, ctxt->server, ctxt);
306fa1
+		ret = do_connect(logopt, &ldap, ctxt->server, ctxt);
306fa1
 #ifdef WITH_SASL
306fa1
 		/* Dispose of the sasl authentication connection and try again. */
306fa1
-		if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
306fa1
+		if (ret != NSS_STATUS_SUCCESS &&
306fa1
+		    ctxt->auth_required & LDAP_NEED_AUTH) {
306fa1
 			ldapinit_mutex_lock();
306fa1
 			autofs_sasl_dispose(ctxt);
306fa1
 			ldapinit_mutex_unlock();
306fa1
@@ -977,13 +990,14 @@ static LDAP *do_reconnect(unsigned logop
306fa1
 	if (!ctxt->uri)
306fa1
 		goto find_server;
306fa1
 
306fa1
-	ldap = do_connect(logopt, ctxt->uri->uri, ctxt);
306fa1
+	ret = do_connect(logopt, &ldap, ctxt->uri->uri, ctxt);
306fa1
 #ifdef WITH_SASL
306fa1
 	/*
306fa1
 	 * Dispose of the sasl authentication connection and try the
306fa1
 	 * current server again before trying other servers in the list.
306fa1
 	 */
306fa1
-	if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
306fa1
+	if (ret != NSS_STATUS_SUCCESS &&
306fa1
+	    ctxt->auth_required & LDAP_NEED_AUTH) {
306fa1
 		ldapinit_mutex_lock();
306fa1
 		autofs_sasl_dispose(ctxt);
306fa1
 		ldapinit_mutex_unlock();