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)
This commit is contained in:
Jaakko Heinonen 2012-01-16 19:34:21 +00:00
parent 03c142e762
commit d325001438
15 changed files with 43 additions and 20 deletions

View File

@ -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

View File

@ -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, ...);

View File

@ -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)

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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",

View File

@ -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 */

View File

@ -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");

View File

@ -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);
/*

View File

@ -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",

View File

@ -140,7 +140,8 @@ main(int argc, char *argv[])
}
/* resolve the mountpoint with realpath(3) */
(void)checkpath(argv[optind+1], mountpt);
if (checkpath(argv[optind+1], mountpt) != 0)
err(EX_USAGE, "%s", mountpt);
/*
* Construct the listening socket