use super::{Dacl, Sid};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SecurityTarget {
FilePath(String),
RegistryPath(String),
Detached,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SecurityDescriptor {
target: SecurityTarget,
owner: Option<Sid>,
group: Option<Sid>,
dacl: Dacl,
}
impl SecurityDescriptor {
pub fn new() -> Self {
Self {
target: SecurityTarget::Detached,
owner: None,
group: None,
dacl: Dacl::new(),
}
}
pub fn for_file_path(path: impl Into<String>) -> Self {
Self {
target: SecurityTarget::FilePath(path.into()),
owner: None,
group: None,
dacl: Dacl::new(),
}
}
pub fn for_registry_path(path: impl Into<String>) -> Self {
Self {
target: SecurityTarget::RegistryPath(path.into()),
owner: None,
group: None,
dacl: Dacl::new(),
}
}
pub fn with_owner(mut self, owner: Sid) -> Self {
self.owner = Some(owner);
self
}
pub fn with_group(mut self, group: Sid) -> Self {
self.group = Some(group);
self
}
pub fn with_dacl(mut self, dacl: Dacl) -> Self {
self.dacl = dacl;
self
}
pub fn target(&self) -> &SecurityTarget {
&self.target
}
pub fn owner(&self) -> Option<&Sid> {
self.owner.as_ref()
}
pub fn group(&self) -> Option<&Sid> {
self.group.as_ref()
}
pub fn dacl(&self) -> &Dacl {
&self.dacl
}
pub fn dacl_mut(&mut self) -> &mut Dacl {
&mut self.dacl
}
}
impl Default for SecurityDescriptor {
fn default() -> Self {
Self::new()
}
}