mscorlib(4.0.0.0) API with additions
GenericAce.cs
2 
4 {
6  public abstract class GenericAce
7  {
8  private readonly AceType _type;
9 
10  private AceFlags _flags;
11 
12  internal ushort _indexInAcl;
13 
14  internal const int HeaderLength = 4;
15 
18  public AceType AceType => _type;
19 
22  public AceFlags AceFlags
23  {
24  get
25  {
26  return _flags;
27  }
28  set
29  {
30  _flags = value;
31  }
32  }
33 
37  public bool IsInherited => (AceFlags & AceFlags.Inherited) != AceFlags.None;
38 
42  {
43  get
44  {
45  InheritanceFlags inheritanceFlags = InheritanceFlags.None;
46  if ((AceFlags & AceFlags.ContainerInherit) != 0)
47  {
48  inheritanceFlags |= InheritanceFlags.ContainerInherit;
49  }
50  if ((AceFlags & AceFlags.ObjectInherit) != 0)
51  {
52  inheritanceFlags |= InheritanceFlags.ObjectInherit;
53  }
54  return inheritanceFlags;
55  }
56  }
57 
60  public PropagationFlags PropagationFlags
61  {
62  get
63  {
64  PropagationFlags propagationFlags = PropagationFlags.None;
65  if ((AceFlags & AceFlags.InheritOnly) != 0)
66  {
67  propagationFlags |= PropagationFlags.InheritOnly;
68  }
69  if ((AceFlags & AceFlags.NoPropagateInherit) != 0)
70  {
71  propagationFlags |= PropagationFlags.NoPropagateInherit;
72  }
73  return propagationFlags;
74  }
75  }
76 
79  public AuditFlags AuditFlags
80  {
81  get
82  {
83  AuditFlags auditFlags = AuditFlags.None;
84  if ((AceFlags & AceFlags.SuccessfulAccess) != 0)
85  {
86  auditFlags |= AuditFlags.Success;
87  }
88  if ((AceFlags & AceFlags.FailedAccess) != 0)
89  {
90  auditFlags |= AuditFlags.Failure;
91  }
92  return auditFlags;
93  }
94  }
95 
98  public abstract int BinaryLength
99  {
100  get;
101  }
102 
103  internal void MarshalHeader(byte[] binaryForm, int offset)
104  {
105  int binaryLength = BinaryLength;
106  if (binaryForm == null)
107  {
108  throw new ArgumentNullException("binaryForm");
109  }
110  if (offset < 0)
111  {
112  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
113  }
114  if (binaryForm.Length - offset < BinaryLength)
115  {
116  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
117  }
118  if (binaryLength > 65535)
119  {
120  throw new SystemException();
121  }
122  binaryForm[offset + 0] = (byte)AceType;
123  binaryForm[offset + 1] = (byte)AceFlags;
124  binaryForm[offset + 2] = (byte)binaryLength;
125  binaryForm[offset + 3] = (byte)(binaryLength >> 8);
126  }
127 
128  internal GenericAce(AceType type, AceFlags flags)
129  {
130  _type = type;
131  _flags = flags;
132  }
133 
134  internal static AceFlags AceFlagsFromAuditFlags(AuditFlags auditFlags)
135  {
136  AceFlags aceFlags = AceFlags.None;
137  if ((auditFlags & AuditFlags.Success) != 0)
138  {
139  aceFlags |= AceFlags.SuccessfulAccess;
140  }
141  if ((auditFlags & AuditFlags.Failure) != 0)
142  {
143  aceFlags |= AceFlags.FailedAccess;
144  }
145  if (aceFlags == AceFlags.None)
146  {
147  throw new ArgumentException(Environment.GetResourceString("Arg_EnumAtLeastOneFlag"), "auditFlags");
148  }
149  return aceFlags;
150  }
151 
152  internal static AceFlags AceFlagsFromInheritanceFlags(InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
153  {
154  AceFlags aceFlags = AceFlags.None;
155  if ((inheritanceFlags & InheritanceFlags.ContainerInherit) != 0)
156  {
157  aceFlags |= AceFlags.ContainerInherit;
158  }
159  if ((inheritanceFlags & InheritanceFlags.ObjectInherit) != 0)
160  {
161  aceFlags |= AceFlags.ObjectInherit;
162  }
163  if (aceFlags != 0)
164  {
165  if ((propagationFlags & PropagationFlags.NoPropagateInherit) != 0)
166  {
167  aceFlags |= AceFlags.NoPropagateInherit;
168  }
169  if ((propagationFlags & PropagationFlags.InheritOnly) != 0)
170  {
171  aceFlags |= AceFlags.InheritOnly;
172  }
173  }
174  return aceFlags;
175  }
176 
177  internal static void VerifyHeader(byte[] binaryForm, int offset)
178  {
179  if (binaryForm == null)
180  {
181  throw new ArgumentNullException("binaryForm");
182  }
183  if (offset < 0)
184  {
185  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
186  }
187  if (binaryForm.Length - offset < 4)
188  {
189  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
190  }
191  if ((binaryForm[offset + 3] << 8) + binaryForm[offset + 2] > binaryForm.Length - offset)
192  {
193  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
194  }
195  }
196 
201  public static GenericAce CreateFromBinaryForm(byte[] binaryForm, int offset)
202  {
203  VerifyHeader(binaryForm, offset);
204  AceType aceType = (AceType)binaryForm[offset];
205  GenericAce genericAce;
206  if (aceType == AceType.AccessAllowed || aceType == AceType.AccessDenied || aceType == AceType.SystemAudit || aceType == AceType.SystemAlarm || aceType == AceType.AccessAllowedCallback || aceType == AceType.AccessDeniedCallback || aceType == AceType.SystemAuditCallback || aceType == AceType.SystemAlarmCallback)
207  {
208  if (CommonAce.ParseBinaryForm(binaryForm, offset, out AceQualifier qualifier, out int accessMask, out SecurityIdentifier sid, out bool isCallback, out byte[] opaque))
209  {
210  AceFlags flags = (AceFlags)binaryForm[offset + 1];
211  genericAce = new CommonAce(flags, qualifier, accessMask, sid, isCallback, opaque);
212  goto IL_0154;
213  }
214  }
215  else if (aceType == AceType.AccessAllowedObject || aceType == AceType.AccessDeniedObject || aceType == AceType.SystemAuditObject || aceType == AceType.SystemAlarmObject || aceType == AceType.AccessAllowedCallbackObject || aceType == AceType.AccessDeniedCallbackObject || aceType == AceType.SystemAuditCallbackObject || aceType == AceType.SystemAlarmCallbackObject)
216  {
217  if (ObjectAce.ParseBinaryForm(binaryForm, offset, out AceQualifier qualifier2, out int accessMask2, out SecurityIdentifier sid2, out ObjectAceFlags objectFlags, out Guid objectAceType, out Guid inheritedObjectAceType, out bool isCallback2, out byte[] opaque2))
218  {
219  AceFlags aceFlags = (AceFlags)binaryForm[offset + 1];
220  genericAce = new ObjectAce(aceFlags, qualifier2, accessMask2, sid2, objectFlags, objectAceType, inheritedObjectAceType, isCallback2, opaque2);
221  goto IL_0154;
222  }
223  }
224  else if (aceType == AceType.AccessAllowedCompound)
225  {
226  if (CompoundAce.ParseBinaryForm(binaryForm, offset, out int accessMask3, out CompoundAceType compoundAceType, out SecurityIdentifier sid3))
227  {
228  AceFlags flags2 = (AceFlags)binaryForm[offset + 1];
229  genericAce = new CompoundAce(flags2, accessMask3, compoundAceType, sid3);
230  goto IL_0154;
231  }
232  }
233  else
234  {
235  AceFlags flags3 = (AceFlags)binaryForm[offset + 1];
236  byte[] array = null;
237  int num = binaryForm[offset + 2] + (binaryForm[offset + 3] << 8);
238  if (num % 4 == 0)
239  {
240  int num2 = num - 4;
241  if (num2 > 0)
242  {
243  array = new byte[num2];
244  for (int i = 0; i < num2; i++)
245  {
246  array[i] = binaryForm[offset + num - num2 + i];
247  }
248  }
249  genericAce = new CustomAce(aceType, flags3, array);
250  goto IL_0154;
251  }
252  }
253  goto IL_01a8;
254  IL_01a8:
255  throw new ArgumentException(Environment.GetResourceString("ArgumentException_InvalidAceBinaryForm"), "binaryForm");
256  IL_0154:
257  if ((genericAce is ObjectAce || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) == genericAce.BinaryLength) && (!(genericAce is ObjectAce) || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) == genericAce.BinaryLength || binaryForm[offset + 2] + (binaryForm[offset + 3] << 8) - 32 == genericAce.BinaryLength))
258  {
259  return genericAce;
260  }
261  goto IL_01a8;
262  }
263 
269  public abstract void GetBinaryForm(byte[] binaryForm, int offset);
270 
273  public GenericAce Copy()
274  {
275  byte[] binaryForm = new byte[BinaryLength];
276  GetBinaryForm(binaryForm, 0);
277  return CreateFromBinaryForm(binaryForm, 0);
278  }
279 
284  public sealed override bool Equals(object o)
285  {
286  if (o == null)
287  {
288  return false;
289  }
290  GenericAce genericAce = o as GenericAce;
291  if (genericAce == null)
292  {
293  return false;
294  }
295  if (AceType != genericAce.AceType || AceFlags != genericAce.AceFlags)
296  {
297  return false;
298  }
299  int binaryLength = BinaryLength;
300  int binaryLength2 = genericAce.BinaryLength;
301  if (binaryLength != binaryLength2)
302  {
303  return false;
304  }
305  byte[] array = new byte[binaryLength];
306  byte[] array2 = new byte[binaryLength2];
307  GetBinaryForm(array, 0);
308  genericAce.GetBinaryForm(array2, 0);
309  for (int i = 0; i < array.Length; i++)
310  {
311  if (array[i] != array2[i])
312  {
313  return false;
314  }
315  }
316  return true;
317  }
318 
321  public sealed override int GetHashCode()
322  {
323  int binaryLength = BinaryLength;
324  byte[] array = new byte[binaryLength];
325  GetBinaryForm(array, 0);
326  int num = 0;
327  for (int i = 0; i < binaryLength; i += 4)
328  {
329  int num2 = array[i] + (array[i + 1] << 8) + (array[i + 2] << 16) + (array[i + 3] << 24);
330  num ^= num2;
331  }
332  return num;
333  }
334 
340  public static bool operator ==(GenericAce left, GenericAce right)
341  {
342  if ((object)left == null && (object)right == null)
343  {
344  return true;
345  }
346  if ((object)left == null || (object)right == null)
347  {
348  return false;
349  }
350  return left.Equals(right);
351  }
352 
358  public static bool operator !=(GenericAce left, GenericAce right)
359  {
360  return !(left == right);
361  }
362  }
363 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
PropagationFlags
Specifies how Access Control Entries (ACEs) are propagated to child objects. These flags are signific...
AceType AceType
Gets the type of this Access Control Entry (ACE).
Definition: GenericAce.cs:18
Represents a compound Access Control Entry (ACE).
Definition: CompoundAce.cs:6
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static GenericAce CreateFromBinaryForm(byte[] binaryForm, int offset)
Creates a T:System.Security.AccessControl.GenericAce object from the specified binary data.
Definition: GenericAce.cs:201
AceType
Defines the available access control entry (ACE) types.
Definition: AceType.cs:4
Represents an Access Control Entry (ACE), and is the base class for all other ACE classes.
Definition: GenericAce.cs:6
sealed override int GetHashCode()
Serves as a hash function for the T:System.Security.AccessControl.GenericAce class....
Definition: GenericAce.cs:321
AceFlags AceFlags
Gets or sets the T:System.Security.AccessControl.AceFlags associated with this T:System....
Definition: GenericAce.cs:23
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
static bool operator !=(GenericAce left, GenericAce right)
Determines whether the specified T:System.Security.AccessControl.GenericAce objects are considered un...
Definition: GenericAce.cs:358
GenericAce Copy()
Creates a deep copy of this Access Control Entry (ACE).
Definition: GenericAce.cs:273
sealed override bool Equals(object o)
Determines whether the specified T:System.Security.AccessControl.GenericAce object is equal to the cu...
Definition: GenericAce.cs:284
Controls access to Directory Services objects. This class represents an Access Control Entry (ACE) as...
Definition: ObjectAce.cs:6
Represents an access control entry (ACE).
Definition: CommonAce.cs:6
AceFlags
Specifies the inheritance and auditing behavior of an access control entry (ACE).
Definition: AceFlags.cs:5
The exception that is thrown when one of the arguments provided to a method is not valid.
abstract void GetBinaryForm(byte[] binaryForm, int offset)
Marshals the contents of the T:System.Security.AccessControl.GenericAce object into the specified byt...
AceQualifier
Specifies the function of an access control entry (ACE).
Definition: AceQualifier.cs:4
Represents a security identifier (SID) and provides marshaling and comparison operations for SIDs.
bool IsInherited
Gets a Boolean value that specifies whether this Access Control Entry (ACE) is inherited or is set ex...
Definition: GenericAce.cs:37
CompoundAceType
Specifies the type of a T:System.Security.AccessControl.CompoundAce object.
InheritanceFlags
Inheritance flags specify the semantics of inheritance for access control entries (ACEs).
Represents an Access Control Entry (ACE) that is not defined by one of the members of the T:System....
Definition: CustomAce.cs:6
ObjectAceFlags
Specifies the presence of object types for Access Control Entries (ACEs).
abstract int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
Definition: GenericAce.cs:99
AuditFlags
Specifies the conditions for auditing attempts to access a securable object.
Definition: AuditFlags.cs:5