use linux_syscall::syscall;
use linux_syscall::Result as LinuxSyscallResult;
use crate::bindings;
use crate::errno::Errno;
pub const LINUX_CAPABILITY_VERSION_3: u32 = bindings::LINUX__LINUX_CAPABILITY_VERSION_3;
#[allow(non_camel_case_types)]
pub type user_cap_header = __user_cap_header_struct;
#[allow(non_camel_case_types)]
pub type user_cap_data = __user_cap_data_struct;
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct __user_cap_header_struct {
pub version: bindings::linux___u32,
pub pid: ::core::ffi::c_int,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct __user_cap_data_struct {
pub effective: bindings::linux___u32,
pub permitted: bindings::linux___u32,
pub inheritable: bindings::linux___u32,
}
unsafe fn capget_raw(hdrp: *const user_cap_header, datap: *mut user_cap_data) -> Result<(), Errno> {
unsafe { syscall!(linux_syscall::SYS_capget, hdrp, datap) }
.check()
.map_err(Errno::from)
}
pub fn capget(hdrp: &user_cap_header, datap: Option<&mut [user_cap_data; 2]>) -> Result<(), Errno> {
unsafe {
capget_raw(
hdrp,
datap
.map(|x| x.as_mut_ptr())
.unwrap_or(core::ptr::null_mut()),
)
}
}
unsafe fn capset_raw(
hdrp: *const user_cap_header,
datap: *const user_cap_data,
) -> Result<(), Errno> {
unsafe { syscall!(linux_syscall::SYS_capset, hdrp, datap) }
.check()
.map_err(Errno::from)
}
pub fn capset(hdrp: &user_cap_header, datap: &[user_cap_data; 2]) -> Result<(), Errno> {
unsafe { capset_raw(hdrp, datap.as_ptr()) }
}
unsafe impl shadow_pod::Pod for __user_cap_header_struct {}
unsafe impl shadow_pod::Pod for __user_cap_data_struct {}