@@ -46,37 +46,50 @@ fn main() {
4646fn run ( ) -> Result < ( ) > {
4747 let ( args, skip_questions_positively, file_visibility_policy) = CliArgs :: parse_and_validate_args ( ) ?;
4848
49- // check args if case A: "decompress -d <outputdir>" or case B: "decompress -r" is used
50- //if true
51- //Case A:
52- // write_dirs = outputdir
53- //Case B:
54- // write_dir = inputdir
5549
56- //init_sandbox( write_dirs );
57- init_sandbox ( ) ;
50+ let working_dir = args. output_dir
51+
52+
53+ // Get the output dir if specified, else use current dir
54+ let working_dir = args. output_dir
55+ . clone ( )
56+ . unwrap_or_else ( || env:: current_dir ( ) . unwrap_or_default ( ) ) ;
57+
58+ // restrict filesystem access to working_dir;
59+ init_sandbox ( & working_dir) ;
5860
5961 commands:: run ( args, skip_questions_positively, file_visibility_policy)
6062}
6163
6264// init_sandbox( write_dirs
6365fn init_sandbox ( ) {
6466
67+
68+ use std:: ffi:: OsStr ;
69+ use std:: os:: unix:: ffi:: OsStrExt ;
70+
6571 if landlock_support:: is_landlock_supported ( ) {
66- println ! ( "Landlock is supported and can be enabled." ) ;
72+ info ! ( "Landlock is supported and will be enabled" ) ;
73+
74+ let path_str = allowed_dir. to_str ( ) . expect ( "Cannot convert path" ) ;
75+ //let status = sandbox::restrict_paths(&[path_str]).expect("failed to build the ruleset");
76+
77+ match sandbox:: restrict_paths ( & [ path_str] ) {
78+ Ok ( status) => {
79+ if !status. is_restricted ( ) {
80+ warn ! ( "Landlock restriction was not successfully applied!" ) ;
81+ }
82+ }
83+ Err ( e) => {
84+ error ! ( "Failed to build the Landlock ruleset: {e}" ) ;
85+ std:: process:: exit ( EXIT_FAILURE ) ;
86+ }
87+ }
6788
68- let working_dir = get_current_working_dir ( ) . expect ( "Cannot get current working dir" ) ;
69- let path_str = working_dir. to_str ( ) . expect ( "Cannot convert path" ) ;
70- let status = sandbox:: restrict_paths ( & [ path_str] ) . expect ( "failed to build the ruleset" ) ;
7189
7290 } else {
73- println ! ( "Landlock is NOT supported on this platform or kernel (<5.19). " ) ;
91+ info ! ( "Landlock is NOT supported on this platform or kernel (<5.19)" ) ;
7492 }
7593
76- // todos:
77- // check status and report error or warning if landlock restriction failed
7894}
7995
80- fn get_current_working_dir ( ) -> std:: io:: Result < PathBuf > {
81- env:: current_dir ( )
82- }
0 commit comments