use alloc::sync::Arc;
#[derive(Clone, Debug)]
pub struct Cred {
pub uid: u32,
pub gid: u32,
pub euid: u32,
pub egid: u32,
pub suid: u32,
pub sgid: u32,
pub fsuid: u32,
pub fsgid: u32,
pub groups: Arc<[u32]>,
}
impl Cred {
pub fn root() -> Self {
Self {
uid: 0,
gid: 0,
euid: 0,
egid: 0,
suid: 0,
sgid: 0,
fsuid: 0,
fsgid: 0,
groups: Arc::from([].as_slice()),
}
}
pub fn has_cap_setuid(&self) -> bool {
self.euid == 0
}
pub fn has_cap_setgid(&self) -> bool {
self.euid == 0
}
pub fn has_cap_net_raw(&self) -> bool {
self.euid == 0
}
pub fn has_cap_sys_nice(&self) -> bool {
self.euid == 0
}
pub fn has_cap_chown(&self) -> bool {
self.fsuid == 0
}
pub fn has_cap_fowner(&self) -> bool {
self.fsuid == 0
}
pub fn in_group(&self, gid: u32) -> bool {
self.fsgid == gid || self.groups.contains(&gid)
}
}
impl Default for Cred {
fn default() -> Self {
Self::root()
}
}