autofs-5.0.6 - dont retry ldap connect if not required

From: Ian Kent <ikent@redhat.com>

When using LDAP and the server is not available autofs retries the
connection when  it fails in case the SASL credentail has expired.
But this is done even when not using SASL, so change it check if
SASL authentication is required.
---

 CHANGELOG             |    1 +
 include/lookup_ldap.h |    1 +
 modules/lookup_ldap.c |    6 +++---
 3 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index 9589139..aa2b55b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -49,6 +49,7 @@
 - update ->timeout() function to not return timeout.
 - move timeout to map_source (allow per direct map timeout).
 - fix kernel verion check of version components.
+- dont retry ldap connect if not required.
 
 28/06/2011 autofs-5.0.6
 -----------------------
diff --git a/include/lookup_ldap.h b/include/lookup_ldap.h
index d34c9b8..e441a61 100644
--- a/include/lookup_ldap.h
+++ b/include/lookup_ldap.h
@@ -104,6 +104,7 @@ struct lookup_context {
 #define LDAP_AUTH_NOTREQUIRED	0x0001
 #define LDAP_AUTH_REQUIRED	0x0002
 #define LDAP_AUTH_AUTODETECT	0x0004
+#define LDAP_NEED_AUTH		(LDAP_AUTH_REQUIRED|LDAP_AUTH_AUTODETECT)
 #endif
 
 #define LDAP_AUTH_USESIMPLE	0x0008
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
index 041120f..3bc4dc5 100644
--- a/modules/lookup_ldap.c
+++ b/modules/lookup_ldap.c
@@ -511,7 +511,7 @@ static int do_bind(unsigned logopt, LDAP *ldap, const char *uri, struct lookup_c
 	debug(logopt, MODPREFIX "auth_required: %d, sasl_mech %s",
 	      ctxt->auth_required, ctxt->sasl_mech);
 
-	if (ctxt->auth_required & (LDAP_AUTH_REQUIRED|LDAP_AUTH_AUTODETECT)) {
+	if (ctxt->auth_required & LDAP_NEED_AUTH) {
 		rv = autofs_sasl_bind(logopt, ldap, ctxt);
 		debug(logopt, MODPREFIX "autofs_sasl_bind returned %d", rv);
 	} else {
@@ -731,7 +731,7 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
 		ldap = do_connect(logopt, ctxt->server, ctxt);
 #ifdef WITH_SASL
 		/* Dispose of the sasl authentication connection and try again. */
-		if (!ldap) {
+		if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
 			autofs_sasl_dispose(ctxt);
 			ldap = connect_to_server(logopt, ctxt->server, ctxt);
 		}
@@ -767,7 +767,7 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
 	 * Dispose of the sasl authentication connection and try the
 	 * current server again before trying other servers in the list.
 	 */
-	if (!ldap) {
+	if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
 		autofs_sasl_dispose(ctxt);
 		ldap = connect_to_server(logopt, ctxt->uri->uri, ctxt);
 	}