windows_erg/security/
descriptor.rs1use super::{Dacl, Sid};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum SecurityTarget {
8 FilePath(String),
10 RegistryPath(String),
12 Detached,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct SecurityDescriptor {
19 target: SecurityTarget,
20 owner: Option<Sid>,
21 group: Option<Sid>,
22 dacl: Dacl,
23}
24
25impl SecurityDescriptor {
26 pub fn new() -> Self {
28 Self {
29 target: SecurityTarget::Detached,
30 owner: None,
31 group: None,
32 dacl: Dacl::new(),
33 }
34 }
35
36 pub fn for_file_path(path: impl Into<String>) -> Self {
38 Self {
39 target: SecurityTarget::FilePath(path.into()),
40 owner: None,
41 group: None,
42 dacl: Dacl::new(),
43 }
44 }
45
46 pub fn for_registry_path(path: impl Into<String>) -> Self {
48 Self {
49 target: SecurityTarget::RegistryPath(path.into()),
50 owner: None,
51 group: None,
52 dacl: Dacl::new(),
53 }
54 }
55
56 pub fn with_owner(mut self, owner: Sid) -> Self {
58 self.owner = Some(owner);
59 self
60 }
61
62 pub fn with_group(mut self, group: Sid) -> Self {
64 self.group = Some(group);
65 self
66 }
67
68 pub fn with_dacl(mut self, dacl: Dacl) -> Self {
70 self.dacl = dacl;
71 self
72 }
73
74 pub fn target(&self) -> &SecurityTarget {
76 &self.target
77 }
78
79 pub fn owner(&self) -> Option<&Sid> {
81 self.owner.as_ref()
82 }
83
84 pub fn group(&self) -> Option<&Sid> {
86 self.group.as_ref()
87 }
88
89 pub fn dacl(&self) -> &Dacl {
91 &self.dacl
92 }
93
94 pub fn dacl_mut(&mut self) -> &mut Dacl {
96 &mut self.dacl
97 }
98}
99
100impl Default for SecurityDescriptor {
101 fn default() -> Self {
102 Self::new()
103 }
104}