158 {
159 if (sourceAccounts == null)
160 {
161 throw new ArgumentNullException("sourceAccounts");
162 }
163 if (sourceAccounts.Count == 0)
164 {
166 }
170 try
171 {
172 global::Interop.Advapi32.MARSHALLED_UNICODE_STRING[]
array =
new global::Interop.Advapi32.MARSHALLED_UNICODE_STRING[sourceAccounts.Count];
173 int num = 0;
175 {
176 if (!(sourceAccount is
NTAccount nTAccount))
177 {
179 }
180 array[num].Buffer = nTAccount.ToString();
182 {
184 }
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;
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];
223 {
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)
static string Argument_ImproperType
static string Arg_EmptyCollection
NTAccount(string domainName, string accountName)
@ InvalidOperationException