Debian Codegraph @

README.md

raw symbols SCIP
1 # caps
2
3 [![crates.io](https://img.shields.io/crates/v/caps.svg)](https://crates.io/crates/caps)
4 [![Documentation](https://docs.rs/caps/badge.svg)](https://docs.rs/caps)
5
6 A pure-Rust library to work with Linux capabilities.
7
8 `caps` provides support for manipulating capabilities available in modern Linux
9 kernels. It supports traditional POSIX sets (Effective, Inheritable, Permitted)
10 as well as Linux-specific Ambient and Bounding capabilities sets.
11
12 `caps` provides a simple and idiomatic interface to handle capabilities on Linux.
13 See `capabilities(7)` for more details.
14
15 ## Motivations
16
17 This library tries to achieve the following goals:
18 * fully support modern kernels, including recent capabilities and sets
19 * provide an idiomatic interface
20 * be usable in static targets, without requiring an external C library
21
22 ## Example
23
24 ```rust
25 type ExResult<T> = Result<T, Box<dyn std::error::Error + 'static>>;
26
27 fn manipulate_caps() -> ExResult<()> {
28 use caps::{Capability, CapSet};
29
30 // Retrieve permitted set.
31 let cur = caps::read(None, CapSet::Permitted)?;
32 println!("Current permitted caps: {:?}.", cur);
33
34 // Retrieve effective set.
35 let cur = caps::read(None, CapSet::Effective)?;
36 println!("Current effective caps: {:?}.", cur);
37
38 // Check if CAP_CHOWN is in permitted set.
39 let perm_chown = caps::has_cap(None, CapSet::Permitted, Capability::CAP_CHOWN)?;
40 if !perm_chown {
41 return Err("Try running this as root!".into());
42 }
43
44 // Clear all effective caps.
45 caps::clear(None, CapSet::Effective)?;
46 println!("Cleared effective caps.");
47 let cur = caps::read(None, CapSet::Effective)?;
48 println!("Current effective caps: {:?}.", cur);
49
50 // Since `CAP_CHOWN` is still in permitted, it can be raised again.
51 caps::raise(None, CapSet::Effective, Capability::CAP_CHOWN)?;
52 println!("Raised CAP_CHOWN in effective set.");
53 let cur = caps::read(None, CapSet::Effective)?;
54 println!("Current effective caps: {:?}.", cur);
55
56 Ok(())
57 }
58 ```
59
60 Some more examples are available under [examples](examples).
61
62 ## License
63
64 Licensed under either of
65
66 * MIT license - <http://opensource.org/licenses/MIT>
67 * Apache License, Version 2.0 - <http://www.apache.org/licenses/LICENSE-2.0>
68
69 at your option.