Blame SOURCES/autofs-5.1.2-add-support-for-amd-browsable-option.patch

306fa1
autofs-5.1.2 - add support for amd browsable option
306fa1
306fa1
From: Ian Kent <ikent@redhat.com>
306fa1
306fa1
Add support for the "browsable_dirs" configuration option and the
306fa1
pseudo mount option "browsable" of amd format maps.
306fa1
306fa1
Note that support for the configuration option "browsable_dirs = full"
306fa1
and the pseudo mount option "fullybrowsable" of type auto map entries
306fa1
cannot be implemented using  the existing kernel to user space autofs
306fa1
implementation.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG                      |    1 
306fa1
 README.amd-maps                |    2 
306fa1
 daemon/lookup.c                |  106 ++++++++++++++++++++++++++++++++---------
306fa1
 lib/master_parse.y             |   14 ++++-
306fa1
 man/autofs.conf.5.in           |    7 ++
306fa1
 modules/amd_parse.y            |    3 -
306fa1
 modules/mount_autofs.c         |    8 +--
306fa1
 modules/parse_amd.c            |    2 
306fa1
 redhat/autofs.conf.default.in  |    7 +-
306fa1
 samples/autofs.conf.default.in |    7 +-
306fa1
 10 files changed, 120 insertions(+), 37 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -224,6 +224,7 @@
306fa1
 - fix _strncmp() usage.
306fa1
 - fix typos in README.amd-maps.
306fa1
 - add ref counting to struct map_source.
306fa1
+- add support for amd browsable option.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/README.amd-maps
306fa1
+++ autofs-5.0.7/README.amd-maps
306fa1
@@ -101,7 +101,7 @@ What hasn't been implemented
306fa1
 ----------------------------
306fa1
 
306fa1
 The configuration options fully_qualified_hosts, unmount_on_exit and
306fa1
-browsable_dirs (and a couple of others) aren't implemented.
306fa1
+browsable_dirs = full (and a couple of others) aren't implemented.
306fa1
 
306fa1
 Map types (sources) ndbm, passwd are not implemented.
306fa1
 The map source "sss" can't be used for amd format maps.
306fa1
--- autofs-5.0.7.orig/daemon/lookup.c
306fa1
+++ autofs-5.0.7/daemon/lookup.c
306fa1
@@ -663,6 +663,56 @@ int lookup_nss_read_map(struct autofs_po
306fa1
 	return 0;
306fa1
 }
306fa1
 
306fa1
+static char *make_browse_path(unsigned int logopt,
306fa1
+			      const char *root, const char *key,
306fa1
+			      const char *prefix)
306fa1
+{
306fa1
+	unsigned int l_prefix;
306fa1
+	unsigned int k_len, r_len;
306fa1
+	char *k_start;
306fa1
+	char *path;
306fa1
+
306fa1
+	k_start = (char *) key;
306fa1
+	k_len = strlen(key);
306fa1
+	l_prefix = 0;
306fa1
+
306fa1
+	if (prefix) {
306fa1
+		l_prefix = strlen(prefix);
306fa1
+
306fa1
+		if (l_prefix > k_len)
306fa1
+			return NULL;
306fa1
+
306fa1
+		/* If the prefix doesn't match the beginning
306fa1
+		 * of the key this entry isn't a sub directory
306fa1
+		 * at this level.
306fa1
+		 */
306fa1
+		if (strncmp(key, prefix, l_prefix))
306fa1
+			return NULL;
306fa1
+
306fa1
+		/* Directory entry starts following the prefix */
306fa1
+		k_start += l_prefix;
306fa1
+	}
306fa1
+
306fa1
+	/* No remaining "/" allowed here */
306fa1
+	if (strchr(k_start, '/'))
306fa1
+		return NULL;
306fa1
+
306fa1
+	r_len = strlen(root);
306fa1
+
306fa1
+	if ((r_len + strlen(k_start)) > KEY_MAX_LEN)
306fa1
+		return NULL;
306fa1
+
306fa1
+	path = malloc(r_len + k_len + 2);
306fa1
+	if (!path) {
306fa1
+		warn(logopt, "failed to allocate full path");
306fa1
+		return NULL;
306fa1
+	}
306fa1
+
306fa1
+	sprintf(path, "%s/%s", root, k_start);
306fa1
+
306fa1
+	return path;
306fa1
+}
306fa1
+
306fa1
 int lookup_ghost(struct autofs_point *ap, const char *root)
306fa1
 {
306fa1
 	struct master_mapent *entry = ap->entry;
306fa1
@@ -706,10 +756,19 @@ int lookup_ghost(struct autofs_point *ap
306fa1
 			if (!me->mapent)
306fa1
 				goto next;
306fa1
 
306fa1
-			if (!strcmp(me->key, "*"))
306fa1
+			/* Wildcard cannot be a browse directory and amd map
306fa1
+			 * keys may end with the wildcard.
306fa1
+			 */
306fa1
+			if (strchr(me->key, '*'))
306fa1
 				goto next;
306fa1
 
306fa1
+			/* This will also take care of amd "/defaults" entry as
306fa1
+			 * amd map keys are not allowd to start with "/"
306fa1
+			 */
306fa1
 			if (*me->key == '/') {
306fa1
+				if (map->flags & MAP_FLAG_FORMAT_AMD)
306fa1
+					goto next;
306fa1
+
306fa1
 				/* It's a busy multi-mount - leave till next time */
306fa1
 				if (list_empty(&me->multi_list))
306fa1
 					error(ap->logopt,
306fa1
@@ -717,12 +776,10 @@ int lookup_ghost(struct autofs_point *ap
306fa1
 				goto next;
306fa1
 			}
306fa1
 
306fa1
-			fullpath = malloc(strlen(me->key) + strlen(root) + 3);
306fa1
-			if (!fullpath) {
306fa1
-				warn(ap->logopt, "failed to allocate full path");
306fa1
+			fullpath = make_browse_path(ap->logopt,
306fa1
+						    root, me->key, ap->pref);
306fa1
+			if (!fullpath)
306fa1
 				goto next;
306fa1
-			}
306fa1
-			sprintf(fullpath, "%s/%s", root, me->key);
306fa1
 
306fa1
 			ret = stat(fullpath, &st);
306fa1
 			if (ret == -1 && errno != ENOENT) {
306fa1
@@ -732,6 +789,17 @@ int lookup_ghost(struct autofs_point *ap
306fa1
 				goto next;
306fa1
 			}
306fa1
 
306fa1
+			/* Directory already exists? */
306fa1
+			if (!ret) {
306fa1
+				/* Shouldn't need this
306fa1
+				me->dev = st.st_dev;
306fa1
+				me->ino = st.st_ino;
306fa1
+				*/
306fa1
+				debug(ap->logopt, "me->dev %d me->ino %d", me->dev, me->ino);
306fa1
+				free(fullpath);
306fa1
+				goto next;
306fa1
+			}
306fa1
+
306fa1
 			ret = mkdir_path(fullpath, 0555);
306fa1
 			if (ret < 0 && errno != EEXIST) {
306fa1
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
@@ -1238,28 +1306,23 @@ void lookup_close_lookup(struct autofs_p
306fa1
 	return;
306fa1
 }
306fa1
 
306fa1
-static char *make_fullpath(const char *root, const char *key)
306fa1
+static char *make_fullpath(struct autofs_point *ap, const char *key)
306fa1
 {
306fa1
+	char *path = NULL;
306fa1
 	int l;
306fa1
-	char *path;
306fa1
 
306fa1
-	if (*key == '/') {
306fa1
+	if (*key != '/')
306fa1
+		path = make_browse_path(ap->logopt, ap->path, key, ap->pref);
306fa1
+	else {
306fa1
 		l = strlen(key) + 1;
306fa1
 		if (l > KEY_MAX_LEN)
306fa1
-			return NULL;
306fa1
+			goto out;
306fa1
 		path = malloc(l);
306fa1
 		if (!path)
306fa1
-			return NULL;
306fa1
+			goto out;
306fa1
 		strcpy(path, key);
306fa1
-	} else {
306fa1
-		l = strlen(key) + 1 + strlen(root) + 1;
306fa1
-		if (l > KEY_MAX_LEN)
306fa1
-			return NULL;
306fa1
-		path = malloc(l);
306fa1
-		if (!path)
306fa1
-			return NULL;
306fa1
-		sprintf(path, "%s/%s", root, key);
306fa1
 	}
306fa1
+out:
306fa1
 	return path;
306fa1
 }
306fa1
 
306fa1
@@ -1290,13 +1353,14 @@ void lookup_prune_one_cache(struct autof
306fa1
 
306fa1
 		key = strdup(me->key);
306fa1
 		me = cache_enumerate(mc, me);
306fa1
-		if (!key || !strcmp(key, "*")) {
306fa1
+		/* Don't consider any entries with a wildcard */
306fa1
+		if (!key || strchr(key, '*')) {
306fa1
 			if (key)
306fa1
 				free(key);
306fa1
 			continue;
306fa1
 		}
306fa1
 
306fa1
-		path = make_fullpath(ap->path, key);
306fa1
+		path = make_fullpath(ap, key);
306fa1
 		if (!path) {
306fa1
 			warn(ap->logopt, "can't malloc storage for path");
306fa1
 			free(key);
306fa1
--- autofs-5.0.7.orig/lib/master_parse.y
306fa1
+++ autofs-5.0.7/lib/master_parse.y
306fa1
@@ -806,14 +806,22 @@ int master_parse_entry(const char *buffe
306fa1
 
306fa1
 	if (format && !strcmp(format, "amd")) {
306fa1
 		unsigned int loglevel = conf_amd_get_log_options();
306fa1
+		unsigned int flags = conf_amd_get_flags(path);
306fa1
+
306fa1
 		if (loglevel <= LOG_DEBUG && loglevel > LOG_INFO)
306fa1
 			logopt = LOGOPT_DEBUG;
306fa1
 		else if (loglevel <= LOG_INFO && loglevel > LOG_ERR)
306fa1
 			logopt = LOGOPT_VERBOSE;
306fa1
-		/* amd mounts don't support browse mode */
306fa1
-		ghost = 0;
306fa1
-	}
306fa1
 
306fa1
+		/* It isn't possible to provide the fullybrowsable amd
306fa1
+		 * browsing functionality within the autofs framework.
306fa1
+		 * This flag will not be set if browsable_dirs = full
306fa1
+		 * in the configuration or fullybrowsable is present as
306fa1
+		 * an option.
306fa1
+		 */
306fa1
+		if (flags & CONF_BROWSABLE_DIRS)
306fa1
+			ghost = 1;
306fa1
+	}
306fa1
 
306fa1
 	if (timeout < 0) {
306fa1
 		/*
306fa1
--- autofs-5.0.7.orig/man/autofs.conf.5.in
306fa1
+++ autofs-5.0.7/man/autofs.conf.5.in
306fa1
@@ -348,7 +348,12 @@ and that will be done.
306fa1
 .TP
306fa1
 .B browsable_dirs
306fa1
 .br
306fa1
-Not yet implemented.
306fa1
+Allow map keys to be shown in directory listings. This option
306fa1
+can have values of "yes" or "no". The default is "no". A variation
306fa1
+of this option, "browsable", can be used as a pseudo mount option
306fa1
+in type "auto" map entries to provide provide browsing funtionality
306fa1
+in sub-mounts. The amd "browsable_dirs = full" option cannot be
306fa1
+implemented within the current autofs framework and is not supported.
306fa1
 .TP
306fa1
 .B exec_map_timeout
306fa1
 .br
306fa1
--- autofs-5.0.7.orig/modules/amd_parse.y
306fa1
+++ autofs-5.0.7/modules/amd_parse.y
306fa1
@@ -432,8 +432,7 @@ option_assignment: MAP_OPTION OPTION_ASS
306fa1
 
306fa1
 options: OPTION
306fa1
 	{
306fa1
-		if (!strcmp($1, "browsable") ||
306fa1
-		    !strcmp($1, "fullybrowsable") ||
306fa1
+		if (!strcmp($1, "fullybrowsable") ||
306fa1
 		    !strcmp($1, "nounmount") ||
306fa1
 		    !strcmp($1, "unmount")) {
306fa1
 			sprintf(msg_buf, "option %s is not currently "
306fa1
--- autofs-5.0.7.orig/modules/mount_autofs.c
306fa1
+++ autofs-5.0.7/modules/mount_autofs.c
306fa1
@@ -121,11 +121,13 @@ int mount_mount(struct autofs_point *ap,
306fa1
 			while (*comma != '\0' && *comma != ',')
306fa1
 				comma++;
306fa1
 
306fa1
-			if (_strncmp("nobrowse", cp, 8) == 0)
306fa1
+			if (_strncmp("nobrowse", cp, 8) == 0 ||
306fa1
+			    _strncmp("nobrowsable", cp, 11) == 0)
306fa1
 				ghost = 0;
306fa1
 			else if (_strncmp("nobind", cp, 6) == 0)
306fa1
 				nobind = 1;
306fa1
-			else if (_strncmp("browse", cp, 6) == 0)
306fa1
+			else if (_strncmp("browse", cp, 6) == 0 ||
306fa1
+				 _strncmp("browsable", cp, 9) == 0)
306fa1
 				ghost = 1;
306fa1
 			else if (_strncmp("symlink", cp, 7) == 0)
306fa1
 				symlnk = 1;
306fa1
@@ -286,8 +288,6 @@ int mount_mount(struct autofs_point *ap,
306fa1
 			nap->pref = am_entry->pref;
306fa1
 			am_entry->pref = NULL;
306fa1
 		}
306fa1
-		/* amd mounts don't support browse mode */
306fa1
-		nap->flags &= ~MOUNT_FLAG_GHOST;
306fa1
 	}
306fa1
 
306fa1
 	if (handle_mounts_startup_cond_init(&suc)) {
306fa1
--- autofs-5.0.7.orig/modules/parse_amd.c
306fa1
+++ autofs-5.0.7/modules/parse_amd.c
306fa1
@@ -932,7 +932,7 @@ static int do_auto_mount(struct autofs_p
306fa1
 	}
306fa1
 
306fa1
 	return do_mount(ap, ap->path,
306fa1
-			name, strlen(name), target, "autofs", NULL);
306fa1
+			name, strlen(name), target, "autofs", entry->opts);
306fa1
 }
306fa1
 
306fa1
 static int do_link_mount(struct autofs_point *ap, const char *name,
306fa1
--- autofs-5.0.7.orig/redhat/autofs.conf.default.in
306fa1
+++ autofs-5.0.7/redhat/autofs.conf.default.in
306fa1
@@ -264,8 +264,6 @@ mount_nfs_default_protocol = 4
306fa1
 #	is a sensible option to implement and that will be
306fa1
 #	done.
306fa1
 #
306fa1
-# browsable_dirs - not yet implemented.
306fa1
-#
306fa1
 # exec_map_timeout - a timeout is not currently used for
306fa1
 #	for program maps, might be implemented.
306fa1
 #
306fa1
@@ -308,6 +306,11 @@ mount_nfs_default_protocol = 4
306fa1
 #	takes its default value from the autofs internal default
306fa1
 #	of 600 seconds.
306fa1
 #
306fa1
+# browsable_dirs - make map keys visible in directory listings.
306fa1
+#	Note that support for the "fullybrowsable" option cannot
306fa1
+#	be added using the existing kernel to user space autofs
306fa1
+#	implementation.
306fa1
+#
306fa1
 # autofs_use_lofs - if set to "yes" autofs will attempt to use bind
306fa1
 #	mounts for type "auto" when possible.
306fa1
 #
306fa1
--- autofs-5.0.7.orig/samples/autofs.conf.default.in
306fa1
+++ autofs-5.0.7/samples/autofs.conf.default.in
306fa1
@@ -263,8 +263,6 @@ browse_mode = no
306fa1
 #	is a sensible option to implement and that will be
306fa1
 #	done.
306fa1
 #
306fa1
-# browsable_dirs - not yet implemented.
306fa1
-#
306fa1
 # exec_map_timeout - a timeout is not currently used for
306fa1
 #	for program maps, might be implemented.
306fa1
 #
306fa1
@@ -307,6 +305,11 @@ browse_mode = no
306fa1
 #	takes its default value from the autofs internal default
306fa1
 #	of 600 seconds.
306fa1
 #
306fa1
+# browsable_dirs - make map keys visible in directory listings.
306fa1
+#	Note that support for the "fullybrowsable" option cannot
306fa1
+#	be added using the existing kernel to user space autofs
306fa1
+#	implementation.
306fa1
+#
306fa1
 # autofs_use_lofs - if set to "yes" autofs will attempt to use bind
306fa1
 #	mounts for type "auto" when possible.
306fa1
 #