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 <[email protected]> Coding style looks OK to me and there are multiple comments that it works, so just merging it.
This commit is contained in:
committed by
Augustin Cavalier
parent
73e180c9b9
commit
ef9b129675
+33
-24
@@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fssh.h"
|
#include "fssh.h"
|
||||||
|
|
||||||
@@ -479,40 +480,48 @@ fssh_fuse_session(const char* device, const char* mntPoint, const char* fsName,
|
|||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
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* fuseOptions = NULL;
|
||||||
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;
|
// default FUSE options
|
||||||
if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
|
char* fsNameOption = NULL;
|
||||||
int blkSize = 512;
|
if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0
|
||||||
fssh_dev_t volumeID = get_volume_id();
|
|| asprintf(&fsNameOption, "fsname=%s", device) < 0
|
||||||
if (volumeID >= 0) {
|
|| fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) {
|
||||||
fssh_fs_info info;
|
unmount_volume(device, mntPoint);
|
||||||
if (_kern_read_fs_info(volumeID, &info) == FSSH_B_OK)
|
return 1;
|
||||||
blkSize = info.block_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* blkSizeOption = NULL;
|
struct stat sbuf;
|
||||||
if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0
|
if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) {
|
||||||
|| asprintf(&blkSizeOption, "blksize=%i", blkSize) < 0
|
int blkSize = 512;
|
||||||
|| fuse_opt_add_opt(&fuseOptions, blkSizeOption) < 0) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fuse_opt_add_arg(&fuseArgs, "-o") < 0
|
||||||
|
|| fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
|
||||||
unmount_volume(device, mntPoint);
|
unmount_volume(device, mntPoint);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the fuse_main() loop.
|
// Run the fuse_main() loop.
|
||||||
if (fuse_opt_add_arg(&fuseArgs, "-s") < 0
|
if (fuse_opt_add_arg(&fuseArgs, "-s") < 0) {
|
||||||
|| fuse_opt_add_arg(&fuseArgs, "-o") < 0
|
|
||||||
|| fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) {
|
|
||||||
unmount_volume(device, mntPoint);
|
unmount_volume(device, mntPoint);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user