Crates.io | casper-sys |
lib.rs | casper-sys |
version | |
source | src |
created_at | 2023-02-16 13:35:55.144143 |
updated_at | 2024-10-14 17:24:55.233467 |
description | FFI bindings for FreeBSD's libcasper |
homepage | |
repository | https://github.com/dlrobertson/capsicum-rs |
max_upload_size | |
id | 786774 |
Cargo.toml error: | TOML parse error at line 20, column 1 | 20 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rust bindings for the FreeBSD capsicum framework for OS capability and sandboxing
Note: This currently only compiles on FreeBSD
git clone https://github.com/danlrobertson/capsicum-rs
cd capsicum-rs
cargo build
capsicum-rs
use capsicum::{enter, sandboxed};
use std::fs::File;
use std::io::Read;
let mut ok_file = File::open("/tmp/foo").unwrap();
let mut s = String::new();
enter().expect("enter failed!");
assert!(sandboxed(), "application is not sandboxed!");
match File::create("/tmp/cant_touch_this") {
Ok(_) => panic!("application is not properly sandboxed!"),
Err(e) => println!("properly sandboxed: {:?}", e)
}
match ok_file.read_to_string(&mut s) {
Ok(_) => println!("This is okay since we opened the descriptor before sandboxing"),
Err(_) => panic!("application is not properly sandboxed!")
}
use capsicum::{CapRights, Right, RightsBuilder};
use std::fs::File;
use std::io::Read;
let x = rand::random::<bool>();
let mut ok_file = File::open("/tmp/foo").unwrap();
let mut s = String::new();
let mut builder = RightsBuilder::new(Right::Seek);
if x {
builder.add(Right::Read);
}
let rights = builder.finalize().unwrap();
rights.limit(&ok_file).unwrap();
match ok_file.read_to_string(&mut s) {
Ok(_) if x => println!("Allowed reading: x = {} ", x),
Err(_) if !x => println!("Did not allow reading: x = {}", x),
_ => panic!("Not properly sandboxed"),
}