mscorlib(4.0.0.0) API with additions
GenericSecurityDescriptor.cs
2 
4 {
6  public abstract class GenericSecurityDescriptor
7  {
8  internal const int HeaderLength = 20;
9 
10  internal const int OwnerFoundAt = 4;
11 
12  internal const int GroupFoundAt = 8;
13 
14  internal const int SaclFoundAt = 12;
15 
16  internal const int DaclFoundAt = 16;
17 
18  internal abstract GenericAcl GenericSacl
19  {
20  get;
21  }
22 
23  internal abstract GenericAcl GenericDacl
24  {
25  get;
26  }
27 
28  private bool IsCraftedAefaDacl
29  {
30  get
31  {
32  if (GenericDacl is DiscretionaryAcl)
33  {
34  return (GenericDacl as DiscretionaryAcl).EveryOneFullAccessForNullDacl;
35  }
36  return false;
37  }
38  }
39 
42  public static byte Revision => 1;
43 
46  public abstract ControlFlags ControlFlags
47  {
48  get;
49  }
50 
53  public abstract SecurityIdentifier Owner
54  {
55  get;
56  set;
57  }
58 
61  public abstract SecurityIdentifier Group
62  {
63  get;
64  set;
65  }
66 
69  public int BinaryLength
70  {
71  get
72  {
73  int num = 20;
74  if (Owner != null)
75  {
76  num += Owner.BinaryLength;
77  }
78  if (Group != null)
79  {
80  num += Group.BinaryLength;
81  }
82  if ((ControlFlags & ControlFlags.SystemAclPresent) != 0 && GenericSacl != null)
83  {
84  num += GenericSacl.BinaryLength;
85  }
86  if ((ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0 && GenericDacl != null && !IsCraftedAefaDacl)
87  {
88  num += GenericDacl.BinaryLength;
89  }
90  return num;
91  }
92  }
93 
94  private static void MarshalInt(byte[] binaryForm, int offset, int number)
95  {
96  binaryForm[offset + 0] = (byte)number;
97  binaryForm[offset + 1] = (byte)(number >> 8);
98  binaryForm[offset + 2] = (byte)(number >> 16);
99  binaryForm[offset + 3] = (byte)(number >> 24);
100  }
101 
102  internal static int UnmarshalInt(byte[] binaryForm, int offset)
103  {
104  return binaryForm[offset + 0] + (binaryForm[offset + 1] << 8) + (binaryForm[offset + 2] << 16) + (binaryForm[offset + 3] << 24);
105  }
106 
110  public static bool IsSddlConversionSupported()
111  {
112  return true;
113  }
114 
118  [SecuritySafeCritical]
119  public string GetSddlForm(AccessControlSections includeSections)
120  {
121  byte[] binaryForm = new byte[BinaryLength];
122  GetBinaryForm(binaryForm, 0);
123  SecurityInfos securityInfos = (SecurityInfos)0;
124  if ((includeSections & AccessControlSections.Owner) != 0)
125  {
126  securityInfos |= SecurityInfos.Owner;
127  }
128  if ((includeSections & AccessControlSections.Group) != 0)
129  {
130  securityInfos |= SecurityInfos.Group;
131  }
132  if ((includeSections & AccessControlSections.Audit) != 0)
133  {
134  securityInfos |= SecurityInfos.SystemAcl;
135  }
136  if ((includeSections & AccessControlSections.Access) != 0)
137  {
138  securityInfos |= SecurityInfos.DiscretionaryAcl;
139  }
140  string resultSddl;
141  switch (Win32.ConvertSdToSddl(binaryForm, 1, securityInfos, out resultSddl))
142  {
143  case 87:
144  case 1305:
145  throw new InvalidOperationException();
146  default:
147  throw new InvalidOperationException();
148  case 0:
149  return resultSddl;
150  }
151  }
152 
158  public void GetBinaryForm(byte[] binaryForm, int offset)
159  {
160  if (binaryForm == null)
161  {
162  throw new ArgumentNullException("binaryForm");
163  }
164  if (offset < 0)
165  {
166  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
167  }
168  if (binaryForm.Length - offset < BinaryLength)
169  {
170  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
171  }
172  int num = offset;
173  int binaryLength = BinaryLength;
174  byte b = (byte)((this is RawSecurityDescriptor && (ControlFlags & ControlFlags.RMControlValid) != 0) ? (this as RawSecurityDescriptor).ResourceManagerControl : 0);
175  int num2 = (int)ControlFlags;
176  if (IsCraftedAefaDacl)
177  {
178  num2 &= -5;
179  }
180  binaryForm[offset + 0] = Revision;
181  binaryForm[offset + 1] = b;
182  binaryForm[offset + 2] = (byte)num2;
183  binaryForm[offset + 3] = (byte)(num2 >> 8);
184  int offset2 = offset + 4;
185  int offset3 = offset + 8;
186  int offset4 = offset + 12;
187  int offset5 = offset + 16;
188  offset += 20;
189  if (Owner != null)
190  {
191  MarshalInt(binaryForm, offset2, offset - num);
192  Owner.GetBinaryForm(binaryForm, offset);
193  offset += Owner.BinaryLength;
194  }
195  else
196  {
197  MarshalInt(binaryForm, offset2, 0);
198  }
199  if (Group != null)
200  {
201  MarshalInt(binaryForm, offset3, offset - num);
202  Group.GetBinaryForm(binaryForm, offset);
203  offset += Group.BinaryLength;
204  }
205  else
206  {
207  MarshalInt(binaryForm, offset3, 0);
208  }
209  if ((ControlFlags & ControlFlags.SystemAclPresent) != 0 && GenericSacl != null)
210  {
211  MarshalInt(binaryForm, offset4, offset - num);
212  GenericSacl.GetBinaryForm(binaryForm, offset);
213  offset += GenericSacl.BinaryLength;
214  }
215  else
216  {
217  MarshalInt(binaryForm, offset4, 0);
218  }
219  if ((ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0 && GenericDacl != null && !IsCraftedAefaDacl)
220  {
221  MarshalInt(binaryForm, offset5, offset - num);
222  GenericDacl.GetBinaryForm(binaryForm, offset);
223  offset += GenericDacl.BinaryLength;
224  }
225  else
226  {
227  MarshalInt(binaryForm, offset5, 0);
228  }
229  }
230  }
231 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void GetBinaryForm(byte[] binaryForm, int offset)
Returns an array of byte values that represents the information contained in this T:System....
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
abstract int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
Definition: GenericAcl.cs:29
static byte Revision
Gets the revision level of the T:System.Security.AccessControl.GenericSecurityDescriptor object.
abstract SecurityIdentifier Group
Gets or sets the primary group for this T:System.Security.AccessControl.GenericSecurityDescriptor obj...
SecurityInfos
Specifies the section of a security descriptor to be queried or set.
Definition: SecurityInfos.cs:5
static bool IsSddlConversionSupported()
Returns a boolean value that specifies whether the security descriptor associated with this T:System....
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
int BinaryLength
Returns the length, in bytes, of the security identifier (SID) represented by the T:System....
Represents a security descriptor. A security descriptor includes an owner, a primary group,...
ControlFlags
These flags affect the security descriptor behavior.
Definition: ControlFlags.cs:5
string GetSddlForm(AccessControlSections includeSections)
Returns the Security Descriptor Definition Language (SDDL) representation of the specified sections o...
abstract SecurityIdentifier Owner
Gets or sets the owner of the object associated with this T:System.Security.AccessControl....
Represents a security descriptor. A security descriptor includes an owner, a primary group,...
Represents an access control list (ACL) and is the base class for the T:System.Security....
Definition: GenericAcl.cs:6
void GetBinaryForm(byte[] binaryForm, int offset)
Copies the binary representation of the specified security identifier (SID) represented by the T:Syst...
Represents a security identifier (SID) and provides marshaling and comparison operations for SIDs.
abstract void GetBinaryForm(byte[] binaryForm, int offset)
Marshals the contents of the T:System.Security.AccessControl.GenericAcl object into the specified byt...
The exception that is thrown when a method call is invalid for the object's current state.
Represents a Discretionary Access Control List (DACL).
int BinaryLength
Gets the length, in bytes, of the binary representation of the current T:System.Security....
AccessControlSections
Specifies which sections of a security descriptor to save or load.