Skip to content

Commit

Permalink
Support unmount FUSE mounts
Browse files Browse the repository at this point in the history
FUSE mounts don't need an fstab entry to be unmounted.
This checks if a mount is a FUSE mount before checking for
the fstab entry, and if so returns success.
  • Loading branch information
rianhunter committed Oct 14, 2018
1 parent e4f29ab commit 96c0051
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions libmount/src/context_umount.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,50 @@ static int prepare_helper_from_options(struct libmnt_context *cxt,
return rc;
}

static int is_fuse_mount(const struct libmnt_fs *fs)
{
int found;
char *user;
char uidstr[32];
unsigned uidlen = 0;

user = mnt_get_username(getuid());
if (!user)
return -1;

uidlen = sprintf(uidstr, "%u", getuid());

found = 0;

if (strcmp(fs->fstype, "fuse") == 0 ||
strcmp(fs->fstype, "fuseblk") == 0 ||
strncmp(fs->fstype, "fuse.", 5) == 0 ||
strncmp(fs->fstype, "fuseblk.", 8) == 0) {

char *p = strstr(fs->optstr, "user=");
if (p &&
(p == fs->optstr || *(p-1) == ',') &&
strcmp(p + 5, user) == 0) {
found = 1;
}
/* /etc/mtab is a link pointing to
/proc/mounts: */
else if ((p =
strstr(fs->optstr, "user_id=")) &&
(p == fs->optstr ||
*(p-1) == ',') &&
strncmp(p + 8, uidstr, uidlen) == 0 &&
(*(p+8+uidlen) == ',' ||
*(p+8+uidlen) == '\0')) {
found = 1;
}
}

if (!found)
return -1;
return 0;
}

/*
* Note that cxt->fs contains relevant mtab entry!
*/
Expand Down Expand Up @@ -424,6 +468,14 @@ static int evaluate_permissions(struct libmnt_context *cxt)
return 0; /* we'll call /sbin/umount.<uhelper> */
}

/*
* Check if this is a fuse mount for the current user,
* if so then unmounting is allowed
*/
if (!is_fuse_mount(cxt->fs)) {
return 0;
}

/*
* User mounts have to be in /etc/fstab
*/
Expand Down

0 comments on commit 96c0051

Please sign in to comment.