Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] umount: allow non-root umount of FUSE even if not in fstab
@ 2011-03-28 14:04 Petr Uzel
  2011-03-28 14:23 ` Miklos Szeredi
  2011-03-28 22:03 ` Karel Zak
  0 siblings, 2 replies; 12+ messages in thread
From: Petr Uzel @ 2011-03-28 14:04 UTC (permalink / raw)
  To: util-linux; +Cc: Miklos Szeredi

[-- Attachment #1: Type: text/plain, Size: 2766 bytes --]

Hi all,

I hacked the following patch with which it is possible to use 
"umount $dir" instead of "fusermount -u $dir", which IMHO is an
improvement in usability. It seems to work (at least for me), however,
I have to admit that I don't like it very much, because:
- it complicates umount
- duplicates code from fusermount
- should (???) be implemented using umount helpers

With regard to uhelpers: I spent some time looking into the fuse code,
but I don't think it could be done easily - has anybody investigated
this?

Related discussion (from 2006):
http://sourceforge.net/mailarchive/forum.php?thread_name=1253960851.6399.43.camel%40localhost.localdomain&forum_name=fuse-devel

This feature addresses:
https://fate.novell.com/310710

---------- 8< ---------- 8< -----------

This patch introduces an exception to the "no non-root unmounts
unless the mount is in fstab", which is necessary to allow
unmounting FUSE filesystems with umount (originally, one
had to use fusermount -u).

Umount makes the same checks as fusermount -u does, namely:
- if the fstype starts with fuse/fuseblk
- compares the user_id stored in /etc/mtab (or /proc/mounts) with
  real UID of the calling user

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 mount/umount.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/mount/umount.c b/mount/umount.c
index 42671f4..f887c6f 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -592,6 +592,33 @@ umount_file (char *arg) {
 			    _("umount: it seems %s is mounted multiple times"),
 			    file);
 
+		/* If this is fuse-based filesystem, allow user unmount even
+		 * if the FS is not in fstab.
+		 *
+		 * Based on fusermount code. */
+		if (strcmp(mc->m.mnt_type, "fuse") == 0 ||
+		    strcmp(mc->m.mnt_type, "fuseblk") == 0 ||
+		    strncmp(mc->m.mnt_type, "fuse.", 5) == 0 ||
+		    strncmp(mc->m.mnt_type, "fuseblk.", 8) == 0) {
+			char *fuse_uidstr;
+			fuse_uidstr = get_option_value(mc->m.mnt_opts, "user=");
+			if (!fuse_uidstr)
+				fuse_uidstr = get_option_value(mc->m.mnt_opts, "user_id=");
+			if (fuse_uidstr) {
+				char uidstr[32];
+				unsigned uidlen;
+				uidlen = sprintf(uidstr, "%u", getuid());
+				if (strncmp(uidstr, fuse_uidstr, uidlen) == 0) {
+					if (verbose)
+						printf(_("Unmounting %s (FUSE filesystem, mounted by uid=%s)\n"),
+						       arg, uidstr);
+					int ret = umount_one(arg, arg, arg, arg, NULL);
+					free(fuse_uidstr);
+					return ret;
+				}
+			}
+		}
+
 		/* If fstab contains the two lines
 		   /dev/sda1 /mnt/zip auto user,noauto  0 0
 		   /dev/sda4 /mnt/zip auto user,noauto  0 0
-- 
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-03-29 10:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-28 14:04 [PATCH] umount: allow non-root umount of FUSE even if not in fstab Petr Uzel
2011-03-28 14:23 ` Miklos Szeredi
2011-03-29  8:08   ` Petr Uzel
2011-03-29  8:28   ` Karel Zak
2011-03-29  8:48     ` Miklos Szeredi
2011-03-29 10:13       ` Karel Zak
2011-03-28 22:03 ` Karel Zak
2011-03-29  8:46   ` Petr Uzel
2011-03-29  8:51     ` Miklos Szeredi
2011-03-29  8:56       ` Petr Uzel
2011-03-29 10:03         ` Karel Zak
2011-03-29 10:36     ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox