diff --git a/SOURCES/autofs-5.1.2-fix-cachefs-parse-message-not-being-logged.patch b/SOURCES/autofs-5.1.2-fix-cachefs-parse-message-not-being-logged.patch
new file mode 100644
index 0000000..111e6ad
--- /dev/null
+++ b/SOURCES/autofs-5.1.2-fix-cachefs-parse-message-not-being-logged.patch
@@ -0,0 +1,30 @@
+autofs-5.1.2 - fix cachefs parse message not being logged
+
+From: Ian Kent <raven@themaw.net>
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/amd_parse.y |    1 +
+ 2 files changed, 2 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -267,6 +267,7 @@
+ - improve description of mount_nfs_default_protocol.
+ - reset master map list on startup retry.
+ - improve debug logging of lookup key.
++- fix cachefs parse message not being logged.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -301,6 +301,7 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 		} else if (!strcmp($3, "cachefs")) {
+ 			sprintf(msg_buf, "file syatem %s is not "
+ 					 "supported by autofs, ignored", $3);
++			amd_msg(msg_buf);
+ 		} else {
+ 			amd_notify($1);
+ 			YYABORT;
diff --git a/SOURCES/autofs-5.1.3-add-amd-mount-type-program-mount-support.patch b/SOURCES/autofs-5.1.3-add-amd-mount-type-program-mount-support.patch
new file mode 100644
index 0000000..3dd9eee
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-add-amd-mount-type-program-mount-support.patch
@@ -0,0 +1,375 @@
+autofs-5.1.3 - add amd mount type program mount support
+
+From: Ian Kent <raven@themaw.net>
+
+Add support for the amd mount type "program" and its option "mount",
+and its mutually exclusive options "umount" or "unmount" for specifying
+the program to be used to perform the mount and optionally also the
+umount.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ README.amd-maps     |    6 +-
+ include/parse_amd.h |    3 +
+ lib/mounts.c        |   42 ++++++++++++++-
+ modules/amd_parse.y |   36 +++++++++----
+ modules/parse_amd.c |  143 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 6 files changed, 216 insertions(+), 15 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -281,6 +281,7 @@
+ - add function umount_amd_ext_mount().
+ - add function ext_mount_inuse().
+ - add function construct_argv().
++- add amd mount type program mount support.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/README.amd-maps
++++ autofs-5.0.7/README.amd-maps
+@@ -146,9 +146,9 @@ always used for available map sources.
+ 
+ The regex map key matching feature is not implemented.
+ 
+-Mount types lustre, nfsx, jfs, program and direct haven't been
+-implemented and other mount types that aren't implemented in amd are
+-also not available.
++Mount types lustre, nfsx, jfs and direct haven't been implemented
++and other mount types that aren't implemented in amd are also not
++available.
+ 
+ How to find out more
+ --------------------
+--- autofs-5.0.7.orig/include/parse_amd.h
++++ autofs-5.0.7/include/parse_amd.h
+@@ -30,6 +30,7 @@
+ #define AMD_MOUNT_TYPE_JFS	0x00000800
+ #define AMD_MOUNT_TYPE_CACHEFS	0x00001000
+ #define AMD_MOUNT_TYPE_CDFS	0x00002000
++#define AMD_MOUNT_TYPE_PROGRAM	0x00004000
+ #define AMD_MOUNT_TYPE_MASK	0x0000ffff
+ 
+ #define AMD_ENTRY_CUT		0x00010000
+@@ -60,6 +61,8 @@ struct amd_entry {
+ 	char *addopts;
+ 	char *remopts;
+ 	char *sublink;
++	char *mount;
++	char *umount;
+ 	struct selector *selector;
+ 	struct list_head list;
+ 	struct list_head entries;
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -2056,6 +2056,46 @@ int umount_amd_ext_mount(struct autofs_p
+ {
+ 	int rv = 1;
+ 
++	if (entry->umount) {
++		char *prog, *str;
++		char **argv;
++		int argc = -1;
++
++		str = strdup(entry->umount);
++		if (!str)
++			goto out;
++
++		prog = NULL;
++		argv = NULL;
++
++		argc = construct_argv(str, &prog, &argv);
++		if (argc == -1) {
++			free(str);
++			goto out;
++		}
++
++		if (!ext_mount_remove(&entry->ext_mount, entry->fs)) {
++			rv =0;
++			goto out;
++		}
++
++		rv = spawnv(ap->logopt, prog, (const char * const *) argv);
++		if (rv == -1 || (WIFEXITED(rv) && WEXITSTATUS(rv)))
++			error(ap->logopt,
++			     "failed to umount program mount at %s", entry->fs);
++		else {
++			rv = 0;
++			debug(ap->logopt,
++			      "umounted program mount at %s", entry->fs);
++			rmdir_path(ap, entry->fs, ap->dev);
++		}
++
++		free_argv(argc, (const char **) argv);
++		free(str);
++
++		goto out;
++	}
++
+ 	if (ext_mount_remove(&entry->ext_mount, entry->fs)) {
+ 		rv = umount_ent(ap, entry->fs);
+ 		if (rv)
+@@ -2065,7 +2105,7 @@ int umount_amd_ext_mount(struct autofs_p
+ 			debug(ap->logopt,
+ 			      "umounted external mount %s", entry->fs);
+ 	}
+-
++out:
+ 	return rv;
+ }
+ 
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -347,13 +347,18 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 			amd_set_value(&entry.rfs, fs_opt_val);
+ 		else if (!strcmp($1, "dev"))
+ 			amd_set_value(&entry.dev, fs_opt_val);
+-		else if (!strcmp($1, "mount") ||
+-			 !strcmp($1, "unmount") ||
++		else if (!strcmp($1, "mount"))
++			amd_set_value(&entry.mount, fs_opt_val);
++		else if (!strcmp($1, "unmount") ||
+ 			 !strcmp($1, "umount")) {
+-			amd_info("file system type program is not "
+-				 "yet implemented, option ignored");
+-			free(fs_opt_val);
+-			YYABORT;
++			if (entry.umount) {
++				sprintf(msg_buf,
++				    "unmount or umount may only be used once");
++				amd_info(msg_buf);
++				free(fs_opt_val);
++				YYABORT;
++			}
++			entry.umount = fs_opt_val;
+ 		} else if (!strcmp($1, "delay") ||
+ 			   !strcmp($1, "cachedir")) {
+ 			sprintf(msg_buf, "option %s is not used by autofs", $1);
+@@ -381,7 +386,14 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 			amd_set_value(&entry.rfs, empty);
+ 		else if (!strcmp($1, "dev"))
+ 			amd_set_value(&entry.dev, empty);
+-		else {
++		else if (!strcmp($1, "mount")) {
++			amd_set_value(&entry.mount, NULL);
++			free(empty);
++		} else if (!strcmp($1, "umount") ||
++			   !strcmp($1, "unmount")) {
++			amd_set_value(&entry.umount, NULL);
++			free(empty);
++		} else {
+ 			amd_notify($1);
+ 			free(empty);
+ 			YYABORT;
+@@ -426,8 +438,7 @@ option_assignment: MAP_OPTION OPTION_ASS
+ options: OPTION
+ 	{
+ 		if (!strcmp($1, "fullybrowsable") ||
+-		    !strcmp($1, "nounmount") ||
+-		    !strcmp($1, "unmount")) {
++		    !strcmp($1, "nounmount")) {
+ 			sprintf(msg_buf, "option %s is not currently "
+ 					 "implemented, ignored", $1);
+ 			amd_info(msg_buf);
+@@ -496,7 +507,9 @@ static int match_map_option_fs_type(char
+ 		   !strcmp(fs_type, "ext3") ||
+ 		   !strcmp(fs_type, "ext4"))
+ 		entry.flags |= AMD_MOUNT_TYPE_EXT;
+-	} else if (!strcmp(fs_type, "ufs")) {
++	else if (!strcmp(fs_type, "program"))
++		entry.flags |= AMD_MOUNT_TYPE_PROGRAM;
++	else if (!strcmp(fs_type, "ufs")) {
+ 		entry.flags |= AMD_MOUNT_TYPE_UFS;
+ 		entry.type = conf_amd_get_linux_ufs_mount_type();
+ 		if (!entry.type) {
+@@ -520,7 +533,6 @@ static int match_map_option_fs_type(char
+ 		fs_type = NULL;
+ 	} else if (!strcmp(fs_type, "jfs") ||
+ 		   !strcmp(fs_type, "nfsx") ||
+-		   !strcmp(fs_type, "program") ||
+ 		   !strcmp(fs_type, "lustre") ||
+ 		   !strcmp(fs_type, "direct")) {
+ 		sprintf(msg_buf, "file system type %s is "
+@@ -880,6 +892,8 @@ static int add_location(void)
+ 	new->addopts = entry.addopts;
+ 	new->remopts = entry.remopts;
+ 	new->sublink = entry.sublink;
++	new->mount = entry.mount;
++	new->umount = entry.umount;
+ 	new->selector = entry.selector;
+ 	list_add_tail(&new->list, entries);
+ 	memset(&entry, 0, sizeof(struct amd_entry));
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -790,6 +790,35 @@ next:
+ 		sv = macro_addvar(sv, "remopts", 7, entry->remopts);
+ 	}
+ 
++	if (entry->mount) {
++		if (!expand_selectors(ap, entry->mount, &expand, sv)) {
++			free(entry->mount);
++			if (entry->umount)
++				free(entry->umount);
++			entry->mount = NULL;
++			entry->umount = NULL;
++			goto done;
++		}
++		debug(logopt, MODPREFIX
++		      "mount expand(\"%s\") -> %s", entry->mount, expand);
++		free(entry->mount);
++		entry->mount = expand;
++		sv = macro_addvar(sv, "mount", 5, entry->mount);
++	}
++
++	if (entry->umount) {
++		if (!expand_selectors(ap, entry->umount, &expand, sv)) {
++			free(entry->umount);
++			entry->umount = NULL;
++			goto done;
++		}
++		debug(logopt, MODPREFIX
++		      "umount expand(\"%s\") -> %s", entry->umount, expand);
++		free(entry->umount);
++		entry->umount = expand;
++		sv = macro_addvar(sv, "umount", 5, entry->umount);
++	}
++done:
+ 	return sv;
+ }
+ 
+@@ -1224,6 +1253,91 @@ out:
+ 	return ret;
+ }
+ 
++static int do_program_mount(struct autofs_point *ap,
++			    struct amd_entry *entry, const char *name)
++{
++	char *prog, *str;
++	char **argv;
++	int argc = -1;
++	int rv = 1;
++
++	str = strdup(entry->mount);
++	if (!str)
++		goto out;
++
++	prog = NULL;
++	argv = NULL;
++
++	argc = construct_argv(str, &prog, &argv);
++	if (argc == -1) {
++		error(ap->logopt, MODPREFIX
++		      "%s: error creating mount arguments", entry->type);
++		free(str);
++		goto out;
++	}
++
++	/* The am-utils documentation doesn't actually say that the
++	 * mount (and umount, if given) command need to use ${fs} as
++	 * the mount point in the command.
++	 *
++	 * For program mounts there's no way to know what the mount
++	 * point is so ${fs} must be used in the mount (and umount,
++	 * if given) in order to create the mount point directory
++	 * before executing the mount command and removing it at
++	 * umount.
++	 */
++	if (ext_mount_inuse(entry->fs)) {
++		rv = 0;
++		ext_mount_add(&entry->ext_mount, entry->fs, 1);
++	} else {
++		rv = mkdir_path(entry->fs, 0555);
++		if (rv && errno != EEXIST) {
++			char *buf[MAX_ERR_BUF];
++			char * estr;
++
++			estr = strerror_r(errno, buf, MAX_ERR_BUF);
++			error(ap->logopt,
++			      MODPREFIX "%s: mkdir_path %s failed: %s",
++			      entry->type, entry->fs, estr);
++			goto do_free;
++		}
++
++		rv = spawnv(ap->logopt, prog, (const char * const *) argv);
++		if (WIFEXITED(rv) && !WEXITSTATUS(rv)) {
++			rv = 0;
++			ext_mount_add(&entry->ext_mount, entry->fs, 1);
++			debug(ap->logopt, MODPREFIX
++			      "%s: mounted %s", entry->type, entry->fs);
++		} else {
++			if (!ext_mount_inuse(entry->fs))
++				rmdir_path(ap, entry->fs, ap->dev);
++			error(ap->logopt, MODPREFIX
++			     "%s: failed to mount using: %s",
++			     entry->type, entry->mount);
++		}
++	}
++do_free:
++	free_argv(argc, (const char **) argv);
++	free(str);
++
++	if (rv)
++		goto out;
++
++	rv = do_link_mount(ap, name, entry, 0);
++	if (!rv)
++		goto out;
++
++	if (umount_amd_ext_mount(ap, entry)) {
++		if (!ext_mount_inuse(entry->fs))
++			rmdir_path(ap, entry->fs, ap->dev);
++		debug(ap->logopt, MODPREFIX
++		      "%s: failed to umount external mount at %s",
++		      entry->type, entry->fs);
++	}
++out:
++	return rv;
++}
++
+ static unsigned int validate_auto_options(unsigned int logopt,
+ 					  struct amd_entry *entry)
+ {
+@@ -1350,6 +1464,29 @@ static unsigned int validate_host_option
+ 	return 1;
+ }
+ 
++static unsigned int validate_program_options(unsigned int logopt,
++					     struct amd_entry *entry)
++{
++	/*
++	 * entry->mount will be NULL if there is a problem expanding
++	 * ${} macros in expandamdent().
++	 */
++	if (!entry->mount) {
++		error(logopt, MODPREFIX
++		      "%s: mount program invalid or not set", entry->type);
++		return 0;
++	}
++
++	if (!entry->fs && !*entry->fs) {
++		error(logopt, MODPREFIX
++		    "%s: ${fs} must be used as the mount point but is not set",
++		    entry->type);
++		return 0;
++	}
++
++	return 1;
++}
++
+ static int amd_mount(struct autofs_point *ap, const char *name,
+ 		     struct amd_entry *entry, struct map_source *source,
+ 		     struct substvar *sv, unsigned int flags,
+@@ -1415,6 +1552,12 @@ static int amd_mount(struct autofs_point
+ 		ret = do_host_mount(ap, name, entry, source, flags);
+ 		break;
+ 
++	case AMD_MOUNT_TYPE_PROGRAM:
++		if (!validate_program_options(ap->logopt, entry))
++			return 1;
++		ret = do_program_mount(ap, entry, name);
++		break;
++
+ 	default:
+ 		info(ap->logopt,
+ 		     MODPREFIX "unkown file system type %x", fstype);
diff --git a/SOURCES/autofs-5.1.3-add-function-construct_argv.patch b/SOURCES/autofs-5.1.3-add-function-construct_argv.patch
new file mode 100644
index 0000000..4e4141c
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-add-function-construct_argv.patch
@@ -0,0 +1,123 @@
+autofs-5.1.3 - add function construct_argv()
+
+From: Ian Kent <raven@themaw.net>
+
+Add a function to decompose a string into a program path and an
+arguments vector ready for an execv(3) invocation.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG            |    1 
+ include/parse_subs.h |    1 
+ lib/parse_subs.c     |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 82 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -280,6 +280,7 @@
+ - remove path restriction of amd external mount.
+ - add function umount_amd_ext_mount().
+ - add function ext_mount_inuse().
++- add function construct_argv().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/include/parse_subs.h
++++ autofs-5.0.7/include/parse_subs.h
+@@ -125,6 +125,7 @@ char *sanitize_path(const char *, int, u
+ char *merge_options(const char *, const char *);
+ int expandamdent(const char *, char *, const struct substvar *);
+ int expand_selectors(struct autofs_point *, const char *, char **, struct substvar *);
++int construct_argv(char *, char **, char ***);
+ void free_map_type_info(struct map_type_info *);
+ struct map_type_info *parse_map_type_info(const char *);
+ 
+--- autofs-5.0.7.orig/lib/parse_subs.c
++++ autofs-5.0.7/lib/parse_subs.c
+@@ -1191,6 +1191,86 @@ int expand_selectors(struct autofs_point
+ 	return len;
+ }
+ 
++/* Get next space seperated argument, arguments containing
++ * space characters may be single quoted.
++ */
++static char *next_arg(char *str, char **next)
++{
++	char *start;
++	char *ptr;
++
++	if (!*str)
++		return NULL;
++
++	start = ptr = str;
++
++	/* The amd map format parser should ensure there
++	 * are matching single quotes.
++	 */
++	if (*start == 39) {
++		start++;
++		ptr++;
++		while (*ptr && *ptr != 39)
++			ptr++;
++	} else {
++		while (*ptr && *ptr != ' ')
++			ptr++;
++	}
++
++	if (*ptr)
++		*ptr++ = 0;
++	*next = ptr;
++
++	return start;
++}
++
++/* Construct program path name plus argument array for use with
++ * execv(3).
++ */
++int construct_argv(char *str, char **prog, char ***argv)
++{
++	char *program = NULL;
++	char *start, *next;
++	char **args, *arg;
++	int argc;
++
++	start = str;
++
++	args = malloc(sizeof(char *));
++	if (!args)
++		return -1;
++
++	args[0] = NULL;
++	argc = 0;
++
++	next = NULL;
++	program = next_arg(str, &next);
++	if (!program) {
++		free(args);
++		return -1;
++	}
++
++	start = next;
++
++	while (1) {
++		if (!*next)
++			break;
++		arg = next_arg(start, &next);
++		if (arg) {
++			argc++;
++			args = add_argv(argc, args, arg);
++			if (!args)
++				return -1;
++		}
++		start = next;
++	}
++
++	*prog = program;
++	*argv = args;
++
++	return argc;
++}
++
+ void free_map_type_info(struct map_type_info *info)
+ {
+ 	if (info->type)
diff --git a/SOURCES/autofs-5.1.3-add-function-ext_mount_inuse.patch b/SOURCES/autofs-5.1.3-add-function-ext_mount_inuse.patch
new file mode 100644
index 0000000..ad5f9e6
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-add-function-ext_mount_inuse.patch
@@ -0,0 +1,59 @@
+autofs-5.1.3 - add function ext_mount_inuse()
+
+From: Ian Kent <raven@themaw.net>
+
+Add function to check if a path is an amd externally managed mount.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG        |    1 +
+ include/mounts.h |    1 +
+ lib/mounts.c     |   17 +++++++++++++++++
+ 3 files changed, 19 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -279,6 +279,7 @@
+ - fix possible memory leak during amd parse.
+ - remove path restriction of amd external mount.
+ - add function umount_amd_ext_mount().
++- add function ext_mount_inuse().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/include/mounts.h
++++ autofs-5.0.7/include/mounts.h
+@@ -98,6 +98,7 @@ char *make_options_string(char *path, in
+ char *make_mnt_name_string(char *path);
+ int ext_mount_add(struct list_head *, const char *, unsigned int);
+ int ext_mount_remove(struct list_head *, const char *);
++int ext_mount_inuse(const char *);
+ struct mnt_list *get_mnt_list(const char *table, const char *path, int include);
+ struct mnt_list *reverse_mnt_list(struct mnt_list *list);
+ void free_mnt_list(struct mnt_list *list);
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -768,6 +768,23 @@ done:
+ 	return ret;
+ }
+ 
++int ext_mount_inuse(const char *path)
++{
++	struct ext_mount *em;
++	int ret = 0;
++
++	pthread_mutex_lock(&ext_mount_hash_mutex);
++	em = ext_mount_lookup(path);
++	if (!em)
++		goto done;
++
++	if (!list_empty(&em->mounts))
++		ret = 1;
++done:
++	pthread_mutex_unlock(&ext_mount_hash_mutex);
++	return ret;
++}
++
+ /*
+  * Get list of mounts under path in longest->shortest order
+  */
diff --git a/SOURCES/autofs-5.1.3-add-function-umount_amd_ext_mount.patch b/SOURCES/autofs-5.1.3-add-function-umount_amd_ext_mount.patch
new file mode 100644
index 0000000..c892a12
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-add-function-umount_amd_ext_mount.patch
@@ -0,0 +1,115 @@
+autofs-5.1.3 - add function umount_amd_ext_mount()
+
+From: Ian Kent <raven@themaw.net>
+
+Refactor amd external umount code, move the code into its own
+function.
+
+Later amd umounting of program mounts with a custom command will
+be added.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ daemon/automount.c  |   22 ++--------------------
+ include/mounts.h    |    1 +
+ lib/mounts.c        |   17 +++++++++++++++++
+ modules/parse_amd.c |    3 +--
+ 5 files changed, 22 insertions(+), 22 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -278,6 +278,7 @@
+ - fix expandamdent() quote handling.
+ - fix possible memory leak during amd parse.
+ - remove path restriction of amd external mount.
++- add function umount_amd_ext_mount().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/automount.c
++++ autofs-5.0.7/daemon/automount.c
+@@ -614,16 +614,7 @@ static int umount_subtree_mounts(struct
+ 		}
+ 		list_del(&entry->entries);
+ 		mounts_mutex_unlock(ap);
+-		if (ext_mount_remove(&entry->ext_mount, entry->fs)) {
+-			if (umount_ent(ap, entry->fs))
+-				debug(ap->logopt,
+-				      "failed to umount external mount %s",
+-				      entry->fs);
+-			else
+-				debug(ap->logopt,
+-				      "umounted external mount %s",
+-				      entry->fs);
+-		}
++		umount_amd_ext_mount(ap, entry);
+ 		free_amd_entry(entry);
+ 	}
+ done:
+@@ -670,16 +661,7 @@ int umount_multi(struct autofs_point *ap
+ 		}
+ 		list_del(&entry->entries);
+ 		mounts_mutex_unlock(ap);
+-		if (ext_mount_remove(&entry->ext_mount, entry->fs)) {
+-			if (umount_ent(ap, entry->fs))
+-				debug(ap->logopt,
+-				      "failed to umount external mount %s",
+-				      entry->fs);
+-			else
+-				debug(ap->logopt,
+-				      "umounted external mount %s",
+-				      entry->fs);
+-		}
++		umount_amd_ext_mount(ap, entry);
+ 		free_amd_entry(entry);
+ 		return 0;
+ 	}
+--- autofs-5.0.7.orig/include/mounts.h
++++ autofs-5.0.7/include/mounts.h
+@@ -118,6 +118,7 @@ int try_remount(struct autofs_point *, s
+ void set_indirect_mount_tree_catatonic(struct autofs_point *);
+ void set_direct_mount_tree_catatonic(struct autofs_point *, struct mapent *);
+ int umount_ent(struct autofs_point *, const char *);
++int umount_amd_ext_mount(struct autofs_point *, struct amd_entry *);
+ int mount_multi_triggers(struct autofs_point *, struct mapent *, const char *, unsigned int, const char *);
+ int umount_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
+ int clean_stale_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -2035,6 +2035,23 @@ int umount_ent(struct autofs_point *ap,
+ 	return rv;
+ }
+ 
++int umount_amd_ext_mount(struct autofs_point *ap, struct amd_entry *entry)
++{
++	int rv = 1;
++
++	if (ext_mount_remove(&entry->ext_mount, entry->fs)) {
++		rv = umount_ent(ap, entry->fs);
++		if (rv)
++			error(ap->logopt,
++			      "failed to umount external mount %s", entry->fs);
++		else
++			debug(ap->logopt,
++			      "umounted external mount %s", entry->fs);
++	}
++
++	return rv;
++}
++
+ static int do_mount_autofs_offset(struct autofs_point *ap,
+ 				  struct mapent *oe, const char *root,
+ 				  char *offset)
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -982,8 +982,7 @@ symlink:
+ 
+ 	if (entry->sublink) {
+ 		/* failed to complete sublink mount */
+-		if (ext_mount_remove(&entry->ext_mount, entry->fs))
+-			umount_ent(ap, entry->fs);
++		umount_amd_ext_mount(ap, entry);
+ 	}
+ out:
+ 	return ret;
diff --git a/SOURCES/autofs-5.1.3-add-missing-MODPREFIX-to-logging-in-amd-parser.patch b/SOURCES/autofs-5.1.3-add-missing-MODPREFIX-to-logging-in-amd-parser.patch
new file mode 100644
index 0000000..89c3c83
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-add-missing-MODPREFIX-to-logging-in-amd-parser.patch
@@ -0,0 +1,127 @@
+autofs-5.1.3 - add missing MODPREFIX to logging in amd parser
+
+From: Ian Kent <raven@themaw.net>
+
+Some of the logging in the amd parser is missing the log identifier
+MODPREFIX so add it.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |   25 ++++++++++++++-----------
+ 2 files changed, 15 insertions(+), 11 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -269,6 +269,7 @@
+ - improve debug logging of lookup key.
+ - fix cachefs parse message not being logged.
+ - fix typo in amd_parse.c.
++- add missing MODPREFIX to logging in amd parser.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -245,7 +245,7 @@ static int match_my_name(unsigned int lo
+ 	}
+ 
+ 	if (!v || !v->val) {
+-		error(logopt, "error: ${host} not set");
++		error(logopt, MODPREFIX "error: ${host} not set");
+ 		goto out;
+ 	}
+ 
+@@ -259,7 +259,7 @@ static int match_my_name(unsigned int lo
+ 	/* Get host canonical name */
+ 	ret = getaddrinfo(v->val, NULL, &hints, &cni);
+ 	if (ret) {
+-		error(logopt,
++		error(logopt, MODPREFIX
+ 		      "hostname lookup failed: %s\n", gai_strerror(ret));
+ 		goto out;
+ 	}
+@@ -269,7 +269,7 @@ static int match_my_name(unsigned int lo
+ 	/* Resolve comparison name to its names and compare */
+ 	ret = getaddrinfo(name, NULL, &hints, &ni);
+ 	if (ret) {
+-		error(logopt,
++		error(logopt, MODPREFIX
+ 		      "hostname lookup failed: %s\n", gai_strerror(ret));
+ 		freeaddrinfo(cni);
+ 		goto out;
+@@ -282,7 +282,7 @@ static int match_my_name(unsigned int lo
+ 				  numeric, sizeof(numeric), NULL, 0,
+ 				  NI_NUMERICHOST);
+ 		if (ret) {
+-			error(logopt,
++			error(logopt, MODPREFIX
+ 			      "host address info lookup failed: %s\n",
+ 			      gai_strerror(ret));
+ 			freeaddrinfo(cni);
+@@ -293,7 +293,7 @@ static int match_my_name(unsigned int lo
+ 		ret = getnameinfo(haddr->ai_addr, haddr->ai_addrlen,
+ 				  host, NI_MAXHOST, NULL, 0, 0);
+ 		if (ret) {
+-			error(logopt,
++			error(logopt, MODPREFIX
+ 			      "host address info lookup failed: %s\n",
+ 			      gai_strerror(ret));
+ 			freeaddrinfo(cni);
+@@ -330,7 +330,8 @@ static int eval_selector(unsigned int lo
+ 	case SEL_FLAG_MACRO:
+ 		v = macro_findvar(sv, s->sel->name, strlen(s->sel->name));
+ 		if (!v) {
+-			error(logopt, "failed to get selector %s", s->sel->name);
++			error(logopt, MODPREFIX
++			      "failed to get selector %s", s->sel->name);
+ 			return 0;
+ 		}
+ 
+@@ -499,7 +500,7 @@ static int eval_selector(unsigned int lo
+ 				else
+ 					v = macro_findvar(sv, "hostd", 5);
+ 				if (!v || !*v->val) {
+-					error(logopt,
++					error(logopt, MODPREFIX
+ 					     "failed to get value of ${host}");
+ 					break;
+ 				}
+@@ -666,7 +667,8 @@ static char *normalize_hostname(unsigned
+ 
+ 		ret = getaddrinfo(host, NULL, &hints, &ni);
+ 		if (ret) {
+-			error(logopt, "hostname lookup failed: %s", gai_strerror(ret));
++			error(logopt, MODPREFIX
++			      "hostname lookup failed: %s", gai_strerror(ret));
+ 			return NULL;
+ 		}
+ 		name = strdup(ni->ai_canonname);
+@@ -1302,7 +1304,7 @@ static unsigned int validate_generic_opt
+ 			 * Can't use entry->type as the mount type to reprot
+ 			 * the error since entry->type == "bind" not "lofs".
+ 			 */
+-			error(logopt, "lofs: mount device not given");
++			error(logopt, MODPREFIX "lofs: mount device not given");
+ 			return 0;
+ 		} else if (!*entry->rfs)
+ 			return 0;
+@@ -1575,7 +1577,7 @@ static int match_selectors(unsigned int
+ 
+ 	/* No selectors, always match */
+ 	if (!s) {
+-		debug(logopt, "no selectors found in location");
++		debug(logopt, MODPREFIX "no selectors found in location");
+ 		return 1;
+ 	}
+ 
+@@ -2000,7 +2002,8 @@ int parse_mount(struct autofs_point *ap,
+ 	free_amd_entry(cur_defaults);
+ 
+ 	if (rv)
+-		debug(ap->logopt, "no more locations to try, returning fail");
++		debug(ap->logopt, MODPREFIX
++		      "no more locations to try, returning fail");
+ done:
+ 	free_amd_entry_list(&entries);
+ 	free_amd_entry(defaults_entry);
diff --git a/SOURCES/autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch b/SOURCES/autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch
index e4ae4e7..b765d57 100644
--- a/SOURCES/autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch
+++ b/SOURCES/autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch
@@ -17,10 +17,10 @@ Signed-off-by: Ian Kent <raven@themaw.net>
 
 --- autofs-5.0.7.orig/CHANGELOG
 +++ autofs-5.0.7/CHANGELOG
-@@ -252,6 +252,7 @@
- - add congigure option for limiting getgrgid_r() stack usage.
- - fix unset tsd group name handling.
- - revert fix argc off by one in mount_autofs.c.
+@@ -255,6 +255,7 @@
+ - fix mount.nfs blocks on first mount.
+ - fix typos in autofs man pages.
+ - fix some man page problems.
 +- allow dot in OPTIONSTR value lexer pattern.
  
  25/07/2012 autofs-5.0.7
diff --git a/SOURCES/autofs-5.1.3-be-silent-about-nis-domain-not-set.patch b/SOURCES/autofs-5.1.3-be-silent-about-nis-domain-not-set.patch
new file mode 100644
index 0000000..c07ce34
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-be-silent-about-nis-domain-not-set.patch
@@ -0,0 +1,47 @@
+autofs-5.1.3 - be silent about nis domain not set
+
+From: Ian Kent <raven@themaw.net>
+
+When initializing the lookup module for NIS or NISPLUS if the domain
+is found to be not set then the service is not configured.
+
+So be silent about the failure.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                |    1 +
+ modules/lookup_nisplus.c |    1 -
+ modules/lookup_yp.c      |    2 --
+ 3 files changed, 1 insertion(+), 3 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -261,6 +261,7 @@
+ - fix nisplus lookup init not configured check.
+ - make open_lookup() error handling more consistent.
+ - be silent about sss library not found.
++- be silent about nis domain not set.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/lookup_nisplus.c
++++ autofs-5.0.7/modules/lookup_nisplus.c
+@@ -49,7 +49,6 @@ static int do_init(const char *mapfmt,
+ 	 */
+ 	ctxt->domainname = nis_local_directory();
+ 	if (!ctxt->domainname || !strcmp(ctxt->domainname, "(none).")) {
+-		logmsg(MODPREFIX "NIS+ domain not set");
+ 		ret = 1;
+ 		goto out;
+ 	}
+--- autofs-5.0.7.orig/modules/lookup_yp.c
++++ autofs-5.0.7/modules/lookup_yp.c
+@@ -127,8 +127,6 @@ static int do_init(const char *mapfmt,
+ 		/* This should, but doesn't, take a const char ** */
+ 		err = yp_get_default_domain(&domainname);
+ 		if (err) {
+-			logerr(MODPREFIX
+-			      "map %s: %s", ctxt->mapname, yperr_string(err));
+ 			ret = 1;
+ 			goto out;
+ 		}
diff --git a/SOURCES/autofs-5.1.3-be-silent-about-sss-library-not-found.patch b/SOURCES/autofs-5.1.3-be-silent-about-sss-library-not-found.patch
new file mode 100644
index 0000000..0ee500d
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-be-silent-about-sss-library-not-found.patch
@@ -0,0 +1,40 @@
+autofs-5.1.3 - be silent about sss library not found
+
+From: Ian Kent <raven@themaw.net>
+
+When sss is set as an nsswitch source but the sss autofs shared library
+isn't found then sssd is probably not installed so it's essentially an
+unconfigured source.
+
+So be silent about the library not being found.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG            |    1 +
+ modules/lookup_sss.c |    4 +---
+ 2 files changed, 2 insertions(+), 3 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -260,6 +260,7 @@
+ - only take master map mutex for master map update.
+ - fix nisplus lookup init not configured check.
+ - make open_lookup() error handling more consistent.
++- be silent about sss library not found.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/lookup_sss.c
++++ autofs-5.0.7/modules/lookup_sss.c
+@@ -74,10 +74,8 @@ static int open_sss_lib(struct lookup_co
+ 	}
+ 
+ 	dh = dlopen(dlbuf, RTLD_LAZY);
+-	if (!dh) {
+-		logerr(MODPREFIX "failed to open %s: %s", dlbuf, dlerror());
++	if (!dh)
+ 		return 1;
+-	}
+ 	ctxt->dlhandle = dh;
+ 
+ 	ctxt->setautomntent = (setautomntent_t) dlsym(dh, "_sss_setautomntent");
diff --git a/SOURCES/autofs-5.1.3-fix-a-couple-of-typos-in-autofs-man-pages.patch b/SOURCES/autofs-5.1.3-fix-a-couple-of-typos-in-autofs-man-pages.patch
new file mode 100644
index 0000000..7b9cdf5
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-a-couple-of-typos-in-autofs-man-pages.patch
@@ -0,0 +1,45 @@
+autofs-5.1.3 - fix typos in autofs man pages
+
+From: Ian Kent <raven@themaw.net>
+
+Add missing section in the title of the autofs.conf(5) man page
+and fix a duplicated i in file system types description of autofs(5).
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+Reported-by: Roland Hopferwieser <rhopfer@ica.jku.at>
+---
+ CHANGELOG            |    1 +
+ man/autofs.5         |    2 +-
+ man/autofs.conf.5.in |    2 +-
+ 3 files changed, 3 insertions(+), 2 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -253,6 +253,7 @@
+ - fix unset tsd group name handling.
+ - set systemd KillMode to process.
+ - fix mount.nfs blocks on first mount.
++- fix typos in autofs man pages.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/man/autofs.5
++++ autofs-5.0.7/man/autofs.5
+@@ -447,7 +447,7 @@ This is the mount filesystem \fBtype\fP.
+ It can have a value of
+ .BR auto ", " link ", " linkx ", " host ", " lofs ", " ext2-4 ", "
+ .BR xfs ", " nfs ", " nfsl " or " cdfs "."
+-Other types that are not yet implemented or are not available iin autofs are
++Other types that are not yet implemented or are not available in autofs are
+ .BR nfsx ", " lustre ", " jfs ", " program ", " cachefs " and " direct "."
+ .TP
+ .B maptype
+--- autofs-5.0.7.orig/man/autofs.conf.5.in
++++ autofs-5.0.7/man/autofs.conf.5.in
+@@ -1,5 +1,5 @@
+ .\" t
+-.TH AUTOFS.CONF "23 Jan 2014"
++.TH AUTOFS.CONF 5 "23 Jan 2014"
+ .SH NAME
+ autofs.conf \- autofs configuration
+ .SH "DESCRIPTION"
diff --git a/SOURCES/autofs-5.1.3-fix-amd-defaults-map-entry-handling.patch b/SOURCES/autofs-5.1.3-fix-amd-defaults-map-entry-handling.patch
new file mode 100644
index 0000000..5aa0a5d
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-amd-defaults-map-entry-handling.patch
@@ -0,0 +1,189 @@
+autofs-5.1.3 - fix amd defaults map entry handling
+
+From: Ian Kent <raven@themaw.net>
+
+When parsing an amd map entry the map entry defaults were not being
+handled properly.
+
+A "-" in the map entry requires a reset to defaults, which wasn't being
+done.
+
+A "-<map options>" in the map entry requires merging the <map options>
+with the current defaults map entry, which was also not being done
+properly.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ modules/parse_amd.c |  109 +++++++++++++++++++++++++++++++++-------------------
+ 2 files changed, 72 insertions(+), 38 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -272,6 +272,7 @@
+ - add missing MODPREFIX to logging in amd parser.
+ - fix symlink false negative in umount_multi().
+ - remove expand_selectors() on amd parser entry.
++- fix amd defaults map entry handling.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -1832,45 +1832,24 @@ out:
+ 	return make_default_entry(ap, sv);
+ }
+ 
+-int parse_mount(struct autofs_point *ap, const char *name,
+-		int name_len, const char *mapent, void *context)
++static struct amd_entry *setup_defaults(struct autofs_point *ap,
++					const char *name, int name_len,
++					struct map_source *source,
++					struct substvar **sv)
+ {
+-	struct parse_context *ctxt = (struct parse_context *) context;
+-	unsigned int flags = conf_amd_get_flags(ap->path);
+-	struct substvar *sv = NULL;
+-	struct map_source *source;
++	struct amd_entry *defaults_entry;
+ 	struct mapent_cache *mc;
+ 	struct mapent *me;
+-	unsigned int at_least_one;
+-	struct list_head entries, *p, *head;
+-	struct amd_entry *defaults_entry;
+-	struct amd_entry *cur_defaults;
++	struct substvar *nsv;
+ 	char *defaults;
+-	int len, rv = 1;
+-	int cur_state;
+-	int ret;
+-
+-	source = ap->entry->current;
+-	ap->entry->current = NULL;
+-	master_source_current_signal(ap->entry);
+ 
+ 	mc = source->mc;
++	defaults = NULL;
++	defaults_entry = NULL;
+ 
+-	if (!mapent) {
+-		warn(ap->logopt, MODPREFIX "error: empty map entry");
+-		return 1;
+-	}
+-
+-	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
+-
+-	sv = add_lookup_vars(ap, name, name_len, source, sv);
+-	if (!sv) {
+-		macro_free_table(sv);
+-		pthread_setcancelstate(cur_state, NULL);
+-		return 1;
+-	}
+-
+-	pthread_setcancelstate(cur_state, NULL);
++	nsv = add_lookup_vars(ap, name, name_len, source, NULL);
++	if (!nsv)
++		goto done;
+ 
+ 	defaults = conf_amd_get_map_defaults(ap->path);
+ 	if (defaults) {
+@@ -1885,22 +1864,63 @@ int parse_mount(struct autofs_point *ap,
+ 			char buf[MAX_ERR_BUF];
+ 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ 			error(ap->logopt, MODPREFIX "malloc: %s", estr);
++			macro_free_table(nsv);
++			nsv = NULL;
++			goto done;
+ 		}
+ 	}
+ 
+-	defaults_entry = get_defaults_entry(ap, defaults, sv);
++	defaults_entry = get_defaults_entry(ap, defaults, nsv);
+ 	if (!defaults_entry) {
+ 		error(ap->logopt, MODPREFIX "failed to get a defaults entry");
+-		if (defaults)
+-			free(defaults);
+-		macro_free_table(sv);
+-		return 1;
++		macro_free_table(nsv);
++		nsv = NULL;
+ 	}
++done:
+ 	if (defaults)
+ 		free(defaults);
++	if (*sv)
++		macro_free_table(*sv);
++	*sv = nsv;
++
++	return defaults_entry;
++}
++
++int parse_mount(struct autofs_point *ap, const char *name,
++		int name_len, const char *mapent, void *context)
++{
++	struct parse_context *ctxt = (struct parse_context *) context;
++	unsigned int flags = conf_amd_get_flags(ap->path);
++	struct substvar *sv = NULL;
++	struct map_source *source;
++	unsigned int at_least_one;
++	struct list_head entries, *p, *head;
++	struct amd_entry *defaults_entry;
++	struct amd_entry *cur_defaults;
++	int rv = 1;
++	int cur_state;
++	int ret;
++
++	source = ap->entry->current;
++	ap->entry->current = NULL;
++	master_source_current_signal(ap->entry);
++
++	if (!mapent) {
++		warn(ap->logopt, MODPREFIX "error: empty map entry");
++		return 1;
++	}
+ 
+ 	INIT_LIST_HEAD(&entries);
+ 
++	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
++
++	defaults_entry = setup_defaults(ap, name, name_len, source, &sv);
++	if (!defaults_entry) {
++		error(ap->logopt, MODPREFIX
++		      "failed to setup defaults entry");
++		goto done;
++	}
++
+ 	ret = amd_parse_list(ap, mapent, &entries, &sv);
+ 	if (ret) {
+ 		error(ap->logopt,
+@@ -1931,9 +1951,20 @@ int parse_mount(struct autofs_point *ap,
+ 			free_amd_entry(cur_defaults);
+ 			list_del_init(&this->list);
+ 			cur_defaults = this;
++			update_with_defaults(defaults_entry, cur_defaults, sv);
+ 			continue;
+ 		} else if (this->flags & AMD_DEFAULTS_RESET) {
+-			struct amd_entry *new;
++			struct amd_entry *nd, *new;
++			struct substvar *nsv = NULL;
++
++			nd = setup_defaults(ap, name, name_len, source, &nsv);
++			if (nd) {
++				free_amd_entry(defaults_entry);
++				defaults_entry = nd;
++				macro_free_table(sv);
++				sv = nsv;
++			}
++
+ 			new = dup_defaults_entry(defaults_entry);
+ 			if (new) {
+ 				free_amd_entry(cur_defaults);
+@@ -1999,6 +2030,8 @@ done:
+ 	free_amd_entry(defaults_entry);
+ 	macro_free_table(sv);
+ 
++	pthread_setcancelstate(cur_state, NULL);
++
+ 	return rv;
+ }
+ 
diff --git a/SOURCES/autofs-5.1.3-fix-amd-parser-double-quote-handling.patch b/SOURCES/autofs-5.1.3-fix-amd-parser-double-quote-handling.patch
new file mode 100644
index 0000000..f0e2fce
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-amd-parser-double-quote-handling.patch
@@ -0,0 +1,266 @@
+autofs-5.1.3 - fix amd parser double quote handling
+
+From: Ian Kent <raven@themaw.net>
+
+While the natuaral usage of amd maps doesn't use double quotes
+it is allowed to use them to enclose option values.
+
+The options mount, umount and unmount usually require them to
+preserve spaces in the option value.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ modules/amd_parse.y |  150 ++++++++++++++++++++++++++++++++++++++++++++--------
+ modules/amd_tok.l   |    4 +
+ 3 files changed, 132 insertions(+), 23 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -274,6 +274,7 @@
+ - remove expand_selectors() on amd parser entry.
+ - fix amd defaults map entry handling.
+ - refactor amd_parse.c.
++- fix amd parser double quote handling.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -99,6 +99,7 @@ static int amd_fprintf(FILE *, char *, .
+ %token CUT
+ %token NOT_EQUAL
+ %token COMMA
++%token QUOTE
+ %token OPTION_ASSIGN
+ %token LBRACKET
+ %token RBRACKET
+@@ -268,62 +269,114 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 	}
+ 	| MAP_OPTION OPTION_ASSIGN FS_OPT_VALUE
+ 	{
+-		if (!strcmp($1, "fs"))
+-			entry.fs = amd_strdup($3);
+-		else if (!strcmp($1, "sublink"))
+-			entry.sublink = amd_strdup($3);
+-		else if (!strcmp($1, "pref")) {
+-			if (!strcmp($3, "null"))
+-				entry.pref = amd_strdup("");
+-			else
+-				entry.pref = amd_strdup($3);
++		/* Quoted value for type, maptype or cache assign */
++		if (!strcmp($1, "type")) {
++			if (!match_map_option_fs_type($1, $3))
++				YYABORT;
++		} else if (!strcmp($1, "maptype")) {
++			if (!match_map_option_map_type($1, $3))
++				YYABORT;
++		} else if (!strcmp($1, "cache")) {
++			if (!match_map_option_cache_option($3))
++				YYABORT;
+ 		} else {
+-			amd_notify($1);
+-			YYABORT;
++			char *fs_opt_val;
++
++			fs_opt_val = amd_strdup($3);
++			if (!fs_opt_val) {
++				amd_notify($3);
++				YYABORT;
++			}
++
++			if (!strcmp($1, "fs"))
++				entry.fs = fs_opt_val;
++			else if (!strcmp($1, "sublink")) {
++				entry.sublink = fs_opt_val;
++			} else if (!strcmp($1, "pref")) {
++				if (strcmp(fs_opt_val, "null"))
++					entry.pref = fs_opt_val;
++				else {
++					entry.pref = amd_strdup("");
++					if (!entry.pref) {
++						amd_notify($3);
++						free(fs_opt_val);
++						YYABORT;
++					}
++					free(fs_opt_val);
++				}
++			} else {
++				amd_notify($1);
++				free(fs_opt_val);
++				YYABORT;
++			}
+ 		}
+ 	}
+ 	| MAP_OPTION OPTION_ASSIGN
+ 	{
+-		if (!strcmp($1, "fs"))
++		if (!strcmp($1, "fs")) {
+ 			entry.fs = amd_strdup("");
+-		else {
++			if (!entry.fs) {
++				amd_notify($1);
++				YYABORT;
++			}
++		} else {
+ 			amd_notify($1);
+ 			YYABORT;
+ 		}
+ 	}
+ 	| FS_OPTION OPTION_ASSIGN FS_OPT_VALUE
+ 	{
++		char *fs_opt_val;
++
++		fs_opt_val = amd_strdup($3);
++		if (!fs_opt_val) {
++			amd_notify($1);
++			YYABORT;
++		}
++
+ 		if (!strcmp($1, "rhost"))
+-			entry.rhost = amd_strdup($3);
++			entry.rhost = fs_opt_val;
+ 		else if (!strcmp($1, "rfs"))
+-			entry.rfs = amd_strdup($3);
++			entry.rfs = fs_opt_val;
+ 		else if (!strcmp($1, "dev"))
+-			entry.dev = amd_strdup($3);
++			entry.dev = fs_opt_val;
+ 		else if (!strcmp($1, "mount") ||
+ 			 !strcmp($1, "unmount") ||
+ 			 !strcmp($1, "umount")) {
+ 			amd_info("file system type program is not "
+ 				 "yet implemented, option ignored");
++			free(fs_opt_val);
+ 			YYABORT;
+ 		} else if (!strcmp($1, "delay") ||
+ 			   !strcmp($1, "cachedir")) {
+ 			sprintf(msg_buf, "option %s is not used by autofs", $1);
+ 			amd_info(msg_buf);
++			free(fs_opt_val);
+ 		} else {
+ 			amd_notify($1);
++			free(fs_opt_val);
+ 			YYABORT;
+ 		}
+ 	}
+ 	| FS_OPTION OPTION_ASSIGN
+ 	{
++		char *empty;
++
++		empty = amd_strdup("");
++		if (!empty) {
++			amd_notify($1);
++			YYABORT;
++		}
++
+ 		if (!strcmp($1, "rhost"))
+-			entry.rhost = amd_strdup("");
++			entry.rhost = empty;
+ 		else if (!strcmp($1, "rfs"))
+-			entry.rfs = amd_strdup("");
++			entry.rfs = empty;
+ 		else if (!strcmp($1, "dev"))
+-			entry.dev = amd_strdup("");
++			entry.dev = empty;
+ 		else {
+ 			amd_notify($1);
++			free(empty);
+ 			YYABORT;
+ 		}
+ 	}
+@@ -335,6 +388,14 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 		}
+ 		memset(opts, 0, sizeof(opts));
+ 	}
++	| MNT_OPTION OPTION_ASSIGN QUOTE options QUOTE
++	{
++		if (!match_mnt_option_options($1, $4)) {
++			amd_notify($1);
++			YYABORT;
++		}
++		memset(opts, 0, sizeof(opts));
++	}
+ 	| MNT_OPTION OPTION_ASSIGN
+ 	{
+ 		memset(opts, 0, sizeof(opts));
+@@ -601,11 +662,56 @@ static int amd_fprintf(FILE *f, char *ms
+ 
+ static char *amd_strdup(char *str)
+ {
++	unsigned int quoted, len;
+ 	char *tmp;
+ 
+-	tmp = strdup(str);
+-	if (!tmp)
+-		amd_error("memory allocation error");
++	len = strlen(str);
++	quoted = 0;
++
++	if (*str == '"') {
++		quoted = 1;
++		len -= 2;
++	}
++
++	tmp = strdup(str + quoted);
++	if (!tmp) {
++		amd_msg("memory allocation error");
++		return NULL;
++	} else {
++		unsigned int squote;
++		char *ptr;
++
++		if (quoted) {
++			if (tmp[len] != '"') {
++				sprintf(msg_buf,
++					"unmatched double quote near: %s", str);
++				amd_info(msg_buf);
++				free(tmp);
++				return NULL;
++			}
++			tmp[len] = 0;
++		}
++
++		/* Check for matching single quotes */
++		if (!strchr(tmp, 39))
++			goto done;
++
++		ptr = tmp;
++		squote = 0;
++		while (*ptr) {
++			if (*ptr == 39)
++				squote = !squote;
++			ptr++;
++		}
++		if (squote) {
++			sprintf(msg_buf,
++				"unmatched single quote near: %s", str);
++			amd_info(msg_buf);
++			free(tmp);
++			return NULL;
++		}
++	}
++done:
+ 	return tmp;
+ }
+ 
+--- autofs-5.0.7.orig/modules/amd_tok.l
++++ autofs-5.0.7/modules/amd_tok.l
+@@ -94,7 +94,7 @@ IP6ADDR		((([A-Fa-f0-9]{1,4}\:\:?){1,7}[
+ V6MASK		(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[1-9])
+ 
+ FOPT		(({QSTR}|{FSTR}|{MACRO})+)
+-OPTS		({OSTR}(=({VSTR}|{QSTR}|{MACRO})+)?)
++OPTS		({OSTR}(=({VSTR}|{MACRO})+)?)
+ SOPT		(({SSTR}|{QSTR}|{MACRO})+)
+ NOPT		({SSTR}|(({IP4ADDR}(\/{V4MASK})?)|({IP6ADDR}(\/{V6MASK})?)))
+ 
+@@ -288,6 +288,8 @@ CUTSEP		(\|\||\/)
+ 
+ 	,+ { return COMMA; }
+ 
++	"\"" { return QUOTE; }
++
+ 	{OPTS} {
+ 		amd_copy_buffer();
+ 		return OPTION;
diff --git a/SOURCES/autofs-5.1.3-fix-expandamdent-quote-handling.patch b/SOURCES/autofs-5.1.3-fix-expandamdent-quote-handling.patch
new file mode 100644
index 0000000..b1fa04d
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-expandamdent-quote-handling.patch
@@ -0,0 +1,87 @@
+autofs-5.1.3 - fix expandamdent() quote handling
+
+From: Ian Kent <raven@themaw.net>
+
+The amd map entry option value expansion isn't quite right.
+
+It shouldn't be possible to get double quotes in a map entry option
+value, only single quotes should be seen. And within single quotes
+only expand ${} macros.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG        |    1 +
+ lib/parse_subs.c |   23 ++++++-----------------
+ 2 files changed, 7 insertions(+), 17 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -275,6 +275,7 @@
+ - fix amd defaults map entry handling.
+ - refactor amd_parse.c.
+ - fix amd parser double quote handling.
++- fix expandamdent() quote handling.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/lib/parse_subs.c
++++ autofs-5.0.7/lib/parse_subs.c
+@@ -1028,12 +1028,12 @@ static char *expand_slash_or_dot(char *s
+  * $-expand an amd-style map entry and return the length of the entry.
+  * If "dst" is NULL, just count the length.
+  */
+-/* TODO: how should quoting be handled? */
+ int expandamdent(const char *src, char *dst, const struct substvar *svc)
+ {
+ 	unsigned int flags = conf_amd_get_flags(NULL);
+ 	const struct substvar *sv;
+ 	const char *o_src = src;
++	unsigned int squote = 0;
+ 	int len, l;
+ 	const char *p;
+ 	char ch;
+@@ -1104,7 +1104,7 @@ int expandamdent(const char *src, char *
+ 			break;
+ 
+ 		case '\\':
+-			if (!(flags & CONF_NORMALIZE_SLASHES)) {
++			if (squote || !(flags & CONF_NORMALIZE_SLASHES)) {
+ 				len++;
+ 				if (dst)
+ 					*dst++ = ch;
+@@ -1124,7 +1124,7 @@ int expandamdent(const char *src, char *
+ 			if (dst)
+ 				*dst++ = ch;
+ 
+-			if (!(flags & CONF_NORMALIZE_SLASHES))
++			if (squote || !(flags & CONF_NORMALIZE_SLASHES))
+ 				break;
+ 
+ 			/* Double slash at start is allowed */
+@@ -1138,23 +1138,12 @@ int expandamdent(const char *src, char *
+ 				src++;
+ 			break;
+ 
+-		case '"':
++		/* 39 is single quote */
++		case 39:
+ 			len++;
+ 			if (dst)
+ 				*dst++ = ch;
+-
+-			while (*src && *src != '"') {
+-				len++;
+-				if (dst)
+-					*dst++ = *src;
+-				src++;
+-			}
+-			if (*src) {
+-				len++;
+-				if (dst)
+-					*dst++ = *src;
+-				src++;
+-			}
++			squote = !squote;
+ 			break;
+ 
+ 		default:
diff --git a/SOURCES/autofs-5.1.3-fix-incorrect-check-in-validate_program_options.patch b/SOURCES/autofs-5.1.3-fix-incorrect-check-in-validate_program_options.patch
new file mode 100644
index 0000000..61feb91
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-incorrect-check-in-validate_program_options.patch
@@ -0,0 +1,34 @@
+autofs-5.1.3 - fix incorrect check in validate_program_options()
+
+From: Ian Kent <raven@themaw.net>
+
+Fix incorrectly checking *entry->fs when entry->fs is NULL in
+validate_program_options().
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -284,6 +284,7 @@
+ - add amd mount type program mount support.
+ - fix memory leak in umount_amd_ext_mount().
+ - fix strerror_r() parameter declaration in do program_mount().
++- fix incorrect check in validate_program_options().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -1477,7 +1477,7 @@ static unsigned int validate_program_opt
+ 		return 0;
+ 	}
+ 
+-	if (!entry->fs && !*entry->fs) {
++	if (!entry->fs || !*entry->fs) {
+ 		error(logopt, MODPREFIX
+ 		    "%s: ${fs} must be used as the mount point but is not set",
+ 		    entry->type);
diff --git a/SOURCES/autofs-5.1.3-fix-memory-leak-in-umount_amd_ext_mount.patch b/SOURCES/autofs-5.1.3-fix-memory-leak-in-umount_amd_ext_mount.patch
new file mode 100644
index 0000000..41f163b
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-memory-leak-in-umount_amd_ext_mount.patch
@@ -0,0 +1,43 @@
+autofs-5.1.3 - fix memory leak in umount_amd_ext_mount()
+
+From: Ian Kent <raven@themaw.net>
+
+Free allocated resources before returning success if mount is
+found to be in use by another user.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG    |    1 +
+ lib/mounts.c |    4 ++--
+ 2 files changed, 3 insertions(+), 2 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -282,6 +282,7 @@
+ - add function ext_mount_inuse().
+ - add function construct_argv().
+ - add amd mount type program mount support.
++- fix memory leak in umount_amd_ext_mount().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -2076,7 +2076,7 @@ int umount_amd_ext_mount(struct autofs_p
+ 
+ 		if (!ext_mount_remove(&entry->ext_mount, entry->fs)) {
+ 			rv =0;
+-			goto out;
++			goto out_free;
+ 		}
+ 
+ 		rv = spawnv(ap->logopt, prog, (const char * const *) argv);
+@@ -2089,7 +2089,7 @@ int umount_amd_ext_mount(struct autofs_p
+ 			      "umounted program mount at %s", entry->fs);
+ 			rmdir_path(ap, entry->fs, ap->dev);
+ 		}
+-
++out_free:
+ 		free_argv(argc, (const char **) argv);
+ 		free(str);
+ 
diff --git a/SOURCES/autofs-5.1.3-fix-mount_nfs-blocks-on-first-mount.patch b/SOURCES/autofs-5.1.3-fix-mount_nfs-blocks-on-first-mount.patch
new file mode 100644
index 0000000..6ba96a5
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-mount_nfs-blocks-on-first-mount.patch
@@ -0,0 +1,39 @@
+autofs-5.1.3 - fix mount.nfs blocks on first mount
+
+From: Ian Kent <raven@themaw.net>
+
+The first time an NFS mount is tried mount.nfs tries to start rpc.statd
+using systemctl. If /usr/local is being used to provide automounts in
+that directory the first mount will hang becuase some directories under
+/usr/local are included in the path used by systemctl.
+
+Add rpc-statd.service (and for good measure rpcbind.service) to the
+autofs Wants line in the unit file to work around this.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                 |    1 +
+ samples/autofs.service.in |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -252,6 +252,7 @@
+ - add congigure option for limiting getgrgid_r() stack usage.
+ - fix unset tsd group name handling.
+ - set systemd KillMode to process.
++- fix mount.nfs blocks on first mount.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/samples/autofs.service.in
++++ autofs-5.0.7/samples/autofs.service.in
+@@ -1,7 +1,7 @@
+ [Unit]
+ Description=Automounts filesystems on demand
+ After=network.target ypbind.service sssd.service network-online.target remote-fs.target
+-Wants=network-online.target
++Wants=network-online.target rpc-statd.service rpcbind.service
+ 
+ [Service]
+ Type=forking
diff --git a/SOURCES/autofs-5.1.3-fix-nisplus-lookup-init-not-configured-check.patch b/SOURCES/autofs-5.1.3-fix-nisplus-lookup-init-not-configured-check.patch
new file mode 100644
index 0000000..6ccea45
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-nisplus-lookup-init-not-configured-check.patch
@@ -0,0 +1,34 @@
+autofs-5.1.3 - fix nisplus lookup init not configured check
+
+From: Ian Kent <raven@themaw.net>
+
+If nisplus is not configured nis_local_directory() can return the domain
+name "(none).".
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                |    1 +
+ modules/lookup_nisplus.c |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -258,6 +258,7 @@
+ - allow dot in OPTIONSTR value lexer pattern.
+ - revert fix argc off by one in mount_autofs.c.
+ - only take master map mutex for master map update.
++- fix nisplus lookup init not configured check.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/lookup_nisplus.c
++++ autofs-5.0.7/modules/lookup_nisplus.c
+@@ -48,7 +48,7 @@ static int do_init(const char *mapfmt,
+ 	 * We don't need to copy or free it.
+ 	 */
+ 	ctxt->domainname = nis_local_directory();
+-	if (!ctxt->domainname) {
++	if (!ctxt->domainname || !strcmp(ctxt->domainname, "(none).")) {
+ 		logmsg(MODPREFIX "NIS+ domain not set");
+ 		ret = 1;
+ 		goto out;
diff --git a/SOURCES/autofs-5.1.3-fix-open-calls-not-using-open_xxxx-calls.patch b/SOURCES/autofs-5.1.3-fix-open-calls-not-using-open_xxxx-calls.patch
new file mode 100644
index 0000000..d4a5a4f
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-open-calls-not-using-open_xxxx-calls.patch
@@ -0,0 +1,46 @@
+autofs-5.1.3 - fix open calls not using open_xxxx() calls
+
+From: Ian Kent <raven@themaw.net>
+
+Fix a couple of remaining open descriptor calls to use the autofs
+open_xxxx() calls.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG          |    1 +
+ daemon/automount.c |    2 +-
+ lib/mounts.c       |    2 +-
+ 3 files changed, 3 insertions(+), 2 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -286,6 +286,7 @@
+ - fix strerror_r() parameter declaration in do program_mount().
+ - fix incorrect check in validate_program_options().
+ - update configure to check for pipe2(2).
++- fix open calls not using open_xxxx() calls.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/automount.c
++++ autofs-5.0.7/daemon/automount.c
+@@ -981,7 +981,7 @@ static int set_log_priority(const char *
+ 	 * Specify O_NONBLOCK so that the open will fail if there is no
+ 	 * daemon reading from the other side of the FIFO.
+ 	 */
+-	fd = open(fifo_name, O_WRONLY|O_NONBLOCK);
++	fd = open_fd(fifo_name, O_WRONLY|O_NONBLOCK);
+ 	if (fd < 0) {
+ 		fprintf(stderr, "%s: open of %s failed with %s\n",
+ 			__FUNCTION__, fifo_name, strerror(errno));
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -222,7 +222,7 @@ int check_nfs_mount_version(struct nfs_m
+ 	char *s_ver;
+ 	int cancel_state;
+ 
+-	if (pipe(pipefd))
++	if (open_pipe(pipefd))
+ 		return -1;
+ 
+ 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
diff --git a/SOURCES/autofs-5.1.3-fix-possible-memory-leak-during-amd-parse.patch b/SOURCES/autofs-5.1.3-fix-possible-memory-leak-during-amd-parse.patch
new file mode 100644
index 0000000..a4a570b
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-possible-memory-leak-during-amd-parse.patch
@@ -0,0 +1,246 @@
+autofs-5.1.3 - fix possible memory leak during amd parse
+
+From: Ian Kent <raven@themaw.net>
+
+If an amd map entry option is given more than once subsequent assignment
+could result in a memory leak.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ modules/amd_parse.y |   92 +++++++++++++++++++++++++++++-----------------------
+ 2 files changed, 54 insertions(+), 39 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -276,6 +276,7 @@
+ - refactor amd_parse.c.
+ - fix amd parser double quote handling.
+ - fix expandamdent() quote handling.
++- fix possible memory leak during amd parse.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -41,6 +41,7 @@ extern int amd_lex(void);
+ extern void amd_set_scan_buffer(const char *);
+ 
+ static char *amd_strdup(char *);
++static void amd_set_value(char **, char *);
+ static void local_init_vars(void);
+ static void local_free_vars(void);
+ 
+@@ -289,19 +290,22 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 			}
+ 
+ 			if (!strcmp($1, "fs"))
+-				entry.fs = fs_opt_val;
++				amd_set_value(&entry.fs, fs_opt_val);
+ 			else if (!strcmp($1, "sublink")) {
+-				entry.sublink = fs_opt_val;
++				amd_set_value(&entry.sublink, fs_opt_val);
+ 			} else if (!strcmp($1, "pref")) {
+ 				if (strcmp(fs_opt_val, "null"))
+-					entry.pref = fs_opt_val;
++					amd_set_value(&entry.pref, fs_opt_val);
+ 				else {
+-					entry.pref = amd_strdup("");
+-					if (!entry.pref) {
++					char *empty;
++
++					empty = amd_strdup("");
++					if (!empty) {
+ 						amd_notify($3);
+ 						free(fs_opt_val);
+ 						YYABORT;
+ 					}
++					amd_set_value(&entry.pref, empty);
+ 					free(fs_opt_val);
+ 				}
+ 			} else {
+@@ -314,11 +318,14 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 	| MAP_OPTION OPTION_ASSIGN
+ 	{
+ 		if (!strcmp($1, "fs")) {
+-			entry.fs = amd_strdup("");
+-			if (!entry.fs) {
++			char *empty;
++
++			empty = amd_strdup("");
++			if (!empty) {
+ 				amd_notify($1);
+ 				YYABORT;
+ 			}
++			amd_set_value(&entry.fs, empty);
+ 		} else {
+ 			amd_notify($1);
+ 			YYABORT;
+@@ -335,11 +342,11 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 		}
+ 
+ 		if (!strcmp($1, "rhost"))
+-			entry.rhost = fs_opt_val;
++			amd_set_value(&entry.rhost, fs_opt_val);
+ 		else if (!strcmp($1, "rfs"))
+-			entry.rfs = fs_opt_val;
++			amd_set_value(&entry.rfs, fs_opt_val);
+ 		else if (!strcmp($1, "dev"))
+-			entry.dev = fs_opt_val;
++			amd_set_value(&entry.dev, fs_opt_val);
+ 		else if (!strcmp($1, "mount") ||
+ 			 !strcmp($1, "unmount") ||
+ 			 !strcmp($1, "umount")) {
+@@ -369,11 +376,11 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 		}
+ 
+ 		if (!strcmp($1, "rhost"))
+-			entry.rhost = empty;
++			amd_set_value(&entry.rhost, empty);
+ 		else if (!strcmp($1, "rfs"))
+-			entry.rfs = empty;
++			amd_set_value(&entry.rfs, empty);
+ 		else if (!strcmp($1, "dev"))
+-			entry.dev = empty;
++			amd_set_value(&entry.dev, empty);
+ 		else {
+ 			amd_notify($1);
+ 			free(empty);
+@@ -468,36 +475,27 @@ static int match_map_option_fs_type(char
+ 		return 0;
+ 	}
+ 
+-	if (!strcmp(fs_type, "auto")) {
++	if (!strcmp(fs_type, "auto"))
+ 		entry.flags |= AMD_MOUNT_TYPE_AUTO;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "nfs") ||
+-		   !strcmp(fs_type, "nfs4")) {
++	else if (!strcmp(fs_type, "nfs") ||
++		 !strcmp(fs_type, "nfs4"))
+ 		entry.flags |= AMD_MOUNT_TYPE_NFS;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "nfsl")) {
++	else if (!strcmp(fs_type, "nfsl"))
+ 		entry.flags |= AMD_MOUNT_TYPE_NFSL;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "link")) {
++	else if (!strcmp(fs_type, "link"))
+ 		entry.flags |= AMD_MOUNT_TYPE_LINK;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "linkx")) {
++	else if (!strcmp(fs_type, "linkx"))
+ 		entry.flags |= AMD_MOUNT_TYPE_LINKX;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "host")) {
++	else if (!strcmp(fs_type, "host"))
+ 		entry.flags |= AMD_MOUNT_TYPE_HOST;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "lofs")) {
++	else if (!strcmp(fs_type, "lofs"))
+ 		entry.flags |= AMD_MOUNT_TYPE_LOFS;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "xfs")) {
++	else if (!strcmp(fs_type, "xfs"))
+ 		entry.flags |= AMD_MOUNT_TYPE_XFS;
+-		entry.type = fs_type;
+-	} else if (!strcmp(fs_type, "ext2") ||
++	else if (!strcmp(fs_type, "ext2") ||
+ 		   !strcmp(fs_type, "ext3") ||
+-		   !strcmp(fs_type, "ext4")) {
++		   !strcmp(fs_type, "ext4"))
+ 		entry.flags |= AMD_MOUNT_TYPE_EXT;
+-		entry.type = fs_type;
+ 	} else if (!strcmp(fs_type, "ufs")) {
+ 		entry.flags |= AMD_MOUNT_TYPE_UFS;
+ 		entry.type = conf_amd_get_linux_ufs_mount_type();
+@@ -508,6 +506,7 @@ static int match_map_option_fs_type(char
+ 			return 0;
+ 		}
+ 		free(fs_type);
++		fs_type = NULL;
+ 	} else if (!strcmp(fs_type, "cdfs")) {
+ 		entry.flags |= AMD_MOUNT_TYPE_CDFS;
+ 		entry.type = amd_strdup("iso9660");
+@@ -518,6 +517,7 @@ static int match_map_option_fs_type(char
+ 			return 0;
+ 		}
+ 		free(fs_type);
++		fs_type = NULL;
+ 	} else if (!strcmp(fs_type, "jfs") ||
+ 		   !strcmp(fs_type, "nfsx") ||
+ 		   !strcmp(fs_type, "program") ||
+@@ -534,12 +534,16 @@ static int match_map_option_fs_type(char
+ 				 fs_type);
+ 		amd_msg(msg_buf);
+ 		free(fs_type);
++		fs_type = NULL;
+ 	} else {
+ 		amd_notify(fs_type);
+ 		free(fs_type);
+ 		return 0;
+ 	}
+ 
++	if (fs_type)
++		amd_set_value(&entry.type, fs_type);
++
+ 	return 1;
+ }
+ 
+@@ -558,15 +562,18 @@ static int match_map_option_map_type(cha
+ 	    !strcmp(map_type, "nisplus") ||
+ 	    !strcmp(map_type, "ldap") ||
+ 	    !strcmp(map_type, "hesiod")) {
+-		entry.map_type = map_type;
++		amd_set_value(&entry.map_type, map_type);
+ 	} else if (!strcmp(map_type, "exec")) {
+ 		/* autofs uses "program" for "exec" map type */
+-		entry.map_type = amd_strdup("program");
+-		if (!entry.map_type) {
++		char * tmp;
++
++		tmp = amd_strdup("program");
++		if (!tmp) {
+ 			amd_notify(type);
+ 			free(map_type);
+ 			return 0;
+ 		}
++		amd_set_value(&entry.map_type, tmp);
+ 		free(map_type);
+ 	} else if (!strcmp(map_type, "passwd")) {
+ 		sprintf(msg_buf, "map type %s is "
+@@ -621,17 +628,17 @@ static int match_mnt_option_options(char
+ 		tmp = amd_strdup(options);
+ 		if (!tmp)
+ 			return 0;
+-		entry.opts = tmp;
++		amd_set_value(&entry.opts, tmp);
+ 	} else if (!strcmp(mnt_option, "addopts")) {
+ 		tmp = amd_strdup(options);
+ 		if (!tmp)
+ 			return 0;
+-		entry.addopts = tmp;
++		amd_set_value(&entry.addopts, tmp);
+ 	} else if (!strcmp(mnt_option, "remopts")) {
+ 		tmp = amd_strdup(options);
+ 		if (!tmp)
+ 			return 0;
+-		entry.remopts = tmp;
++		amd_set_value(&entry.remopts, tmp);
+ 	} else
+ 		return 0;
+ 
+@@ -715,6 +722,13 @@ done:
+ 	return tmp;
+ }
+ 
++static void amd_set_value(char **field, char *value)
++{
++	if (*field)
++		free(*field);
++	*field = value;
++}
++
+ static int amd_error(const char *s)
+ {
+ 	if (strcmp(s, "syntax"))
diff --git a/SOURCES/autofs-5.1.3-fix-some-man-problems.patch b/SOURCES/autofs-5.1.3-fix-some-man-problems.patch
new file mode 100644
index 0000000..d724391
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-some-man-problems.patch
@@ -0,0 +1,119 @@
+autofs-5.1.3 - fix some man page problems
+
+From: Ian Kent <raven@themaw.net>
+
+Fix a few problems with the autofs man pages:
+- autofs(8) missing "autofs -" in NAME string.
+- punctuation marks in some SEE ALSO sections.
+- change NAME string to include key word "autofs" in auto.master(5).
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                      |    1 +
+ man/auto.master.5.in           |    4 ++--
+ man/autofs.5                   |    4 ++--
+ man/autofs.8.in                |    8 ++++----
+ man/autofs.conf.5.in           |    2 +-
+ man/autofs_ldap_auth.conf.5.in |    2 +-
+ man/automount.8                |    4 ++--
+ 7 files changed, 13 insertions(+), 12 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -254,6 +254,7 @@
+ - set systemd KillMode to process.
+ - fix mount.nfs blocks on first mount.
+ - fix typos in autofs man pages.
++- fix some man page problems.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/man/auto.master.5.in
++++ autofs-5.0.7/man/auto.master.5.in
+@@ -1,7 +1,7 @@
+ .\" t
+ .TH AUTO.MASTER 5 "11 Apr 2006"
+ .SH NAME
+-auto.master \- Master Map for automounter
++auto.master \- Master Map for automounter consulted by autofs
+ .SH "DESCRIPTION"
+ The
+ .B auto.master
+@@ -362,7 +362,7 @@ configuration will be used to locate the
+ .BR autofs (5),
+ .BR autofs (8),
+ .BR autofs.conf (5),
+-.BR autofs_ldap_auth.conf (5)
++.BR autofs_ldap_auth.conf (5).
+ .SH AUTHOR
+ This manual page was written by Christoph Lameter <chris@waterf.org>,
+ for the Dean GNU/Linux system.  Edited by <hpa@transmeta.com> and
+--- autofs-5.0.7.orig/man/autofs.5
++++ autofs-5.0.7/man/autofs.5
+@@ -596,8 +596,8 @@ to the "local" subdirectory of the exter
+ .BR auto.master (5),
+ .BR autofs (8),
+ .BR autofs.conf (5),
+-.BR mount (8).
+-.BR autofs_ldap_auth.conf (5)
++.BR mount (8),
++.BR autofs_ldap_auth.conf (5).
+ .SH AUTHOR
+ This manual page was written by Christoph Lameter <chris@waterf.org>,
+ for the Debian GNU/Linux system.  Edited by H. Peter Avian
+--- autofs-5.0.7.orig/man/autofs.8.in
++++ autofs-5.0.7/man/autofs.8.in
+@@ -1,6 +1,6 @@
+ .TH AUTOFS 8 "9 Sep 1997"
+ .SH NAME
+-Service control for the automounter
++autofs \- Service control for the automounter
+ .SH SYNOPSIS
+ If a SysV init script system is being used:
+ .br
+@@ -72,9 +72,9 @@ for more information.
+ .BR automount (8),
+ .BR autofs (5),
+ .BR autofs.conf (5),
+-.BR auto.master (5).
+-.BR autofs_ldap_auth.conf (5)
+-.BR systemctl(1)
++.BR auto.master (5),
++.BR autofs_ldap_auth.conf (5),
++.BR systemctl(1).
+ .SH AUTHOR
+ This manual page was written by Christoph Lameter <chris@waterf.org>,
+ for the Debi GNU/Linux system.  Edited by H. Peter Anvin
+--- autofs-5.0.7.orig/man/autofs.conf.5.in
++++ autofs-5.0.7/man/autofs.conf.5.in
+@@ -513,6 +513,6 @@ map_type = file
+ .SH "SEE ALSO"
+ .BR automount (8),
+ .BR auto.master (5),
+-.BR autofs_ldap_auth.conf (5)
++.BR autofs_ldap_auth.conf (5).
+ .SH AUTHOR
+ This manual page was written by Ian Kent <raven@themaw.net>.
+--- autofs-5.0.7.orig/man/autofs_ldap_auth.conf.5.in
++++ autofs-5.0.7/man/autofs_ldap_auth.conf.5.in
+@@ -113,6 +113,6 @@ externally configured credential cache t
+ By default, autofs will setup a memory based credential cache.
+ .SH "SEE ALSO"
+ .BR auto.master (5),
+-.BR autofs.conf (5),
++.BR autofs.conf (5).
+ .SH AUTHOR
+ This manual page was written by Ian Kent <raven@themaw.net>.
+--- autofs-5.0.7.orig/man/automount.8
++++ autofs-5.0.7/man/automount.8
+@@ -178,8 +178,8 @@ constructed has been detached from the m
+ .BR autofs (8),
+ .BR autofs.conf (5),
+ .BR auto.master (5),
+-.BR mount (8).
+-.BR autofs_ldap_auth.conf (5)
++.BR mount (8),
++.BR autofs_ldap_auth.conf (5).
+ .SH BUGS
+ Don't know, I've fixed everything I know about.
+ 
diff --git a/SOURCES/autofs-5.1.3-fix-strerror_r-parameter-declaration-in-do_program_mount.patch b/SOURCES/autofs-5.1.3-fix-strerror_r-parameter-declaration-in-do_program_mount.patch
new file mode 100644
index 0000000..c774279
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-strerror_r-parameter-declaration-in-do_program_mount.patch
@@ -0,0 +1,36 @@
+autofs-5.1.3 - fix strerror_r() parameter declaration in do program_mount()
+
+From: Ian Kent <raven@themaw.net>
+
+Fix an incorrect declaration for an error message buffer on function
+program_mount().
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |    4 ++--
+ 2 files changed, 3 insertions(+), 2 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -283,6 +283,7 @@
+ - add function construct_argv().
+ - add amd mount type program mount support.
+ - fix memory leak in umount_amd_ext_mount().
++- fix strerror_r() parameter declaration in do program_mount().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -1292,8 +1292,8 @@ static int do_program_mount(struct autof
+ 	} else {
+ 		rv = mkdir_path(entry->fs, 0555);
+ 		if (rv && errno != EEXIST) {
+-			char *buf[MAX_ERR_BUF];
+-			char * estr;
++			char buf[MAX_ERR_BUF];
++			char *estr;
+ 
+ 			estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ 			error(ap->logopt,
diff --git a/SOURCES/autofs-5.1.3-fix-symlink-false-negative-in-umount_multi.patch b/SOURCES/autofs-5.1.3-fix-symlink-false-negative-in-umount_multi.patch
new file mode 100644
index 0000000..b0fbdbc
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-symlink-false-negative-in-umount_multi.patch
@@ -0,0 +1,47 @@
+autofs-5.1.3 - fix symlink false negative in umount_multi()
+
+From: Ian Kent <raven@themaw.net>
+
+Using is_mounted() on a symlink will give a false negative for MNTS_ALL
+since the kernel will return mounted true for a dentry within an autofs
+mount point.
+
+Just remove the check and rely on lstat().
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG          |    1 +
+ daemon/automount.c |    5 -----
+ 2 files changed, 1 insertion(+), 5 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -270,6 +270,7 @@
+ - fix cachefs parse message not being logged.
+ - fix typo in amd_parse.c.
+ - add missing MODPREFIX to logging in amd parser.
++- fix symlink false negative in umount_multi().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/automount.c
++++ autofs-5.0.7/daemon/automount.c
+@@ -640,10 +640,6 @@ int umount_multi(struct autofs_point *ap
+ 
+ 	debug(ap->logopt, "path %s incl %d", path, incl);
+ 
+-	/* If path is a mount it can't be a symlink */
+-	if (is_mounted(_PATH_MOUNTED, path, MNTS_ALL))
+-		goto real_mount;
+-
+ 	if (lstat(path, &st)) {
+ 		warn(ap->logopt,
+ 		     "failed to stat directory or symlink %s", path);
+@@ -688,7 +684,6 @@ int umount_multi(struct autofs_point *ap
+ 		return 0;
+ 	}
+ 
+-real_mount:
+ 	is_autofs_fs = 0;
+ 	if (master_find_submount(ap, path))
+ 		is_autofs_fs = 1;
diff --git a/SOURCES/autofs-5.1.3-fix-typo-in-amd_parse_c.patch b/SOURCES/autofs-5.1.3-fix-typo-in-amd_parse_c.patch
new file mode 100644
index 0000000..9659c86
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-fix-typo-in-amd_parse_c.patch
@@ -0,0 +1,33 @@
+autofs-5.1.3 - fix typo in amd_parse.c
+
+From: Ian Kent <raven@themaw.net>
+
+Fix a typo in the "cachefs" fs type value syntax error message.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/amd_parse.y |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -268,6 +268,7 @@
+ - reset master map list on startup retry.
+ - improve debug logging of lookup key.
+ - fix cachefs parse message not being logged.
++- fix typo in amd_parse.c.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -299,7 +299,7 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 			amd_msg(msg_buf);
+ 			YYABORT;
+ 		} else if (!strcmp($3, "cachefs")) {
+-			sprintf(msg_buf, "file syatem %s is not "
++			sprintf(msg_buf, "file system %s is not "
+ 					 "supported by autofs, ignored", $3);
+ 			amd_msg(msg_buf);
+ 		} else {
diff --git a/SOURCES/autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch b/SOURCES/autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch
index 37508a7..97290d6 100644
--- a/SOURCES/autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch
+++ b/SOURCES/autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch
@@ -16,10 +16,10 @@ Signed-off-by: Ian Kent <raven@themaw.net>
 
 --- autofs-5.0.7.orig/CHANGELOG
 +++ autofs-5.0.7/CHANGELOG
-@@ -253,6 +253,7 @@
- - fix unset tsd group name handling.
- - revert fix argc off by one in mount_autofs.c.
- - allow dot in OPTIONSTR value lexer pattern.
+@@ -263,6 +263,7 @@
+ - be silent about sss library not found.
+ - be silent about nis domain not set.
+ - make map source reference message debug only.
 +- handle additional nfs versions in mount_nfs.c.
  
  25/07/2012 autofs-5.0.7
diff --git a/SOURCES/autofs-5.1.3-improve-debug-logging-of-lookup-key.patch b/SOURCES/autofs-5.1.3-improve-debug-logging-of-lookup-key.patch
new file mode 100644
index 0000000..9dfb71f
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-improve-debug-logging-of-lookup-key.patch
@@ -0,0 +1,210 @@
+autofs-5.1.3 - improve debug logging of lookup key
+
+From: Ian Kent <raven@themaw.net>
+
+When looking up an amd format map key, if there is a prefix it
+will be used in matching the map key.
+
+So print the actual matched key string in debug log output.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                |    1 +
+ modules/lookup_file.c    |   14 ++++++++++----
+ modules/lookup_hesiod.c  |   20 +++++++++++++++++---
+ modules/lookup_ldap.c    |   15 ++++++++++++---
+ modules/lookup_nisplus.c |   15 ++++++++++++---
+ modules/lookup_yp.c      |   43 +++++++++++++++++++++++++------------------
+ 6 files changed, 77 insertions(+), 31 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -266,6 +266,7 @@
+ - handle additional nfs versions in mount_nfs.c.
+ - improve description of mount_nfs_default_protocol.
+ - reset master map list on startup retry.
++- improve debug logging of lookup key.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/lookup_file.c
++++ autofs-5.0.7/modules/lookup_file.c
+@@ -1290,18 +1290,24 @@ do_cache_lookup:
+ 		}
+ 	}
+ 	cache_unlock(mc);
+-	free(lkp_key);
+ 
+-	if (!me)
++	if (!me) {
++		free(lkp_key);
+ 		return NSS_STATUS_NOTFOUND;
++	}
+ 
+-	if (!mapent)
++	if (!mapent) {
++		free(lkp_key);
+ 		return NSS_STATUS_TRYAGAIN;
++	}
++
++	debug(ap->logopt, MODPREFIX "%s -> %s", lkp_key, mapent);
++
++	free(lkp_key);
+ 
+ 	master_source_current_wait(ap->entry);
+ 	ap->entry->current = source;
+ 
+-	debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
+ 	ret = ctxt->parse->parse_mount(ap, key, key_len,
+ 				       mapent, ctxt->parse->context);
+ 	if (ret) {
+--- autofs-5.0.7.orig/modules/lookup_hesiod.c
++++ autofs-5.0.7/modules/lookup_hesiod.c
+@@ -466,14 +466,28 @@ int lookup_mount(struct autofs_point *ap
+ 	}
+ 
+ 	me = match_cached_key(ap, MODPREFIX, source, lkp_key);
+-	free(lkp_key);
+-	if (!me)
++
++	if (!me) {
++		free(lkp_key);
+ 		return NSS_STATUS_NOTFOUND;
++	}
+ 
+-	if (!me->mapent)
++	if (!me->mapent) {
++		free(lkp_key);
+ 		return NSS_STATUS_UNAVAIL;
++	}
+ 
+ 	mapent = strdup(me->mapent);
++	if (!mapent) {
++		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
++		error(ap->logopt, "malloc: %s", estr);
++		free(lkp_key);
++		return NSS_STATUS_UNKNOWN;
++	}
++
++	debug(ap->logopt, MODPREFIX "%s -> %s", lkp_key, mapent);
++
++	free(lkp_key);
+ 
+ 	rv = ctxt->parser->parse_mount(ap, key, key_len,
+ 				       mapent, ctxt->parser->context);
+--- autofs-5.0.7.orig/modules/lookup_ldap.c
++++ autofs-5.0.7/modules/lookup_ldap.c
+@@ -3785,15 +3785,24 @@ int lookup_mount(struct autofs_point *ap
+ 		}
+ 	}
+ 	cache_unlock(mc);
+-	free(lkp_key);
+ 
+-	if (!mapent)
++	if (!me) {
++		free(lkp_key);
++		return NSS_STATUS_NOTFOUND;
++	}
++
++	if (!mapent) {
++		free(lkp_key);
+ 		return NSS_STATUS_TRYAGAIN;
++	}
++
++	debug(ap->logopt, MODPREFIX "%s -> %s", lkp_key, mapent);
++
++	free(lkp_key);
+ 
+ 	master_source_current_wait(ap->entry);
+ 	ap->entry->current = source;
+ 
+-	debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
+ 	ret = ctxt->parse->parse_mount(ap, key, key_len,
+ 				       mapent, ctxt->parse->context);
+ 	if (ret) {
+--- autofs-5.0.7.orig/modules/lookup_nisplus.c
++++ autofs-5.0.7/modules/lookup_nisplus.c
+@@ -824,15 +824,24 @@ int lookup_mount(struct autofs_point *ap
+ 		}
+ 	}
+ 	cache_unlock(mc);
+-	free(lkp_key);
+ 
+-	if (!mapent)
++	if (!me) {
++		free(lkp_key);
++		return NSS_STATUS_NOTFOUND;
++	}
++
++	if (!mapent) {
++		free(lkp_key);
+ 		return NSS_STATUS_TRYAGAIN;
++	}
++
++	debug(ap->logopt, MODPREFIX "%s -> %s", lkp_key, mapent);
++
++	free(lkp_key);
+ 
+ 	master_source_current_wait(ap->entry);
+ 	ap->entry->current = source;
+ 
+-	debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
+ 	ret = ctxt->parse->parse_mount(ap, key, key_len,
+ 				       mapent, ctxt->parse->context);
+ 	if (ret) {
+--- autofs-5.0.7.orig/modules/lookup_yp.c
++++ autofs-5.0.7/modules/lookup_yp.c
+@@ -928,28 +928,35 @@ int lookup_mount(struct autofs_point *ap
+ 		}
+ 	}
+ 	cache_unlock(mc);
++
++	if (!me) {
++		free(lkp_key);
++		return NSS_STATUS_NOTFOUND;
++	}
++
++	if (!mapent) {
++		free(lkp_key);
++		return NSS_STATUS_TRYAGAIN;
++	}
++
++	debug(ap->logopt, MODPREFIX "%s -> %s", lkp_key, mapent);
++
+ 	free(lkp_key);
+ 
+-	if (mapent) {
+-		master_source_current_wait(ap->entry);
+-		ap->entry->current = source;
+-
+-		debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
+-		ret = ctxt->parse->parse_mount(ap, key, key_len,
+-					       mapent, ctxt->parse->context);
+-		if (ret) {
+-			/* Don't update negative cache when re-connecting */
+-			if (ap->flags & MOUNT_FLAG_REMOUNT)
+-				return NSS_STATUS_TRYAGAIN;
+-			cache_writelock(mc);
+-			cache_update_negative(mc, source, key, ap->negative_timeout);
+-			cache_unlock(mc);
+-			return NSS_STATUS_TRYAGAIN;
+-		}
+-	 }
++	master_source_current_wait(ap->entry);
++	ap->entry->current = source;
+ 
+-	if (ret)
++	ret = ctxt->parse->parse_mount(ap, key, key_len,
++				       mapent, ctxt->parse->context);
++	if (ret) {
++		/* Don't update negative cache when re-connecting */
++		if (ap->flags & MOUNT_FLAG_REMOUNT)
++			return NSS_STATUS_TRYAGAIN;
++		cache_writelock(mc);
++		cache_update_negative(mc, source, key, ap->negative_timeout);
++		cache_unlock(mc);
+ 		return NSS_STATUS_TRYAGAIN;
++	}
+ 
+ 	return NSS_STATUS_SUCCESS;
+ }
diff --git a/SOURCES/autofs-5.1.3-improve-description-of-mount_nfs_default_protocol.patch b/SOURCES/autofs-5.1.3-improve-description-of-mount_nfs_default_protocol.patch
new file mode 100644
index 0000000..0dd0c9d
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-improve-description-of-mount_nfs_default_protocol.patch
@@ -0,0 +1,89 @@
+autofs-5.1.3 - improve description of mount_nfs_default_protocol
+
+From: Ian Kent <raven@themaw.net>
+
+The description of the mount_nfs_default_protocol configuration
+option is not clear, it sounds like it's a setting that causes
+autofs to use the specified NFS version as a mount default which
+it doesn't, so try and improve it.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                      |    1 +
+ man/autofs.conf.5.in           |   10 +++++++---
+ redhat/autofs.conf.default.in  |   12 ++++++++----
+ samples/autofs.conf.default.in |   12 ++++++++----
+ 4 files changed, 24 insertions(+), 11 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -264,6 +264,7 @@
+ - be silent about nis domain not set.
+ - make map source reference message debug only.
+ - handle additional nfs versions in mount_nfs.c.
++- improve description of mount_nfs_default_protocol.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/man/autofs.conf.5.in
++++ autofs-5.0.7/man/autofs.conf.5.in
+@@ -62,10 +62,14 @@ Maps are browsable by default (program d
+ .TP
+ .B mount_nfs_default_protocol
+ .br
+-Specify the default protocol used by
++Set the default protocol that
+ .BR mount.nfs (8)
+-(program default 3). Since we can't identify this default automatically
+-we need to set it in the autofs configuration.
++uses when performing a mount (program default 3). Autofs needs to know
++the default NFS protocol that
++.BR mount.nfs(8)
++uses so it can do special case handling for its availability probe for
++different NFS protocols. Since we can't identify this default
++automatically we need to set it in the autofs configuration.
+ .TP
+ .B append_options
+ .br
+--- autofs-5.0.7.orig/redhat/autofs.conf.default.in
++++ autofs-5.0.7/redhat/autofs.conf.default.in
+@@ -44,10 +44,14 @@ timeout = 300
+ #
+ browse_mode = no
+ #
+-# mount_nfs_default_protocol - specify the default protocol used by
+-# 			       mount.nfs(8). Since we can't identify
+-# 			       the default automatically we need to
+-# 			       set it in our configuration.
++# mount_nfs_default_protocol - set the default protocol that mount.nfs(8)
++# 			       uses when performing a mount. Autofs needs
++# 			       to know the default NFS protocol that
++# 			       mount.nfs(8) uses so it can do special case
++# 			       handling for its availability probe for
++# 			       different NFS protocols. Since we can't
++# 			       identify the default automatically we need
++# 			       to set it in our configuration.
+ #
+ #mount_nfs_default_protocol = 3
+ mount_nfs_default_protocol = 4
+--- autofs-5.0.7.orig/samples/autofs.conf.default.in
++++ autofs-5.0.7/samples/autofs.conf.default.in
+@@ -44,10 +44,14 @@ timeout = 300
+ #
+ browse_mode = no
+ #
+-# mount_nfs_default_protocol - specify the default protocol used by
+-# 			       mount.nfs(8). Since we can't identify
+-# 			       the default automatically we need to
+-# 			       set it in our configuration.
++# mount_nfs_default_protocol - set the default protocol that mount.nfs(8)
++#			       uses when performing a mount. Autofs needs
++#			       to know the default NFS protocol that
++#			       mount.nfs(8) uses so it can do special case
++#			       handling for its availability probe for
++#			       different NFS protocols. Since we can't
++#			       identify the default automatically we need
++#			       to set it in our configuration.
+ #
+ #mount_nfs_default_protocol = 3
+ #
diff --git a/SOURCES/autofs-5.1.3-make-map-source-reference-message-debug-only.patch b/SOURCES/autofs-5.1.3-make-map-source-reference-message-debug-only.patch
new file mode 100644
index 0000000..c1e3e87
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-make-map-source-reference-message-debug-only.patch
@@ -0,0 +1,38 @@
+autofs-5.1.3 - make map source reference message debug only
+
+From: Ian Kent <raven@themaw.net>
+
+The message "map source used without taking reference" was added during
+development of an additional amd format map feature.
+
+It appears far too often but hasn't been seen to be a real problem so
+make it a debug only message and postpone deeper investigation until
+later.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG    |    1 +
+ lib/master.c |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -262,6 +262,7 @@
+ - make open_lookup() error handling more consistent.
+ - be silent about sss library not found.
+ - be silent about nis domain not set.
++- make map source reference message debug only.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/lib/master.c
++++ autofs-5.0.7/lib/master.c
+@@ -233,7 +233,7 @@ master_add_map_source(struct master_mape
+ 
+ 		this = __master_find_map_source(entry, type, format, argc, tmpargv);
+ 		if (this) {
+-			error(entry->ap->logopt,
++			debug(entry->ap->logopt,
+ 			      "map source used without taking reference");
+ 			this->age = age;
+ 			master_free_map_source(source, 0);
diff --git a/SOURCES/autofs-5.1.3-make-open_lookup-error-handling-more-consistent.patch b/SOURCES/autofs-5.1.3-make-open_lookup-error-handling-more-consistent.patch
new file mode 100644
index 0000000..89ad1cf
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-make-open_lookup-error-handling-more-consistent.patch
@@ -0,0 +1,98 @@
+autofs-5.1.3 - make open_lookup() error handling more consistent
+
+From: Ian Kent <raven@themaw.net>
+
+If the open of a lookup module fails then open_lookup() should return
+an NSS status that causes the source to be skipped as it is most likely
+due to the map source not being configured.
+
+Currently open_lookup() returns NSS_STATUS_UNAVAIL for failures whereas
+much of the other lookup code returns NSS_STATUS_UNKNOWN for similar
+errors encountered by open_lookup().
+
+But NSS_STATUS_UNAVAIL will result in waiting for the lookup module to
+become avaiable when trying to read the master map at startup even
+though it isn't likely to become available. So NSS_STATUS_UNKNOWN is
+more appropriate becuase that will cause the source to be skipped and
+is used for the same purpose elsewhere.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG       |    1 +
+ daemon/module.c |   14 +++++++-------
+ 2 files changed, 8 insertions(+), 7 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -259,6 +259,7 @@
+ - revert fix argc off by one in mount_autofs.c.
+ - only take master map mutex for master map update.
+ - fix nisplus lookup init not configured check.
++- make open_lookup() error handling more consistent.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/module.c
++++ autofs-5.0.7/daemon/module.c
+@@ -73,7 +73,7 @@ int open_lookup(const char *name, const
+ 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ 			logerr("%s%s", err_prefix, estr);
+ 		}
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	type = strdup(name);
+@@ -83,7 +83,7 @@ int open_lookup(const char *name, const
+ 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ 			logerr("%s%s", err_prefix, estr);
+ 		}
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	size = snprintf(fnbuf, sizeof(fnbuf),
+@@ -95,7 +95,7 @@ int open_lookup(const char *name, const
+ 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ 			logerr("%s%s", err_prefix, estr);
+ 		}
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
+@@ -104,7 +104,7 @@ int open_lookup(const char *name, const
+ 			       err_prefix, name, dlerror());
+ 		free(mod);
+ 		free(type);
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	if (!(ver = (int *) dlsym(dh, "lookup_version"))
+@@ -115,7 +115,7 @@ int open_lookup(const char *name, const
+ 		dlclose(dh);
+ 		free(mod);
+ 		free(type);
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	if (!(mod->lookup_init = (lookup_init_t) dlsym(dh, "lookup_init")) ||
+@@ -129,14 +129,14 @@ int open_lookup(const char *name, const
+ 		dlclose(dh);
+ 		free(mod);
+ 		free(type);
+-		return NSS_STATUS_UNAVAIL;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	if (mod->lookup_init(mapfmt, argc, argv, &mod->context)) {
+ 		dlclose(dh);
+ 		free(mod);
+ 		free(type);
+-		return NSS_STATUS_NOTFOUND;
++		return NSS_STATUS_UNKNOWN;
+ 	}
+ 
+ 	mod->type = type;
diff --git a/SOURCES/autofs-5.1.3-move-open_xxxx-functions-to-spawn_c.patch b/SOURCES/autofs-5.1.3-move-open_xxxx-functions-to-spawn_c.patch
new file mode 100644
index 0000000..0297971
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-move-open_xxxx-functions-to-spawn_c.patch
@@ -0,0 +1,342 @@
+autofs-5.1.3 - move open_xxxx() functions to spawn.c
+
+From: Ian Kent <raven@themaw.net>
+
+In a bug report by John Salmon has described a race between the
+autofs open_xxxx() functions and fork(2) that can cause file handles
+that don't have close on exec set to leak into subprocesses.
+
+Basically, in some cases there can be a finite time between performing
+the open and setting the descriptor close on exec and it's this window
+that leads to the problem.
+
+The description went on to talk about a case where autofs can hang when
+this happens. That is when the leaked decriptor causes poll(2) to not
+return in another process because it is waiting for the decriptor to
+close (on mount completion) but another execed process has the cloned
+descriptor open.
+
+Serializing access to the open_xxxx() functions wrt. to fork(2) calls
+should be suficient to resolve this leakage.
+
+This patch starts this by moving the open_xxxx() out of the automount.h
+include file and into spawn.c.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ daemon/automount.c  |    3 -
+ daemon/spawn.c      |  125 +++++++++++++++++++++++++++++++++++++++++++++++++
+ include/automount.h |  132 ++--------------------------------------------------
+ 4 files changed, 133 insertions(+), 128 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -287,6 +287,7 @@
+ - fix incorrect check in validate_program_options().
+ - update configure to check for pipe2(2).
+ - fix open calls not using open_xxxx() calls.
++- move open_xxxx() functions to spawn.c.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/spawn.c
++++ autofs-5.0.7/daemon/spawn.c
+@@ -49,6 +49,131 @@ void dump_core(void)
+ }
+ 
+ /*
++ * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
++ * socket() if possible.
++ */
++static int cloexec_works = 0;
++
++static void check_cloexec(int fd)
++{
++	if (cloexec_works == 0) {
++		int fl = fcntl(fd, F_GETFD);
++		if (fl != -1)
++			cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
++	}
++	if (cloexec_works > 0)
++		return;
++	fcntl(fd, F_SETFD, FD_CLOEXEC);
++	return;
++}
++
++int open_fd(const char *path, int flags)
++{
++	int fd;
++
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
++	if (cloexec_works != -1)
++		flags |= O_CLOEXEC;
++#endif
++	fd = open(path, flags);
++	if (fd == -1)
++		return -1;
++	check_cloexec(fd);
++	return fd;
++}
++
++int open_fd_mode(const char *path, int flags, int mode)
++{
++	int fd;
++
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
++	if (cloexec_works != -1)
++		flags |= O_CLOEXEC;
++#endif
++	fd = open(path, flags, mode);
++	if (fd == -1)
++		return -1;
++	check_cloexec(fd);
++	return fd;
++}
++
++int open_pipe(int pipefd[2])
++{
++	int ret;
++
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_PIPE2)
++	if (cloexec_works != -1) {
++		ret = pipe2(pipefd, O_CLOEXEC);
++		if (ret != -1)
++			return 0;
++		if (errno != EINVAL)
++			return -1;
++	}
++#endif
++	ret = pipe(pipefd);
++	if (ret == -1)
++		return -1;
++	check_cloexec(pipefd[0]);
++	check_cloexec(pipefd[1]);
++	return 0;
++}
++
++int open_sock(int domain, int type, int protocol)
++{
++	int fd;
++
++#ifdef SOCK_CLOEXEC
++	if (cloexec_works != -1)
++		type |= SOCK_CLOEXEC;
++#endif
++	fd = socket(domain, type, protocol);
++	if (fd == -1)
++		return -1;
++	check_cloexec(fd);
++	return fd;
++}
++
++FILE *open_fopen_r(const char *path)
++{
++	FILE *f;
++
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
++	if (cloexec_works != -1) {
++		f = fopen(path, "re");
++		if (f != NULL) {
++			check_cloexec(fileno(f));
++			return f;
++		}
++	}
++#endif
++	f = fopen(path, "r");
++	if (f == NULL)
++		return NULL;
++	check_cloexec(fileno(f));
++	return f;
++}
++
++FILE *open_setmntent_r(const char *table)
++{
++	FILE *tab;
++
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
++	if (cloexec_works != -1) {
++		tab = setmntent(table, "re");
++		if (tab != NULL) {
++			check_cloexec(fileno(tab));
++			return tab;
++		}
++	}
++#endif
++	tab = fopen(table, "r");
++	if (tab == NULL)
++		return NULL;
++	check_cloexec(fileno(tab));
++	return tab;
++}
++
++/*
+  * Used by subprocesses which exec to avoid carrying over the main
+  * daemon's signalling environment
+  */
+--- autofs-5.0.7.orig/include/automount.h
++++ autofs-5.0.7/include/automount.h
+@@ -8,6 +8,7 @@
+ #ifndef AUTOMOUNT_H
+ #define AUTOMOUNT_H
+ 
++#include <stdio.h>
+ #include <paths.h>
+ #include <limits.h>
+ #include <time.h>
+@@ -256,6 +257,12 @@ int spawnv(unsigned logopt, const char *
+ int spawn_mount(unsigned logopt, ...);
+ int spawn_bind_mount(unsigned logopt, ...);
+ int spawn_umount(unsigned logopt, ...);
++int open_fd(const char *, int);
++int open_fd_mode(const char *, int, int);
++int open_pipe(int[2]);
++int open_sock(int, int, int);
++FILE *open_fopen_r(const char *);
++FILE *open_setmntent_r(const char *);
+ void reset_signals(void);
+ int do_mount(struct autofs_point *ap, const char *root, const char *name,
+ 	     int name_len, const char *what, const char *fstype,
+@@ -600,130 +607,5 @@ int alarm_start_handler(void);
+ int alarm_add(struct autofs_point *ap, time_t seconds);
+ void alarm_delete(struct autofs_point *ap);
+ 
+-/*
+- * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
+- * socket() if possible.
+- */
+-static int cloexec_works;
+-
+-static inline void check_cloexec(int fd)
+-{
+-	if (cloexec_works == 0) {
+-		int fl = fcntl(fd, F_GETFD);
+-		if (fl != -1)
+-			cloexec_works = (fl & FD_CLOEXEC) ? 1 : -1;
+-	}
+-	if (cloexec_works > 0)
+-		return;
+-	fcntl(fd, F_SETFD, FD_CLOEXEC);
+-	return;
+-}
+-
+-static inline int open_fd(const char *path, int flags)
+-{
+-	int fd;
+-
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+-	if (cloexec_works != -1)
+-		flags |= O_CLOEXEC;
+-#endif
+-	fd = open(path, flags);
+-	if (fd == -1)
+-		return -1;
+-	check_cloexec(fd);
+-	return fd;
+-}
+-
+-static inline int open_fd_mode(const char *path, int flags, int mode)
+-{
+-	int fd;
+-
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+-	if (cloexec_works != -1)
+-		flags |= O_CLOEXEC;
+-#endif
+-	fd = open(path, flags, mode);
+-	if (fd == -1)
+-		return -1;
+-	check_cloexec(fd);
+-	return fd;
+-}
+-
+-static inline int open_pipe(int pipefd[2])
+-{
+-	int ret;
+-
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_PIPE2)
+-	if (cloexec_works != -1) {
+-		ret = pipe2(pipefd, O_CLOEXEC);
+-		if (ret != -1)
+-			return 0;
+-		if (errno != EINVAL)
+-			return -1;
+-	}
+-#endif
+-	ret = pipe(pipefd);
+-	if (ret == -1)
+-		return -1;
+-	check_cloexec(pipefd[0]);
+-	check_cloexec(pipefd[1]);
+-	return 0;
+-}
+-
+-static inline int open_sock(int domain, int type, int protocol)
+-{
+-	int fd;
+-
+-#ifdef SOCK_CLOEXEC
+-	if (cloexec_works != -1)
+-		type |= SOCK_CLOEXEC;
+-#endif
+-	fd = socket(domain, type, protocol);
+-	if (fd == -1)
+-		return -1;
+-	check_cloexec(fd);
+-	return fd;
+-}
+-
+-static inline FILE *open_fopen_r(const char *path)
+-{
+-	FILE *f;
+-
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+-	if (cloexec_works != -1) {
+-		f = fopen(path, "re");
+-		if (f != NULL) {
+-			check_cloexec(fileno(f));
+-			return f;
+-		}
+-	}
+-#endif
+-	f = fopen(path, "r");
+-	if (f == NULL)
+-		return NULL;
+-	check_cloexec(fileno(f));
+-	return f;
+-}
+-
+-static inline FILE *open_setmntent_r(const char *table)
+-{
+-	FILE *tab;
+-
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+-	if (cloexec_works != -1) {
+-		tab = setmntent(table, "re");
+-		if (tab != NULL) {
+-			check_cloexec(fileno(tab));
+-			return tab;
+-		}
+-	}
+-#endif
+-	tab = fopen(table, "r");
+-	if (tab == NULL)
+-		return NULL;
+-	check_cloexec(fileno(tab));
+-	return tab;
+-}
+-
+ #endif
+ 
+--- autofs-5.0.7.orig/daemon/automount.c
++++ autofs-5.0.7/daemon/automount.c
+@@ -75,9 +75,6 @@ static sigset_t block_sigs;
+ /* Pre-calculated kernel packet length */
+ static size_t kpkt_len;
+ 
+-/* Does kernel know about SOCK_CLOEXEC and friends */
+-static int cloexec_works = 0;
+-
+ /* Attributes for creating detached and joinable threads */
+ pthread_attr_t th_attr;
+ pthread_attr_t th_attr_detached;
diff --git a/SOURCES/autofs-5.1.3-only-take-master-map-mutex-for-master-map-update.patch b/SOURCES/autofs-5.1.3-only-take-master-map-mutex-for-master-map-update.patch
new file mode 100644
index 0000000..179c1bf
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-only-take-master-map-mutex-for-master-map-update.patch
@@ -0,0 +1,150 @@
+autofs-5.1.3 - only take master map mutex for master map update
+
+From: Ian Kent <raven@themaw.net>
+
+When a map read is done it's neccessary to re-initialize the lookup
+context which requires a write lock to be taken on the master map
+entry source. Currently a map re-read also takes the master map lock
+which will block new lookups.
+
+If the lookup module thinks the map has been modified it will queue
+a map read which will take these locks.
+
+Now, when a bind mount (or symlink) is triggered by a lookup it's
+necessary to trigger automounts that are included in the target path
+for the dependent path to be valid.
+
+When the target path triggers automounts in this way and refers to the
+same master map entry, and a map re-read is scheduled and started and
+manages to take the master map lock before the dependent lookup gets
+past the master map lock check, the dependent path lookup will deadlock.
+
+But the master map lock is meant to gaurd against master map entries
+going away during lookups so isn't really needed for map reads as long
+as the master map lock is held during the update of the mounted
+automounts.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG      |    1 +
+ daemon/state.c |    3 ---
+ lib/master.c   |   45 +++++++++++++++++++++++++++++++++++++--------
+ 3 files changed, 38 insertions(+), 11 deletions(-)
+
+--- autofs-5.0.7.orig/daemon/state.c
++++ autofs-5.0.7/daemon/state.c
+@@ -484,12 +484,9 @@ static void *do_readmap(void *arg)
+ 
+ 	info(ap->logopt, "re-reading map for %s", ap->path);
+ 
+-	pthread_cleanup_push(master_mutex_lock_cleanup, NULL);
+-	master_mutex_lock();
+ 	status = lookup_nss_read_map(ap, NULL, now);
+ 	if (!status)
+ 		pthread_exit(NULL);
+-	pthread_cleanup_pop(1);
+ 
+ 	if (ap->type == LKP_INDIRECT) {
+ 		struct ioctl_ops *ops = get_ioctl_ops();
+--- autofs-5.0.7.orig/lib/master.c
++++ autofs-5.0.7/lib/master.c
+@@ -1089,6 +1089,39 @@ next:
+ 	free(paths);
+ }
+ 
++static void wait_for_lookups_and_lock(struct master *master)
++{
++	struct list_head *p, *head;
++	int status;
++
++again:
++	master_mutex_lock();
++
++	head = &master->mounts;
++	p = head->next;
++	while (p != head) {
++		struct master_mapent *this;
++
++		this = list_entry(p, struct master_mapent, list);
++
++		status = pthread_rwlock_trywrlock(&this->source_lock);
++		if (status) {
++			struct timespec t = { 0, 200000000 };
++			struct timespec r;
++
++			master_mutex_unlock();
++
++			while (nanosleep(&t, &r) == -1 && errno == EINTR)
++				memcpy(&t, &r, sizeof(struct timespec));
++
++			goto again;
++		}
++		master_source_unlock(this);
++
++		p = p->next;
++	}
++}
++
+ int master_read_master(struct master *master, time_t age, int readall)
+ {
+ 	unsigned int logopt = master->logopt;
+@@ -1098,7 +1131,7 @@ int master_read_master(struct master *ma
+ 	 * We need to clear and re-populate the null map entry cache
+ 	 * before alowing anyone else to use it.
+ 	 */
+-	master_mutex_lock();
++	wait_for_lookups_and_lock(master);
+ 	if (master->nc) {
+ 		cache_writelock(master->nc);
+ 		nc = master->nc;
+@@ -1118,21 +1151,19 @@ int master_read_master(struct master *ma
+ 	lookup_nss_read_master(master, age);
+ 	cache_unlock(nc);
+ 	master_add_amd_mount_section_mounts(master, age);
+-	master_mutex_unlock();
+ 
+ 	if (!master->read_fail)
+ 		master_mount_mounts(master, age, readall);
+ 	else {
+ 		master->read_fail = 0;
+ 		/* HUP signal sets readall == 1 only */
+-		if (!readall)
++		if (!readall) {
++			master_mutex_unlock();
+ 			return 0;
+-		else
++		} else
+ 			master_mount_mounts(master, age, readall);
+ 	}
+ 
+-	master_mutex_lock();
+-
+ 	if (list_empty(&master->mounts))
+ 		warn(logopt, "no mounts in table");
+ 
+@@ -1422,7 +1453,6 @@ int master_mount_mounts(struct master *m
+ 	int cur_state;
+ 
+ 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
+-	master_mutex_lock();
+ 
+ 	head = &master->mounts;
+ 	p = head->next;
+@@ -1510,7 +1540,6 @@ cont:
+ 		}
+ 	}
+ 
+-	master_mutex_unlock();
+ 	pthread_setcancelstate(cur_state, NULL);
+ 
+ 	return 1;
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -257,6 +257,7 @@
+ - fix some man page problems.
+ - allow dot in OPTIONSTR value lexer pattern.
+ - revert fix argc off by one in mount_autofs.c.
++- only take master map mutex for master map update.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
diff --git a/SOURCES/autofs-5.1.3-refactor-amd_parse_c.patch b/SOURCES/autofs-5.1.3-refactor-amd_parse_c.patch
new file mode 100644
index 0000000..105f1ce
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-refactor-amd_parse_c.patch
@@ -0,0 +1,363 @@
+autofs-5.1.3 - refactor amd_parse.c
+
+From: Ian Kent <raven@themaw.net>
+
+Refactor some blocks of code into functions to allow later reuse.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 
+ modules/amd_parse.y |  293 ++++++++++++++++++++++++++++++++++------------------
+ 2 files changed, 197 insertions(+), 97 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -273,6 +273,7 @@
+ - fix symlink false negative in umount_multi().
+ - remove expand_selectors() on amd parser entry.
+ - fix amd defaults map entry handling.
++- refactor amd_parse.c.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/amd_parse.y
++++ autofs-5.0.7/modules/amd_parse.y
+@@ -55,6 +55,11 @@ static int make_selector(char *name,
+ 			 unsigned int compare);
+ static void add_selector(struct selector *selector);
+ 
++static int match_map_option_fs_type(char *map_option, char *type);
++static int match_map_option_map_type(char *map_option, char *type);
++static int match_map_option_cache_option(char *type);
++static int match_mnt_option_options(char *mnt_option, char *options);
++
+ static struct amd_entry entry;
+ static struct list_head *entries;
+ static struct autofs_point *pap;
+@@ -253,86 +258,13 @@ selection: SELECTOR IS_EQUAL SELECTOR_VA
+ 
+ option_assignment: MAP_OPTION OPTION_ASSIGN FS_TYPE
+ 	{
+-		if (!strcmp($3, "auto")) {
+-			entry.flags |= AMD_MOUNT_TYPE_AUTO;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "nfs") ||
+-			   !strcmp($3, "nfs4")) {
+-			entry.flags |= AMD_MOUNT_TYPE_NFS;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "nfsl")) {
+-			entry.flags |= AMD_MOUNT_TYPE_NFSL;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "link")) {
+-			entry.flags |= AMD_MOUNT_TYPE_LINK;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "linkx")) {
+-			entry.flags |= AMD_MOUNT_TYPE_LINKX;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "host")) {
+-			entry.flags |= AMD_MOUNT_TYPE_HOST;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "lofs")) {
+-			entry.flags |= AMD_MOUNT_TYPE_LOFS;
+-			entry.type = amd_strdup("bind");
+-		} else if (!strcmp($3, "xfs")) {
+-			entry.flags |= AMD_MOUNT_TYPE_XFS;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "ext2") ||
+-			   !strcmp($3, "ext3") ||
+-			   !strcmp($3, "ext4")) {
+-			entry.flags |= AMD_MOUNT_TYPE_EXT;
+-			entry.type = amd_strdup($3);
+-		} else if (!strcmp($3, "ufs")) {
+-			entry.flags |= AMD_MOUNT_TYPE_UFS;
+-			entry.type = conf_amd_get_linux_ufs_mount_type();
+-		} else if (!strcmp($3, "cdfs")) {
+-			entry.flags |= AMD_MOUNT_TYPE_CDFS;
+-			entry.type = amd_strdup("iso9660");
+-		} else if (!strcmp($3, "jfs") ||
+-			   !strcmp($3, "nfsx") ||
+-			   !strcmp($3, "program") ||
+-			   !strcmp($3, "lustre") ||
+-			   !strcmp($3, "direct")) {
+-			sprintf(msg_buf, "file system type %s is "
+-					 "not yet implemented", $3);
+-			amd_msg(msg_buf);
+-			YYABORT;
+-		} else if (!strcmp($3, "cachefs")) {
+-			sprintf(msg_buf, "file system %s is not "
+-					 "supported by autofs, ignored", $3);
+-			amd_msg(msg_buf);
+-		} else {
+-			amd_notify($1);
++		if (!match_map_option_fs_type($1, $3))
+ 			YYABORT;
+-		}
+ 	}
+ 	| MAP_OPTION OPTION_ASSIGN MAP_TYPE
+ 	{
+-		if (!strcmp($3, "file") ||
+-		    !strcmp($3, "nis") ||
+-		    !strcmp($3, "nisplus") ||
+-		    !strcmp($3, "ldap") ||
+-		    !strcmp($3, "hesiod"))
+-			entry.map_type = amd_strdup($3);
+-		else if (!strcmp($3, "exec"))
+-			/* autofs uses "program" for "exec" map type */
+-			entry.map_type = amd_strdup("program");
+-		else if (!strcmp($3, "passwd")) {
+-			sprintf(msg_buf, "map type %s is "
+-					 "not yet implemented", $3);
+-			amd_msg(msg_buf);
+-			YYABORT;
+-		} else if (!strcmp($3, "ndbm") ||
+-			   !strcmp($3, "union")) {
+-			sprintf(msg_buf, "map type %s is not "
+-					 "supported by autofs", $3);
+-			amd_msg(msg_buf);
++		if (!match_map_option_map_type($1, $3))
+ 			YYABORT;
+-		} else {
+-			amd_notify($1);
+-			YYABORT;
+-		}
+ 	}
+ 	| MAP_OPTION OPTION_ASSIGN FS_OPT_VALUE
+ 	{
+@@ -397,13 +329,7 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 	}
+ 	| MNT_OPTION OPTION_ASSIGN options
+ 	{
+-		if (!strcmp($1, "opts"))
+-			entry.opts = amd_strdup(opts);
+-		else if (!strcmp($1, "addopts"))
+-			entry.addopts = amd_strdup(opts);
+-		else if (!strcmp($1, "remopts"))
+-			entry.remopts = amd_strdup(opts);
+-		else {
++		if (!match_mnt_option_options($1, $3)) {
+ 			amd_notify($1);
+ 			YYABORT;
+ 		}
+@@ -412,27 +338,20 @@ option_assignment: MAP_OPTION OPTION_ASS
+ 	| MNT_OPTION OPTION_ASSIGN
+ 	{
+ 		memset(opts, 0, sizeof(opts));
+-		if (!strcmp($1, "opts"))
+-			entry.opts = amd_strdup("");
+-		else if (!strcmp($1, "addopts"))
+-			entry.addopts = amd_strdup("");
+-		else if (!strcmp($1, "remopts"))
+-			entry.remopts = amd_strdup("");
+-		else {
++		if (!match_mnt_option_options($1, "")) {
+ 			amd_notify($1);
+ 			YYABORT;
+ 		}
+ 	}
+ 	| MAP_OPTION OPTION_ASSIGN CACHE_OPTION
+ 	{
+-		if (strncmp($3, "inc", 3))
+-			entry.cache_opts = AMD_CACHE_OPTION_INC;
+-		else if (strncmp($3, "all", 3))
+-			entry.cache_opts = AMD_CACHE_OPTION_ALL;
+-		else if (strncmp($3, "re", 2))
+-			entry.cache_opts = AMD_CACHE_OPTION_REGEXP;
+-		if (strstr($3, "sync"))
+-			entry.cache_opts |= AMD_CACHE_OPTION_SYNC;
++		if (!strcmp($1, "cache")) {
++			if (!match_map_option_cache_option($3))
++				YYABORT;
++		} else {
++			amd_notify($1);
++			YYABORT;
++		}
+ 	}
+ 	;
+ 
+@@ -478,6 +397,186 @@ options: OPTION
+ 
+ %%
+ 
++static int match_map_option_fs_type(char *map_option, char *type)
++{
++	char *fs_type;
++
++	fs_type = amd_strdup(type);
++	if (!fs_type) {
++		amd_notify(type);
++		return 0;
++	}
++
++	if (!strcmp(fs_type, "auto")) {
++		entry.flags |= AMD_MOUNT_TYPE_AUTO;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "nfs") ||
++		   !strcmp(fs_type, "nfs4")) {
++		entry.flags |= AMD_MOUNT_TYPE_NFS;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "nfsl")) {
++		entry.flags |= AMD_MOUNT_TYPE_NFSL;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "link")) {
++		entry.flags |= AMD_MOUNT_TYPE_LINK;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "linkx")) {
++		entry.flags |= AMD_MOUNT_TYPE_LINKX;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "host")) {
++		entry.flags |= AMD_MOUNT_TYPE_HOST;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "lofs")) {
++		entry.flags |= AMD_MOUNT_TYPE_LOFS;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "xfs")) {
++		entry.flags |= AMD_MOUNT_TYPE_XFS;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "ext2") ||
++		   !strcmp(fs_type, "ext3") ||
++		   !strcmp(fs_type, "ext4")) {
++		entry.flags |= AMD_MOUNT_TYPE_EXT;
++		entry.type = fs_type;
++	} else if (!strcmp(fs_type, "ufs")) {
++		entry.flags |= AMD_MOUNT_TYPE_UFS;
++		entry.type = conf_amd_get_linux_ufs_mount_type();
++		if (!entry.type) {
++			amd_msg("memory allocation error");
++			amd_notify(type);
++			free(fs_type);
++			return 0;
++		}
++		free(fs_type);
++	} else if (!strcmp(fs_type, "cdfs")) {
++		entry.flags |= AMD_MOUNT_TYPE_CDFS;
++		entry.type = amd_strdup("iso9660");
++		if (!entry.type) {
++			amd_msg("memory allocation error");
++			amd_notify(map_option);
++			free(fs_type);
++			return 0;
++		}
++		free(fs_type);
++	} else if (!strcmp(fs_type, "jfs") ||
++		   !strcmp(fs_type, "nfsx") ||
++		   !strcmp(fs_type, "program") ||
++		   !strcmp(fs_type, "lustre") ||
++		   !strcmp(fs_type, "direct")) {
++		sprintf(msg_buf, "file system type %s is "
++				 "not yet implemented", fs_type);
++		amd_msg(msg_buf);
++		free(fs_type);
++		return 0;
++	} else if (!strcmp(fs_type, "cachefs")) {
++		sprintf(msg_buf, "file system %s is not "
++				 "supported by autofs, ignored",
++				 fs_type);
++		amd_msg(msg_buf);
++		free(fs_type);
++	} else {
++		amd_notify(fs_type);
++		free(fs_type);
++		return 0;
++	}
++
++	return 1;
++}
++
++static int match_map_option_map_type(char *map_option, char *type)
++{
++	char *map_type;
++
++	map_type = amd_strdup(type);
++	if (!map_type) {
++		amd_notify(type);
++		return 0;
++	}
++
++	if (!strcmp(map_type, "file") ||
++	    !strcmp(map_type, "nis") ||
++	    !strcmp(map_type, "nisplus") ||
++	    !strcmp(map_type, "ldap") ||
++	    !strcmp(map_type, "hesiod")) {
++		entry.map_type = map_type;
++	} else if (!strcmp(map_type, "exec")) {
++		/* autofs uses "program" for "exec" map type */
++		entry.map_type = amd_strdup("program");
++		if (!entry.map_type) {
++			amd_notify(type);
++			free(map_type);
++			return 0;
++		}
++		free(map_type);
++	} else if (!strcmp(map_type, "passwd")) {
++		sprintf(msg_buf, "map type %s is "
++				 "not yet implemented", map_type);
++		amd_msg(msg_buf);
++		free(map_type);
++		return 0;
++	} else if (!strcmp(map_type, "ndbm") ||
++		   !strcmp(map_type, "union")) {
++		sprintf(msg_buf, "map type %s is not "
++				 "supported by autofs", map_type);
++		amd_msg(msg_buf);
++		free(map_type);
++		return 0;
++	} else {
++		amd_notify(type);
++		free(map_type);
++		return 0;
++	}
++
++	return 1;
++}
++
++static int match_map_option_cache_option(char *type)
++{
++	char *cache_opt;
++
++	cache_opt = amd_strdup(type);
++	if (!cache_opt) {
++		amd_notify(type);
++		return 0;
++	}
++
++	if (strncmp(cache_opt, "inc", 3))
++		entry.cache_opts = AMD_CACHE_OPTION_INC;
++	else if (strncmp(cache_opt, "all", 3))
++		entry.cache_opts = AMD_CACHE_OPTION_ALL;
++	else if (strncmp(cache_opt, "re", 2))
++		entry.cache_opts = AMD_CACHE_OPTION_REGEXP;
++	if (strstr(cache_opt, "sync"))
++		entry.cache_opts |= AMD_CACHE_OPTION_SYNC;
++	free(cache_opt);
++
++	return 1;
++}
++
++static int match_mnt_option_options(char *mnt_option, char *options)
++{
++	char *tmp;
++
++	if (!strcmp(mnt_option, "opts")) {
++		tmp = amd_strdup(options);
++		if (!tmp)
++			return 0;
++		entry.opts = tmp;
++	} else if (!strcmp(mnt_option, "addopts")) {
++		tmp = amd_strdup(options);
++		if (!tmp)
++			return 0;
++		entry.addopts = tmp;
++	} else if (!strcmp(mnt_option, "remopts")) {
++		tmp = amd_strdup(options);
++		if (!tmp)
++			return 0;
++		entry.remopts = tmp;
++	} else
++		return 0;
++
++	return 1;
++}
++
+ static void prepend_opt(char *dest, char *opt)
+ {
+ 	char new[MAX_OPTS_LEN];
diff --git a/SOURCES/autofs-5.1.3-remove-expand_selectors-call-on-amd-parser-entry.patch b/SOURCES/autofs-5.1.3-remove-expand_selectors-call-on-amd-parser-entry.patch
new file mode 100644
index 0000000..f8baa92
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-remove-expand_selectors-call-on-amd-parser-entry.patch
@@ -0,0 +1,97 @@
+autofs-5.1.3 - remove expand_selectors() call on amd parser entry
+
+From: Ian Kent <raven@themaw.net>
+
+Macro expansion within the amd parser has to be done during the mount
+attempt loop, after any defaults are setup and also after any defaults
+overrides from the map entry itself.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |   22 ++++++----------------
+ 2 files changed, 7 insertions(+), 16 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -271,6 +271,7 @@
+ - fix typo in amd_parse.c.
+ - add missing MODPREFIX to logging in amd parser.
+ - fix symlink false negative in umount_multi().
++- remove expand_selectors() on amd parser entry.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -1846,7 +1846,6 @@ int parse_mount(struct autofs_point *ap,
+ 	struct amd_entry *defaults_entry;
+ 	struct amd_entry *cur_defaults;
+ 	char *defaults;
+-	char *pmapent;
+ 	int len, rv = 1;
+ 	int cur_state;
+ 	int ret;
+@@ -1871,17 +1870,8 @@ int parse_mount(struct autofs_point *ap,
+ 		return 1;
+ 	}
+ 
+-	len = expand_selectors(ap, mapent, &pmapent, sv);
+-	if (!len) {
+-		macro_free_table(sv);
+-		pthread_setcancelstate(cur_state, NULL);
+-		return 1;
+-	}
+-
+ 	pthread_setcancelstate(cur_state, NULL);
+ 
+-	debug(ap->logopt, MODPREFIX "expanded mapent: %s", pmapent);
+-
+ 	defaults = conf_amd_get_map_defaults(ap->path);
+ 	if (defaults) {
+ 		debug(ap->logopt, MODPREFIX
+@@ -1903,7 +1893,6 @@ int parse_mount(struct autofs_point *ap,
+ 		error(ap->logopt, MODPREFIX "failed to get a defaults entry");
+ 		if (defaults)
+ 			free(defaults);
+-		free(pmapent);
+ 		macro_free_table(sv);
+ 		return 1;
+ 	}
+@@ -1912,16 +1901,13 @@ int parse_mount(struct autofs_point *ap,
+ 
+ 	INIT_LIST_HEAD(&entries);
+ 
+-	ret = amd_parse_list(ap, pmapent, &entries, &sv);
++	ret = amd_parse_list(ap, mapent, &entries, &sv);
+ 	if (ret) {
+ 		error(ap->logopt,
+-		      MODPREFIX "failed to parse entry: %s", pmapent);
+-		free(pmapent);
++		      MODPREFIX "failed to parse entry: %s", mapent);
+ 		goto done;
+ 	}
+ 
+-	free(pmapent);
+-
+ 	if (list_empty(&entries)) {
+ 		error(ap->logopt, MODPREFIX "no location found after parse");
+ 		goto done;
+@@ -1958,6 +1944,9 @@ int parse_mount(struct autofs_point *ap,
+ 			continue;
+ 		}
+ 
++		debug(ap->logopt, "expand defaults entry");
++		sv = expand_entry(ap, cur_defaults, flags, sv);
++
+ 		if (this->flags & AMD_ENTRY_CUT && at_least_one) {
+ 			info(ap->logopt, MODPREFIX
+ 			     "at least one entry tried before cut selector, "
+@@ -1970,6 +1959,7 @@ int parse_mount(struct autofs_point *ap,
+ 
+ 		at_least_one = 1;
+ 
++		debug(ap->logopt, "expand mount entry");
+ 		update_with_defaults(cur_defaults, this, sv);
+ 		sv = expand_entry(ap, this, flags, sv);
+ 		sv = merge_entry_options(ap, this, sv);
diff --git a/SOURCES/autofs-5.1.3-remove-path-restriction-of-amd-external-mount.patch b/SOURCES/autofs-5.1.3-remove-path-restriction-of-amd-external-mount.patch
new file mode 100644
index 0000000..7472d7e
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-remove-path-restriction-of-amd-external-mount.patch
@@ -0,0 +1,62 @@
+autofs-5.1.3 - remove path restriction of amd external mount
+
+From: Ian Kent <raven@themaw.net>
+
+Remove the restriction that the external mount path must must be
+within the configured external mounts directory.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG    |    1 +
+ lib/mounts.c |   18 ------------------
+ 2 files changed, 1 insertion(+), 18 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -277,6 +277,7 @@
+ - fix amd parser double quote handling.
+ - fix expandamdent() quote handling.
+ - fix possible memory leak during amd parse.
++- remove path restriction of amd external mount.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -694,18 +694,9 @@ static struct ext_mount *ext_mount_looku
+ int ext_mount_add(struct list_head *entry, const char *path, unsigned int umount)
+ {
+ 	struct ext_mount *em;
+-	char *auto_dir;
+ 	u_int32_t hval;
+ 	int ret = 0;
+ 
+-	/* Not a mount in the external mount directory */
+-	auto_dir = conf_amd_get_auto_dir();
+-	if (strncmp(path, auto_dir, strlen(auto_dir))) {
+-		free(auto_dir);
+-		return 0;
+-	}
+-	free(auto_dir);
+-
+ 	pthread_mutex_lock(&ext_mount_hash_mutex);
+ 
+ 	em = ext_mount_lookup(path);
+@@ -751,17 +742,8 @@ done:
+ int ext_mount_remove(struct list_head *entry, const char *path)
+ {
+ 	struct ext_mount *em;
+-	char *auto_dir;
+ 	int ret = 0;
+ 
+-	/* Not a mount in the external mount directory */
+-	auto_dir = conf_amd_get_auto_dir();
+-	if (strncmp(path, auto_dir, strlen(auto_dir))) {
+-		free(auto_dir);
+-		return 0;
+-	}
+-	free(auto_dir);
+-
+ 	pthread_mutex_lock(&ext_mount_hash_mutex);
+ 
+ 	em = ext_mount_lookup(path);
diff --git a/SOURCES/autofs-5.1.3-reset-master-map-list-on-startup-retry.patch b/SOURCES/autofs-5.1.3-reset-master-map-list-on-startup-retry.patch
new file mode 100644
index 0000000..5abbfee
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-reset-master-map-list-on-startup-retry.patch
@@ -0,0 +1,76 @@
+autofs-5.1.3 - reset master map list on startup retry
+
+From: Ian Kent <raven@themaw.net>
+
+On autofs startup if automount thinks the master map read failed
+for some reason it retries the read after waiting for a fairly
+short delay.
+
+It should be ok to retry with the entries seen so far but there
+may be cases where that causes problems so release any existing
+master map entries before retrying.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG          |    1 +
+ daemon/automount.c |   25 +++++++++++++++++++++++++
+ 2 files changed, 26 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -265,6 +265,7 @@
+ - make map source reference message debug only.
+ - handle additional nfs versions in mount_nfs.c.
+ - improve description of mount_nfs_default_protocol.
++- reset master map list on startup retry.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/automount.c
++++ autofs-5.0.7/daemon/automount.c
+@@ -2099,6 +2099,27 @@ static void remove_empty_args(char **arg
+ 	*argc = j;
+ }
+ 
++static void do_master_list_reset(struct master *master)
++{
++	struct list_head *head, *p;
++
++	master_mutex_lock();
++
++	head = &master->mounts;
++	list_for_each(p, head) {
++		struct master_mapent *entry;
++
++		entry = list_entry(p, struct master_mapent, list);
++
++		if (!list_empty(&entry->list))
++			list_del(&entry->list);
++		master_free_mapent_sources(entry, 1);
++		master_free_mapent(entry);
++	}
++
++	master_mutex_unlock();
++}
++
+ static int do_master_read_master(struct master *master, int wait)
+ {
+ 	sigset_t signalset;
+@@ -2118,6 +2139,8 @@ static int do_master_read_master(struct
+ 	while (1) {
+ 		struct timespec t = { retry_wait, 0 };
+ 
++		do_master_list_reset(master);
++
+ 		age = time(NULL);
+ 		if (master_read_master(master, age, 0)) {
+ 			ret = 1;
+@@ -2586,6 +2609,8 @@ int main(int argc, char *argv[])
+ 			 * Failed to read master map, continue with what
+ 			 * we have anyway.
+ 			 */
++			do_master_list_reset(master_list);
++			age = time(NULL);
+ 			master_read_master(master_list, age, 1);
+ 		}
+ 	}
diff --git a/SOURCES/autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch b/SOURCES/autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch
index b5049a4..a61d8f9 100644
--- a/SOURCES/autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch
+++ b/SOURCES/autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch
@@ -16,10 +16,10 @@ Signed-off-by: Ian Kent <raven@themaw.net>
 
 --- autofs-5.0.7.orig/CHANGELOG
 +++ autofs-5.0.7/CHANGELOG
-@@ -251,6 +251,7 @@
- - limit getgrgid_r() buffer size.
- - add congigure option for limiting getgrgid_r() stack usage.
- - fix unset tsd group name handling.
+@@ -256,6 +256,7 @@
+ - fix typos in autofs man pages.
+ - fix some man page problems.
+ - allow dot in OPTIONSTR value lexer pattern.
 +- revert fix argc off by one in mount_autofs.c.
  
  25/07/2012 autofs-5.0.7
diff --git a/SOURCES/autofs-5.1.3-serialize-calls-to-open_xxxx-functions.patch b/SOURCES/autofs-5.1.3-serialize-calls-to-open_xxxx-functions.patch
new file mode 100644
index 0000000..da74a31
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-serialize-calls-to-open_xxxx-functions.patch
@@ -0,0 +1,271 @@
+autofs-5.1.3 - serialize calls to open_xxxx() functions
+
+From: Ian Kent <raven@themaw.net>
+
+This patch is the second part of the change described in "move
+open_xxxx() functions to spawn.c" to serialize the open_xxxx()
+functions wrt. to fork(2).
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                |    1 
+ daemon/spawn.c           |   61 ++++++++++++++++++++++++++++++++++++++++-------
+ include/automount.h      |    2 +
+ lib/mounts.c             |    2 +
+ modules/lookup_program.c |    3 ++
+ 5 files changed, 61 insertions(+), 8 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -288,6 +288,7 @@
+ - update configure to check for pipe2(2).
+ - fix open calls not using open_xxxx() calls.
+ - move open_xxxx() functions to spawn.c.
++- serialize calls to open_xxxx() functions.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/spawn.c
++++ autofs-5.0.7/daemon/spawn.c
+@@ -29,6 +29,7 @@
+ #include "automount.h"
+ 
+ static pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER;
++static pthread_mutex_t open_mutex = PTHREAD_MUTEX_INITIALIZER;
+ 
+ #define SPAWN_OPT_NONE		0x0000
+ #define SPAWN_OPT_LOCK		0x0001
+@@ -48,6 +49,20 @@ void dump_core(void)
+ 	raise(SIGSEGV);
+ }
+ 
++void open_mutex_lock(void)
++{
++	int _o_lock = pthread_mutex_lock(&open_mutex);
++	if (_o_lock)
++		fatal(_o_lock);
++}
++
++void open_mutex_unlock(void)
++{
++	int _o_unlock = pthread_mutex_unlock(&open_mutex);
++	if (_o_unlock)
++		fatal(_o_unlock);
++}
++
+ /*
+  * Use CLOEXEC flag for open(), pipe(), fopen() (read-only case) and
+  * socket() if possible.
+@@ -71,14 +86,18 @@ int open_fd(const char *path, int flags)
+ {
+ 	int fd;
+ 
++	open_mutex_lock();
+ #if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+ 	if (cloexec_works != -1)
+ 		flags |= O_CLOEXEC;
+ #endif
+ 	fd = open(path, flags);
+-	if (fd == -1)
++	if (fd == -1) {
++		open_mutex_unlock();
+ 		return -1;
++	}
+ 	check_cloexec(fd);
++	open_mutex_unlock();
+ 	return fd;
+ }
+ 
+@@ -86,14 +105,18 @@ int open_fd_mode(const char *path, int f
+ {
+ 	int fd;
+ 
++	open_mutex_lock();
+ #if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+ 	if (cloexec_works != -1)
+ 		flags |= O_CLOEXEC;
+ #endif
+ 	fd = open(path, flags, mode);
+-	if (fd == -1)
++	if (fd == -1) {
++		open_mutex_unlock();
+ 		return -1;
++	}
+ 	check_cloexec(fd);
++	open_mutex_unlock();
+ 	return fd;
+ }
+ 
+@@ -101,35 +124,45 @@ int open_pipe(int pipefd[2])
+ {
+ 	int ret;
+ 
++	open_mutex_lock();
+ #if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_PIPE2)
+ 	if (cloexec_works != -1) {
+ 		ret = pipe2(pipefd, O_CLOEXEC);
+ 		if (ret != -1)
+-			return 0;
++			goto done;
+ 		if (errno != EINVAL)
+-			return -1;
++			goto err;
+ 	}
+ #endif
+ 	ret = pipe(pipefd);
+ 	if (ret == -1)
+-		return -1;
++		goto err;
+ 	check_cloexec(pipefd[0]);
+ 	check_cloexec(pipefd[1]);
++done:
++	open_mutex_unlock();
+ 	return 0;
++err:
++	open_mutex_unlock();
++	return -1;
+ }
+ 
+ int open_sock(int domain, int type, int protocol)
+ {
+ 	int fd;
+ 
++	open_mutex_lock();
+ #ifdef SOCK_CLOEXEC
+ 	if (cloexec_works != -1)
+ 		type |= SOCK_CLOEXEC;
+ #endif
+ 	fd = socket(domain, type, protocol);
+-	if (fd == -1)
++	if (fd == -1) {
++		open_mutex_unlock();
+ 		return -1;
++	}
+ 	check_cloexec(fd);
++	open_mutex_unlock();
+ 	return fd;
+ }
+ 
+@@ -137,19 +170,24 @@ FILE *open_fopen_r(const char *path)
+ {
+ 	FILE *f;
+ 
++	open_mutex_lock();
+ #if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+ 	if (cloexec_works != -1) {
+ 		f = fopen(path, "re");
+ 		if (f != NULL) {
+ 			check_cloexec(fileno(f));
++			open_mutex_unlock();
+ 			return f;
+ 		}
+ 	}
+ #endif
+ 	f = fopen(path, "r");
+-	if (f == NULL)
++	if (f == NULL) {
++		open_mutex_unlock();
+ 		return NULL;
++	}
+ 	check_cloexec(fileno(f));
++	open_mutex_unlock();
+ 	return f;
+ }
+ 
+@@ -157,19 +195,24 @@ FILE *open_setmntent_r(const char *table
+ {
+ 	FILE *tab;
+ 
++	open_mutex_lock();
+ #if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+ 	if (cloexec_works != -1) {
+ 		tab = setmntent(table, "re");
+ 		if (tab != NULL) {
+ 			check_cloexec(fileno(tab));
++			open_mutex_unlock();
+ 			return tab;
+ 		}
+ 	}
+ #endif
+ 	tab = fopen(table, "r");
+-	if (tab == NULL)
++	if (tab == NULL) {
++		open_mutex_unlock();
+ 		return NULL;
++	}
+ 	check_cloexec(fileno(tab));
++	open_mutex_unlock();
+ 	return tab;
+ }
+ 
+@@ -283,6 +326,7 @@ static int do_spawn(unsigned logopt, uns
+ 		egid = tsv->gid;
+ 	}
+ 
++	open_mutex_lock();
+ 	f = fork();
+ 	if (f == 0) {
+ 		char **pargv = (char **) argv;
+@@ -377,6 +421,7 @@ done:
+ 
+ 		sigaddset(&tmpsig, SIGCHLD);
+ 		pthread_sigmask(SIG_SETMASK, &tmpsig, NULL);
++		open_mutex_unlock();
+ 
+ 		close(pipefd[1]);
+ 
+--- autofs-5.0.7.orig/include/automount.h
++++ autofs-5.0.7/include/automount.h
+@@ -257,6 +257,8 @@ int spawnv(unsigned logopt, const char *
+ int spawn_mount(unsigned logopt, ...);
+ int spawn_bind_mount(unsigned logopt, ...);
+ int spawn_umount(unsigned logopt, ...);
++void open_mutex_lock(void);
++void open_mutex_unlock(void);
+ int open_fd(const char *, int);
+ int open_fd_mode(const char *, int, int);
+ int open_pipe(int[2]);
+--- autofs-5.0.7.orig/lib/mounts.c
++++ autofs-5.0.7/lib/mounts.c
+@@ -230,6 +230,7 @@ int check_nfs_mount_version(struct nfs_m
+ 	sigfillset(&allsigs);
+ 	pthread_sigmask(SIG_BLOCK, &allsigs, &oldsig);
+ 
++	open_mutex_lock();
+ 	f = fork();
+ 	if (f == 0) {
+ 		reset_signals();
+@@ -248,6 +249,7 @@ int check_nfs_mount_version(struct nfs_m
+ 
+ 	sigaddset(&tmpsig, SIGCHLD);
+ 	pthread_sigmask(SIG_SETMASK, &tmpsig, NULL);
++	open_mutex_unlock();
+ 
+ 	close(pipefd[1]);
+ 
+--- autofs-5.0.7.orig/modules/lookup_program.c
++++ autofs-5.0.7/modules/lookup_program.c
+@@ -225,6 +225,7 @@ static char *lookup_one(struct autofs_po
+ 		goto out_error;
+ 	}
+ 
++	open_mutex_lock();
+ 	f = fork();
+ 	if (f < 0) {
+ 		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+@@ -233,6 +234,7 @@ static char *lookup_one(struct autofs_po
+ 		close(pipefd[1]);
+ 		close(epipefd[0]);
+ 		close(epipefd[1]);
++		open_mutex_unlock();
+ 		goto out_error;
+ 	} else if (f == 0) {
+ 		reset_signals();
+@@ -262,6 +264,7 @@ static char *lookup_one(struct autofs_po
+ 	}
+ 	close(pipefd[1]);
+ 	close(epipefd[1]);
++	open_mutex_unlock();
+ 
+ 	mapp = mapent;
+ 	errp = errbuf;
diff --git a/SOURCES/autofs-5.1.3-set-systemd-KillMode-to-process.patch b/SOURCES/autofs-5.1.3-set-systemd-KillMode-to-process.patch
new file mode 100644
index 0000000..41bdfe3
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-set-systemd-KillMode-to-process.patch
@@ -0,0 +1,41 @@
+autofs-5.1.3 - set systemd KillMode to process
+
+From: Ian Kent <raven@themaw.net>
+
+It's been reported that fuse based filesystem mounts are lost when
+restarting autofs.
+
+This behaviour is due to systemd default KillMode being control-group
+rather than process.
+
+While changing this from control-group to process might occassionally
+not kill some processes that should be killed on shutdown or restart
+these processes are much less common and less problematic than processes
+managing fuse based mounts.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG                 |    1 +
+ samples/autofs.service.in |    1 +
+ 2 files changed, 2 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -251,6 +251,7 @@
+ - limit getgrgid_r() buffer size.
+ - add congigure option for limiting getgrgid_r() stack usage.
+ - fix unset tsd group name handling.
++- set systemd KillMode to process.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/samples/autofs.service.in
++++ autofs-5.0.7/samples/autofs.service.in
+@@ -9,6 +9,7 @@ PIDFile=@@autofspiddir@@/autofs.pid
+ EnvironmentFile=-@@autofsconfdir@@/autofs
+ ExecStart=@@sbindir@@/automount $OPTIONS --pid-file @@autofspiddir@@/autofs.pid
+ ExecReload=/usr/bin/kill -HUP $MAINPID
++KillMode=process
+ TimeoutSec=180
+ 
+ [Install]
diff --git a/SOURCES/autofs-5.1.3-update-configure-to-check-for-pipe2.patch b/SOURCES/autofs-5.1.3-update-configure-to-check-for-pipe2.patch
new file mode 100644
index 0000000..4441ccd
--- /dev/null
+++ b/SOURCES/autofs-5.1.3-update-configure-to-check-for-pipe2.patch
@@ -0,0 +1,87 @@
+commit f103a48636a7979c68c7a64cb381a4d0942c5109
+Author: Ian Kent <raven@themaw.net>
+Date:   Mon Nov 13 09:48:39 2017 +0800
+
+    autofs-5.1.3 - update configure to check for pipe2(2)
+    
+    In a bug report by John Salmon it appears that the use of __have_pipe2
+    isn't doing what's needed when checking for pipe2(2).
+    
+    Hopefully updating configure to explicity check for pipe2(2), lifted
+    from John's patch, will be more reliable.
+    
+    Signed-off-by: Ian Kent <raven@themaw.net>
+
+---
+ CHANGELOG           |    1 +
+ configure           |   12 ++++++++++++
+ configure.in        |    2 ++
+ include/automount.h |    2 +-
+ include/config.h.in |    3 +++
+ 5 files changed, 19 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -285,6 +285,7 @@
+ - fix memory leak in umount_amd_ext_mount().
+ - fix strerror_r() parameter declaration in do program_mount().
+ - fix incorrect check in validate_program_options().
++- update configure to check for pipe2(2).
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/configure.in
++++ autofs-5.0.7/configure.in
+@@ -153,6 +153,8 @@ AF_CHECK_SSS_LIB(SSS_AUTOFS, libsss_auto
+ AC_SUBST(HAVE_SSS_AUTOFS)
+ AC_SUBST(sssldir)
+ 
++AC_CHECK_FUNCS(pipe2)
++
+ #
+ # Newer mounts have the -s (sloppy) option to ignore unknown options,
+ # good for portability
+--- autofs-5.0.7.orig/include/automount.h
++++ autofs-5.0.7/include/automount.h
+@@ -653,7 +653,7 @@ static inline int open_pipe(int pipefd[2
+ {
+ 	int ret;
+ 
+-#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(__have_pipe2)
++#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_PIPE2)
+ 	if (cloexec_works != -1) {
+ 		ret = pipe2(pipefd, O_CLOEXEC);
+ 		if (ret != -1)
+--- autofs-5.0.7.orig/include/config.h.in
++++ autofs-5.0.7/include/config.h.in
+@@ -54,6 +54,9 @@
+ /* define if you have MOUNT_NFS */
+ #undef HAVE_MOUNT_NFS
+ 
++/* Define to 1 if you have the `pipe2' function. */
++#undef HAVE_PIPE2
++
+ /* define if the mount command supports the -s option */
+ #undef HAVE_SLOPPY_MOUNT
+ 
+--- autofs-5.0.7.orig/configure
++++ autofs-5.0.7/configure
+@@ -3955,6 +3955,18 @@ fi
+ 
+ 
+ 
++for ac_func in pipe2
++do :
++  ac_fn_c_check_func "$LINENO" "pipe2" "ac_cv_func_pipe2"
++if test "x$ac_cv_func_pipe2" = xyes; then :
++  cat >>confdefs.h <<_ACEOF
++#define HAVE_PIPE2 1
++_ACEOF
++
++fi
++done
++
++
+ #
+ # Newer mounts have the -s (sloppy) option to ignore unknown options,
+ # good for portability
diff --git a/SOURCES/autofs-5.1.4-dont-use-array-for-path-when-not-neccessary.patch b/SOURCES/autofs-5.1.4-dont-use-array-for-path-when-not-neccessary.patch
new file mode 100644
index 0000000..df7206e
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-dont-use-array-for-path-when-not-neccessary.patch
@@ -0,0 +1,52 @@
+autofs-5.1.4 - dont use array for path when not necessary
+
+From: Ian Kent <raven@themaw.net>
+
+In parse_amd.c:do_link_mount() a character array is used to construct
+a path when a pointer to the relevant amd entry field is sufficient.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |    6 +++---
+ 2 files changed, 4 insertions(+), 3 deletions(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -291,6 +291,7 @@
+ - serialize calls to open_xxxx() functions.
+ - fix use after free in do_master_list_reset().
+ - fix deadlock in dumpmaps.
++- dont use array for path when not necessary.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -969,8 +969,8 @@ static int do_auto_mount(struct autofs_p
+ static int do_link_mount(struct autofs_point *ap, const char *name,
+ 			 struct amd_entry *entry, unsigned int flags)
+ {
+-	char target[PATH_MAX + 1];
+ 	const char *opts = (entry->opts && *entry->opts) ? entry->opts : NULL;
++	char *target;
+ 	int ret;
+ 
+ 	if (entry->sublink) {
+@@ -979,14 +979,14 @@ static int do_link_mount(struct autofs_p
+ 			     "error: sublink option length is too long");
+ 			return 0;
+ 		}
+-		strcpy(target, entry->sublink);
++		target = entry->sublink;
+ 	} else {
+ 		if (strlen(entry->fs) > PATH_MAX) {
+ 			error(ap->logopt, MODPREFIX
+ 			     "error: fs option length is too long");
+ 			return 0;
+ 		}
+-		strcpy(target, entry->fs);
++		target = entry->fs;
+ 	}
+ 
+ 	if (!(flags & CONF_AUTOFS_USE_LOFS))
diff --git a/SOURCES/autofs-5.1.4-fix-deadlock-in-dumpmaps.patch b/SOURCES/autofs-5.1.4-fix-deadlock-in-dumpmaps.patch
new file mode 100644
index 0000000..db9768f
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-fix-deadlock-in-dumpmaps.patch
@@ -0,0 +1,36 @@
+autofs-5.1.4 - fix deadlock in dumpmaps
+
+From: Ian Kent <raven@themaw.net>
+
+Commit a223d11fa8e (autofs-5.1.3 - serialize calls to open_xxxx()
+functions) introduces a deadlock when using the dumpmaps function.
+
+In this case the open fd mutex needs to be unlocked in the forked
+child process of the do_spawn() function.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG      |    1 +
+ daemon/spawn.c |    1 +
+ 2 files changed, 2 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -290,6 +290,7 @@
+ - move open_xxxx() functions to spawn.c.
+ - serialize calls to open_xxxx() functions.
+ - fix use after free in do_master_list_reset().
++- fix deadlock in dumpmaps.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/daemon/spawn.c
++++ autofs-5.0.7/daemon/spawn.c
+@@ -337,6 +337,7 @@ static int do_spawn(unsigned logopt, uns
+ 		dup2(pipefd[1], STDOUT_FILENO);
+ 		dup2(pipefd[1], STDERR_FILENO);
+ 		close(pipefd[1]);
++		open_mutex_unlock();
+ 
+ 		/* what to mount must always be second last */
+ 		while (*pargv++)
diff --git a/SOURCES/autofs-5.1.4-fix-error-return-in-do_nfs_mount.patch b/SOURCES/autofs-5.1.4-fix-error-return-in-do_nfs_mount.patch
new file mode 100644
index 0000000..7a42e9a
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-fix-error-return-in-do_nfs_mount.patch
@@ -0,0 +1,31 @@
+autofs-5.1.4 - fix error return in do_nfs_mount()
+
+From: Ian Kent <raven@themaw.net>
+
+Fix incorrect error return in modules/parse_amd.c:do_nfs_mount().
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |    2 +-
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -294,6 +294,7 @@
+ - dont use array for path when not necessary.
+ - fix prefix option handling in expand_entry().
+ - fix sublink option not set from defaults.
++- fix error return in do_nfs_mount().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -1101,7 +1101,7 @@ static int do_nfs_mount(struct autofs_po
+ 	if (strlen(entry->rhost) + strlen(entry->rfs) + 1 > PATH_MAX) {
+ 		error(ap->logopt, MODPREFIX
+ 		     "error: rhost + rfs options length is too long");
+-		return 0;
++		return 1;
+ 	}
+ 
+ 	strcpy(target, entry->rhost);
diff --git a/SOURCES/autofs-5.1.4-fix-prefix-option-handling-in-expand_entry.patch b/SOURCES/autofs-5.1.4-fix-prefix-option-handling-in-expand_entry.patch
new file mode 100644
index 0000000..ff234e9
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-fix-prefix-option-handling-in-expand_entry.patch
@@ -0,0 +1,51 @@
+autofs-5.1.4 - fix prefix option handling in expand_entry()
+
+From: Ian Kent <raven@themaw.net>
+
+The changes to fix the defaults handling in the amd map parser caused
+the prefix option to not be expanded and also to not be propagated to
+submounts in some cases.
+
+But the prefix should be expanded in modules/parse_amd.c:expand_entry()
+along with the reset of the amd map entry fields.
+
+Just adding this to modules/parse_amd.c:expand_entry() (where it should
+be) fixes the amd map entry expansion and also fixes the propagation
+of the prefix to submounts.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |   11 +++++++++++
+ 2 files changed, 12 insertions(+)
+
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -292,6 +292,7 @@
+ - fix use after free in do_master_list_reset().
+ - fix deadlock in dumpmaps.
+ - dont use array for path when not necessary.
++- fix prefix option handling in expand_entry().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -727,6 +727,17 @@ static struct substvar *expand_entry(str
+ 		entry->rhost = host;
+ 	}
+ next:
++	if (entry->pref) {
++		if (expand_selectors(ap, entry->pref, &expand, sv)) {
++			debug(logopt, MODPREFIX
++			      "pref expand(\"%s\") -> %s",
++			      entry->pref, expand);
++			free(entry->pref);
++			entry->pref = expand;
++		}
++		sv = macro_addvar(sv, "pref", 4, entry->pref);
++	}
++
+ 	if (entry->sublink) {
+ 		if (expand_selectors(ap, entry->sublink, &expand, sv)) {
+ 			debug(logopt, MODPREFIX
diff --git a/SOURCES/autofs-5.1.4-fix-sublink-option-not-set-from-defaults.patch b/SOURCES/autofs-5.1.4-fix-sublink-option-not-set-from-defaults.patch
new file mode 100644
index 0000000..ea7c6fc
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-fix-sublink-option-not-set-from-defaults.patch
@@ -0,0 +1,44 @@
+autofs-5.1.4 - fix sublink option not set from defaults
+
+From: Ian Kent <raven@themaw.net>
+
+If the amd entry sublink option is given in a defaults entry
+it isn't merged into the current entry during parsing.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG           |    1 +
+ modules/parse_amd.c |   12 ++++++++++++
+ 2 files changed, 13 insertions(+)
+
+--- autofs-5.0.7.orig/modules/parse_amd.c
++++ autofs-5.0.7/modules/parse_amd.c
+@@ -647,6 +647,18 @@ static void update_with_defaults(struct
+ 		}
+ 	}
+ 
++	if (!entry->sublink) {
++		if (defaults->sublink) {
++			tmp = strdup(defaults->sublink);
++			if (tmp)
++				entry->sublink = tmp;
++		} else {
++			v = macro_findvar(sv, "sublink", 2);
++			if (v)
++				entry->sublink = strdup(v->val);
++		}
++	}
++
+ 	return;
+ }
+ 
+--- autofs-5.0.7.orig/CHANGELOG
++++ autofs-5.0.7/CHANGELOG
+@@ -293,6 +293,7 @@
+ - fix deadlock in dumpmaps.
+ - dont use array for path when not necessary.
+ - fix prefix option handling in expand_entry().
++- fix sublink option not set from defaults.
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
diff --git a/SOURCES/autofs-5.1.4-fix-use-after-free-in-do_master_list_reset.patch b/SOURCES/autofs-5.1.4-fix-use-after-free-in-do_master_list_reset.patch
new file mode 100644
index 0000000..8649fe1
--- /dev/null
+++ b/SOURCES/autofs-5.1.4-fix-use-after-free-in-do_master_list_reset.patch
@@ -0,0 +1,55 @@
+autofs-5.1.4 - fix use after free in do_master_list_reset()
+
+From: Ian Kent <raven@themaw.net>
+
+Umm ... list_for_each() can't be used in do_master_list_reset() because
+the subject entry of the loop is removed for the list within the loop
+body. Therefore it can't be used to calculate the next pointer within a
+for (...) loop.
+
+There is no list_for_each_safe() macro in the list.h of autofs so it
+needs to be done manually.
+
+Signed-off-by: Ian Kent <raven@themaw.net>
+---
+ CHANGELOG          |    1 +
+ daemon/automount.c |    8 ++++++--
+ 2 files changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/CHANGELOG b/CHANGELOG
+index 4cb23f2..6cd3029 100644
+--- a/CHANGELOG
++++ b/CHANGELOG
+@@ -289,6 +289,7 @@
+ - fix open calls not using open_xxxx() calls.
+ - move open_xxxx() functions to spawn.c.
+ - serialize calls to open_xxxx() functions.
++- fix use after free in do_master_list_reset().
+ 
+ 25/07/2012 autofs-5.0.7
+ =======================
+diff --git a/daemon/automount.c b/daemon/automount.c
+index d96cd35..1a61b90 100644
+--- a/daemon/automount.c
++++ b/daemon/automount.c
+@@ -2075,14 +2075,18 @@ static void remove_empty_args(char **argv, int *argc)
+ 
+ static void do_master_list_reset(struct master *master)
+ {
+-	struct list_head *head, *p;
++	struct list_head *head, *p, *n;
+ 
+ 	master_mutex_lock();
+ 
+ 	head = &master->mounts;
+-	list_for_each(p, head) {
++	n = head->next;
++	while (n != head) {
+ 		struct master_mapent *entry;
+ 
++		p = n;
++		n = p->next;
++
+ 		entry = list_entry(p, struct master_mapent, list);
+ 
+ 		if (!list_empty(&entry->list))
diff --git a/SPECS/autofs.spec b/SPECS/autofs.spec
index e048848..378d1f8 100644
--- a/SPECS/autofs.spec
+++ b/SPECS/autofs.spec
@@ -8,7 +8,7 @@
 Summary: A tool for automatically mounting and unmounting filesystems
 Name: autofs
 Version: 5.0.7
-Release: 70%{?dist}
+Release: 83%{?dist}
 Epoch: 1
 License: GPLv2+
 Group: System Environment/Daemons
@@ -406,9 +406,55 @@ Patch790: autofs-5.1.2-limit-getgrgid_r-buffer-size.patch
 Patch791: autofs-5.1.2-add-congigure-option-for-limiting-getgrgid_r-stack-usage.patch
 Patch792: autofs-5.1.3-fix-unset-tsd-group-name-handling.patch
 
-Patch793: autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch
-Patch794: autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch
-Patch795: autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch
+Patch793: autofs-5.1.3-set-systemd-KillMode-to-process.patch
+Patch794: autofs-5.1.3-fix-mount_nfs-blocks-on-first-mount.patch
+Patch795: autofs-5.1.3-fix-a-couple-of-typos-in-autofs-man-pages.patch
+Patch796: autofs-5.1.3-fix-some-man-problems.patch
+Patch797: autofs-5.1.3-allow-dot-in-OPTIONSTR-value-lexer-pattern.patch
+Patch798: autofs-5.1.3-revert-fix-argc-off-by-one-in-mount_autofs_c.patch
+Patch799: autofs-5.1.3-only-take-master-map-mutex-for-master-map-update.patch
+Patch800: autofs-5.1.3-fix-nisplus-lookup-init-not-configured-check.patch
+Patch801: autofs-5.1.3-make-open_lookup-error-handling-more-consistent.patch
+Patch802: autofs-5.1.3-be-silent-about-sss-library-not-found.patch
+Patch803: autofs-5.1.3-be-silent-about-nis-domain-not-set.patch
+Patch804: autofs-5.1.3-make-map-source-reference-message-debug-only.patch
+Patch805: autofs-5.1.3-handle-additional-nfs-versions-in-mount_nfs_c.patch
+Patch806: autofs-5.1.3-improve-description-of-mount_nfs_default_protocol.patch
+Patch807: autofs-5.1.3-reset-master-map-list-on-startup-retry.patch
+
+# Bug 1509043
+Patch810: autofs-5.1.3-improve-debug-logging-of-lookup-key.patch
+Patch811: autofs-5.1.2-fix-cachefs-parse-message-not-being-logged.patch
+Patch812: autofs-5.1.3-fix-typo-in-amd_parse_c.patch
+Patch813: autofs-5.1.3-add-missing-MODPREFIX-to-logging-in-amd-parser.patch
+Patch814: autofs-5.1.3-fix-symlink-false-negative-in-umount_multi.patch
+Patch815: autofs-5.1.3-remove-expand_selectors-call-on-amd-parser-entry.patch
+Patch816: autofs-5.1.3-fix-amd-defaults-map-entry-handling.patch
+Patch817: autofs-5.1.3-refactor-amd_parse_c.patch
+Patch818: autofs-5.1.3-fix-amd-parser-double-quote-handling.patch
+Patch819: autofs-5.1.3-fix-expandamdent-quote-handling.patch
+Patch820: autofs-5.1.3-fix-possible-memory-leak-during-amd-parse.patch
+Patch821: autofs-5.1.3-remove-path-restriction-of-amd-external-mount.patch
+Patch822: autofs-5.1.3-add-function-umount_amd_ext_mount.patch
+Patch823: autofs-5.1.3-add-function-ext_mount_inuse.patch
+Patch824: autofs-5.1.3-add-function-construct_argv.patch
+Patch825: autofs-5.1.3-add-amd-mount-type-program-mount-support.patch
+Patch826: autofs-5.1.3-fix-memory-leak-in-umount_amd_ext_mount.patch
+Patch827: autofs-5.1.3-fix-strerror_r-parameter-declaration-in-do_program_mount.patch
+Patch828: autofs-5.1.3-fix-incorrect-check-in-validate_program_options.patch
+
+Patch829: autofs-5.1.3-update-configure-to-check-for-pipe2.patch
+Patch830: autofs-5.1.3-fix-open-calls-not-using-open_xxxx-calls.patch
+Patch831: autofs-5.1.3-move-open_xxxx-functions-to-spawn_c.patch
+Patch832: autofs-5.1.3-serialize-calls-to-open_xxxx-functions.patch
+
+Patch833: autofs-5.1.4-fix-use-after-free-in-do_master_list_reset.patch
+Patch834: autofs-5.1.4-fix-deadlock-in-dumpmaps.patch
+
+Patch835: autofs-5.1.4-dont-use-array-for-path-when-not-neccessary.patch
+Patch836: autofs-5.1.4-fix-prefix-option-handling-in-expand_entry.patch
+Patch837: autofs-5.1.4-fix-sublink-option-not-set-from-defaults.patch
+Patch838: autofs-5.1.4-fix-error-return-in-do_nfs_mount.patch
 
 Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 %if %{with_systemd}
@@ -856,6 +902,52 @@ echo %{version}-%{release} > .version
 %patch793 -p1
 %patch794 -p1
 %patch795 -p1
+%patch796 -p1
+%patch797 -p1
+%patch798 -p1
+%patch799 -p1
+%patch800 -p1
+%patch801 -p1
+%patch802 -p1
+%patch803 -p1
+%patch804 -p1
+%patch805 -p1
+%patch806 -p1
+%patch807 -p1
+
+# Bug 1509043
+%patch810 -p1
+%patch811 -p1
+%patch812 -p1
+%patch813 -p1
+%patch814 -p1
+%patch815 -p1
+%patch816 -p1
+%patch817 -p1
+%patch818 -p1
+%patch819 -p1
+%patch820 -p1
+%patch821 -p1
+%patch822 -p1
+%patch823 -p1
+%patch824 -p1
+%patch825 -p1
+%patch826 -p1
+%patch827 -p1
+%patch828 -p1
+
+%patch829 -p1
+%patch830 -p1
+%patch831 -p1
+%patch832 -p1
+
+%patch833 -p1
+%patch834 -p1
+
+%patch835 -p1
+%patch836 -p1
+%patch837 -p1
+%patch838 -p1
 
 %build
 LDFLAGS=-Wl,-z,now
@@ -953,15 +1045,116 @@ fi
 %dir /etc/auto.master.d
 
 %changelog
-* Thu Oct 19 2017 Ian Kent <ikent@redhat.com> - 5.0.7-70.el7_4
-- bz1503945 - autofs option parsing for maps with fstype=autofs no longer
-  works [rhel-7.4.z]
+* Fri Feb 02 2018 Ian Kent <ikent@redhat.com> - 5.0.7-83
+- bz1509043 - [RFE] "automount / amd: file system type program is not
+  yet implemented"
+  - dont use array for path when not necessary.
+  - fix prefix option handling in expand_entry().
+  - fix sublink handling in do_nfs_mount().
+  - add fix error return in do_nfs_mount().
+- Related: rhbz#1509043
+
+* Fri Dec 22 2017 Ian Kent <ikent@redhat.com> - 5.0.7-82
+- bz1527815 - automount[1979]: segfault at 55f5101d30e8 ip 000055f50f177668
+              sp 00007ffffa85fdd0 error 4 in automount[55f50f16d000+48000]
+  - fix deadlock in dumpmaps.
+- Related: rhbz#1527815
+
+* Thu Dec 21 2017 Ian Kent <ikent@redhat.com> - 5.0.7-81
+- bz1527815 - automount[1979]: segfault at 55f5101d30e8 ip 000055f50f177668
+              sp 00007ffffa85fdd0 error 4 in automount[55f50f16d000+48000]
+  - fix use after free in do_master_list_reset()
+- Resolves: rhbz#1527815
+
+* Mon Dec 18 2017 Ian Kent <ikent@redhat.com> - 5.0.7-80
+- bz1509088 - autofs hangs due to race condition in do_spawn
+  - update configure to check for pipe2(2).
+  - fix open calls not using open_xxxx() calls.
+  - move open_xxxx() functions to spawn.c.
+  - serialize calls to open_xxxx() functions.
+- Resolves: rhbz#1509088
+
+* Mon Dec 11 2017 Ian Kent <ikent@redhat.com> - 5.0.7-79
+- bz1509043 - [RFE] "automount / amd: file system type program is not
+  yet implemented"
+  - fix memory leak in umount_amd_ext_mount().
+  - fix strerror_r() parameter declaration in do program_mount().
+  - fix incorrect check in validate_program_options().
+- Related: rhbz#1509043
+
+* Mon Dec 11 2017 Ian Kent <ikent@redhat.com> - 5.0.7-78
+- bz1509043 - [RFE] "automount / amd: file system type program is not
+  yet implemented"
+  - improve debug logging of lookup key.
+  - fix cachefs parse message not being logged.
+  - fix typo in amd_parse.c.
+  - add missing MODPREFIX to logging in amd parser.
+  - fix symlink false negative in umount_multi().
+  - remove expand_selectors() call on amd parser entry.
+  - fix amd defaults map entry handling.
+  - refactor amd_parse.c.
+  - fix amd parser double quote handling.
+  - fix expandamdent() quote handling.
+  - fix possible memory leak during amd parse.
+  - remove path restriction of amd external mount.
+  - add function umount_amd_ext_mount().
+  - add function ext_mount_inuse().
+  - add function construct_argv().
+  - add amd mount type program mount support.
+- Resolves: rhbz#1509043
+
+* Tue Oct 31 2017 Ian Kent <ikent@redhat.com> - 5.0.7-77
+- bz1504145 - Automount cannot access host shares after a reboot
+  - fix reject in patch changelog hunk.
+- Related: rhbz#1504145
+
+* Tue Oct 31 2017 Ian Kent <ikent@redhat.com> - 5.0.7-76
+- bz1504145 - Automount cannot access host shares after a reboot
+  - reset master map list on startup retry.
+- Resolves: rhbz#1504145
+
+* Fri Oct 27 2017 Ian Kent <ikent@redhat.com> - 5.0.7-75
+- bz1489247 - autofs: config mount_nfs_default_protocol doesn't work
+  - improve description of mount_nfs_default_protocol.
+- Resolves: rhbz#1489247
+
+* Thu Oct 19 2017 Ian Kent <ikent@redhat.com> - 5.0.7-74
+- bz1486035 - autofs map entry options field does not accept dot character
+  - handle additional nfs versions in mount_nfs.c.
+- Related: rhbz#1486035
+
+* Wed Oct 11 2017 Ian Kent <ikent@redhat.com> - 5.0.7-73
+- bz1489648 - autofs missing dependency with libsss_autofs cause missing file
+  messages during boot
+  - fix nisplus lookup init not configured check.
+  - make open_lookup() error handling more consistent.
+  - be silent about sss library not found.
+  - be silent about nis domain not set.
+  - make map source reference message debug only.
+- Resolves: rhbz#1489648
+
+* Mon Oct 9 2017 Ian Kent <ikent@redhat.com> - 5.0.7-72
+- bz1499287 - Autofs processes hung while waiting for the release of an entry
+  master_lock that is held by another thread waiting on a bind mount
+  - only take master map mutex for master map update.
+- Resolves: rhbz#1499287
+
+* Thu Oct 5 2017 Ian Kent <ikent@redhat.com> - 5.0.7-71
+- bz1497846 - Macro definitions specified in mount entries are no longer getting set
   - revert fix argc off by one in mount_autofs.c.
-- bz1503946 - autofs map entry options field does not accept dot character
-  [rhel-7.4.z]
+- Resolves: rhbz#1497846
+
+* Mon Oct 2 2017 Ian Kent <ikent@redhat.com> - 5.0.7-70
+- bz1442926 - Systemd kills autofs fuse mount on service restart
+  - set systemd KillMode to process.
+- bz1466256 - autofs: unable to mount nfs share after reboot
+  - fix mount.nfs blocks on first mount.
+- bz1476850 - Man page: Make auto.master 's summary findable via 'man -k autofs'
+  - fix typos in autofs man pages.
+  - fix some man page problems.
+- bz1486035 - autofs map entry options field does not accept dot character
   - allow dot in OPTIONSTR value lexer pattern.
-  - handle additional nfs versions in mount_nfs.c.
-- Resolves: rhbz#1503945 rhbz#1503946
+-Resolves: rhbz#1442926 rhbz#1466256 rhbz#1476850 rhbz#1486035
 
 * Fri Jun 2 2017 Ian Kent <ikent@redhat.com> - 5.0.7-69
 - bz1435736 - autofs fails with kernel: automount[3386]: