summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorJaakko Heinonen <jh@FreeBSD.org>2012-01-16 19:34:21 +0000
committerJaakko Heinonen <jh@FreeBSD.org>2012-01-16 19:34:21 +0000
commitd3250014386b2eae2bf27edcde24d97f7bbfcfc5 (patch)
tree54d0a2f2ed01c217587bf7b24aec11a7fbcadd97 /sbin
parent03c142e76290016711675793c65fe924a3d1b779 (diff)
downloadsrc-test2-d3250014386b2eae2bf27edcde24d97f7bbfcfc5.tar.gz
src-test2-d3250014386b2eae2bf27edcde24d97f7bbfcfc5.zip
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)
Notes
Notes: svn path=/head/; revision=230226
Diffstat (limited to 'sbin')
-rw-r--r--sbin/mount/getmntopts.c12
-rw-r--r--sbin/mount/mntopts.h2
-rw-r--r--sbin/mount/mount.c5
-rw-r--r--sbin/mount/mount_fs.c5
-rw-r--r--sbin/mount_cd9660/mount_cd9660.c3
-rw-r--r--sbin/mount_ext2fs/mount_ext2fs.c3
-rw-r--r--sbin/mount_msdosfs/mount_msdosfs.c3
-rw-r--r--sbin/mount_nfs/mount_nfs.c3
-rw-r--r--sbin/mount_ntfs/mount_ntfs.c3
-rw-r--r--sbin/mount_nullfs/mount_nullfs.c6
-rw-r--r--sbin/mount_reiserfs/mount_reiserfs.c3
-rw-r--r--sbin/mount_std/mount_std.c3
-rw-r--r--sbin/mount_udf/mount_udf.c3
-rw-r--r--sbin/mount_unionfs/mount_unionfs.c6
14 files changed, 41 insertions, 19 deletions
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c
index 194b3df56846..350306062632 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 2903d553f4ef..86a350fcab50 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 cf142e48f98e..ca81795c0d69 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 526d493f9fd3..4c5885750a92 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 3b2827eb7ebe..22159661db7a 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 04d2ea08c86e..87539976e6e9 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 3ba67ea60eb3..3da673dd6fe4 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 c6235e08f279..d71e952ab60f 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 80fcab02e16b..9adfeb586f2a 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 4f84954756d9..c88db3d91cb5 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 5fccfbe9950c..bf625267b9ba 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 3f292b4a9a1d..c7f1643ebfeb 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 033db70b9e6f..8ee1286eea33 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 edb0fff07596..c42bf04dbed4 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",