fusermount: only allow mount and umount if util-linux suppports --no-canonicalize
authorMiklos Szeredi <mszeredi@suse.cz>
Mon, 31 Jan 2011 15:22:41 +0000 (16:22 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Mon, 31 Jan 2011 15:33:22 +0000 (16:33 +0100)
Remove "legacy" util-linux support as missing --no-canonicalize cannot
be worked around in fuse.

ChangeLog
configure.in
lib/mount_util.c
util/fusermount.c

index 2dd811dad5de2a66d34bf4207852f4b446933fb2..297ac827ba0ba4990797fd9c721fd5346898961b 100644 (file)
--- 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
index 7487fb68df27dba365e7aedbc75cfe4d7a4089d8..47bb20602d67ba44f9522c140f5e86e4a36ae8f5 100644 (file)
@@ -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])
index edbba1215af58ce9185dde90239b75b99ebf02ae..5b660d653dd5fe2d5335c8283c0b35c7ea714384 100644 (file)
@@ -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)
index bbed25f82f28e5bad8762eb62bf26bb3d35c48f4..94a5dbcd5f88c709ff428bb4224bab6d7afab642 100644 (file)
@@ -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)