Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CommonSecurityDescriptor.cs
Go to the documentation of this file.
3
5
7{
8 private bool _isContainer;
9
10 private bool _isDS;
11
13
15
17
18 internal sealed override GenericAcl? GenericSacl => _sacl;
19
20 internal sealed override GenericAcl? GenericDacl => _dacl;
21
22 public bool IsContainer => _isContainer;
23
24 public bool IsDS => _isDS;
25
27
28 public override SecurityIdentifier? Owner
29 {
30 get
31 {
32 return _rawSd.Owner;
33 }
34 set
35 {
36 _rawSd.Owner = value;
37 }
38 }
39
40 public override SecurityIdentifier? Group
41 {
42 get
43 {
44 return _rawSd.Group;
45 }
46 set
47 {
48 _rawSd.Group = value;
49 }
50 }
51
53 {
54 get
55 {
56 return _sacl;
57 }
58 set
59 {
60 if (value != null)
61 {
62 if (value.IsContainer != IsContainer)
63 {
65 }
66 if (value.IsDS != IsDS)
67 {
69 }
70 }
71 _sacl = value;
72 if (_sacl != null)
73 {
74 _rawSd.SystemAcl = _sacl.RawAcl;
75 AddControlFlags(ControlFlags.SystemAclPresent);
76 }
77 else
78 {
79 _rawSd.SystemAcl = null;
80 RemoveControlFlags(ControlFlags.SystemAclPresent);
81 }
82 }
83 }
84
86 {
87 get
88 {
89 return _dacl;
90 }
91 set
92 {
93 if (value != null)
94 {
95 if (value.IsContainer != IsContainer)
96 {
98 }
99 if (value.IsDS != IsDS)
100 {
102 }
103 }
104 if (value == null)
105 {
107 }
108 else
109 {
110 _dacl = value;
111 }
112 _rawSd.DiscretionaryAcl = _dacl.RawAcl;
113 AddControlFlags(ControlFlags.DiscretionaryAclPresent);
114 }
115 }
116
118 {
119 get
120 {
121 if (SystemAcl != null)
122 {
123 return SystemAcl.IsCanonical;
124 }
125 return true;
126 }
127 }
128
130 {
131 get
132 {
133 if (DiscretionaryAcl != null)
134 {
136 }
137 return true;
138 }
139 }
140
141 internal bool IsSystemAclPresent => (_rawSd.ControlFlags & ControlFlags.SystemAclPresent) != 0;
142
143 internal bool IsDiscretionaryAclPresent => (_rawSd.ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0;
144
145 [MemberNotNull("_rawSd")]
146 private void CreateFromParts(bool isContainer, bool isDS, ControlFlags flags, SecurityIdentifier owner, SecurityIdentifier group, SystemAcl systemAcl, DiscretionaryAcl discretionaryAcl)
147 {
148 if (systemAcl != null && systemAcl.IsContainer != isContainer)
149 {
151 }
152 if (discretionaryAcl != null && discretionaryAcl.IsContainer != isContainer)
153 {
155 }
156 _isContainer = isContainer;
157 if (systemAcl != null && systemAcl.IsDS != isDS)
158 {
160 }
161 if (discretionaryAcl != null && discretionaryAcl.IsDS != isDS)
162 {
164 }
165 _isDS = isDS;
166 _sacl = systemAcl;
167 if (discretionaryAcl == null)
168 {
170 }
171 _dacl = discretionaryAcl;
172 ControlFlags controlFlags = flags | ControlFlags.DiscretionaryAclPresent;
173 controlFlags = ((systemAcl != null) ? (controlFlags | ControlFlags.SystemAclPresent) : (controlFlags & ~ControlFlags.SystemAclPresent));
174 _rawSd = new RawSecurityDescriptor(controlFlags, owner, group, systemAcl?.RawAcl, discretionaryAcl.RawAcl);
175 }
176
177 public CommonSecurityDescriptor(bool isContainer, bool isDS, ControlFlags flags, SecurityIdentifier? owner, SecurityIdentifier? group, SystemAcl? systemAcl, DiscretionaryAcl? discretionaryAcl)
178 {
179 CreateFromParts(isContainer, isDS, flags, owner, group, systemAcl, discretionaryAcl);
180 }
181
182 public CommonSecurityDescriptor(bool isContainer, bool isDS, RawSecurityDescriptor rawSecurityDescriptor)
183 : this(isContainer, isDS, rawSecurityDescriptor, trusted: false)
184 {
185 }
186
187 internal CommonSecurityDescriptor(bool isContainer, bool isDS, RawSecurityDescriptor rawSecurityDescriptor, bool trusted)
188 {
189 if (rawSecurityDescriptor == null)
190 {
191 throw new ArgumentNullException("rawSecurityDescriptor");
192 }
193 CreateFromParts(isContainer, isDS, rawSecurityDescriptor.ControlFlags, rawSecurityDescriptor.Owner, rawSecurityDescriptor.Group, (rawSecurityDescriptor.SystemAcl == null) ? null : new SystemAcl(isContainer, isDS, rawSecurityDescriptor.SystemAcl, trusted), (rawSecurityDescriptor.DiscretionaryAcl == null) ? null : new DiscretionaryAcl(isContainer, isDS, rawSecurityDescriptor.DiscretionaryAcl, trusted));
194 }
195
196 public CommonSecurityDescriptor(bool isContainer, bool isDS, string sddlForm)
197 : this(isContainer, isDS, new RawSecurityDescriptor(sddlForm), trusted: true)
198 {
199 }
200
201 public CommonSecurityDescriptor(bool isContainer, bool isDS, byte[] binaryForm, int offset)
202 : this(isContainer, isDS, new RawSecurityDescriptor(binaryForm, offset), trusted: true)
203 {
204 }
205
206 public void SetSystemAclProtection(bool isProtected, bool preserveInheritance)
207 {
208 if (!isProtected)
209 {
210 RemoveControlFlags(ControlFlags.SystemAclProtected);
211 return;
212 }
213 if (!preserveInheritance && SystemAcl != null)
214 {
216 }
217 AddControlFlags(ControlFlags.SystemAclProtected);
218 }
219
220 public void SetDiscretionaryAclProtection(bool isProtected, bool preserveInheritance)
221 {
222 if (!isProtected)
223 {
224 RemoveControlFlags(ControlFlags.DiscretionaryAclProtected);
225 }
226 else
227 {
228 if (!preserveInheritance && DiscretionaryAcl != null)
229 {
231 }
232 AddControlFlags(ControlFlags.DiscretionaryAclProtected);
233 }
235 {
236 DiscretionaryAcl.EveryOneFullAccessForNullDacl = false;
237 }
238 }
239
241 {
242 if (sid == null)
243 {
244 throw new ArgumentNullException("sid");
245 }
246 if (DiscretionaryAcl != null)
247 {
249 }
250 }
251
253 {
254 if (sid == null)
255 {
256 throw new ArgumentNullException("sid");
257 }
258 if (SystemAcl != null)
259 {
260 SystemAcl.Purge(sid);
261 }
262 }
263
264 public void AddDiscretionaryAcl(byte revision, int trusted)
265 {
266 DiscretionaryAcl = new DiscretionaryAcl(IsContainer, IsDS, revision, trusted);
267 AddControlFlags(ControlFlags.DiscretionaryAclPresent);
268 }
269
270 public void AddSystemAcl(byte revision, int trusted)
271 {
272 SystemAcl = new SystemAcl(IsContainer, IsDS, revision, trusted);
273 AddControlFlags(ControlFlags.SystemAclPresent);
274 }
275
276 internal void UpdateControlFlags(ControlFlags flagsToUpdate, ControlFlags newFlags)
277 {
278 ControlFlags flags = newFlags | (_rawSd.ControlFlags & ~flagsToUpdate);
279 _rawSd.SetFlags(flags);
280 }
281
282 internal void AddControlFlags(ControlFlags flags)
283 {
285 }
286
287 internal void RemoveControlFlags(ControlFlags flags)
288 {
290 }
291}
static string AccessControl_MustSpecifyNonDirectoryObjectAcl
Definition SR.cs:38
static string AccessControl_MustSpecifyLeafObjectAcl
Definition SR.cs:36
static string AccessControl_MustSpecifyContainerAcl
Definition SR.cs:32
static string AccessControl_MustSpecifyDirectoryObjectAcl
Definition SR.cs:34
Definition SR.cs:7
void Purge(SecurityIdentifier sid)
void CreateFromParts(bool isContainer, bool isDS, ControlFlags flags, SecurityIdentifier owner, SecurityIdentifier group, SystemAcl systemAcl, DiscretionaryAcl discretionaryAcl)
void UpdateControlFlags(ControlFlags flagsToUpdate, ControlFlags newFlags)
CommonSecurityDescriptor(bool isContainer, bool isDS, byte[] binaryForm, int offset)
CommonSecurityDescriptor(bool isContainer, bool isDS, string sddlForm)
void SetDiscretionaryAclProtection(bool isProtected, bool preserveInheritance)
CommonSecurityDescriptor(bool isContainer, bool isDS, RawSecurityDescriptor rawSecurityDescriptor)
void SetSystemAclProtection(bool isProtected, bool preserveInheritance)
CommonSecurityDescriptor(bool isContainer, bool isDS, ControlFlags flags, SecurityIdentifier? owner, SecurityIdentifier? group, SystemAcl? systemAcl, DiscretionaryAcl? discretionaryAcl)
CommonSecurityDescriptor(bool isContainer, bool isDS, RawSecurityDescriptor rawSecurityDescriptor, bool trusted)
static DiscretionaryAcl CreateAllowEveryoneFullAccess(bool isDS, bool isContainer)