Initial commit
This commit is contained in:
41
src/lib.rs
Normal file
41
src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
mod agents;
|
||||
mod blacklist;
|
||||
mod errors;
|
||||
mod preflight;
|
||||
mod sandbox;
|
||||
|
||||
pub use errors::SandboxError;
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub enum SandboxMode {
|
||||
Blacklist,
|
||||
Whitelist,
|
||||
}
|
||||
|
||||
pub struct SandboxConfig {
|
||||
pub mode: SandboxMode,
|
||||
pub hardened: bool,
|
||||
pub no_net: bool,
|
||||
pub extra_rw: Vec<PathBuf>,
|
||||
pub extra_ro: Vec<PathBuf>,
|
||||
pub command: PathBuf,
|
||||
pub command_args: Vec<OsString>,
|
||||
pub chdir: PathBuf,
|
||||
pub dry_run: bool,
|
||||
}
|
||||
|
||||
pub fn run(config: SandboxConfig) -> Result<(), SandboxError> {
|
||||
preflight::check(&config)?;
|
||||
|
||||
let mut cmd = sandbox::build_command(&config)?;
|
||||
|
||||
if config.dry_run {
|
||||
println!("{:?}", cmd);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(SandboxError::Io(cmd.exec()))
|
||||
}
|
||||
Reference in New Issue
Block a user