diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index f90ff00..096c3de 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -5,7 +5,7 @@ use std::{ }; use fs_err as fs; -use crate::utils::landlock; +//use crate::utils::landlock; #[cfg(not(feature = "bzip3"))] use crate::archive; @@ -19,7 +19,7 @@ use crate::{ utils::{ self, io::lock_and_flush_output_stdio, - is_path_stdin, + is_path_stdin, landlock, logger::{info, info_accessible}, nice_directory_display, user_wants_to_continue, }, @@ -324,21 +324,17 @@ fn execute_decompression( is_smart_unpack: bool, disable_sandbox: bool, ) -> crate::Result> { - // init landlock sandbox to restrict file system write access to output_dir // The output directory iseither specified with the -d option or the current working directory is used // TODO: restrict acess to the current working directory to allow only creating new files - // TODO: move to unpack and smart_unpack to cover the differetn dirctories used for // decompression - //if !input_is_stdin && options.remove { //permit write access to input_file_path //} else { //} - + landlock::init_sandbox(&[output_dir], disable_sandbox); - if is_smart_unpack { return smart_unpack(unpack_fn, output_dir, output_file_path, question_policy); diff --git a/src/commands/list.rs b/src/commands/list.rs index e5c1e0d..7dd956e 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -4,14 +4,14 @@ use std::{ }; use fs_err as fs; -use crate::utils::landlock; +//use crate::utils::landlock; use crate::{ archive, commands::warn_user_about_loading_zip_in_memory, extension::CompressionFormat::{self, *}, list::{self, FileInArchive, ListOptions}, - utils::{io::lock_and_flush_output_stdio, user_wants_to_continue}, + utils::{io::lock_and_flush_output_stdio, user_wants_to_continue, landlock}, QuestionAction, QuestionPolicy, BUFFER_CAPACITY, }; @@ -25,7 +25,6 @@ pub fn list_archive_contents( password: Option<&[u8]>, disable_sandbox: bool, ) -> crate::Result<()> { - //rar uses a temporary file which needs to be defined early to be permitted in landlock let mut temp_file = tempfile::NamedTempFile::new()?; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 780bda0..4579ef3 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -261,9 +261,7 @@ pub fn run( .map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")), args.disable_sandbox, )?; - } - Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 4375188..f282dcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,9 +21,6 @@ use self::{ }, }; -//use utils::landlock::*; - - // Used in BufReader and BufWriter to perform less syscalls const BUFFER_CAPACITY: usize = 1024 * 32; @@ -51,7 +48,7 @@ fn run() -> Result<()> { //let working_dir = args.output_dir // .clone() // .unwrap_or_else(|| env::current_dir().unwrap_or_default()); - + // restrict filesystem access to working_dir; // 1. working_dir is either the output_dir specified by the -d option or // 2. it is the temporary .tmp-ouch-XXXXXX directory that is renamed after decompression @@ -64,7 +61,6 @@ fn run() -> Result<()> { // Since either the specified output directory is created if it did not exist, or the .ouch-tmp // directory is created in the current working directory, the parent directory of the target // directory requires LANDLOCK_ACCESS_FS_MAKE_DIR - // expects either the .tmp-ouch-XXXXXX path or the specified output directory (-d option) //utils::landlock::init_sandbox(&working_dir); diff --git a/src/utils/landlock.rs b/src/utils/landlock.rs index 2c28723..ffb4400 100644 --- a/src/utils/landlock.rs +++ b/src/utils/landlock.rs @@ -1,14 +1,14 @@ // Landlock support and generic Landlock sandbox implementation. // https://landlock.io/rust-landlock/landlock/struct.Ruleset.html +use std::path::Path; + use landlock::{ Access, AccessFs, PathBeneath, PathFd, PathFdError, RestrictionStatus, Ruleset, RulesetAttr, RulesetCreatedAttr, RulesetError, ABI, }; use thiserror::Error; -use std::path::Path; - /// The status code returned from `ouch` on error pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 611ee89..126aa0f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -8,9 +8,9 @@ mod file_visibility; mod formatting; mod fs; pub mod io; +pub mod landlock; pub mod logger; mod question; -pub mod landlock; pub use self::{ file_visibility::FileVisibilityPolicy,