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

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