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

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