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

◆ TranslateToSids()

static IdentityReferenceCollection System.Security.Principal.NTAccount.TranslateToSids ( IdentityReferenceCollection sourceAccounts,
out bool someFailed )
inlinestaticprivate

Definition at line 157 of file NTAccount.cs.

158 {
159 if (sourceAccounts == null)
160 {
161 throw new ArgumentNullException("sourceAccounts");
162 }
163 if (sourceAccounts.Count == 0)
164 {
165 throw new ArgumentException(System.SR.Arg_EmptyCollection, "sourceAccounts");
166 }
167 SafeLsaPolicyHandle safeLsaPolicyHandle = null;
168 SafeLsaMemoryHandle referencedDomains = null;
169 SafeLsaMemoryHandle sids = null;
170 try
171 {
172 global::Interop.Advapi32.MARSHALLED_UNICODE_STRING[] array = new global::Interop.Advapi32.MARSHALLED_UNICODE_STRING[sourceAccounts.Count];
173 int num = 0;
174 foreach (IdentityReference sourceAccount in sourceAccounts)
175 {
176 if (!(sourceAccount is NTAccount nTAccount))
177 {
178 throw new ArgumentException(System.SR.Argument_ImproperType, "sourceAccounts");
179 }
180 array[num].Buffer = nTAccount.ToString();
181 if (array[num].Buffer.Length * 2 + 2 > 65535)
182 {
183 throw new InvalidOperationException();
184 }
185 array[num].Length = (ushort)(array[num].Buffer.Length * 2);
186 array[num].MaximumLength = (ushort)(array[num].Length + 2);
187 num++;
188 }
189 safeLsaPolicyHandle = Win32.LsaOpenPolicy(null, PolicyRights.POLICY_LOOKUP_NAMES);
190 someFailed = false;
191 uint num2 = global::Interop.Advapi32.LsaLookupNames2(safeLsaPolicyHandle, 0, sourceAccounts.Count, array, out referencedDomains, out sids);
192 switch (num2)
193 {
194 case 3221225495u:
195 case 3221225626u:
196 throw new OutOfMemoryException();
197 case 3221225506u:
198 throw new UnauthorizedAccessException();
199 case 3221225587u:
200 case 263u:
201 someFailed = true;
202 break;
203 default:
204 {
205 uint error = global::Interop.Advapi32.LsaNtStatusToWinError(num2);
206 _ = 1789;
207 throw new Win32Exception((int)error);
208 }
209 case 0u:
210 break;
211 }
212 IdentityReferenceCollection identityReferenceCollection = new IdentityReferenceCollection(sourceAccounts.Count);
213 if (num2 == 0 || num2 == 263)
214 {
215 sids.Initialize((uint)sourceAccounts.Count, (uint)Marshal.SizeOf<global::Interop.LSA_TRANSLATED_SID2>());
216 Win32.InitializeReferencedDomainsPointer(referencedDomains);
217 global::Interop.LSA_TRANSLATED_SID2[] array2 = new global::Interop.LSA_TRANSLATED_SID2[sourceAccounts.Count];
218 sids.ReadArray(0uL, array2, 0, array2.Length);
219 for (int i = 0; i < sourceAccounts.Count; i++)
220 {
221 global::Interop.LSA_TRANSLATED_SID2 lSA_TRANSLATED_SID = array2[i];
222 switch ((SidNameUse)lSA_TRANSLATED_SID.Use)
223 {
224 case SidNameUse.User:
225 case SidNameUse.Group:
226 case SidNameUse.Alias:
227 case SidNameUse.WellKnownGroup:
228 case SidNameUse.Computer:
229 identityReferenceCollection.Add(new SecurityIdentifier(lSA_TRANSLATED_SID.Sid));
230 break;
231 default:
232 someFailed = true;
233 identityReferenceCollection.Add(sourceAccounts[i]);
234 break;
235 }
236 }
237 }
238 else
239 {
240 for (int j = 0; j < sourceAccounts.Count; j++)
241 {
242 identityReferenceCollection.Add(sourceAccounts[j]);
243 }
244 }
245 return identityReferenceCollection;
246 }
247 finally
248 {
249 safeLsaPolicyHandle?.Dispose();
250 referencedDomains?.Dispose();
251 sids?.Dispose();
252 }
253 }
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
NTAccount(string domainName, string accountName)
Definition NTAccount.cs:14

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

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