Blame SOURCES/autofs-5.1.4-fix-update_negative_cache-map-source-usage.patch

135b98
autofs-5.1.4 - fix update_negative_cache() map source usage
135b98
135b98
From: Ian Kent <raven@themaw.net>
135b98
135b98
File map sources can be either plain text or executable.
135b98
135b98
When the map path is specified without a type (eg. when a
135b98
full path is used) an instance map source is used and the
135b98
original map is left unchanged.
135b98
135b98
But update_negative_cache() fails to take this into account
135b98
causing it to update the wrong map cache.
135b98
135b98
When a map reload is done the map entry appears to not exist
135b98
so the new map entry is added.
135b98
135b98
This could go unnoticed except that, after a map read, the
135b98
map entry cache cleans stale map entries and the existence
135b98
of this negative entry causes the new map entry to be deleted
135b98
and map lookups continue to fail.
135b98
135b98
In hindsite the use of an instance map source for this is
135b98
probably uneccessary but changing it will be risky so, for
135b98
now, just make update_negative_cache() use the correct map.
135b98
135b98
Signed-off-by: Ian Kent <raven@themaw.net>
135b98
---
135b98
 CHANGELOG       |    1 +
135b98
 daemon/lookup.c |   38 ++++++++++++++++++++++++++++++++++++--
135b98
 2 files changed, 37 insertions(+), 2 deletions(-)
135b98
135b98
--- autofs-5.1.4.orig/CHANGELOG
135b98
+++ autofs-5.1.4/CHANGELOG
135b98
@@ -28,6 +28,7 @@ xx/xx/2018 autofs-5.1.5
135b98
 - add-man page note about extra slashes in paths.
135b98
 - covarity fixes.
135b98
 - fix program usage message.
135b98
+- fix update_negative_cache() map source usage.
135b98
 
135b98
 19/12/2017 autofs-5.1.4
135b98
 - fix spec file url.
135b98
--- autofs-5.1.4.orig/daemon/lookup.c
135b98
+++ autofs-5.1.4/daemon/lookup.c
135b98
@@ -1100,6 +1100,37 @@ static enum nsswitch_status lookup_map_n
135b98
 	return result;
135b98
 }
135b98
 
135b98
+static struct map_source *lookup_get_map_source(struct master_mapent *entry)
135b98
+{
135b98
+	struct map_source *map = entry->maps;
135b98
+	struct stat st;
135b98
+	char *type;
135b98
+
135b98
+	if (map->type || *map->argv[0] != '/')
135b98
+		return map;
135b98
+
135b98
+	if (*(map->argv[0] + 1) == '/')
135b98
+		return map;
135b98
+
135b98
+	if (stat(map->argv[0], &st) == -1)
135b98
+		return NULL;
135b98
+
135b98
+	if (!S_ISREG(st.st_mode))
135b98
+		return NULL;
135b98
+
135b98
+	if (st.st_mode & __S_IEXEC)
135b98
+		type = "program";
135b98
+	else
135b98
+		type = "file";
135b98
+
135b98
+	/* This is a file source with a path starting with "/".
135b98
+	 * But file maps can be either plain text or executable
135b98
+	 * so they use a map instance and the actual map source
135b98
+	 * remains untouched.
135b98
+	 */
135b98
+	return master_find_source_instance(map, type, map->format, 0, NULL);
135b98
+}
135b98
+
135b98
 static void update_negative_cache(struct autofs_point *ap, struct map_source *source, const char *name)
135b98
 {
135b98
 	struct master_mapent *entry = ap->entry;
135b98
@@ -1133,11 +1164,14 @@ static void update_negative_cache(struct
135b98
 			logmsg("key \"%s\" not found in map source(s).", name);
135b98
 		}
135b98
 
135b98
-		/* Doesn't exist in any source, just add it somewhere */
135b98
+		/* Doesn't exist in any source, just add it somewhere.
135b98
+		 * Also take care to use the same map source used by
135b98
+		 * map reads and key lookups for the update.
135b98
+		 */
135b98
 		if (source)
135b98
 			map = source;
135b98
 		else
135b98
-			map = entry->maps;
135b98
+			map = lookup_get_map_source(entry);
135b98
 		if (map) {
135b98
 			time_t now = monotonic_time(NULL);
135b98
 			int rv = CHE_FAIL;