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

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