Ticket #8254: 0002-Allow-non-root-to-mount-BFS-partition-with-bfs_fuse.patch

File 0002-Allow-non-root-to-mount-BFS-partition-with-bfs_fuse.patch, 3.1 KB (added by idefix, 7 years ago)

Only add FUSE options when user is root (updated commit message)

  • src/tools/fs_shell/fuse.cpp

    From 897340d29d918fa2015f293284a5f408c415dccc Mon Sep 17 00:00:00 2001
    From: Jeroen Oortwijn <oortwijn@gmail.com>
    Date: Sat, 31 Mar 2012 21:14:19 +0200
    Subject: [PATCH] Allow non-root to mount BFS partition with bfs_fuse
    
    * Most FUSE options are only allowed for root, so don't add these options
      when user is not root.
    * Fixes ticket #8254.
    ---
     src/tools/fs_shell/fuse.cpp |   57 +++++++++++++++++++++++++------------------
     1 files changed, 33 insertions(+), 24 deletions(-)
    
    diff --git a/src/tools/fs_shell/fuse.cpp b/src/tools/fs_shell/fuse.cpp
    index 6ccd69a..37841f3 100644
    a b  
    99#include <stdio.h>
    1010#include <stdlib.h>
    1111#include <syslog.h>
     12#include <unistd.h>
    1213
    1314#include "fssh.h"
    1415
    fssh_fuse_session(const char* device, const char* mntPoint, const char* fsName, 
    484485    if (ret != 0)
    485486        return ret;
    486487   
    487     char* fuseOptions = NULL;
     488    if (getuid() == 0 && geteuid() == 0 && getgid() == 0 && getegid() == 0) {
     489        // only add FUSE options when user is root
    488490
    489     // default FUSE options
    490     char* fsNameOption = NULL;
    491     if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0
    492         || asprintf(&fsNameOption, "fsname=%s", device) < 0
    493         || fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) {
    494         unmount_volume(device, mntPoint);
    495         return 1;
    496     }
     491        char* fuseOptions = NULL;
    497492
    498     struct stat sbuf;
    499     if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
    500         int blkSize = 512;
    501         fssh_dev_t volumeID = get_volume_id();
    502         if (volumeID >= 0) {
    503             fssh_fs_info info;
    504             if (_kern_read_fs_info(volumeID, &info) == FSSH_B_OK)
    505                 blkSize = info.block_size;
     493        // default FUSE options
     494        char* fsNameOption = NULL;
     495        if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0
     496            || asprintf(&fsNameOption, "fsname=%s", device) < 0
     497            || fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) {
     498            unmount_volume(device, mntPoint);
     499            return 1;
     500        }
     501
     502        struct stat sbuf;
     503        if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
     504            int blkSize = 512;
     505            fssh_dev_t volumeID = get_volume_id();
     506            if (volumeID >= 0) {
     507                fssh_fs_info info;
     508                if (_kern_read_fs_info(volumeID, &info) == FSSH_B_OK)
     509                    blkSize = info.block_size;
     510            }
     511
     512            char* blkSizeOption = NULL;
     513            if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0
     514                || asprintf(&blkSizeOption, "blksize=%i", blkSize) < 0
     515                || fuse_opt_add_opt(&fuseOptions, blkSizeOption) < 0) {
     516                unmount_volume(device, mntPoint);
     517                return 1;
     518            }
    506519        }
    507520
    508         char* blkSizeOption = NULL;
    509         if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0
    510             || asprintf(&blkSizeOption, "blksize=%i", blkSize) < 0
    511             || fuse_opt_add_opt(&fuseOptions, blkSizeOption) < 0) {
     521        if (fuse_opt_add_arg(&fuseArgs, "-o") < 0
     522            || fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
    512523            unmount_volume(device, mntPoint);
    513524            return 1;
    514525        }
    515526    }
    516527
    517528    // Run the fuse_main() loop.
    518     if (fuse_opt_add_arg(&fuseArgs, "-s") < 0
    519         || fuse_opt_add_arg(&fuseArgs, "-o") < 0
    520         || fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
     529    if (fuse_opt_add_arg(&fuseArgs, "-s") < 0) {
    521530        unmount_volume(device, mntPoint);
    522531        return 1;
    523532    }