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

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