Blame SOURCES/autofs-5.0.7-allow-use-of-hosts-map-in-maps.patch

4d476f
autofs-5.0.7 - allow use of hosts map in maps
4d476f
4d476f
From: Ian Kent <raven@themaw.net>
4d476f
4d476f
At the moment the internal hosts map can only be use as an entry in the
4d476f
master map but there's no reason (I can think of so far) that it shouldn't
4d476f
be possible to use it in map entries.
4d476f
---
4d476f
 lib/parse_subs.c       |   17 ++++++-----
4d476f
 modules/mount_autofs.c |   29 ++++++++++++++++----
4d476f
 modules/parse_sun.c    |   71 +++++++++++++++++++++++++++++++------------------
4d476f
 3 files changed, 80 insertions(+), 37 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/lib/parse_subs.c
4d476f
+++ autofs-5.0.7/lib/parse_subs.c
4d476f
@@ -35,6 +35,7 @@ static struct types map_type[] = {
4d476f
 	{ "ldaps", 5 },
4d476f
 	{ "hesiod", 6 },
4d476f
 	{ "userdir", 7 },
4d476f
+	{ "hosts", 5 },
4d476f
 };
4d476f
 static unsigned int map_type_count = sizeof(map_type)/sizeof(struct types);
4d476f
 
4d476f
@@ -384,7 +385,7 @@ struct map_type_info *parse_map_type_inf
4d476f
 					return NULL;
4d476f
 				} else {
4d476f
 					*pos++ = '\0';
4d476f
-					while (*pos == ' ')
4d476f
+					while (*pos && *pos == ' ')
4d476f
 						*pos++ = '\0';
4d476f
 					map = pos;
4d476f
 					break;
4d476f
@@ -412,7 +413,7 @@ struct map_type_info *parse_map_type_inf
4d476f
 							return NULL;
4d476f
 						} else {
4d476f
 							*pos++ = '\0';
4d476f
-							while (*pos == ' ')
4d476f
+							while (*pos && *pos == ' ')
4d476f
 								*pos++ = '\0';
4d476f
 							map = pos;
4d476f
 							break;
4d476f
@@ -458,11 +459,13 @@ struct map_type_info *parse_map_type_inf
4d476f
 		}
4d476f
 	}
4d476f
 
4d476f
-	info->map = strdup(map);
4d476f
-	if (!info->map) {
4d476f
-		free(buf);
4d476f
-		free_map_type_info(info);
4d476f
-		return NULL;
4d476f
+	if (map) {
4d476f
+		info->map = strdup(map);
4d476f
+		if (!info->map) {
4d476f
+			free(buf);
4d476f
+			free_map_type_info(info);
4d476f
+			return NULL;
4d476f
+		}
4d476f
 	}
4d476f
 
4d476f
 	free(buf);
4d476f
--- autofs-5.0.7.orig/modules/mount_autofs.c
4d476f
+++ autofs-5.0.7/modules/mount_autofs.c
4d476f
@@ -62,6 +62,7 @@ int mount_mount(struct autofs_point *ap,
4d476f
 	char buf[MAX_ERR_BUF];
4d476f
 	char *options, *p;
4d476f
 	int len, ret;
4d476f
+	int hosts = 0;
4d476f
 
4d476f
 	/* Root offset of multi-mount */
4d476f
 	len = strlen(root);
4d476f
@@ -123,6 +124,8 @@ int mount_mount(struct autofs_point *ap,
4d476f
 				ghost = 1;
4d476f
 			else if (strncmp(cp, "symlink", 7) == 0)
4d476f
 				symlnk = 1;
4d476f
+			else if (strncmp(cp, "hosts", 5) == 0)
4d476f
+				hosts = 1;
4d476f
 			else if (strncmp(cp, "timeout=", 8) == 0) {
4d476f
 				char *val = strchr(cp, '=');
4d476f
 				unsigned tout;
4d476f
@@ -164,7 +167,10 @@ int mount_mount(struct autofs_point *ap,
4d476f
 	if (symlnk)
4d476f
 		nap->flags |= MOUNT_FLAG_SYMLINK;
4d476f
 
4d476f
-	argc = 1;
4d476f
+	if (hosts)
4d476f
+		argc = 0;
4d476f
+	else
4d476f
+		argc = 1;
4d476f
 
4d476f
 	if (options) {
4d476f
 		char *t = options;
4d476f
@@ -176,14 +182,27 @@ int mount_mount(struct autofs_point *ap,
4d476f
 	}
4d476f
 	argv = (const char **) alloca((argc + 1) * sizeof(char *));
4d476f
 
4d476f
-	argc = 1;
4d476f
-
4d476f
-	if (!(info = parse_map_type_info(what))) {
4d476f
+	if (hosts)
4d476f
+		argc = 0;
4d476f
+	else
4d476f
+		argc = 1;
4d476f
+
4d476f
+	/*
4d476f
+	 * If a mount of a hosts map is being requested it will come
4d476f
+	 * ro us via the options. Catch that below when processing the
4d476f
+	 * option and create type info struct then.
4d476f
+	 */
4d476f
+	if (hosts)
4d476f
+		info = parse_map_type_info("hosts:");
4d476f
+	else
4d476f
+		info = parse_map_type_info(what);
4d476f
+	if (!info) {
4d476f
 		error(ap->logopt, MODPREFIX "failed to parse map info");
4d476f
 		master_free_mapent(entry);
4d476f
 		return 1;
4d476f
 	}
4d476f
-	argv[0] = info->map;
4d476f
+	if (info->map)
4d476f
+		argv[0] = info->map;
4d476f
 
4d476f
 	if (options) {
4d476f
 		p = options;
4d476f
--- autofs-5.0.7.orig/modules/parse_sun.c
4d476f
+++ autofs-5.0.7/modules/parse_sun.c
4d476f
@@ -695,14 +695,18 @@ static int sun_mount(struct autofs_point
4d476f
 		rv = mount_nfs->mount_mount(ap, root, mountpoint, strlen(mountpoint),
4d476f
 					    what, fstype, options, mount_nfs->context);
4d476f
 	} else {
4d476f
-		what = alloca(loclen + 1);
4d476f
-		if (*loc == ':') {
4d476f
-			loclen--;
4d476f
-			memcpy(what, loc + 1, loclen);
4d476f
-			what[loclen] = '\0';
4d476f
-		} else {
4d476f
-			memcpy(what, loc, loclen);
4d476f
-			what[loclen] = '\0';
4d476f
+		if (!loclen)
4d476f
+			what = NULL;
4d476f
+		else {
4d476f
+			what = alloca(loclen + 1);
4d476f
+			if (*loc == ':') {
4d476f
+				loclen--;
4d476f
+				memcpy(what, loc + 1, loclen);
4d476f
+				what[loclen] = '\0';
4d476f
+			} else {
4d476f
+				memcpy(what, loc, loclen);
4d476f
+				what[loclen] = '\0';
4d476f
+			}
4d476f
 		}
4d476f
 
4d476f
 		debug(ap->logopt, MODPREFIX
4d476f
@@ -799,7 +803,8 @@ update_offset_entry(struct autofs_point
4d476f
 
4d476f
 	mc = source->mc;
4d476f
 
4d476f
-	if (!*path || !*loc) {
4d476f
+	/* Internal hosts map may have loc == NULL */
4d476f
+	if (!*path) {
4d476f
 		error(ap->logopt,
4d476f
 		      MODPREFIX "syntax error in offset %s -> %s", path, loc);
4d476f
 		return CHE_FAIL;
4d476f
@@ -833,8 +838,10 @@ update_offset_entry(struct autofs_point
4d476f
 	if (*myoptions) {
4d476f
 		strcpy(m_mapent, "-");
4d476f
 		strcat(m_mapent, myoptions);
4d476f
-		strcat(m_mapent, " ");
4d476f
-		strcat(m_mapent, loc);
4d476f
+		if (loc) {
4d476f
+			strcat(m_mapent, " ");
4d476f
+			strcat(m_mapent, loc);
4d476f
+		}
4d476f
 	} else
4d476f
 		strcpy(m_mapent, loc);
4d476f
 
4d476f
@@ -1435,13 +1442,17 @@ int parse_mount(struct autofs_point *ap,
4d476f
 
4d476f
 			l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
4d476f
 			if (!l) {
4d476f
-				cache_delete_offset_list(mc, name);
4d476f
-				cache_multi_unlock(me);
4d476f
-				cache_unlock(mc);
4d476f
-				free(path);
4d476f
-				free(options);
4d476f
-				pthread_setcancelstate(cur_state, NULL);
4d476f
-				return 1;
4d476f
+				if (!(strstr(myoptions, "fstype=autofs") &&
4d476f
+				      strstr(myoptions, "hosts"))) {
4d476f
+					error(LOGOPT_ANY, "I think I'm a hosts map? l %d", l);
4d476f
+					cache_delete_offset_list(mc, name);
4d476f
+					cache_multi_unlock(me);
4d476f
+					cache_unlock(mc);
4d476f
+					free(path);
4d476f
+					free(options);
4d476f
+					pthread_setcancelstate(cur_state, NULL);
4d476f
+					return 1;
4d476f
+				}
4d476f
 			}
4d476f
 
4d476f
 			p += l;
4d476f
@@ -1592,13 +1603,23 @@ int parse_mount(struct autofs_point *ap,
4d476f
 			p = skipspace(p);
4d476f
 		}
4d476f
 
4d476f
-		loclen = strlen(loc);
4d476f
-		if (loclen == 0) {
4d476f
-			free(loc);
4d476f
-			free(options);
4d476f
-			error(ap->logopt,
4d476f
-			      MODPREFIX "entry %s is empty!", name);
4d476f
-			return 1;
4d476f
+		/*
4d476f
+		 * If options are asking for a hosts map loc should be
4d476f
+		 * NULL but we see it can contain junk, so ....
4d476f
+		 */
4d476f
+		if ((strstr(options, "fstype=autofs") &&
4d476f
+		     strstr(options, "hosts"))) {
4d476f
+			loc = NULL;
4d476f
+			loclen = 0;
4d476f
+		} else {
4d476f
+			loclen = strlen(loc);
4d476f
+			if (loclen == 0) {
4d476f
+				free(loc);
4d476f
+				free(options);
4d476f
+				error(ap->logopt,
4d476f
+				      MODPREFIX "entry %s is empty!", name);
4d476f
+				return 1;
4d476f
+			}
4d476f
 		}
4d476f
 
4d476f
 		debug(ap->logopt,