aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMaxime Henrion <mux@FreeBSD.org>2002-04-22 23:03:03 +0000
committerMaxime Henrion <mux@FreeBSD.org>2002-04-22 23:03:03 +0000
commit003dbca6a6224c54037988d32d5c638842fdce61 (patch)
treefed40ffa0841fcb8cf5e5f2eceb00a70c0725205 /sbin
parentc1ab4f157d28f3f929eeed198ea57be36740d2c3 (diff)
downloadsrc-003dbca6a6224c54037988d32d5c638842fdce61.tar.gz
src-003dbca6a6224c54037988d32d5c638842fdce61.zip
Do our best to determine if the user is attempting an NFS mount when
the filesystem type isn't given in the command line. In the case of an IPv6 address containing ':', one must use the '@' separator for it to be properly parsed (mount_nfs(8) still needs fixing at the moment though). PR: bin/37230 Reviewed by: obrien MFC after: 1 week
Notes
Notes: svn path=/head/; revision=95289
Diffstat (limited to 'sbin')
-rw-r--r--sbin/mount/mount.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 3494d9cd0269..b3ffc3af36ee 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -50,6 +50,7 @@ static const char rcsid[] =
#include <sys/stat.h>
#include <sys/wait.h>
+#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fstab.h>
@@ -131,7 +132,7 @@ main(argc, argv)
FILE *mountdfp;
pid_t pid;
int all, ch, i, init_flags, mntsize, rval, have_fstab;
- char *options;
+ char *cp, *ep, *options;
all = init_flags = 0;
options = NULL;
@@ -278,13 +279,25 @@ main(argc, argv)
case 2:
/*
* If -t flag has not been specified, the path cannot be
- * found, spec contains either a ':' or a '@', and the
- * spec is not a file with those characters, then assume
+ * found, spec contains either a ':' or a '@', then assume
* that an NFS filesystem is being specified ala Sun.
+ * Check if the hostname contains only allowed characters
+ * to reduce false positives. IPv6 addresses containing
+ * ':' will be correctly parsed only if the separator is '@'.
+ * The definition of a valid hostname is taken from RFC 1034.
*/
- if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL &&
- access(argv[0], 0) == -1)
- vfstype = "nfs";
+ if (vfslist == NULL && ((ep = strchr(argv[0], '@')) != NULL) ||
+ ((ep = strchr(argv[0], ':')) != NULL)) {
+ cp = argv[0];
+ while (cp != ep) {
+ if (!isdigit(*cp) && !isalpha(*cp) &&
+ *cp != '.' && *cp != '-' && *cp != ':')
+ break;
+ cp++;
+ }
+ if (cp == ep)
+ vfstype = "nfs";
+ }
rval = mountfs(vfstype,
argv[0], argv[1], init_flags, options, NULL);
break;