1818
1919#define FS_NAME "crypt4gh-sqlite.fs"
2020
21+ #define DEFAULT_FILE_MASK 0337
22+ #define DEFAULT_DIR_MASK 0227
23+
2124/* global variable */
2225struct fs_config config ;
2326
@@ -35,7 +38,9 @@ static void usage(struct fuse_args *args)
3538" --debug=N debug level <N>\n"
3639" -o direct_io enable direct i/o\n"
3740" -o file_cache instructs the kernel to cache output data\n"
38- " -o file_cache instructs the kernel to cache output data\n"
41+ " -o dir_cache instructs the kernel to cache directory listings\n"
42+ " -o file_mask=N file permissions' mask [default: %o]\n"
43+ " -o dir_mask=N directory permissions' mask [default: %o]\n"
3944" -o entry_timeout=S seconds for which lookup names are cached [default: one day]\n"
4045" -o attr_timeout=S seconds for which directories/files attributes are cached [default: one day]\n"
4146" -o dotdot Shows '.' and '..' directories [default: ignored]\n"
@@ -46,7 +51,7 @@ static void usage(struct fuse_args *args)
4651" -o seckey=<path> Absolute path to the Crypt4GH secret key\n"
4752" -o passphrase_from_env=<ENVVAR>\n"
4853" read passphrase from environment variable <ENVVAR>\n"
49- , args -> argv [0 ]);
54+ , args -> argv [0 ], DEFAULT_FILE_MASK , DEFAULT_DIR_MASK );
5055}
5156
5257
@@ -68,13 +73,17 @@ static struct fuse_opt fs_opts[] = {
6873
6974 CRYPT4GH_SQLITE_OPT ("direct_io" , direct_io , 1 ),
7075 CRYPT4GH_SQLITE_OPT ("file_cache" , file_cache , 1 ),
76+ CRYPT4GH_SQLITE_OPT ("dir_cache" , dir_cache , 1 ),
7177
7278 CRYPT4GH_SQLITE_OPT ("dotdot" , show_dotdot , 1 ),
7379
7480 /* Mount group id */
7581 CRYPT4GH_SQLITE_OPT ("user_id=%u" , uid , 0 ), // chill... it's not root
7682 CRYPT4GH_SQLITE_OPT ("group_id=%u" , gid , 0 ),
7783
84+ CRYPT4GH_SQLITE_OPT ("file_mask=%u" , fmask , DEFAULT_FILE_MASK ),
85+ CRYPT4GH_SQLITE_OPT ("dir_mask=%u" , dmask , DEFAULT_DIR_MASK ),
86+
7887 /* in case Crypt4GH is enabled */
7988 CRYPT4GH_SQLITE_OPT ("seckey=%s" , seckeypath , 0 ),
8089 CRYPT4GH_SQLITE_OPT ("passphrase_from_env=%s" , passphrase_from_env , 0 ),
@@ -202,6 +211,8 @@ c4gh_init(void)
202211{
203212 int res = 0 ;
204213
214+ D1 ("Initializing the file system" );
215+
205216 if (!config .seckeypath || * config .seckeypath != '/' ){
206217 E ("Missing secret key path, or non-absolute path" );
207218 res ++ ;
@@ -210,7 +221,7 @@ c4gh_init(void)
210221
211222 /* Get the passphrase to unlock the Crypt4GH secret key */
212223 if (config .passphrase_from_env ) {
213- D1 ("Getting the passphrase from envvar %s" , config .passphrase_from_env );
224+ D2 ("Getting the passphrase from envvar %s" , config .passphrase_from_env );
214225 config .passphrase = getenv (config .passphrase_from_env );
215226 } else {
216227 char prompt [PATH_MAX + sizeof ("Enter the passphrase for the Crypt4GH key '': " )];
@@ -235,7 +246,7 @@ c4gh_init(void)
235246 }
236247
237248 /* Load the private key */
238- D2 ("Loading secret key from %s" , config .seckeypath );
249+ D3 ("Loading secret key from %s" , config .seckeypath );
239250
240251 if ( crypt4gh_sqlite_private_key_from_file (config .seckeypath , config .passphrase ,
241252 config .seckey , config .pubkey ) ){
@@ -292,6 +303,9 @@ int main(int argc, char *argv[])
292303 config .uid = getuid (); /* current user */
293304 config .gid = getgid (); /* current group */
294305
306+ config .fmask = DEFAULT_FILE_MASK ;
307+ config .dmask = DEFAULT_DIR_MASK ;
308+
295309 /* General options */
296310 if (fuse_opt_parse (& args , & config , fs_opts , fs_opt_proc ) == -1 )
297311 exit (1 );
@@ -332,6 +346,10 @@ int main(int argc, char *argv[])
332346 exit (1 );
333347 }
334348
349+ /* File and Dir permissions */
350+ config .dperm = 0777 & ~config .dmask ;
351+ config .fperm = 0666 & ~config .dmask ;
352+
335353 fuse_opt_insert_arg (& args , 1 , "-ofsname=" FS_NAME );
336354
337355 if (config .debug )
@@ -392,17 +410,22 @@ int main(int argc, char *argv[])
392410 goto bailout_unmount ;
393411 }
394412
395- D2 ("Mode: %s-threaded" , (config .singlethread )?"single" :"multi" );
396413 D2 ("PID: %d" , getpid ());
397-
398- if (config .singlethread )
414+ D2 ("File cache: %s | Dir cache: %s | File perm: o%o | Dir perm: o%o" ,
415+ (config .file_cache )?"yes" :"no" ,
416+ (config .dir_cache )?"yes" :"no" ,
417+ config .fperm ,
418+ config .dperm );
419+
420+ if (config .singlethread ){
421+ D2 ("Mode: single-threaded" );
399422 res = fuse_session_loop (se );
400- else {
423+ } else {
401424 struct fuse_loop_config cf = {
402425 .clone_fd = config .clone_fd ,
403426 .max_idle_threads = config .max_idle_threads ,
404427 };
405- D2 ("Max idle threads: %d" , cf .max_idle_threads );
428+ D2 ("Mode: multi-threaded (max idle threads: %d) " , cf .max_idle_threads );
406429 res = fuse_session_loop_mt (se , & cf );
407430 }
408431
0 commit comments