Ian Kent 80cd8f
autofs-5.0.5 - dont connect at ldap lookup module init
Ian Kent 80cd8f
Ian Kent 80cd8f
From: Ian Kent <raven@themaw.net>
Ian Kent 80cd8f
Ian Kent 80cd8f
When using LDAP as a map source and no server is available at
Ian Kent 80cd8f
startup autofs will fiail to mount autofs mounts because it
Ian Kent 80cd8f
cannot read the mount maps.
Ian Kent 80cd8f
Ian Kent 80cd8f
For the case were the master map is available (for example as
Ian Kent 80cd8f
a file map) indirect autofs mounts should still be able to
Ian Kent 80cd8f
continue but the LDAP lookup module unnecessarily tryes to
Ian Kent 80cd8f
connect a an LDAP server and returns a fail if it can't
Ian Kent 80cd8f
connect causing the autofs mount to not complete.
Ian Kent 80cd8f
Ian Kent 80cd8f
If no server is available to obtain the mount information and
Ian Kent 80cd8f
an entry for a requested mount has not been seen before then
Ian Kent 80cd8f
mount requests will fail. But, if an entry has previously been
Ian Kent 80cd8f
seen autofs will use that while the server is unavailable.
Ian Kent 80cd8f
Ian Kent 80cd8f
If an autofs indirect mount uses the browse option and no
Ian Kent 80cd8f
server is available at startup the map cannot be read so no
Ian Kent 80cd8f
mount point directories will be created (and the mount will
Ian Kent 80cd8f
behave as though the browse option was not present). A HUP
Ian Kent 80cd8f
signal can be issued to make autofs read the map and create
Ian Kent 80cd8f
the map mount point directores. Or the next access to a mount
Ian Kent 80cd8f
point that isn't already in the cache but in the map on the
Ian Kent 80cd8f
server will trigger a map re-read.
Ian Kent 80cd8f
---
Ian Kent 80cd8f
Ian Kent 80cd8f
 CHANGELOG             |    1 
Ian Kent 80cd8f
 daemon/lookup.c       |    7 ++++-
Ian Kent 80cd8f
 modules/lookup_ldap.c |   61 +++++++++++++++++---------------------------------
Ian Kent 80cd8f
 3 files changed, 28 insertions(+), 41 deletions(-)
Ian Kent 80cd8f
Ian Kent 80cd8f
Ian Kent 80cd8f
--- autofs-5.0.5.orig/CHANGELOG
Ian Kent 80cd8f
+++ autofs-5.0.5/CHANGELOG
Ian Kent 80cd8f
@@ -17,6 +17,7 @@
Ian Kent 80cd8f
 - dont fail mount on access fail.
Ian Kent 80cd8f
 - fix rpc fail on large export list.
Ian Kent 80cd8f
 - fix memory leak on reload.
Ian Kent 80cd8f
+- dont connect at ldap lookup module init.
Ian Kent 80cd8f
 
Ian Kent 80cd8f
 03/09/2009 autofs-5.0.5
Ian Kent 80cd8f
 -----------------------
Ian Kent 80cd8f
--- autofs-5.0.5.orig/daemon/lookup.c
Ian Kent 80cd8f
+++ autofs-5.0.5/daemon/lookup.c
Ian Kent 80cd8f
@@ -292,8 +292,13 @@ static int do_read_map(struct autofs_poi
Ian Kent 80cd8f
 	 * For maps that don't support enumeration return success
Ian Kent 80cd8f
 	 * and do whatever we must to have autofs function with an
Ian Kent 80cd8f
 	 * empty map entry cache.
Ian Kent 80cd8f
+	 *
Ian Kent 80cd8f
+	 * For indirect maps that use the browse option, when the
Ian Kent 80cd8f
+	 * server is unavailable continue as best we can with
Ian Kent 80cd8f
+	 * whatever we have in the cache, if anything.
Ian Kent 80cd8f
 	 */
Ian Kent 80cd8f
-	if (status == NSS_STATUS_UNKNOWN)
Ian Kent 80cd8f
+	if (status == NSS_STATUS_UNKNOWN ||
Ian Kent 80cd8f
+	   (ap->type == LKP_INDIRECT && status == NSS_STATUS_UNAVAIL))
Ian Kent 80cd8f
 		return NSS_STATUS_SUCCESS;
Ian Kent 80cd8f
 
Ian Kent 80cd8f
 	return status;
Ian Kent 80cd8f
--- autofs-5.0.5.orig/modules/lookup_ldap.c
Ian Kent 80cd8f
+++ autofs-5.0.5/modules/lookup_ldap.c
Ian Kent 80cd8f
@@ -724,8 +724,12 @@ static LDAP *do_reconnect(unsigned logop
Ian Kent 80cd8f
 	uris_mutex_lock(ctxt);
Ian Kent 80cd8f
 	if (ctxt->dclist)
Ian Kent 80cd8f
 		uri = strdup(ctxt->dclist->uri);
Ian Kent 80cd8f
-	else
Ian Kent 80cd8f
+	else if (ctxt->uri)
Ian Kent 80cd8f
 		uri = strdup(ctxt->uri->uri);
Ian Kent 80cd8f
+	else {
Ian Kent 80cd8f
+		uris_mutex_unlock(ctxt);
Ian Kent 80cd8f
+		goto find_server;
Ian Kent 80cd8f
+	}
Ian Kent 80cd8f
 	uris_mutex_unlock(ctxt);
Ian Kent 80cd8f
 
Ian Kent 80cd8f
 	if (!uri) {
Ian Kent 80cd8f
@@ -757,6 +761,7 @@ static LDAP *do_reconnect(unsigned logop
Ian Kent 80cd8f
 	autofs_sasl_dispose(ctxt);
Ian Kent 80cd8f
 #endif
Ian Kent 80cd8f
 
Ian Kent 80cd8f
+find_server:
Ian Kent 80cd8f
 	/* Current server failed connect, try the rest */
Ian Kent 80cd8f
 	ldap = find_server(logopt, ctxt);
Ian Kent 80cd8f
 	if (!ldap)
Ian Kent 80cd8f
@@ -1342,7 +1347,6 @@ int lookup_init(const char *mapfmt, int 
Ian Kent 80cd8f
 {
Ian Kent 80cd8f
 	struct lookup_context *ctxt;
Ian Kent 80cd8f
 	char buf[MAX_ERR_BUF];
Ian Kent 80cd8f
-	LDAP *ldap = NULL;
Ian Kent 80cd8f
 	int ret;
Ian Kent 80cd8f
 
Ian Kent 80cd8f
 	*context = NULL;
Ian Kent 80cd8f
@@ -1416,23 +1420,6 @@ int lookup_init(const char *mapfmt, int 
Ian Kent 80cd8f
 	}
Ian Kent 80cd8f
 #endif
Ian Kent 80cd8f
 
Ian Kent 80cd8f
-	if (ctxt->server || !ctxt->uris) {
Ian Kent 80cd8f
-		ldap = connect_to_server(LOGOPT_NONE, ctxt->server, ctxt);
Ian Kent 80cd8f
-		if (!ldap) {
Ian Kent 80cd8f
-			free_context(ctxt);
Ian Kent 80cd8f
-			return 1;
Ian Kent 80cd8f
-		}
Ian Kent 80cd8f
-	} else {
Ian Kent 80cd8f
-		ldap = find_server(LOGOPT_NONE, ctxt);
Ian Kent 80cd8f
-		if (!ldap) {
Ian Kent 80cd8f
-			free_context(ctxt);
Ian Kent 80cd8f
-			error(LOGOPT_ANY, MODPREFIX
Ian Kent 80cd8f
-			     "failed to find available server");
Ian Kent 80cd8f
-			return 1;
Ian Kent 80cd8f
-		}
Ian Kent 80cd8f
-	}
Ian Kent 80cd8f
-	unbind_ldap_connection(LOGOPT_ANY, ldap, ctxt);
Ian Kent 80cd8f
-
Ian Kent 80cd8f
 	/* Open the parser, if we can. */
Ian Kent 80cd8f
 	ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
Ian Kent 80cd8f
 	if (!ctxt->parse) {
Ian Kent 80cd8f
@@ -1463,6 +1450,11 @@ int lookup_read_master(struct master *ma
Ian Kent 80cd8f
 	int scope = LDAP_SCOPE_SUBTREE;
Ian Kent 80cd8f
 	LDAP *ldap;
Ian Kent 80cd8f
 
Ian Kent 80cd8f
+	/* Initialize the LDAP context. */
Ian Kent 80cd8f
+	ldap = do_reconnect(logopt, ctxt);
Ian Kent 80cd8f
+	if (!ldap)
Ian Kent 80cd8f
+		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
+
Ian Kent 80cd8f
 	class = ctxt->schema->entry_class;
Ian Kent 80cd8f
 	entry = ctxt->schema->entry_attr;
Ian Kent 80cd8f
 	info = ctxt->schema->value_attr;
Ian Kent 80cd8f
@@ -1486,13 +1478,6 @@ int lookup_read_master(struct master *ma
Ian Kent 80cd8f
 		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
 	}
Ian Kent 80cd8f
 
Ian Kent 80cd8f
-	/* Initialize the LDAP context. */
Ian Kent 80cd8f
-	ldap = do_reconnect(logopt, ctxt);
Ian Kent 80cd8f
-	if (!ldap) {
Ian Kent 80cd8f
-		free(query);
Ian Kent 80cd8f
-		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
-	}
Ian Kent 80cd8f
-
Ian Kent 80cd8f
 	/* Look around. */
Ian Kent 80cd8f
 	debug(logopt,
Ian Kent 80cd8f
 	      MODPREFIX "searching for \"%s\" under \"%s\"", query, ctxt->qdn);
Ian Kent 80cd8f
@@ -2264,6 +2249,11 @@ static int read_one_map(struct autofs_po
Ian Kent 80cd8f
 	sp.ap = ap;
Ian Kent 80cd8f
 	sp.age = age;
Ian Kent 80cd8f
 
Ian Kent 80cd8f
+	/* Initialize the LDAP context. */
Ian Kent 80cd8f
+	sp.ldap = do_reconnect(ap->logopt, ctxt);
Ian Kent 80cd8f
+	if (!sp.ldap)
Ian Kent 80cd8f
+		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
+
Ian Kent 80cd8f
 	class = ctxt->schema->entry_class;
Ian Kent 80cd8f
 	entry = ctxt->schema->entry_attr;
Ian Kent 80cd8f
 	info = ctxt->schema->value_attr;
Ian Kent 80cd8f
@@ -2289,13 +2279,6 @@ static int read_one_map(struct autofs_po
Ian Kent 80cd8f
 		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
 	}
Ian Kent 80cd8f
 
Ian Kent 80cd8f
-	/* Initialize the LDAP context. */
Ian Kent 80cd8f
-	sp.ldap = do_reconnect(ap->logopt, ctxt);
Ian Kent 80cd8f
-	if (!sp.ldap) {
Ian Kent 80cd8f
-		free(sp.query);
Ian Kent 80cd8f
-		return NSS_STATUS_UNAVAIL;
Ian Kent 80cd8f
-	}
Ian Kent 80cd8f
-
Ian Kent 80cd8f
 	/* Look around. */
Ian Kent 80cd8f
 	debug(ap->logopt,
Ian Kent 80cd8f
 	      MODPREFIX "searching for \"%s\" under \"%s\"", sp.query, ctxt->qdn);
Ian Kent 80cd8f
@@ -2401,6 +2384,11 @@ static int lookup_one(struct autofs_poin
Ian Kent 80cd8f
 		return CHE_FAIL;
Ian Kent 80cd8f
 	}
Ian Kent 80cd8f
 
Ian Kent 80cd8f
+	/* Initialize the LDAP context. */
Ian Kent 80cd8f
+	ldap = do_reconnect(ap->logopt, ctxt);
Ian Kent 80cd8f
+	if (!ldap)
Ian Kent 80cd8f
+		return CHE_UNAVAIL;
Ian Kent 80cd8f
+
Ian Kent 80cd8f
 	class = ctxt->schema->entry_class;
Ian Kent 80cd8f
 	entry = ctxt->schema->entry_attr;
Ian Kent 80cd8f
 	info = ctxt->schema->value_attr;
Ian Kent 80cd8f
@@ -2479,13 +2467,6 @@ static int lookup_one(struct autofs_poin
Ian Kent 80cd8f
 		return CHE_FAIL;
Ian Kent 80cd8f
 	}
Ian Kent 80cd8f
 
Ian Kent 80cd8f
-	/* Initialize the LDAP context. */
Ian Kent 80cd8f
-	ldap = do_reconnect(ap->logopt, ctxt);
Ian Kent 80cd8f
-	if (!ldap) {
Ian Kent 80cd8f
-		free(query);
Ian Kent 80cd8f
-		return CHE_UNAVAIL;
Ian Kent 80cd8f
-	}
Ian Kent 80cd8f
-
Ian Kent 80cd8f
 	debug(ap->logopt,
Ian Kent 80cd8f
 	      MODPREFIX "searching for \"%s\" under \"%s\"", query, ctxt->qdn);
Ian Kent 80cd8f