summaryrefslogtreecommitdiffstats
path: root/sbin/mount
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-10-09 11:54:14 +0000
committerphk <phk@FreeBSD.org>1999-10-09 11:54:14 +0000
commit41c4f3920e76ddd3b3a183fc18e6e0834a26086b (patch)
tree90d36f2866e2e9c8c9fe890230d8240ed54253f1 /sbin/mount
parent977cb3153eec3286210df53421e8494748c21d3a (diff)
downloadFreeBSD-src-41c4f3920e76ddd3b3a183fc18e6e0834a26086b.zip
FreeBSD-src-41c4f3920e76ddd3b3a183fc18e6e0834a26086b.tar.gz
mount* fixes from Martin Blapp <mb@imp.ch>:
Made mount more userfriendly (bad slashes are now filtered out) and we remove in mount_nfs trailing slashes if there are any. Fixed mount_xxx binarys to resolve with realpath(3) the mountpoint. Translate the deprecated nfs-syntax with '@' to ':' . The ':' syntax has now precedence, but '@' still works. Notify the user that the '@' syntax should not be used. PR: 7846 PR: 13692 Submitted by: Martin Blapp <mb@imp.ch> Reviewed by: phk
Diffstat (limited to 'sbin/mount')
-rw-r--r--sbin/mount/getmntopts.c39
-rw-r--r--sbin/mount/mntopts.h2
-rw-r--r--sbin/mount/mount.c14
3 files changed, 44 insertions, 11 deletions
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c
index c80c262..ffc18bf 100644
--- a/sbin/mount/getmntopts.c
+++ b/sbin/mount/getmntopts.c
@@ -41,10 +41,13 @@ static const char rcsid[] =
#endif /* not lint */
#include <sys/param.h>
+#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include "mntopts.h"
@@ -106,3 +109,39 @@ getmntopts(options, m0, flagp, altflagp)
free(optbuf);
}
+
+void
+rmslashes(rrpin, rrpout)
+ char *rrpin;
+ char *rrpout;
+{
+ char *rrpoutstart;
+
+ *rrpout = *rrpin;
+ for (rrpoutstart = rrpout; *rrpin != '\0'; *rrpout++ = *rrpin++) {
+
+ /* skip all double slashes */
+ while (*rrpin == '/' && *(rrpin + 1) == '/')
+ rrpin++;
+ }
+
+ /* remove trailing slash if necessary */
+ if (rrpout - rrpoutstart > 1 && *(rrpout - 1) == '/')
+ *(rrpout - 1) = '\0';
+ else
+ *rrpout = '\0';
+}
+
+void
+checkpath(path, resolved)
+ 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);
+ } else
+ errx(EX_USAGE, "%s: %s", resolved, strerror(errno));
+}
diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h
index dd98298..73c3c15 100644
--- a/sbin/mount/mntopts.h
+++ b/sbin/mount/mntopts.h
@@ -88,4 +88,6 @@ struct mntopt {
MOPT_NOCLUSTERW
void getmntopts __P((const char *, const struct mntopt *, int *, int *));
+void rmslashes __P((char *, char *));
+void checkpath __P((const char *, char resolved_path[]));
extern int getmnt_silent;
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 039ee95..b84696a 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -61,6 +61,7 @@ static const char rcsid[] =
#include <unistd.h>
#include "extern.h"
+#include "mntopts.h"
#include "pathnames.h"
/* `meta' options */
@@ -354,7 +355,6 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
NULL
};
const char *argv[100], **edir;
- struct stat sb;
struct statfs sf;
pid_t pid;
int argc, i, status;
@@ -365,16 +365,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
(void)&name;
#endif
- if (realpath(name, mntpath) != NULL && stat(mntpath, &sb) == 0) {
- if (!S_ISDIR(sb.st_mode)) {
- warnx("%s: not a directory", mntpath);
- return (1);
- }
- } else {
- warn("%s", mntpath);
- return (1);
- }
-
+ /* resolve the mountpoint with realpath(3) */
+ (void)checkpath(name, mntpath);
name = mntpath;
if (mntopts == NULL)
OpenPOWER on IntegriCloud