| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
use crate::errors::CapsError; |
| 8 |
use crate::nr; |
| 9 |
use std::io::Error; |
| 10 |
|
| 11 |
|
| 12 |
pub fn has_keepcaps() -> Result<bool, CapsError> { |
| 13 |
let ret = unsafe { libc::prctl(nr::PR_GET_KEEPCAPS, 0, 0, 0) }; |
| 14 |
match ret { |
| 15 |
0 => Ok(false), |
| 16 |
1 => Ok(true), |
| 17 |
_ => Err(CapsError::from(format!( |
| 18 |
"PR_GET_KEEPCAPS failure: {}", |
| 19 |
Error::last_os_error() |
| 20 |
))), |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
pub fn set_keepcaps(keep_caps: bool) -> Result<(), CapsError> { |
| 26 |
let flag = if keep_caps { 1 } else { 0 }; |
| 27 |
let ret = unsafe { libc::prctl(nr::PR_SET_KEEPCAPS, flag, 0, 0) }; |
| 28 |
match ret { |
| 29 |
0 => Ok(()), |
| 30 |
_ => Err(CapsError::from(format!( |
| 31 |
"PR_SET_KEEPCAPS failure: {}", |
| 32 |
Error::last_os_error() |
| 33 |
))), |
| 34 |
} |
| 35 |
} |