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