Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TranslateToNTAccounts()

static IdentityReferenceCollection System.Security.Principal.SecurityIdentifier.TranslateToNTAccounts ( IdentityReferenceCollection sourceSids,
out bool someFailed )
inlinestaticprivate

Definition at line 485 of file SecurityIdentifier.cs.

486 {
487 if (sourceSids == null)
488 {
489 throw new ArgumentNullException("sourceSids");
490 }
491 if (sourceSids.Count == 0)
492 {
493 throw new ArgumentException(System.SR.Arg_EmptyCollection, "sourceSids");
494 }
495 IntPtr[] array = new IntPtr[sourceSids.Count];
496 GCHandle[] array2 = new GCHandle[sourceSids.Count];
497 SafeLsaPolicyHandle safeLsaPolicyHandle = null;
498 SafeLsaMemoryHandle referencedDomains = null;
499 SafeLsaMemoryHandle names = null;
500 try
501 {
502 int num = 0;
503 foreach (IdentityReference sourceSid in sourceSids)
504 {
505 if (!(sourceSid is SecurityIdentifier securityIdentifier))
506 {
507 throw new ArgumentException(System.SR.Argument_ImproperType, "sourceSids");
508 }
509 array2[num] = GCHandle.Alloc(securityIdentifier.BinaryForm, GCHandleType.Pinned);
510 array[num] = array2[num].AddrOfPinnedObject();
511 num++;
512 }
513 safeLsaPolicyHandle = Win32.LsaOpenPolicy(null, PolicyRights.POLICY_LOOKUP_NAMES);
514 someFailed = false;
515 uint num2 = global::Interop.Advapi32.LsaLookupSids(safeLsaPolicyHandle, sourceSids.Count, array, out referencedDomains, out names);
516 switch (num2)
517 {
518 case 3221225495u:
519 case 3221225626u:
520 throw new OutOfMemoryException();
521 case 3221225506u:
522 throw new UnauthorizedAccessException();
523 case 3221225587u:
524 case 263u:
525 someFailed = true;
526 break;
527 default:
528 {
529 uint error = global::Interop.Advapi32.LsaNtStatusToWinError(num2);
530 throw new Win32Exception((int)error);
531 }
532 case 0u:
533 break;
534 }
535 names.Initialize((uint)sourceSids.Count, (uint)Marshal.SizeOf<global::Interop.LSA_TRANSLATED_NAME>());
536 Win32.InitializeReferencedDomainsPointer(referencedDomains);
537 IdentityReferenceCollection identityReferenceCollection = new IdentityReferenceCollection(sourceSids.Count);
538 if (num2 == 0 || num2 == 263)
539 {
540 global::Interop.LSA_REFERENCED_DOMAIN_LIST lSA_REFERENCED_DOMAIN_LIST = referencedDomains.Read<global::Interop.LSA_REFERENCED_DOMAIN_LIST>(0uL);
541 string[] array3 = new string[lSA_REFERENCED_DOMAIN_LIST.Entries];
542 for (int i = 0; i < lSA_REFERENCED_DOMAIN_LIST.Entries; i++)
543 {
544 global::Interop.LSA_TRUST_INFORMATION lSA_TRUST_INFORMATION = Marshal.PtrToStructure<global::Interop.LSA_TRUST_INFORMATION>(new IntPtr((long)lSA_REFERENCED_DOMAIN_LIST.Domains + i * Marshal.SizeOf<global::Interop.LSA_TRUST_INFORMATION>()));
545 array3[i] = Marshal.PtrToStringUni(lSA_TRUST_INFORMATION.Name.Buffer, lSA_TRUST_INFORMATION.Name.Length / 2);
546 }
547 global::Interop.LSA_TRANSLATED_NAME[] array4 = new global::Interop.LSA_TRANSLATED_NAME[sourceSids.Count];
548 names.ReadArray(0uL, array4, 0, array4.Length);
549 for (int j = 0; j < sourceSids.Count; j++)
550 {
551 global::Interop.LSA_TRANSLATED_NAME lSA_TRANSLATED_NAME = array4[j];
552 switch ((SidNameUse)lSA_TRANSLATED_NAME.Use)
553 {
554 case SidNameUse.User:
555 case SidNameUse.Group:
556 case SidNameUse.Alias:
557 case SidNameUse.WellKnownGroup:
558 case SidNameUse.Computer:
559 {
560 string accountName = Marshal.PtrToStringUni(lSA_TRANSLATED_NAME.Name.Buffer, lSA_TRANSLATED_NAME.Name.Length / 2);
561 string domainName = array3[lSA_TRANSLATED_NAME.DomainIndex];
562 identityReferenceCollection.Add(new NTAccount(domainName, accountName));
563 break;
564 }
565 default:
566 someFailed = true;
567 identityReferenceCollection.Add(sourceSids[j]);
568 break;
569 }
570 }
571 }
572 else
573 {
574 for (int k = 0; k < sourceSids.Count; k++)
575 {
576 identityReferenceCollection.Add(sourceSids[k]);
577 }
578 }
579 return identityReferenceCollection;
580 }
581 finally
582 {
583 for (int l = 0; l < sourceSids.Count; l++)
584 {
585 if (array2[l].IsAllocated)
586 {
587 array2[l].Free();
588 }
589 }
590 safeLsaPolicyHandle?.Dispose();
591 referencedDomains?.Dispose();
592 names?.Dispose();
593 }
594 }
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
static ? object PtrToStructure(IntPtr ptr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type structureType)
Definition Marshal.cs:1164
static int SizeOf(object structure)
Definition Marshal.cs:697
static string Argument_ImproperType
Definition SR.cs:20
static string Arg_EmptyCollection
Definition SR.cs:14
Definition SR.cs:7
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81

References System.Security.Principal.IdentityReferenceCollection.Add(), System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject(), System.Runtime.InteropServices.GCHandle.Alloc(), System.SR.Arg_EmptyCollection, System.SR.Argument_ImproperType, System.array, System.Security.Principal.IdentityReferenceCollection.Count, System.Runtime.InteropServices.SafeHandle.Dispose(), System.Runtime.InteropServices.GCHandle.Free(), System.Security.Principal.Win32.InitializeReferencedDomainsPointer(), System.Security.Principal.Win32.LsaOpenPolicy(), System.Runtime.InteropServices.Marshal.PtrToStringUni(), System.Runtime.InteropServices.Marshal.PtrToStructure(), and System.Runtime.InteropServices.Marshal.SizeOf().

Referenced by System.Security.Principal.SecurityIdentifier.Translate().