[haiku-commits] haiku: hrev50364 - src/tools/fs_shell

  • From: waddlesplash@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 19 Jun 2016 04:55:55 +0200 (CEST)

hrev50364 adds 1 changeset to branch 'master'
old head: 73e180c9b965aaeb034055453e153bc3adf47917
new head: ef9b129675d49eb42d973298cb9c253eb987af55
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=ef9b129675d4+%5E73e180c9b965

----------------------------------------------------------------------------

ef9b129675d4: bfs_fuse: Allow non-root to mount BFS partitions.
  
  * Most FUSE options are only allowed for root, so don't add these options
    when user is not root.
  * Fixes ticket #8254.
  
  Signed-off-by: Augustin Cavalier <waddlesplash@xxxxxxxxx>
  Coding style looks OK to me and there are multiple comments that
  it works, so just merging it.

                                    [ Jeroen Oortwijn <oortwijn@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev50364
Commit:      ef9b129675d49eb42d973298cb9c253eb987af55
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ef9b129675d4
Author:      Jeroen Oortwijn <oortwijn@xxxxxxxxx>
Date:        Sat Mar 31 19:14:19 2012 UTC
Committer:   Augustin Cavalier <waddlesplash@xxxxxxxxx>
Commit-Date: Sun Jun 19 02:11:21 2016 UTC

Ticket:      https://dev.haiku-os.org/ticket/8254

----------------------------------------------------------------------------

1 file changed, 33 insertions(+), 24 deletions(-)
src/tools/fs_shell/fuse.cpp | 57 ++++++++++++++++++++++++-----------------

----------------------------------------------------------------------------

diff --git a/src/tools/fs_shell/fuse.cpp b/src/tools/fs_shell/fuse.cpp
index e9b09f8..d975e4e 100644
--- a/src/tools/fs_shell/fuse.cpp
+++ b/src/tools/fs_shell/fuse.cpp
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include "fssh.h"
 
@@ -479,40 +480,48 @@ fssh_fuse_session(const char* device, const char* 
mntPoint, const char* fsName,
        if (ret != 0)
                return ret;
        
-       char* fuseOptions = NULL;
+       if (getuid() == 0 && geteuid() == 0 && getgid() == 0 && getegid() == 0) 
{
+               // only add FUSE options when user is root
 
-       // default FUSE options
-       char* fsNameOption = NULL;
-       if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0
-               || asprintf(&fsNameOption, "fsname=%s", device) < 0
-               || fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) {
-               unmount_volume(device, mntPoint);
-               return 1;
-       }
+               char* fuseOptions = NULL;
 
-       struct stat sbuf;
-       if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
-               int blkSize = 512;
-               fssh_dev_t volumeID = get_volume_id();
-               if (volumeID >= 0) {
-                       fssh_fs_info info;
-                       if (_kern_read_fs_info(volumeID, &info) == FSSH_B_OK)
-                               blkSize = info.block_size;
+               // default FUSE options
+               char* fsNameOption = NULL;
+               if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0
+                       || asprintf(&fsNameOption, "fsname=%s", device) < 0
+                       || fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) {
+                       unmount_volume(device, mntPoint);
+                       return 1;
+               }
+
+               struct stat sbuf;
+               if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
+                       int blkSize = 512;
+                       fssh_dev_t volumeID = get_volume_id();
+                       if (volumeID >= 0) {
+                               fssh_fs_info info;
+                               if (_kern_read_fs_info(volumeID, &info) == 
FSSH_B_OK)
+                                       blkSize = info.block_size;
+                       }
+
+                       char* blkSizeOption = NULL;
+                       if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0
+                               || asprintf(&blkSizeOption, "blksize=%i", 
blkSize) < 0
+                               || fuse_opt_add_opt(&fuseOptions, 
blkSizeOption) < 0) {
+                               unmount_volume(device, mntPoint);
+                               return 1;
+                       }
                }
 
-               char* blkSizeOption = NULL;
-               if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0
-                       || asprintf(&blkSizeOption, "blksize=%i", blkSize) < 0
-                       || fuse_opt_add_opt(&fuseOptions, blkSizeOption) < 0) {
+               if (fuse_opt_add_arg(&fuseArgs, "-o") < 0
+                       || fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
                        unmount_volume(device, mntPoint);
                        return 1;
                }
        }
 
        // Run the fuse_main() loop.
-       if (fuse_opt_add_arg(&fuseArgs, "-s") < 0
-               || fuse_opt_add_arg(&fuseArgs, "-o") < 0
-               || fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
+       if (fuse_opt_add_arg(&fuseArgs, "-s") < 0) {
                unmount_volume(device, mntPoint);
                return 1;
        }


Other related posts:

  • » [haiku-commits] haiku: hrev50364 - src/tools/fs_shell - waddlesplash