extern crate caps;
use caps::{CapSet, Capability};
fn main() {
let cur = caps::read(None, CapSet::Permitted).unwrap();
println!("-> Current permitted caps: {:?}.", cur);
let cur = caps::read(None, CapSet::Effective).unwrap();
println!("-> Current effective caps: {:?}.", cur);
let perm_chown = caps::has_cap(None, CapSet::Permitted, Capability::CAP_CHOWN);
assert!(perm_chown.is_ok());
if !perm_chown.unwrap() {
println!("Try running this again as root/sudo or with CAP_CHOWN file capability!");
return;
}
let r = caps::clear(None, CapSet::Effective);
assert!(r.is_ok());
println!("Cleared effective caps.");
let cur = caps::read(None, CapSet::Effective).unwrap();
println!("-> Current effective caps: {:?}.", cur);
let r = caps::raise(None, CapSet::Effective, Capability::CAP_CHOWN);
assert!(r.is_ok());
println!("Raised CAP_CHOWN in effective set.");
let cur = caps::read(None, CapSet::Effective).unwrap();
println!("-> Current effective caps: {:?}.", cur);
let r = caps::clear(None, CapSet::Permitted);
assert!(r.is_ok());
println!("Cleared permitted caps.");
let cur = caps::read(None, CapSet::Permitted).unwrap();
println!("-> Current permitted caps: {:?}.", cur);
let cur = caps::read(None, CapSet::Effective).unwrap();
println!("-> Current effective caps: {:?}.", cur);
let r = caps::raise(None, CapSet::Effective, Capability::CAP_CHOWN);
assert!(r.is_err());
println!("Tried to raise CAP_CHOWN but failed.");
let cur = caps::read(None, CapSet::Effective).unwrap();
println!("-> Current effective caps: {:?}.", cur);
}