From ae73284c1a1116d89c84235929df10421a348b30 Mon Sep 17 00:00:00 2001 From: jh Date: Mon, 16 Jan 2012 19:34:21 +0000 Subject: Change checkpath() to not exit on error. This is a prerequisite for fixing the mount(8) "failok" option. PR: 163668 Reviewed by: Garrett Cooper, delphij (previous version) --- sbin/mount/getmntopts.c | 12 ++++++++---- sbin/mount/mntopts.h | 2 +- sbin/mount/mount.c | 5 ++++- sbin/mount/mount_fs.c | 5 ++++- sbin/mount_cd9660/mount_cd9660.c | 3 ++- sbin/mount_ext2fs/mount_ext2fs.c | 3 ++- sbin/mount_msdosfs/mount_msdosfs.c | 3 ++- sbin/mount_nfs/mount_nfs.c | 3 ++- sbin/mount_ntfs/mount_ntfs.c | 3 ++- sbin/mount_nullfs/mount_nullfs.c | 6 ++++-- sbin/mount_reiserfs/mount_reiserfs.c | 3 ++- sbin/mount_std/mount_std.c | 3 ++- sbin/mount_udf/mount_udf.c | 3 ++- sbin/mount_unionfs/mount_unionfs.c | 6 ++++-- 14 files changed, 41 insertions(+), 19 deletions(-) (limited to 'sbin') diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c index 194b3df..3503060 100644 --- a/sbin/mount/getmntopts.c +++ b/sbin/mount/getmntopts.c @@ -124,16 +124,20 @@ rmslashes(char *rrpin, char *rrpout) *rrpout = '\0'; } -void +int checkpath(const char *path, char *resolved) { struct stat sb; if (realpath(path, resolved) != NULL && stat(resolved, &sb) == 0) { - if (!S_ISDIR(sb.st_mode)) - errx(EX_USAGE, "%s: not a directory", resolved); + if (!S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; + return (1); + } } else - errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); + return (1); + + return (0); } void diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h index 2903d55..86a350f 100644 --- a/sbin/mount/mntopts.h +++ b/sbin/mount/mntopts.h @@ -93,7 +93,7 @@ struct mntopt { void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); -void checkpath(const char *, char resolved_path[]); +int checkpath(const char *, char resolved_path[]); extern int getmnt_silent; void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index cf142e4..ca81795 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -539,7 +539,10 @@ mountfs(const char *vfstype, const char *spec, const char *name, int flags, static struct cpa mnt_argv; /* resolve the mountpoint with realpath(3) */ - (void)checkpath(name, mntpath); + if (checkpath(name, mntpath) != 0) { + warn("%s", mntpath); + return (1); + } name = mntpath; if (mntopts == NULL) diff --git a/sbin/mount/mount_fs.c b/sbin/mount/mount_fs.c index 526d493..4c58857 100644 --- a/sbin/mount/mount_fs.c +++ b/sbin/mount/mount_fs.c @@ -118,7 +118,10 @@ mount_fs(const char *vfstype, int argc, char *argv[]) dev = argv[0]; dir = argv[1]; - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) { + warn("%s", mntpath); + return (1); + } (void)rmslashes(dev, dev); build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); diff --git a/sbin/mount_cd9660/mount_cd9660.c b/sbin/mount_cd9660/mount_cd9660.c index 3b2827e..2215966 100644 --- a/sbin/mount_cd9660/mount_cd9660.c +++ b/sbin/mount_cd9660/mount_cd9660.c @@ -149,7 +149,8 @@ main(int argc, char **argv) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) + err(1, "%s", mntpath); (void)rmslashes(dev, dev); if (ssector == -1) { diff --git a/sbin/mount_ext2fs/mount_ext2fs.c b/sbin/mount_ext2fs/mount_ext2fs.c index 04d2ea0..8753997 100644 --- a/sbin/mount_ext2fs/mount_ext2fs.c +++ b/sbin/mount_ext2fs/mount_ext2fs.c @@ -103,7 +103,8 @@ main(int argc, char *argv[]) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(fs_name, mntpath); + if (checkpath(fs_name, mntpath) != 0) + err(EX_USAGE, "%s", mntpath); (void)rmslashes(fspec, fspec); build_iovec(&iov, &iovlen, "fstype", fstype, strlen(fstype) + 1); diff --git a/sbin/mount_msdosfs/mount_msdosfs.c b/sbin/mount_msdosfs/mount_msdosfs.c index 3ba67ea..3da673d 100644 --- a/sbin/mount_msdosfs/mount_msdosfs.c +++ b/sbin/mount_msdosfs/mount_msdosfs.c @@ -193,7 +193,8 @@ main(int argc, char **argv) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) + err(EX_USAGE, "%s", mntpath); (void)rmslashes(dev, dev); if (!set_gid || !set_uid || !set_mask) { diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index c6235e0..d71e952 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -411,7 +411,8 @@ main(int argc, char *argv[]) exit(1); /* resolve the mountpoint with realpath(3) */ - (void)checkpath(name, mntpath); + if (checkpath(name, mntpath) != 0) + err(1, "%s", mntpath); build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1); diff --git a/sbin/mount_ntfs/mount_ntfs.c b/sbin/mount_ntfs/mount_ntfs.c index 80fcab0..9adfeb5 100644 --- a/sbin/mount_ntfs/mount_ntfs.c +++ b/sbin/mount_ntfs/mount_ntfs.c @@ -163,7 +163,8 @@ main(int argc, char *argv[]) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) + err(EX_USAGE, "%s", mntpath); (void)rmslashes(dev, dev); args.fspec = dev; diff --git a/sbin/mount_nullfs/mount_nullfs.c b/sbin/mount_nullfs/mount_nullfs.c index 4f84954..c88db3d 100644 --- a/sbin/mount_nullfs/mount_nullfs.c +++ b/sbin/mount_nullfs/mount_nullfs.c @@ -90,8 +90,10 @@ main(int argc, char *argv[]) usage(); /* resolve target and source with realpath(3) */ - (void)checkpath(argv[0], target); - (void)checkpath(argv[1], source); + if (checkpath(argv[0], target) != 0) + err(EX_USAGE, "%s", target); + if (checkpath(argv[1], source) != 0) + err(EX_USAGE, "%s", source); if (subdir(target, source) || subdir(source, target)) errx(EX_USAGE, "%s (%s) and %s are not distinct paths", diff --git a/sbin/mount_reiserfs/mount_reiserfs.c b/sbin/mount_reiserfs/mount_reiserfs.c index 5fccfbe..bf62526 100644 --- a/sbin/mount_reiserfs/mount_reiserfs.c +++ b/sbin/mount_reiserfs/mount_reiserfs.c @@ -78,7 +78,8 @@ main(int argc, char *argv[]) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) + err(EX_USAGE, "%s", mntpath); (void)rmslashes(dev, dev); /* Read-only support for now */ diff --git a/sbin/mount_std/mount_std.c b/sbin/mount_std/mount_std.c index 3f292b4..c7f1643 100644 --- a/sbin/mount_std/mount_std.c +++ b/sbin/mount_std/mount_std.c @@ -112,7 +112,8 @@ main(int argc, char *argv[]) usage(); /* resolve the mountpoint with realpath(3) */ - (void)checkpath(argv[1], mntpath); + if (checkpath(argv[1], mntpath) != 0) + err(EX_USAGE, "%s", mntpath); iov[0].iov_base = "fstype"; iov[0].iov_len = sizeof("fstype"); diff --git a/sbin/mount_udf/mount_udf.c b/sbin/mount_udf/mount_udf.c index 033db70..8ee1286 100644 --- a/sbin/mount_udf/mount_udf.c +++ b/sbin/mount_udf/mount_udf.c @@ -111,7 +111,8 @@ main(int argc, char **argv) * Resolve the mountpoint with realpath(3) and remove unnecessary * slashes from the devicename if there are any. */ - (void)checkpath(dir, mntpath); + if (checkpath(dir, mntpath) != 0) + err(EX_USAGE, "%s", mntpath); (void)rmslashes(dev, dev); /* diff --git a/sbin/mount_unionfs/mount_unionfs.c b/sbin/mount_unionfs/mount_unionfs.c index edb0fff..c42bf04 100644 --- a/sbin/mount_unionfs/mount_unionfs.c +++ b/sbin/mount_unionfs/mount_unionfs.c @@ -176,8 +176,10 @@ main(int argc, char *argv[]) usage(); /* resolve both target and source with realpath(3) */ - (void)checkpath(argv[0], target); - (void)checkpath(argv[1], source); + if (checkpath(argv[0], target) != 0) + err(EX_USAGE, "%s", target); + if (checkpath(argv[1], source) != 0) + err(EX_USAGE, "%s", source); if (subdir(target, source) || subdir(source, target)) errx(EX_USAGE, "%s (%s) and %s (%s) are not distinct paths", -- cgit v1.1