Skip to content

Commit ae5fed3

Browse files
committed
allow output dir
1 parent 5883498 commit ae5fed3

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/main.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub mod sandbox;
1111

1212
use std::{env, path::PathBuf};
1313

14+
use log::{error, warn, info};
15+
1416
use cli::CliArgs;
1517
use once_cell::sync::Lazy;
1618

@@ -45,37 +47,44 @@ fn main() {
4547
fn run() -> Result<()> {
4648
let (args, skip_questions_positively, file_visibility_policy) = CliArgs::parse_and_validate_args()?;
4749

48-
// check args if case A: "decompress -d <outputdir>" or case B: "decompress -r" is used
49-
//if true
50-
//Case A:
51-
// write_dirs = outputdir
52-
//Case B:
53-
// write_dir = inputdir
50+
// Get the output dir if specified, else use current dir
51+
let working_dir = args.output_dir
52+
.clone()
53+
.unwrap_or_else(|| env::current_dir().unwrap_or_default());
5454

55-
//init_sandbox( write_dirs );
56-
init_sandbox();
55+
// restrict filesystem access to working_dir;
56+
init_sandbox(&working_dir);
5757

5858
commands::run(args, skip_questions_positively, file_visibility_policy)
5959
}
6060

6161
// init_sandbox( write_dirs
62-
fn init_sandbox() {
62+
fn init_sandbox(allowed_dir: &Path) {
6363

64-
if utils::landlock_support::is_landlock_supported() {
65-
println!("Landlock is supported and can be enabled.");
64+
if std::env::var("CI").is_ok() {
65+
warn!("Landlock sandboxing is disabled in CI environments.");
66+
return;
67+
}
6668

67-
let working_dir = get_current_working_dir().expect("Cannot get current working dir");
68-
let path_str = working_dir.to_str().expect("Cannot convert path");
69-
let status = sandbox::restrict_paths(&[path_str]).expect("failed to build the ruleset");
7069

70+
if utils::landlock_support::is_landlock_supported() {
71+
info!("Landlock is supported and can be enabled.");
72+
73+
let path_str = allowed_dir.to_str().expect("Cannot convert path");
74+
match sandbox::restrict_paths(&[path_str]) {
75+
Ok(status) => {
76+
if !status.is_restricted() {
77+
warn!("Landlock restriction was not successfully applied.");
78+
}
79+
}
80+
Err(e) => {
81+
error!("Failed to build the Landlock ruleset: {e}");
82+
std::process::exit(EXIT_FAILURE);
83+
}
84+
}
7185
} else {
72-
println!("Landlock is NOT supported on this platform or kernel (<5.19).");
86+
warn!("Landlock is NOT supported on this platform or kernel (<5.19).");
7387
}
7488

75-
// todos:
76-
// check status and report error or warning if landlock restriction failed
7789
}
7890

79-
fn get_current_working_dir() -> std::io::Result<PathBuf> {
80-
env::current_dir()
81-
}

0 commit comments

Comments
 (0)