mscorlib(4.0.0.0) API with additions
CommonAce.cs
2 
4 {
6  public sealed class CommonAce : QualifiedAce
7  {
10  public override int BinaryLength => 8 + base.SecurityIdentifier.BinaryLength + base.OpaqueLength;
11 
12  internal override int MaxOpaqueLengthInternal => MaxOpaqueLength(base.IsCallback);
13 
22  public CommonAce(AceFlags flags, AceQualifier qualifier, int accessMask, SecurityIdentifier sid, bool isCallback, byte[] opaque)
23  : base(TypeFromQualifier(isCallback, qualifier), flags, accessMask, sid, opaque)
24  {
25  }
26 
27  private static AceType TypeFromQualifier(bool isCallback, AceQualifier qualifier)
28  {
29  switch (qualifier)
30  {
31  case AceQualifier.AccessAllowed:
32  if (!isCallback)
33  {
34  return AceType.AccessAllowed;
35  }
36  return AceType.AccessAllowedCallback;
37  case AceQualifier.AccessDenied:
38  if (!isCallback)
39  {
40  return AceType.AccessDenied;
41  }
42  return AceType.AccessDeniedCallback;
43  case AceQualifier.SystemAudit:
44  if (!isCallback)
45  {
46  return AceType.SystemAudit;
47  }
48  return AceType.SystemAuditCallback;
49  case AceQualifier.SystemAlarm:
50  if (!isCallback)
51  {
52  return AceType.SystemAlarm;
53  }
54  return AceType.SystemAlarmCallback;
55  default:
56  throw new ArgumentOutOfRangeException("qualifier", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
57  }
58  }
59 
60  internal static bool ParseBinaryForm(byte[] binaryForm, int offset, out AceQualifier qualifier, out int accessMask, out SecurityIdentifier sid, out bool isCallback, out byte[] opaque)
61  {
62  GenericAce.VerifyHeader(binaryForm, offset);
63  if (binaryForm.Length - offset >= 8 + SecurityIdentifier.MinBinaryLength)
64  {
65  AceType aceType = (AceType)binaryForm[offset];
66  if (aceType == AceType.AccessAllowed || aceType == AceType.AccessDenied || aceType == AceType.SystemAudit || aceType == AceType.SystemAlarm)
67  {
68  isCallback = false;
69  }
70  else
71  {
72  if (aceType != AceType.AccessAllowedCallback && aceType != AceType.AccessDeniedCallback && aceType != AceType.SystemAuditCallback && aceType != AceType.SystemAlarmCallback)
73  {
74  goto IL_0116;
75  }
76  isCallback = true;
77  }
78  if (aceType == AceType.AccessAllowed || aceType == AceType.AccessAllowedCallback)
79  {
80  qualifier = AceQualifier.AccessAllowed;
81  }
82  else if (aceType == AceType.AccessDenied || aceType == AceType.AccessDeniedCallback)
83  {
84  qualifier = AceQualifier.AccessDenied;
85  }
86  else if (aceType == AceType.SystemAudit || aceType == AceType.SystemAuditCallback)
87  {
88  qualifier = AceQualifier.SystemAudit;
89  }
90  else
91  {
92  if (aceType != AceType.SystemAlarm && aceType != AceType.SystemAlarmCallback)
93  {
94  goto IL_0116;
95  }
96  qualifier = AceQualifier.SystemAlarm;
97  }
98  int num = offset + 4;
99  int num2 = 0;
100  accessMask = binaryForm[num + 0] + (binaryForm[num + 1] << 8) + (binaryForm[num + 2] << 16) + (binaryForm[num + 3] << 24);
101  num2 += 4;
102  sid = new SecurityIdentifier(binaryForm, num + num2);
103  opaque = null;
104  int num3 = (binaryForm[offset + 3] << 8) + binaryForm[offset + 2];
105  if (num3 % 4 == 0)
106  {
107  int num4 = num3 - 4 - 4 - (byte)sid.BinaryLength;
108  if (num4 > 0)
109  {
110  opaque = new byte[num4];
111  for (int i = 0; i < num4; i++)
112  {
113  opaque[i] = binaryForm[offset + num3 - num4 + i];
114  }
115  }
116  return true;
117  }
118  }
119  goto IL_0116;
120  IL_0116:
121  qualifier = AceQualifier.AccessAllowed;
122  accessMask = 0;
123  sid = null;
124  isCallback = false;
125  opaque = null;
126  return false;
127  }
128 
133  public static int MaxOpaqueLength(bool isCallback)
134  {
135  return 65527 - SecurityIdentifier.MaxBinaryLength;
136  }
137 
143  public override void GetBinaryForm(byte[] binaryForm, int offset)
144  {
145  MarshalHeader(binaryForm, offset);
146  int num = offset + 4;
147  int num2 = 0;
148  binaryForm[num + 0] = (byte)base.AccessMask;
149  binaryForm[num + 1] = (byte)(base.AccessMask >> 8);
150  binaryForm[num + 2] = (byte)(base.AccessMask >> 16);
151  binaryForm[num + 3] = (byte)(base.AccessMask >> 24);
152  num2 += 4;
153  base.SecurityIdentifier.GetBinaryForm(binaryForm, num + num2);
154  num2 += base.SecurityIdentifier.BinaryLength;
155  if (GetOpaque() != null)
156  {
157  if (base.OpaqueLength > MaxOpaqueLengthInternal)
158  {
159  throw new SystemException();
160  }
161  GetOpaque().CopyTo(binaryForm, num + num2);
162  }
163  }
164  }
165 }
AceType AceType
Gets the type of this Access Control Entry (ACE).
Definition: GenericAce.cs:18
AceQualifier AceQualifier
Gets a value that specifies whether the ACE allows access, denies access, causes system audits,...
Definition: QualifiedAce.cs:17
Serves as the base class for system exceptions namespace.
Definition: __Canon.cs:3
CommonAce(AceFlags flags, AceQualifier qualifier, int accessMask, SecurityIdentifier sid, bool isCallback, byte[] opaque)
Initializes a new instance of the T:System.Security.AccessControl.CommonAce class.
Definition: CommonAce.cs:22
static int MaxOpaqueLength(bool isCallback)
Gets the maximum allowed length of an opaque data BLOB for callback access control entries (ACEs).
Definition: CommonAce.cs:133
AceType
Defines the available access control entry (ACE) types.
Definition: AceType.cs:4
override int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
Definition: CommonAce.cs:10
SecurityIdentifier SecurityIdentifier
Gets or sets the T:System.Security.Principal.SecurityIdentifier object associated with this T:System....
Definition: KnownAce.cs:31
byte [] GetOpaque()
Returns the opaque callback data associated with this T:System.Security.AccessControl....
override void GetBinaryForm(byte[] binaryForm, int offset)
Marshals the contents of the T:System.Security.AccessControl.CommonAce object into the specified byte...
Definition: CommonAce.cs:143
static readonly int MaxBinaryLength
Returns the maximum size, in bytes, of the binary representation of the security identifier.
Represents an Access Control Entry (ACE) that contains a qualifier. The qualifier,...
Definition: QualifiedAce.cs:7
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
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.
static readonly int MinBinaryLength
Returns the minimum size, in bytes, of the binary representation of the security identifier.