Blame SOURCES/autofs-5.0.9-amd-lookup-add-parent-prefix-handling.patch

304803
autofs-5.0.9 - amd lookup add parent prefix handling
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
304803
---
304803
 include/automount.h |    1 +
304803
 lib/master.c        |    3 +++
304803
 modules/parse_amd.c |   31 +++++++++++++++++++++++++++++++
304803
 3 files changed, 35 insertions(+)
304803
304803
diff --git a/include/automount.h b/include/automount.h
304803
index b304517..615efcc 100644
304803
--- a/include/automount.h
304803
+++ b/include/automount.h
304803
@@ -491,6 +491,7 @@ struct kernel_mod_version {
304803
 struct autofs_point {
304803
 	pthread_t thid;
304803
 	char *path;			/* Mount point name */
304803
+	char *pref;			/* amd prefix */
304803
 	int pipefd;			/* File descriptor for pipe */
304803
 	int kpipefd;			/* Kernel end descriptor for pipe */
304803
 	int ioctlfd;			/* File descriptor for ioctls */
304803
diff --git a/lib/master.c b/lib/master.c
304803
index 4ac3c6a..df4aef6 100644
304803
--- a/lib/master.c
304803
+++ b/lib/master.c
304803
@@ -86,6 +86,7 @@ int master_add_autofs_point(struct master_mapent *entry, unsigned logopt,
304803
 		free(ap);
304803
 		return 0;
304803
 	}
304803
+	ap->pref = NULL;
304803
 
304803
 	ap->entry = entry;
304803
 	ap->exp_thread = 0;
304803
@@ -144,6 +145,8 @@ void master_free_autofs_point(struct autofs_point *ap)
304803
 	if (status)
304803
 		fatal(status);
304803
 
304803
+	if (ap->pref)
304803
+		free(ap->pref);
304803
 	free(ap->path);
304803
 	free(ap);
304803
 }
304803
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
304803
index 54da1a5..295a10f 100644
304803
--- a/modules/parse_amd.c
304803
+++ b/modules/parse_amd.c
304803
@@ -736,6 +736,36 @@ static void normalize_sublink(unsigned int logopt,
304803
 	return;
304803
 }
304803
 
304803
+/*
304803
+ * Set the prefix.
304803
+ *
304803
+ * This is done in a couple of places, here is as good a place as
304803
+ * any to describe it.
304803
+ *
304803
+ * If a prefix is present in the map entry then use it.
304803
+ *
304803
+ * A pref option with the value none is required to use no prefix,
304803
+ * otherwise the prefix of the parent map, if any, will be used.
304803
+ */
304803
+static void update_prefix(struct autofs_point *ap,
304803
+			  struct amd_entry *entry, const char *name)
304803
+{
304803
+	size_t len;
304803
+	char *new;
304803
+
304803
+	if (!entry->pref && ap->pref) {
304803
+		len = strlen(ap->pref) + strlen(name) + 2;
304803
+		new = malloc(len);
304803
+		if (new) {
304803
+			strcpy(new, ap->pref);
304803
+			strcat(new, name);
304803
+			strcat(new, "/");
304803
+			entry->pref = new;
304803
+		}
304803
+	}
304803
+	return;
304803
+}
304803
+
304803
 static struct amd_entry *dup_defaults_entry(struct amd_entry *defaults)
304803
 {
304803
 	struct amd_entry *entry;
304803
@@ -1044,6 +1074,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
304803
 		sv = expand_entry(ap, this, flags, sv);
304803
 		sv = merge_entry_options(ap, this, sv);
304803
 		normalize_sublink(ap->logopt, this, sv);
304803
+		update_prefix(ap, this, name);
304803
 
304803
 		dequote_entry(ap, this);
304803