extern crate gaol;
use gaol::profile::{AddressPattern, Operation, OperationSupport, OperationSupportLevel};
use gaol::profile::{PathPattern, Profile};
use gaol::sandbox::{ChildSandbox, ChildSandboxMethods, Command, Sandbox, SandboxMethods};
use std::env;
use std::fs::File;
use std::path::PathBuf;
fn profile() -> Profile {
let mut operations = vec![
Operation::FileReadAll(PathPattern::Subpath(PathBuf::from("/lib"))),
Operation::FileReadAll(PathPattern::Literal(PathBuf::from("/etc"))),
Operation::NetworkOutbound(AddressPattern::All),
Operation::SystemInfoRead,
];
operations.retain(|operation| {
println!("{:?}: {:?}", operation, operation.support());
match operation.support() {
OperationSupportLevel::NeverAllowed | OperationSupportLevel::CanBeAllowed => true,
_ => false,
}
});
Profile::new(operations).unwrap()
}
fn main() {
match env::args().skip(1).next() {
Some(ref arg) if arg == "child" => {
ChildSandbox::new(profile()).activate().unwrap();
match File::open(&PathBuf::from("/bin/sh")) {
Err(error) => println!("{:?}", error),
Ok(_) => panic!("could access /bin/sh"),
}
}
_ => {
let mut command = Command::me().unwrap();
Sandbox::new(profile()).start(command.arg("child")).unwrap().wait().unwrap();
}
}
}