| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use super::{ambient, CapSet, Capability, CapsHashSet}; |
| 22 |
use crate::errors::CapsError; |
| 23 |
use std::io::Read; |
| 24 |
use std::path::{Path, PathBuf}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
pub fn ambient_set_supported() -> Result<(), CapsError> { |
| 32 |
ambient::has_cap(Capability::CAP_CHOWN)?; |
| 33 |
Ok(()) |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
pub fn procfs_all_supported(proc_mountpoint: Option<PathBuf>) -> Result<CapsHashSet, CapsError> { |
| 41 |
|
| 42 |
const LAST_CAP_FILEPATH: &str = "./sys/kernel/cap_last_cap"; |
| 43 |
let last_cap_path = proc_mountpoint |
| 44 |
.unwrap_or_else(|| PathBuf::from("/proc/")) |
| 45 |
.join(Path::new(LAST_CAP_FILEPATH)); |
| 46 |
|
| 47 |
let max_cap: u8 = { |
| 48 |
let mut buf = String::with_capacity(4); |
| 49 |
std::fs::File::open(last_cap_path.clone()) |
| 50 |
.and_then(|mut file| file.read_to_string(&mut buf)) |
| 51 |
.map_err(|e| format!("failed to read '{}': {}", last_cap_path.display(), e))?; |
| 52 |
buf.trim_end() |
| 53 |
.parse() |
| 54 |
.map_err(|e| format!("failed to parse '{}': {}", last_cap_path.display(), e))? |
| 55 |
}; |
| 56 |
|
| 57 |
let mut supported = super::all(); |
| 58 |
for c in super::all() { |
| 59 |
if c.index() > max_cap { |
| 60 |
supported.remove(&c); |
| 61 |
} |
| 62 |
} |
| 63 |
Ok(supported) |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
pub fn thread_all_supported() -> CapsHashSet { |
| 73 |
let mut supported = super::all(); |
| 74 |
for c in super::all() { |
| 75 |
if super::has_cap(None, CapSet::Bounding, c).is_err() { |
| 76 |
supported.remove(&c); |
| 77 |
} |
| 78 |
} |
| 79 |
supported |
| 80 |
} |