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

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