Blame SOURCES/autofs-5.1.6-add-helper-to-construct-mount-point-path.patch

49b67f
autofs-5.1.6 - add helper to construct mount point path
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Add convenience helper to construct mount point path.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG               |    1 +
49b67f
 include/mounts.h        |    3 +++
49b67f
 lib/mounts.c            |   23 +++++++++++++++++++++++
49b67f
 modules/mount_bind.c    |   19 +++++--------------
49b67f
 modules/mount_changer.c |   19 +++++--------------
49b67f
 modules/mount_ext2.c    |   19 +++++--------------
49b67f
 modules/mount_generic.c |   19 +++++--------------
49b67f
 modules/mount_nfs.c     |   21 ++++++++-------------
49b67f
 8 files changed, 55 insertions(+), 69 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -135,6 +135,7 @@ xx/xx/2018 autofs-5.1.5
49b67f
 - move submount check into conditional_alarm_add().
49b67f
 - move lib/master.c to daemon/master.c.
49b67f
 - use master_list_empty() for list empty check.
49b67f
+- add helper to construct mount point path.
49b67f
 
49b67f
 19/12/2017 autofs-5.1.4
49b67f
 - fix spec file url.
49b67f
--- autofs-5.1.4.orig/include/mounts.h
49b67f
+++ autofs-5.1.4/include/mounts.h
49b67f
@@ -94,6 +94,9 @@ unsigned int linux_version_code(void);
49b67f
 int check_nfs_mount_version(struct nfs_mount_vers *, struct nfs_mount_vers *);
49b67f
 extern unsigned int nfs_mount_uses_string_options;
49b67f
 
49b67f
+int mount_fullpath(char *fullpath, size_t max_len,
49b67f
+		   const char *root, const char *name);
49b67f
+
49b67f
 struct amd_entry;
49b67f
 
49b67f
 struct substvar *addstdenv(struct substvar *sv, const char *prefix);
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -339,6 +339,29 @@ int check_nfs_mount_version(struct nfs_m
49b67f
 }
49b67f
 #endif
49b67f
 
49b67f
+int mount_fullpath(char *fullpath, size_t max_len,
49b67f
+		   const char *root, const char *name)
49b67f
+{
49b67f
+	int last, len;
49b67f
+
49b67f
+	last = strlen(root) - 1;
49b67f
+
49b67f
+	/* Root offset of multi-mount or direct or offset mount.
49b67f
+	 * Direct or offset mount, name (or root) is absolute path.
49b67f
+	 */
49b67f
+	if (root[last] == '/' || *name == '/')
49b67f
+		len = snprintf(fullpath, max_len, "%s", root);
49b67f
+	else
49b67f
+		len = snprintf(fullpath, max_len, "%s/%s", root, name);
49b67f
+
49b67f
+	if (len >= max_len)
49b67f
+		return 0;
49b67f
+
49b67f
+	fullpath[len] = '\0';
49b67f
+
49b67f
+	return len;
49b67f
+}
49b67f
+
49b67f
 static char *set_env_name(const char *prefix, const char *name, char *buf)
49b67f
 {
49b67f
 	size_t len;
49b67f
--- autofs-5.1.4.orig/modules/mount_bind.c
49b67f
+++ autofs-5.1.4/modules/mount_bind.c
49b67f
@@ -122,21 +122,12 @@ int mount_mount(struct autofs_point *ap,
49b67f
 		}
49b67f
 	}
49b67f
 
49b67f
-	/* Root offset of multi-mount */
49b67f
-	len = strlen(root);
49b67f
-	if (root[len - 1] == '/') {
49b67f
-		len = snprintf(fullpath, len, "%s", root);
49b67f
-	} else if (*name == '/') {
49b67f
-		/*
49b67f
-		 * Direct or offset mount, name is absolute path so
49b67f
-		 * don't use root (but with move mount changes root
49b67f
-		 * is now the same as name).
49b67f
-		 */
49b67f
-		len = sprintf(fullpath, "%s", root);
49b67f
-	} else {
49b67f
-		len = sprintf(fullpath, "%s/%s", root, name);
49b67f
+	len = mount_fullpath(fullpath, PATH_MAX, root, name);
49b67f
+	if (!len) {
49b67f
+		error(ap->logopt,
49b67f
+		      MODPREFIX "mount point path too long");
49b67f
+		return 1;
49b67f
 	}
49b67f
-	fullpath[len] = '\0';
49b67f
 
49b67f
 	i = len;
49b67f
 	while (--i > 0 && fullpath[i] == '/')
49b67f
--- autofs-5.1.4.orig/modules/mount_changer.c
49b67f
+++ autofs-5.1.4/modules/mount_changer.c
49b67f
@@ -59,21 +59,12 @@ int mount_mount(struct autofs_point *ap,
49b67f
 
49b67f
 	fstype = "iso9660";
49b67f
 
49b67f
-	/* Root offset of multi-mount */
49b67f
-	len = strlen(root);
49b67f
-	if (root[len - 1] == '/') {
49b67f
-		len = snprintf(fullpath, len, "%s", root);
49b67f
-	} else if (*name == '/') {
49b67f
-		/*
49b67f
-		 * Direct or offset mount, name is absolute path so
49b67f
-		 * don't use root (but with move mount changes root
49b67f
-		 * is now the same as name).
49b67f
-		 */
49b67f
-		len = sprintf(fullpath, "%s", root);
49b67f
-	} else {
49b67f
-		len = sprintf(fullpath, "%s/%s", root, name);
49b67f
+	len = mount_fullpath(fullpath, PATH_MAX, root, name);
49b67f
+	if (!len) {
49b67f
+		error(ap->logopt,
49b67f
+		      MODPREFIX "mount point path too long");
49b67f
+		return 1;
49b67f
 	}
49b67f
-	fullpath[len] = '\0';
49b67f
 
49b67f
 	debug(ap->logopt, MODPREFIX "calling umount %s", what);
49b67f
 
49b67f
--- autofs-5.1.4.orig/modules/mount_ext2.c
49b67f
+++ autofs-5.1.4/modules/mount_ext2.c
49b67f
@@ -55,21 +55,12 @@ int mount_mount(struct autofs_point *ap,
49b67f
 	if (defaults_get_mount_verbose())
49b67f
 		mountlog = &log_info;
49b67f
 
49b67f
-	/* Root offset of multi-mount */
49b67f
-	len = strlen(root);
49b67f
-	if (root[len - 1] == '/') {
49b67f
-		len = snprintf(fullpath, len, "%s", root);
49b67f
-	} else if (*name == '/') {
49b67f
-		/*
49b67f
-		 * Direct or offset mount, name is absolute path so
49b67f
-		 * don't use root (but with move mount changes root
49b67f
-		 * is now the same as name).
49b67f
-		 */
49b67f
-		len = sprintf(fullpath, "%s", root);
49b67f
-	} else {
49b67f
-		len = sprintf(fullpath, "%s/%s", root, name);
49b67f
+	len = mount_fullpath(fullpath, PATH_MAX, root, name);
49b67f
+	if (!len) {
49b67f
+		error(ap->logopt,
49b67f
+		      MODPREFIX "mount point path too long");
49b67f
+		return 1;
49b67f
 	}
49b67f
-	fullpath[len] = '\0';
49b67f
 
49b67f
 	debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);
49b67f
 
49b67f
--- autofs-5.1.4.orig/modules/mount_generic.c
49b67f
+++ autofs-5.1.4/modules/mount_generic.c
49b67f
@@ -54,21 +54,12 @@ int mount_mount(struct autofs_point *ap,
49b67f
 	if (defaults_get_mount_verbose())
49b67f
 		mountlog = &log_info;
49b67f
 
49b67f
-	/* Root offset of multi-mount */
49b67f
-	len = strlen(root);
49b67f
-	if (root[len - 1] == '/') {
49b67f
-		len = snprintf(fullpath, len, "%s", root);
49b67f
-	} else if (*name == '/') {
49b67f
-		/*
49b67f
-		 * Direct or offset mount, name is absolute path so
49b67f
-		 * don't use root (but with move mount changes root
49b67f
-		 * is now the same as name).
49b67f
-		 */
49b67f
-		len = sprintf(fullpath, "%s", root);
49b67f
-	} else {
49b67f
-		len = sprintf(fullpath, "%s/%s", root, name);
49b67f
+	len = mount_fullpath(fullpath, PATH_MAX, root, name);
49b67f
+	if (!len) {
49b67f
+		error(ap->logopt,
49b67f
+		      MODPREFIX "mount point path too long");
49b67f
+		return 1;
49b67f
 	}
49b67f
-	fullpath[len] = '\0';
49b67f
 
49b67f
 	debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);
49b67f
 
49b67f
--- autofs-5.1.4.orig/modules/mount_nfs.c
49b67f
+++ autofs-5.1.4/modules/mount_nfs.c
49b67f
@@ -212,6 +212,14 @@ int mount_mount(struct autofs_point *ap,
49b67f
 			 nfsoptions, nobind, nosymlink, ro);
49b67f
 	}
49b67f
 
49b67f
+	/* Construct mount point directory */
49b67f
+	len = mount_fullpath(fullpath, PATH_MAX, root, name);
49b67f
+	if (!len) {
49b67f
+		error(ap->logopt,
49b67f
+		      MODPREFIX "mount point path too long");
49b67f
+		return 1;
49b67f
+	}
49b67f
+
49b67f
 	if (!parse_location(ap->logopt, &hosts, what, flags)) {
49b67f
 		info(ap->logopt, MODPREFIX "no hosts available");
49b67f
 		return 1;
49b67f
@@ -266,19 +274,6 @@ dont_probe:
49b67f
 		return 1;
49b67f
 	}
49b67f
 
49b67f
-	/* Construct and perhaps create mount point directory */
49b67f
-
49b67f
-	/* Root offset of multi-mount */
49b67f
-	len = strlen(root);
49b67f
-	if (root[len - 1] == '/') {
49b67f
-		len = snprintf(fullpath, len, "%s", root);
49b67f
-	} else if (*name == '/') {
49b67f
-		len = sprintf(fullpath, "%s", root);
49b67f
-	} else {
49b67f
-		len = sprintf(fullpath, "%s/%s", root, name);
49b67f
-	}
49b67f
-	fullpath[len] = '\0';
49b67f
-
49b67f
 	debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);
49b67f
 
49b67f
 	status = mkdir_path(fullpath, mp_mode);