mscorlib(4.0.0.0) API with additions
SecurityIdentifier.cs
1 using Microsoft.Win32;
2 using Microsoft.Win32.SafeHandles;
6 using System.Text;
7 
9 {
11  [ComVisible(false)]
12  public sealed class SecurityIdentifier : IdentityReference, IComparable<SecurityIdentifier>
13  {
14  internal static readonly long MaxIdentifierAuthority = 281474976710655L;
15 
16  internal static readonly byte MaxSubAuthorities = 15;
17 
19  public static readonly int MinBinaryLength = 8;
20 
22  public static readonly int MaxBinaryLength = 8 + MaxSubAuthorities * 4;
23 
24  private IdentifierAuthority _IdentifierAuthority;
25 
26  private int[] _SubAuthorities;
27 
28  private byte[] _BinaryForm;
29 
30  private SecurityIdentifier _AccountDomainSid;
31 
32  private bool _AccountDomainSidInitialized;
33 
34  private string _SddlForm;
35 
36  internal static byte Revision => 1;
37 
38  internal byte[] BinaryForm => _BinaryForm;
39 
40  internal IdentifierAuthority IdentifierAuthority => _IdentifierAuthority;
41 
42  internal int SubAuthorityCount => _SubAuthorities.Length;
43 
46  public int BinaryLength => _BinaryForm.Length;
47 
51  {
52  [SecuritySafeCritical]
53  get
54  {
55  if (!_AccountDomainSidInitialized)
56  {
57  _AccountDomainSid = GetAccountDomainSid();
58  _AccountDomainSidInitialized = true;
59  }
60  return _AccountDomainSid;
61  }
62  }
63 
66  public override string Value => ToString().ToUpper(CultureInfo.InvariantCulture);
67 
68  private void CreateFromParts(IdentifierAuthority identifierAuthority, int[] subAuthorities)
69  {
70  if (subAuthorities == null)
71  {
72  throw new ArgumentNullException("subAuthorities");
73  }
74  if (subAuthorities.Length > MaxSubAuthorities)
75  {
76  throw new ArgumentOutOfRangeException("subAuthorities.Length", subAuthorities.Length, Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", MaxSubAuthorities));
77  }
78  if (identifierAuthority < IdentifierAuthority.NullAuthority || (long)identifierAuthority > MaxIdentifierAuthority)
79  {
80  throw new ArgumentOutOfRangeException("identifierAuthority", identifierAuthority, Environment.GetResourceString("IdentityReference_IdentifierAuthorityTooLarge"));
81  }
82  _IdentifierAuthority = identifierAuthority;
83  _SubAuthorities = new int[subAuthorities.Length];
84  subAuthorities.CopyTo(_SubAuthorities, 0);
85  _BinaryForm = new byte[8 + 4 * SubAuthorityCount];
86  _BinaryForm[0] = Revision;
87  _BinaryForm[1] = (byte)SubAuthorityCount;
88  for (byte b = 0; b < 6; b = (byte)(b + 1))
89  {
90  _BinaryForm[2 + b] = (byte)(((ulong)_IdentifierAuthority >> (5 - b) * 8) & 0xFF);
91  }
92  for (byte b = 0; b < SubAuthorityCount; b = (byte)(b + 1))
93  {
94  for (byte b2 = 0; b2 < 4; b2 = (byte)(b2 + 1))
95  {
96  _BinaryForm[8 + 4 * b + b2] = (byte)((ulong)_SubAuthorities[b] >> b2 * 8);
97  }
98  }
99  }
100 
101  private void CreateFromBinaryForm(byte[] binaryForm, int offset)
102  {
103  if (binaryForm == null)
104  {
105  throw new ArgumentNullException("binaryForm");
106  }
107  if (offset < 0)
108  {
109  throw new ArgumentOutOfRangeException("offset", offset, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
110  }
111  if (binaryForm.Length - offset < MinBinaryLength)
112  {
113  throw new ArgumentOutOfRangeException("binaryForm", Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"));
114  }
115  if (binaryForm[offset] != Revision)
116  {
117  throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidSidRevision"), "binaryForm");
118  }
119  if (binaryForm[offset + 1] > MaxSubAuthorities)
120  {
121  throw new ArgumentException(Environment.GetResourceString("IdentityReference_InvalidNumberOfSubauthorities", MaxSubAuthorities), "binaryForm");
122  }
123  int num = 8 + 4 * binaryForm[offset + 1];
124  if (binaryForm.Length - offset < num)
125  {
126  throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_ArrayTooSmall"), "binaryForm");
127  }
128  IdentifierAuthority identifierAuthority = (IdentifierAuthority)(((ulong)binaryForm[offset + 2] << 40) + ((ulong)binaryForm[offset + 3] << 32) + ((ulong)binaryForm[offset + 4] << 24) + ((ulong)binaryForm[offset + 5] << 16) + ((ulong)binaryForm[offset + 6] << 8) + binaryForm[offset + 7]);
129  int[] array = new int[binaryForm[offset + 1]];
130  for (byte b = 0; b < binaryForm[offset + 1]; b = (byte)(b + 1))
131  {
132  array[b] = binaryForm[offset + 8 + 4 * b + 0] + (binaryForm[offset + 8 + 4 * b + 1] << 8) + (binaryForm[offset + 8 + 4 * b + 2] << 16) + (binaryForm[offset + 8 + 4 * b + 3] << 24);
133  }
134  CreateFromParts(identifierAuthority, array);
135  }
136 
139  [SecuritySafeCritical]
140  public SecurityIdentifier(string sddlForm)
141  {
142  if (sddlForm == null)
143  {
144  throw new ArgumentNullException("sddlForm");
145  }
146  byte[] resultSid;
147  int num = Win32.CreateSidFromString(sddlForm, out resultSid);
148  switch (num)
149  {
150  case 1337:
151  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), "sddlForm");
152  case 8:
153  throw new OutOfMemoryException();
154  default:
155  throw new SystemException(Win32Native.GetMessage(num));
156  case 0:
157  CreateFromBinaryForm(resultSid, 0);
158  break;
159  }
160  }
161 
165  public SecurityIdentifier(byte[] binaryForm, int offset)
166  {
167  CreateFromBinaryForm(binaryForm, offset);
168  }
169 
172  [SecuritySafeCritical]
173  [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
174  public SecurityIdentifier(IntPtr binaryForm)
175  : this(binaryForm, noDemand: true)
176  {
177  }
178 
179  [SecurityCritical]
180  internal SecurityIdentifier(IntPtr binaryForm, bool noDemand)
181  : this(Win32.ConvertIntPtrSidToByteArraySid(binaryForm), 0)
182  {
183  }
184 
188  [SecuritySafeCritical]
190  {
191  if (sidType == WellKnownSidType.LogonIdsSid)
192  {
193  throw new ArgumentException(Environment.GetResourceString("IdentityReference_CannotCreateLogonIdsSid"), "sidType");
194  }
195  if (!Win32.WellKnownSidApisSupported)
196  {
197  throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_RequiresW2kSP3"));
198  }
199  switch (sidType)
200  {
201  default:
202  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), "sidType");
203  case WellKnownSidType.AccountAdministratorSid:
204  case WellKnownSidType.AccountGuestSid:
205  case WellKnownSidType.AccountKrbtgtSid:
206  case WellKnownSidType.AccountDomainAdminsSid:
207  case WellKnownSidType.AccountDomainUsersSid:
208  case WellKnownSidType.AccountDomainGuestsSid:
209  case WellKnownSidType.AccountComputersSid:
210  case WellKnownSidType.AccountControllersSid:
211  case WellKnownSidType.AccountCertAdminsSid:
212  case WellKnownSidType.AccountSchemaAdminsSid:
213  case WellKnownSidType.AccountEnterpriseAdminsSid:
214  case WellKnownSidType.AccountPolicyAdminsSid:
215  case WellKnownSidType.AccountRasAndIasServersSid:
216  {
217  if (domainSid == null)
218  {
219  throw new ArgumentNullException("domainSid", Environment.GetResourceString("IdentityReference_DomainSidRequired", sidType));
220  }
221  SecurityIdentifier resultSid;
222  int windowsAccountDomainSid = Win32.GetWindowsAccountDomainSid(domainSid, out resultSid);
223  switch (windowsAccountDomainSid)
224  {
225  case 122:
226  throw new OutOfMemoryException();
227  case 1257:
228  throw new ArgumentException(Environment.GetResourceString("IdentityReference_NotAWindowsDomain"), "domainSid");
229  default:
230  throw new SystemException(Win32Native.GetMessage(windowsAccountDomainSid));
231  case 0:
232  break;
233  }
234  if (resultSid != domainSid)
235  {
236  throw new ArgumentException(Environment.GetResourceString("IdentityReference_NotAWindowsDomain"), "domainSid");
237  }
238  break;
239  }
240  case WellKnownSidType.NullSid:
241  case WellKnownSidType.WorldSid:
242  case WellKnownSidType.LocalSid:
243  case WellKnownSidType.CreatorOwnerSid:
244  case WellKnownSidType.CreatorGroupSid:
245  case WellKnownSidType.CreatorOwnerServerSid:
246  case WellKnownSidType.CreatorGroupServerSid:
247  case WellKnownSidType.NTAuthoritySid:
248  case WellKnownSidType.DialupSid:
249  case WellKnownSidType.NetworkSid:
250  case WellKnownSidType.BatchSid:
251  case WellKnownSidType.InteractiveSid:
252  case WellKnownSidType.ServiceSid:
253  case WellKnownSidType.AnonymousSid:
254  case WellKnownSidType.ProxySid:
255  case WellKnownSidType.EnterpriseControllersSid:
256  case WellKnownSidType.SelfSid:
257  case WellKnownSidType.AuthenticatedUserSid:
258  case WellKnownSidType.RestrictedCodeSid:
259  case WellKnownSidType.TerminalServerSid:
260  case WellKnownSidType.RemoteLogonIdSid:
261  case WellKnownSidType.LogonIdsSid:
262  case WellKnownSidType.LocalSystemSid:
263  case WellKnownSidType.LocalServiceSid:
264  case WellKnownSidType.NetworkServiceSid:
265  case WellKnownSidType.BuiltinDomainSid:
266  case WellKnownSidType.BuiltinAdministratorsSid:
267  case WellKnownSidType.BuiltinUsersSid:
268  case WellKnownSidType.BuiltinGuestsSid:
269  case WellKnownSidType.BuiltinPowerUsersSid:
270  case WellKnownSidType.BuiltinAccountOperatorsSid:
271  case WellKnownSidType.BuiltinSystemOperatorsSid:
272  case WellKnownSidType.BuiltinPrintOperatorsSid:
273  case WellKnownSidType.BuiltinBackupOperatorsSid:
274  case WellKnownSidType.BuiltinReplicatorSid:
275  case WellKnownSidType.BuiltinPreWindows2000CompatibleAccessSid:
276  case WellKnownSidType.BuiltinRemoteDesktopUsersSid:
277  case WellKnownSidType.BuiltinNetworkConfigurationOperatorsSid:
278  case WellKnownSidType.NtlmAuthenticationSid:
279  case WellKnownSidType.DigestAuthenticationSid:
280  case WellKnownSidType.SChannelAuthenticationSid:
281  case WellKnownSidType.ThisOrganizationSid:
282  case WellKnownSidType.OtherOrganizationSid:
283  case WellKnownSidType.BuiltinIncomingForestTrustBuildersSid:
284  case WellKnownSidType.BuiltinPerformanceMonitoringUsersSid:
285  case WellKnownSidType.BuiltinPerformanceLoggingUsersSid:
286  case WellKnownSidType.BuiltinAuthorizationAccessSid:
287  case WellKnownSidType.WinBuiltinTerminalServerLicenseServersSid:
288  break;
289  }
290  byte[] resultSid2;
291  int num = Win32.CreateWellKnownSid(sidType, domainSid, out resultSid2);
292  switch (num)
293  {
294  case 87:
295  throw new ArgumentException(Win32Native.GetMessage(num), "sidType/domainSid");
296  default:
297  throw new SystemException(Win32Native.GetMessage(num));
298  case 0:
299  CreateFromBinaryForm(resultSid2, 0);
300  break;
301  }
302  }
303 
304  internal SecurityIdentifier(SecurityIdentifier domainSid, uint rid)
305  {
306  int[] array = new int[domainSid.SubAuthorityCount + 1];
307  int i;
308  for (i = 0; i < domainSid.SubAuthorityCount; i++)
309  {
310  array[i] = domainSid.GetSubAuthority(i);
311  }
312  array[i] = (int)rid;
313  CreateFromParts(domainSid.IdentifierAuthority, array);
314  }
315 
316  internal SecurityIdentifier(IdentifierAuthority identifierAuthority, int[] subAuthorities)
317  {
318  CreateFromParts(identifierAuthority, subAuthorities);
319  }
320 
325  public override bool Equals(object o)
326  {
327  if (o == null)
328  {
329  return false;
330  }
331  SecurityIdentifier securityIdentifier = o as SecurityIdentifier;
332  if (securityIdentifier == null)
333  {
334  return false;
335  }
336  return this == securityIdentifier;
337  }
338 
343  public bool Equals(SecurityIdentifier sid)
344  {
345  if (sid == null)
346  {
347  return false;
348  }
349  return this == sid;
350  }
351 
354  public override int GetHashCode()
355  {
356  int num = ((long)IdentifierAuthority).GetHashCode();
357  for (int i = 0; i < SubAuthorityCount; i++)
358  {
359  num ^= GetSubAuthority(i);
360  }
361  return num;
362  }
363 
366  public override string ToString()
367  {
368  if (_SddlForm == null)
369  {
370  StringBuilder stringBuilder = new StringBuilder();
371  stringBuilder.AppendFormat("S-1-{0}", (long)_IdentifierAuthority);
372  for (int i = 0; i < SubAuthorityCount; i++)
373  {
374  stringBuilder.AppendFormat("-{0}", (uint)_SubAuthorities[i]);
375  }
376  _SddlForm = stringBuilder.ToString();
377  }
378  return _SddlForm;
379  }
380 
381  internal static bool IsValidTargetTypeStatic(Type targetType)
382  {
383  if (targetType == typeof(NTAccount))
384  {
385  return true;
386  }
387  if (targetType == typeof(SecurityIdentifier))
388  {
389  return true;
390  }
391  return false;
392  }
393 
398  public override bool IsValidTargetType(Type targetType)
399  {
400  return IsValidTargetTypeStatic(targetType);
401  }
402 
403  [SecurityCritical]
404  internal SecurityIdentifier GetAccountDomainSid()
405  {
406  SecurityIdentifier resultSid;
407  int windowsAccountDomainSid = Win32.GetWindowsAccountDomainSid(this, out resultSid);
408  switch (windowsAccountDomainSid)
409  {
410  case 122:
411  throw new OutOfMemoryException();
412  case 1257:
413  return null;
414  default:
415  throw new SystemException(Win32Native.GetMessage(windowsAccountDomainSid));
416  case 0:
417  return resultSid;
418  }
419  }
420 
424  [SecuritySafeCritical]
425  public bool IsAccountSid()
426  {
427  if (!_AccountDomainSidInitialized)
428  {
429  _AccountDomainSid = GetAccountDomainSid();
430  _AccountDomainSidInitialized = true;
431  }
432  if (_AccountDomainSid == null)
433  {
434  return false;
435  }
436  return true;
437  }
438 
448  [SecuritySafeCritical]
449  [SecurityPermission(SecurityAction.Demand, ControlPrincipal = true)]
450  public override IdentityReference Translate(Type targetType)
451  {
452  if (targetType == null)
453  {
454  throw new ArgumentNullException("targetType");
455  }
456  if (targetType == typeof(SecurityIdentifier))
457  {
458  return this;
459  }
460  if (targetType == typeof(NTAccount))
461  {
462  IdentityReferenceCollection identityReferenceCollection = new IdentityReferenceCollection(1);
463  identityReferenceCollection.Add(this);
464  IdentityReferenceCollection identityReferenceCollection2 = Translate(identityReferenceCollection, targetType, forceSuccess: true);
465  return identityReferenceCollection2[0];
466  }
467  throw new ArgumentException(Environment.GetResourceString("IdentityReference_MustBeIdentityReference"), "targetType");
468  }
469 
475  public static bool operator ==(SecurityIdentifier left, SecurityIdentifier right)
476  {
477  if ((object)left == null && (object)right == null)
478  {
479  return true;
480  }
481  if ((object)left == null || (object)right == null)
482  {
483  return false;
484  }
485  return left.CompareTo(right) == 0;
486  }
487 
493  public static bool operator !=(SecurityIdentifier left, SecurityIdentifier right)
494  {
495  return !(left == right);
496  }
497 
502  {
503  if (sid == null)
504  {
505  throw new ArgumentNullException("sid");
506  }
507  if (IdentifierAuthority < sid.IdentifierAuthority)
508  {
509  return -1;
510  }
511  if (IdentifierAuthority > sid.IdentifierAuthority)
512  {
513  return 1;
514  }
515  if (SubAuthorityCount < sid.SubAuthorityCount)
516  {
517  return -1;
518  }
519  if (SubAuthorityCount > sid.SubAuthorityCount)
520  {
521  return 1;
522  }
523  for (int i = 0; i < SubAuthorityCount; i++)
524  {
525  int num = GetSubAuthority(i) - sid.GetSubAuthority(i);
526  if (num != 0)
527  {
528  return num;
529  }
530  }
531  return 0;
532  }
533 
534  internal int GetSubAuthority(int index)
535  {
536  return _SubAuthorities[index];
537  }
538 
543  [SecuritySafeCritical]
544  public bool IsWellKnown(WellKnownSidType type)
545  {
546  return Win32.IsWellKnownSid(this, type);
547  }
548 
552  public void GetBinaryForm(byte[] binaryForm, int offset)
553  {
554  _BinaryForm.CopyTo(binaryForm, offset);
555  }
556 
561  [SecuritySafeCritical]
563  {
564  return Win32.IsEqualDomainSid(this, sid);
565  }
566 
567  [SecurityCritical]
568  private static IdentityReferenceCollection TranslateToNTAccounts(IdentityReferenceCollection sourceSids, out bool someFailed)
569  {
570  if (sourceSids == null)
571  {
572  throw new ArgumentNullException("sourceSids");
573  }
574  if (sourceSids.Count == 0)
575  {
576  throw new ArgumentException(Environment.GetResourceString("Arg_EmptyCollection"), "sourceSids");
577  }
578  IntPtr[] array = new IntPtr[sourceSids.Count];
579  GCHandle[] array2 = new GCHandle[sourceSids.Count];
580  SafeLsaPolicyHandle safeLsaPolicyHandle = SafeLsaPolicyHandle.InvalidHandle;
581  SafeLsaMemoryHandle referencedDomains = SafeLsaMemoryHandle.InvalidHandle;
582  SafeLsaMemoryHandle names = SafeLsaMemoryHandle.InvalidHandle;
583  try
584  {
585  int num = 0;
586  foreach (IdentityReference sourceSid in sourceSids)
587  {
588  SecurityIdentifier securityIdentifier = sourceSid as SecurityIdentifier;
589  if (securityIdentifier == null)
590  {
591  throw new ArgumentException(Environment.GetResourceString("Argument_ImproperType"), "sourceSids");
592  }
593  array2[num] = GCHandle.Alloc(securityIdentifier.BinaryForm, GCHandleType.Pinned);
594  array[num] = array2[num].AddrOfPinnedObject();
595  num++;
596  }
597  safeLsaPolicyHandle = Win32.LsaOpenPolicy(null, PolicyRights.POLICY_LOOKUP_NAMES);
598  someFailed = false;
599  uint num2 = Win32Native.LsaLookupSids(safeLsaPolicyHandle, sourceSids.Count, array, ref referencedDomains, ref names);
600  switch (num2)
601  {
602  case 3221225495u:
603  case 3221225626u:
604  throw new OutOfMemoryException();
605  case 3221225506u:
606  throw new UnauthorizedAccessException();
607  case 3221225587u:
608  case 263u:
609  someFailed = true;
610  break;
611  default:
612  {
613  int errorCode = Win32Native.LsaNtStatusToWinError((int)num2);
614  throw new SystemException(Win32Native.GetMessage(errorCode));
615  }
616  case 0u:
617  break;
618  }
619  names.Initialize((uint)sourceSids.Count, (uint)Marshal.SizeOf(typeof(Win32Native.LSA_TRANSLATED_NAME)));
620  Win32.InitializeReferencedDomainsPointer(referencedDomains);
621  IdentityReferenceCollection identityReferenceCollection = new IdentityReferenceCollection(sourceSids.Count);
622  if (num2 == 0 || num2 == 263)
623  {
624  Win32Native.LSA_REFERENCED_DOMAIN_LIST lSA_REFERENCED_DOMAIN_LIST = referencedDomains.Read<Win32Native.LSA_REFERENCED_DOMAIN_LIST>(0uL);
625  string[] array3 = new string[lSA_REFERENCED_DOMAIN_LIST.Entries];
626  for (int i = 0; i < lSA_REFERENCED_DOMAIN_LIST.Entries; i++)
627  {
628  Win32Native.LSA_TRUST_INFORMATION lSA_TRUST_INFORMATION = (Win32Native.LSA_TRUST_INFORMATION)Marshal.PtrToStructure(new IntPtr((long)lSA_REFERENCED_DOMAIN_LIST.Domains + i * Marshal.SizeOf(typeof(Win32Native.LSA_TRUST_INFORMATION))), typeof(Win32Native.LSA_TRUST_INFORMATION));
629  array3[i] = Marshal.PtrToStringUni(lSA_TRUST_INFORMATION.Name.Buffer, (int)lSA_TRUST_INFORMATION.Name.Length / 2);
630  }
631  Win32Native.LSA_TRANSLATED_NAME[] array4 = new Win32Native.LSA_TRANSLATED_NAME[sourceSids.Count];
632  names.ReadArray(0uL, array4, 0, array4.Length);
633  for (int j = 0; j < sourceSids.Count; j++)
634  {
635  Win32Native.LSA_TRANSLATED_NAME lSA_TRANSLATED_NAME = array4[j];
636  switch (lSA_TRANSLATED_NAME.Use)
637  {
638  case 1:
639  case 2:
640  case 4:
641  case 5:
642  case 9:
643  {
644  string accountName = Marshal.PtrToStringUni(lSA_TRANSLATED_NAME.Name.Buffer, (int)lSA_TRANSLATED_NAME.Name.Length / 2);
645  string domainName = array3[lSA_TRANSLATED_NAME.DomainIndex];
646  identityReferenceCollection.Add(new NTAccount(domainName, accountName));
647  break;
648  }
649  default:
650  someFailed = true;
651  identityReferenceCollection.Add(sourceSids[j]);
652  break;
653  }
654  }
655  }
656  else
657  {
658  for (int k = 0; k < sourceSids.Count; k++)
659  {
660  identityReferenceCollection.Add(sourceSids[k]);
661  }
662  }
663  return identityReferenceCollection;
664  }
665  finally
666  {
667  for (int l = 0; l < sourceSids.Count; l++)
668  {
669  if (array2[l].IsAllocated)
670  {
671  array2[l].Free();
672  }
673  }
674  safeLsaPolicyHandle.Dispose();
675  referencedDomains.Dispose();
676  names.Dispose();
677  }
678  }
679 
680  [SecurityCritical]
681  internal static IdentityReferenceCollection Translate(IdentityReferenceCollection sourceSids, Type targetType, bool forceSuccess)
682  {
683  bool someFailed = false;
684  IdentityReferenceCollection identityReferenceCollection = Translate(sourceSids, targetType, out someFailed);
685  if (forceSuccess && someFailed)
686  {
687  IdentityReferenceCollection identityReferenceCollection2 = new IdentityReferenceCollection();
688  foreach (IdentityReference item in identityReferenceCollection)
689  {
690  if (item.GetType() != targetType)
691  {
692  identityReferenceCollection2.Add(item);
693  }
694  }
695  throw new IdentityNotMappedException(Environment.GetResourceString("IdentityReference_IdentityNotMapped"), identityReferenceCollection2);
696  }
697  return identityReferenceCollection;
698  }
699 
700  [SecurityCritical]
701  internal static IdentityReferenceCollection Translate(IdentityReferenceCollection sourceSids, Type targetType, out bool someFailed)
702  {
703  if (sourceSids == null)
704  {
705  throw new ArgumentNullException("sourceSids");
706  }
707  if (targetType == typeof(NTAccount))
708  {
709  return TranslateToNTAccounts(sourceSids, out someFailed);
710  }
711  throw new ArgumentException(Environment.GetResourceString("IdentityReference_MustBeIdentityReference"), "targetType");
712  }
713  }
714 }
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
override string Value
Returns an uppercase Security Descriptor Definition Language (SDDL) string for the security identifie...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
Represents an identity and is the base class for the T:System.Security.Principal.NTAccount and T:Syst...
Serves as the base class for system exceptions namespace.
void Add(IdentityReference identity)
Adds an T:System.Security.Principal.IdentityReference object to the T:System.Security....
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
Definition: Marshal.cs:159
int Count
Gets the number of items in the T:System.Security.Principal.IdentityReferenceCollection collection.
override string ToString()
Returns the security identifier (SID), in Security Descriptor Definition Language (SDDL) format,...
bool IsEqualDomainSid(SecurityIdentifier sid)
Returns a value that indicates whether the security identifier (SID) represented by this T:System....
Represents a user or group account.
Definition: NTAccount.cs:10
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
StringBuilder AppendFormat(string format, object arg0)
Appends the string returned by processing a composite format string, which contains zero or more form...
bool Equals(SecurityIdentifier sid)
Indicates whether the specified T:System.Security.Principal.SecurityIdentifier object is equal to the...
SecurityAction
Specifies the security actions that can be performed using declarative security.
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....
The exception that is thrown when a feature does not run on a particular platform.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
static readonly int MaxBinaryLength
Returns the maximum size, in bytes, of the binary representation of the security identifier.
The exception that is thrown when there is not enough memory to continue the execution of a program.
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
static GCHandle Alloc(object value)
Allocates a F:System.Runtime.InteropServices.GCHandleType.Normal handle for the specified object.
Definition: GCHandle.cs:98
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
int CompareTo(SecurityIdentifier sid)
Compares the current T:System.Security.Principal.SecurityIdentifier object with the specified T:Syste...
GCHandleType
Represents the types of handles the T:System.Runtime.InteropServices.GCHandle class can allocate.
Definition: GCHandleType.cs:7
bool IsAccountSid()
Returns a value that indicates whether the security identifier (SID) represented by this T:System....
Provides a way to access a managed object from unmanaged memory.
Definition: GCHandle.cs:10
IntPtr AddrOfPinnedObject()
Retrieves the address of an object in a F:System.Runtime.InteropServices.GCHandleType....
Definition: GCHandle.cs:138
SecurityIdentifier(IntPtr binaryForm)
Initializes a new instance of the T:System.Security.Principal.SecurityIdentifier class by using an in...
Represents a collection of T:System.Security.Principal.IdentityReference objects and provides a means...
static bool operator==(SecurityIdentifier left, SecurityIdentifier right)
Compares two T:System.Security.Principal.SecurityIdentifier objects to determine whether they are equ...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
SecurityIdentifier AccountDomainSid
Returns the account domain security identifier (SID) portion from the SID represented by the T:System...
SecurityIdentifier(byte[] binaryForm, int offset)
Initializes a new instance of the T:System.Security.Principal.SecurityIdentifier class by using a spe...
override int GetHashCode()
Serves as a hash function for the current T:System.Security.Principal.SecurityIdentifier object....
The exception that is thrown when one of the arguments provided to a method is not valid.
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
Definition: GCHandle.cs:119
static unsafe string PtrToStringUni(IntPtr ptr, int len)
Allocates a managed T:System.String and copies a specified number of characters from an unmanaged Uni...
Definition: Marshal.cs:103
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
Definition: Marshal.cs:1198
void GetBinaryForm(byte[] binaryForm, int offset)
Copies the binary representation of the specified security identifier (SID) represented by the T:Syst...
SecurityIdentifier(WellKnownSidType sidType, SecurityIdentifier domainSid)
Initializes a new instance of the T:System.Security.Principal.SecurityIdentifier class by using the s...
Represents a security identifier (SID) and provides marshaling and comparison operations for SIDs.
SecurityIdentifier(string sddlForm)
Initializes a new instance of the T:System.Security.Principal.SecurityIdentifier class by using the s...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
override bool Equals(object o)
Returns a value that indicates whether this T:System.Security.Principal.SecurityIdentifier object is ...
override bool IsValidTargetType(Type targetType)
Returns a value that indicates whether the specified type is a valid translation type for the T:Syste...
bool IsWellKnown(WellKnownSidType type)
Returns a value that indicates whether the T:System.Security.Principal.SecurityIdentifier object matc...
WellKnownSidType
Defines a set of commonly used security identifiers (SIDs).
override IdentityReference Translate(Type targetType)
Translates the account name represented by the T:System.Security.Principal.SecurityIdentifier object ...
static readonly int MinBinaryLength
Returns the minimum size, in bytes, of the binary representation of the security identifier.
static bool operator !=(SecurityIdentifier left, SecurityIdentifier right)
Compares two T:System.Security.Principal.SecurityIdentifier objects to determine whether they are not...