aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <mszeredi@suse.cz>2011-01-31 16:22:41 +0100
committerGravatar Miklos Szeredi <mszeredi@suse.cz>2011-01-31 16:33:22 +0100
commitcbd3a2a84068aae6e3fe32939d88470d712dbf47 (patch)
treea7e22ac017fb90072b78e78f9c2aaf0957a4855e
parent1e7607ff89c65b005f69e27aeb1649d624099873 (diff)
fusermount: only allow mount and umount if util-linux suppports --no-canonicalize
Remove "legacy" util-linux support as missing --no-canonicalize cannot be worked around in fuse.
-rw-r--r--ChangeLog3
-rw-r--r--configure.in6
-rw-r--r--lib/mount_util.c72
-rw-r--r--util/fusermount.c167
4 files changed, 36 insertions, 212 deletions
diff --git a/ChangeLog b/ChangeLog
index 2dd811d..297ac82 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
* fusermount: chdir to / before performing mount/umount
+ * fusermount: only allow mount and umount if util-linux supports
+ --no-canonicalize
+
2010-12-16 Miklos Szeredi <miklos@szeredi.hu>
* Highlevel lib: allow hash tables to shrink
diff --git a/configure.in b/configure.in
index 7487fb6..47bb206 100644
--- a/configure.in
+++ b/configure.in
@@ -33,8 +33,6 @@ AC_ARG_ENABLE(example,
[ --enable-example Compile with examples ])
AC_ARG_ENABLE(mtab,
[ --disable-mtab Disable and ignore usage of /etc/mtab ])
-AC_ARG_ENABLE(legacy-umount,
- [ --disable-legacy-umount If umount(8) is util-linux-ng >= 2.18 ])
AC_ARG_WITH(pkgconfigdir,
[ --with-pkgconfigdir=DIR pkgconfig file in DIR @<:@LIBDIR/pkgconfig@:>@],
@@ -57,10 +55,6 @@ if test "$enable_mtab" = "no"; then
AC_DEFINE(IGNORE_MTAB, 1, [Don't update /etc/mtab])
fi
-if test "$enable_legacy_umount" != "no"; then
- AC_DEFINE(LEGACY_UMOUNT, 1, [Enable legacy umount support])
-fi
-
AC_CHECK_FUNCS([fork setxattr fdatasync])
AC_CHECK_MEMBERS([struct stat.st_atim])
AC_CHECK_MEMBERS([struct stat.st_atimespec])
diff --git a/lib/mount_util.c b/lib/mount_util.c
index edbba12..5b660d6 100644
--- a/lib/mount_util.c
+++ b/lib/mount_util.c
@@ -73,70 +73,6 @@ static int mtab_needs_update(const char *mnt)
}
#endif /* __NetBSD__ */
-static int add_mount_legacy(const char *progname, const char *fsname,
- const char *mnt, const char *type, const char *opts)
-{
- int res;
- int status;
- sigset_t blockmask;
- sigset_t oldmask;
-
- sigemptyset(&blockmask);
- sigaddset(&blockmask, SIGCHLD);
- res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
- if (res == -1) {
- fprintf(stderr, "%s: sigprocmask: %s\n", progname, strerror(errno));
- return -1;
- }
-
- res = fork();
- if (res == -1) {
- fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
- goto out_restore;
- }
- if (res == 0) {
- char templ[] = "/tmp/fusermountXXXXXX";
- char *tmp;
-
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
- setuid(geteuid());
-
- /*
- * hide in a directory, where mount isn't able to resolve
- * fsname as a valid path
- */
- tmp = mkdtemp(templ);
- if (!tmp) {
- fprintf(stderr,
- "%s: failed to create temporary directory\n",
- progname);
- exit(1);
- }
- if (chdir(tmp)) {
- fprintf(stderr, "%s: failed to chdir to %s: %s\n",
- progname, tmp, strerror(errno));
- exit(1);
- }
- rmdir(tmp);
- execl("/bin/mount", "/bin/mount", "-i", "-f", "-t", type,
- "-o", opts, fsname, mnt, NULL);
- fprintf(stderr, "%s: failed to execute /bin/mount: %s\n",
- progname, strerror(errno));
- exit(1);
- }
- res = waitpid(res, &status, 0);
- if (res == -1)
- fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
-
- if (status != 0)
- res = -1;
-
- out_restore:
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
-
- return res;
-}
-
static int add_mount(const char *progname, const char *fsname,
const char *mnt, const char *type, const char *opts)
{
@@ -191,16 +127,10 @@ static int add_mount(const char *progname, const char *fsname,
int fuse_mnt_add_mount(const char *progname, const char *fsname,
const char *mnt, const char *type, const char *opts)
{
- int res;
-
if (!mtab_needs_update(mnt))
return 0;
- res = add_mount(progname, fsname, mnt, type, opts);
- if (res == -1)
- res = add_mount_legacy(progname, fsname, mnt, type, opts);
-
- return res;
+ return add_mount(progname, fsname, mnt, type, opts);
}
static int exec_umount(const char *progname, const char *rel_mnt, int lazy)
diff --git a/util/fusermount.c b/util/fusermount.c
index bbed25f..94a5dbc 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -382,54 +382,6 @@ static int chdir_to_parent(char *copy, const char **lastp)
return 0;
}
-static int unmount_fuse_legacy(const char *mnt, int lazy)
-{
- char *copy;
- const char *last;
- int res;
-
- copy = strdup(mnt);
- if (copy == NULL) {
- fprintf(stderr, "%s: failed to allocate memory\n", progname);
- return -1;
- }
-
- res = chdir_to_parent(copy, &last);
- if (res == -1)
- goto out;
-
- res = check_is_mount(last, mnt);
- if (res == -1)
- goto out;
-
- res = fuse_mnt_umount(progname, mnt, last, lazy);
-
-out:
- free(copy);
-
- return res;
-}
-
-static int unmount_fuse_nofollow(const char *mnt, int quiet, int lazy)
-{
- int res;
- int umount_flags = UMOUNT_NOFOLLOW;
-
- if (lazy)
- umount_flags |= UMOUNT_DETACH;
-
- res = umount2(mnt, umount_flags);
- if (res == -1) {
- if (!quiet) {
- fprintf(stderr, "%s: failed to unmount %s: %s\n",
- progname, mnt, strerror(errno));
- }
- return -1;
- }
-
- return fuse_mnt_remove_mount(progname, mnt);
-}
-
/* Check whether the kernel supports UMOUNT_NOFOLLOW flag */
static int umount_nofollow_support(void)
{
@@ -444,91 +396,12 @@ static int umount_nofollow_support(void)
return 1;
}
-#ifdef LEGACY_UMOUNT
-/* Check if umount(8) supports "--fake" and "--no-canonicalize" options */
-static int umount_fake_support(void)
-{
- int res;
- int status;
- sigset_t blockmask;
- sigset_t oldmask;
- int pip[2];
- char buf[1024];
- char *s;
- unsigned majver;
- unsigned minver;
- int supported = 0;
- int pid;
-
- res = pipe(pip);
- if (res == -1)
- return 0;
-
- sigemptyset(&blockmask);
- sigaddset(&blockmask, SIGCHLD);
- res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
- if (res == -1)
- goto out_close;
-
- pid = fork();
- if (pid == -1)
- goto out_restore;
-
- if (pid == 0) {
- int nullfd;
-
- close(pip[0]);
- dup2(pip[1], 1);
- if (pip[1] != 1)
- close(pip[1]);
- nullfd = open("/dev/null", O_WRONLY);
- dup2(nullfd, 2);
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
- setuid(getuid());
- execl("/bin/umount", "/bin/umount", "--version", NULL);
- exit(1);
- }
- res = read(pip[0], buf, sizeof(buf));
- if (res == -1 || res == sizeof(buf))
- buf[0] = '\0';
- else
- buf[res] = '\0';
-
- res = waitpid(pid, &status, 0);
- if (res == -1 || status != 0)
- goto out_restore;
-
- s = strstr(buf, "util-linux-ng ");
- if (s == NULL)
- goto out_restore;
-
- s += 14;
- if (sscanf(s, "%u.%u", &majver, &minver) < 2)
- goto out_restore;
-
- if (majver < 2 || (majver == 2 && minver < 18))
- goto out_restore;
-
- supported = 1;
-
-out_restore:
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
-out_close:
- close(pip[0]);
- close(pip[1]);
-
- return supported;
-}
-#else
-static int umount_fake_support(void)
-{
- return 1;
-}
-#endif
-
static int unmount_fuse_locked(const char *mnt, int quiet, int lazy)
{
int res;
+ char *copy;
+ const char *last;
+ int umount_flags = lazy ? UMOUNT_DETACH : 0;
if (getuid() != 0) {
res = may_unmount(mnt, quiet);
@@ -536,12 +409,36 @@ static int unmount_fuse_locked(const char *mnt, int quiet, int lazy)
return -1;
}
- if (umount_nofollow_support() && umount_fake_support())
- res = unmount_fuse_nofollow(mnt, quiet, lazy);
- else
- res = unmount_fuse_legacy(mnt, lazy);
+ copy = strdup(mnt);
+ if (copy == NULL) {
+ fprintf(stderr, "%s: failed to allocate memory\n", progname);
+ return -1;
+ }
- return res;
+ res = chdir_to_parent(copy, &last);
+ if (res == -1)
+ goto out;
+
+ if (umount_nofollow_support()) {
+ umount_flags |= UMOUNT_NOFOLLOW;
+ } else {
+ res = check_is_mount(last, mnt);
+ if (res == -1)
+ goto out;
+ }
+
+ res = umount2(last, umount_flags);
+ if (res == -1 && !quiet) {
+ fprintf(stderr, "%s: failed to unmount %s: %s\n",
+ progname, mnt, strerror(errno));
+ }
+
+out:
+ chdir("/");
+ if (res == -1)
+ return -1;
+
+ return fuse_mnt_remove_mount(progname, mnt);
}
static int unmount_fuse(const char *mnt, int quiet, int lazy)