18 次发布
0.5.5 | 2022 年 11 月 2 日 |
---|---|
0.5.3 | 2021 年 9 月 27 日 |
0.5.2 | 2021 年 5 月 10 日 |
0.5.1 | 2021 年 2 月 15 日 |
0.0.1 | 2017 年 2 月 7 日 |
#11 in Unix APIs
每月下载量 176,803
在 546 个crate中使用 (直接使用 30)
40KB
782 行代码 (不含注释)
caps
一个用于操作 Linux 能力的纯 Rust 库。
caps
提供了对现代 Linux 内核中可用的能力的支持。它支持传统的 POSIX 集合(有效、可继承、允许)以及 Linux 特有的环境能力和边界能力集合。
caps
提供了一个简单且符合 Rust 习惯的接口来处理 Linux 上的能力。有关更多详细信息,请参阅 capabilities(7)
。
动机
这个库试图实现以下目标:
- 全面支持现代内核,包括最新的能力和集合
- 提供符合习惯的接口
- 在静态目标中使用,无需外部 C 库
示例
type ExResult<T> = Result<T, Box<dyn std::error::Error + 'static>>;
fn manipulate_caps() -> ExResult<()> {
use caps::{Capability, CapSet};
// Retrieve permitted set.
let cur = caps::read(None, CapSet::Permitted)?;
println!("Current permitted caps: {:?}.", cur);
// Retrieve effective set.
let cur = caps::read(None, CapSet::Effective)?;
println!("Current effective caps: {:?}.", cur);
// Check if CAP_CHOWN is in permitted set.
let perm_chown = caps::has_cap(None, CapSet::Permitted, Capability::CAP_CHOWN)?;
if !perm_chown {
return Err("Try running this as root!".into());
}
// Clear all effective caps.
caps::clear(None, CapSet::Effective)?;
println!("Cleared effective caps.");
let cur = caps::read(None, CapSet::Effective)?;
println!("Current effective caps: {:?}.", cur);
// Since `CAP_CHOWN` is still in permitted, it can be raised again.
caps::raise(None, CapSet::Effective, Capability::CAP_CHOWN)?;
println!("Raised CAP_CHOWN in effective set.");
let cur = caps::read(None, CapSet::Effective)?;
println!("Current effective caps: {:?}.", cur);
Ok(())
}
更多示例可在 示例 下找到。
许可证
许可方式任选以下之一:
- MIT 许可证 - http://opensource.org/licenses/MIT
- Apache 许可证 2.0 版 - https://apache.ac.cn/licenses/LICENSE-2.0
根据您的选择。
依赖项
~0.3–0.8MB
~19K SLoC