autofs-5.0.5 - fix map source check in file lookup

From: Ian Kent <ikent@redhat.com>

With the changes to reduce the scanning of file maps and fixes for
other issues, such as too frequent map reads the key searching has
become broken.

For an automount that has a key present in a file map and the same
key also present in another map source, if the file map entry is
removed and a lookup is performed before a re-load is issued the
map lookup fails. To fix this we need to check the map source, for
indirect maps (since plus included direct maps are handled a little
dirrefently), and continue looking if it doesn't match.
---

 CHANGELOG             |    1 +
 modules/lookup_file.c |   14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index 8f38cd1..66392bf 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -74,6 +74,7 @@
 - remove master_mutex_unlock() leftover.
 - fix sanity checks for brackets in server name.
 - fix lsb service name in init script.
+- fix map source check in file lookup.
 
 03/09/2009 autofs-5.0.5
 -----------------------
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
index b207947..8ead07c 100644
--- a/modules/lookup_file.c
+++ b/modules/lookup_file.c
@@ -554,13 +554,14 @@ prepare_plus_include(struct autofs_point *ap, time_t age, char *key, unsigned in
 	source = master_find_source_instance(current,
 					     info->type, info->format,
 					     argc, argv);
-	if (source)
+	if (source) {
 		/*
 		 * Make sure included map age is in sync with its owner
 		 * or we could incorrectly wipe out its entries.
 		 */
 		source->age = age;
-	else {
+		source->stale = 1;
+	} else {
 		source = master_add_source_instance(current,
 						    info->type, info->format,
 						    age, argc, argv);
@@ -1039,8 +1040,13 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 	cache_readlock(mc);
 do_cache_lookup:
 	me = cache_lookup(mc, key);
-	/* Stale mapent => check for entry in alternate source or wildcard */
-	if (me && !me->mapent) {
+	/*
+	 * Stale mapent => check for entry in alternate source or wildcard.
+	 * Note, plus included direct mount map entries are included as an
+	 * instance (same map entry cache), not in a distinct source.
+	 */
+	if (me && (!me->mapent || 
+	   (ap->type == LKP_INDIRECT && me->source != source))) {
 		while ((me = cache_lookup_key_next(me)))
 			if (me->source == source)
 				break;