ReactOS  r76032
lookup.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: Local Security Authority (LSA) Server
4  * FILE: reactos/dll/win32/lsasrv/lookup.c
5  * PURPOSE: Sid / Name lookup functions
6  *
7  * PROGRAMMERS: Eric Kohl
8  */
9 
10 #include "lsasrv.h"
11 
12 #include "resources.h"
13 
14 /* GLOBALS *****************************************************************/
15 
16 typedef wchar_t *PSAMPR_SERVER_NAME;
17 typedef void *SAMPR_HANDLE;
18 
20 {
21  unsigned long Count;
24 
25 typedef struct _SAMPR_ULONG_ARRAY
26 {
27  unsigned long Count;
28  unsigned long *Element;
30 
31 
32 VOID
33 NTAPI
34 SamIFree_SAMPR_RETURNED_USTRING_ARRAY(PSAMPR_RETURNED_USTRING_ARRAY Ptr);
35 
36 VOID
37 NTAPI
38 SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr);
39 
41 NTAPI
43  OUT SAMPR_HANDLE *ServerHandle,
45 
47 NTAPI
49 
51 NTAPI
52 SamrOpenDomain(IN SAMPR_HANDLE ServerHandle,
54  IN PRPC_SID DomainId,
55  OUT SAMPR_HANDLE *DomainHandle);
56 
58 NTAPI
60  IN ULONG Count,
61  IN ULONG *RelativeIds,
62  OUT PSAMPR_RETURNED_USTRING_ARRAY Names,
63  OUT PSAMPR_ULONG_ARRAY Use);
64 
66 NTAPI
68  IN ULONG Count,
70  OUT PSAMPR_ULONG_ARRAY RelativeIds,
71  OUT PSAMPR_ULONG_ARRAY Use);
72 
73 
74 typedef struct _WELL_KNOWN_SID
75 {
82 
83 
92 
93 
94 /* FUNCTIONS ***************************************************************/
95 
96 BOOLEAN
99  PULONG SubAuthorities,
100  PWSTR AccountName,
101  PWSTR DomainName,
102  SID_NAME_USE Use,
103  PSID *SidPtr)
104 {
105  PWELL_KNOWN_SID SidEntry;
106  PULONG p;
107  ULONG i;
108 
109  SidEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WELL_KNOWN_SID));
110  if (SidEntry == NULL)
111  return FALSE;
112 
113  InitializeListHead(&SidEntry->ListEntry);
114 
115  SidEntry->Sid = RtlAllocateHeap(RtlGetProcessHeap(),
116  0,
117  RtlLengthRequiredSid(SubAuthorityCount));
118  if (SidEntry->Sid == NULL)
119  {
120  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry);
121  return FALSE;
122  }
123 
124  RtlInitializeSid(SidEntry->Sid,
125  IdentifierAuthority,
126  SubAuthorityCount);
127 
128  for (i = 0; i < (ULONG)SubAuthorityCount; i++)
129  {
130  p = RtlSubAuthoritySid(SidEntry->Sid, i);
131  *p = SubAuthorities[i];
132  }
133 
134 // RtlInitUnicodeString(&SidEntry->AccountName,
135 // AccountName);
136  SidEntry->AccountName.Length = wcslen(AccountName) * sizeof(WCHAR);
137  SidEntry->AccountName.MaximumLength = SidEntry->AccountName.Length + sizeof(WCHAR);
138  SidEntry->AccountName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
139  SidEntry->AccountName.MaximumLength);
140  if (SidEntry->AccountName.Buffer == NULL)
141  {
142  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry->Sid);
143  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry);
144  return FALSE;
145  }
146 
147  wcscpy(SidEntry->AccountName.Buffer,
148  AccountName);
149 
150 // RtlInitUnicodeString(&SidEntry->DomainName,
151 // DomainName);
152  SidEntry->DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
153  SidEntry->DomainName.MaximumLength = SidEntry->DomainName.Length + sizeof(WCHAR);
154  SidEntry->DomainName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
155  SidEntry->DomainName.MaximumLength);
156  if (SidEntry->DomainName.Buffer == NULL)
157  {
158  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry->AccountName.Buffer);
159  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry->Sid);
160  RtlFreeHeap(RtlGetProcessHeap(), 0, SidEntry);
161  return FALSE;
162  }
163 
164  wcscpy(SidEntry->DomainName.Buffer,
165  DomainName);
166 
167  SidEntry->Use = Use;
168 
169  InsertTailList(&WellKnownSidListHead,
170  &SidEntry->ListEntry);
171 
172  if (SidPtr != NULL)
173  *SidPtr = SidEntry->Sid;
174 
175  return TRUE;
176 }
177 
178 
179 NTSTATUS
181 {
182  WCHAR szAccountName[80];
183  WCHAR szDomainName[80];
184  ULONG SubAuthorities[8];
186 
187  InitializeListHead(&WellKnownSidListHead);
188 
189  hInstance = GetModuleHandleW(L"lsasrv.dll");
190 
191  /* NT Authority */
192 
193  LsapLoadString(hInstance, IDS_NT_AUTHORITY, szAccountName, ARRAYSIZE(szAccountName));
194  LsapLoadString(hInstance, IDS_NT_AUTHORITY, szDomainName, ARRAYSIZE(szDomainName));
196  0,
197  NULL,
198  szAccountName,
199  szDomainName,
201  NULL);
202 
203  /* Null Sid */
204  LsapLoadString(hInstance, IDS_NULL_RID, szAccountName, ARRAYSIZE(szAccountName));
205 
206  SubAuthorities[0] = SECURITY_NULL_RID;
208  1,
209  SubAuthorities,
210  szAccountName,
211  L"",
213  NULL);
214 
215  /* World Sid */
216  LsapLoadString(hInstance, IDS_WORLD_RID, szAccountName, ARRAYSIZE(szAccountName));
217 
218  SubAuthorities[0] = SECURITY_WORLD_RID;
220  1,
221  SubAuthorities,
222  szAccountName,
223  L"",
225  &LsapWorldSid);
226 
227  /* Local Sid */
228  LsapLoadString(hInstance, IDS_LOCAL_RID, szAccountName, ARRAYSIZE(szAccountName));
229 
230  SubAuthorities[0] = SECURITY_LOCAL_RID;
232  1,
233  SubAuthorities,
234  szAccountName,
235  L"",
237  NULL);
238 
239  /* Creator Owner Sid */
240  LsapLoadString(hInstance, IDS_CREATOR_OWNER_RID, szAccountName, ARRAYSIZE(szAccountName));
241 
242  SubAuthorities[0] = SECURITY_CREATOR_OWNER_RID;
244  1,
245  SubAuthorities,
246  szAccountName,
247  L"",
249  NULL);
250 
251  /* Creator Group Sid */
252  LsapLoadString(hInstance, IDS_CREATOR_GROUP_RID, szAccountName, ARRAYSIZE(szAccountName));
253 
254  SubAuthorities[0] = SECURITY_CREATOR_GROUP_RID;
256  1,
257  SubAuthorities,
258  szAccountName,
259  L"",
261  NULL);
262 
263  /* Creator Owner Server Sid */
264  LsapLoadString(hInstance, IDS_CREATOR_OWNER_SERVER_RID, szAccountName, ARRAYSIZE(szAccountName));
265 
266  SubAuthorities[0] = SECURITY_CREATOR_OWNER_SERVER_RID;
268  1,
269  SubAuthorities,
270  szAccountName,
271  L"",
273  NULL);
274 
275  /* Creator Group Server Sid */
276  LsapLoadString(hInstance, IDS_CREATOR_GROUP_SERVER_RID, szAccountName, ARRAYSIZE(szAccountName));
277 
278  SubAuthorities[0] = SECURITY_CREATOR_GROUP_SERVER_RID;
280  1,
281  SubAuthorities,
282  szAccountName,
283  L"",
285  NULL);
286 
287  /* Dialup Sid */
288  LsapLoadString(hInstance, IDS_DIALUP_RID, szAccountName, ARRAYSIZE(szAccountName));
289  LsapLoadString(hInstance, IDS_NT_AUTHORITY, szDomainName, ARRAYSIZE(szDomainName));
290 
291  SubAuthorities[0] = SECURITY_DIALUP_RID;
293  1,
294  SubAuthorities,
295  szAccountName,
296  szDomainName,
298  NULL);
299 
300  /* Network Sid */
301  LsapLoadString(hInstance, IDS_NETWORK_RID, szAccountName, ARRAYSIZE(szAccountName));
302 
303  SubAuthorities[0] = SECURITY_NETWORK_RID;
305  1,
306  SubAuthorities,
307  szAccountName,
308  szDomainName,
310  &LsapNetworkSid);
311 
312  /* Batch Sid*/
313  LsapLoadString(hInstance, IDS_BATCH_RID, szAccountName, ARRAYSIZE(szAccountName));
314 
315  SubAuthorities[0] = SECURITY_BATCH_RID;
317  1,
318  SubAuthorities,
319  szAccountName,
320  szDomainName,
322  &LsapBatchSid);
323 
324  /* Interactive Sid */
325  LsapLoadString(hInstance, IDS_INTERACTIVE_RID, szAccountName, ARRAYSIZE(szAccountName));
326 
327  SubAuthorities[0] = SECURITY_INTERACTIVE_RID;
329  1,
330  SubAuthorities,
331  szAccountName,
332  szDomainName,
334  &LsapInteractiveSid);
335 
336  /* Service Sid */
337  LsapLoadString(hInstance, IDS_SERVICE_RID, szAccountName, ARRAYSIZE(szAccountName));
338 
339  SubAuthorities[0] = SECURITY_SERVICE_RID;
341  1,
342  SubAuthorities,
343  szAccountName,
344  szDomainName,
346  &LsapServiceSid);
347 
348  /* Anonymous Logon Sid */
349  LsapLoadString(hInstance, IDS_ANONYMOUS_LOGON_RID, szAccountName, ARRAYSIZE(szAccountName));
350 
351  SubAuthorities[0] = SECURITY_ANONYMOUS_LOGON_RID;
353  1,
354  SubAuthorities,
355  szAccountName,
356  szDomainName,
358  NULL);
359 
360  /* Proxy Sid */
361  LsapLoadString(hInstance, IDS_PROXY_RID, szAccountName, ARRAYSIZE(szAccountName));
362 
363  SubAuthorities[0] = SECURITY_PROXY_RID;
365  1,
366  SubAuthorities,
367  szAccountName,
368  szDomainName,
370  NULL);
371 
372  /* Enterprise Controllers Sid */
373  LsapLoadString(hInstance, IDS_ENTERPRISE_CONTROLLERS_RID, szAccountName, ARRAYSIZE(szAccountName));
374 
375  SubAuthorities[0] = SECURITY_ENTERPRISE_CONTROLLERS_RID;
377  1,
378  SubAuthorities,
379  szAccountName,
380  szDomainName,
382  NULL);
383 
384  /* Principal Self Sid */
385  LsapLoadString(hInstance, IDS_PRINCIPAL_SELF_RID, szAccountName, ARRAYSIZE(szAccountName));
386 
387  SubAuthorities[0] = SECURITY_PRINCIPAL_SELF_RID;
389  1,
390  SubAuthorities,
391  szAccountName,
392  szDomainName,
394  NULL);
395 
396  /* Authenticated Users Sid */
397  LsapLoadString(hInstance, IDS_AUTHENTICATED_USER_RID, szAccountName, ARRAYSIZE(szAccountName));
398 
399  SubAuthorities[0] = SECURITY_AUTHENTICATED_USER_RID;
401  1,
402  SubAuthorities,
403  szAccountName,
404  szDomainName,
406  NULL);
407 
408  /* Restricted Code Sid */
409  LsapLoadString(hInstance, IDS_RESTRICTED_CODE_RID, szAccountName, ARRAYSIZE(szAccountName));
410 
411  SubAuthorities[0] = SECURITY_RESTRICTED_CODE_RID;
413  1,
414  SubAuthorities,
415  szAccountName,
416  szDomainName,
418  NULL);
419 
420  /* Terminal Server Sid */
421  LsapLoadString(hInstance, IDS_TERMINAL_SERVER_RID, szAccountName, ARRAYSIZE(szAccountName));
422 
423  SubAuthorities[0] = SECURITY_TERMINAL_SERVER_RID;
425  1,
426  SubAuthorities,
427  szAccountName,
428  szDomainName,
430  NULL);
431 
432  /* Remote Logon Sid */
433  LsapLoadString(hInstance, IDS_REMOTE_LOGON_RID, szAccountName, ARRAYSIZE(szAccountName));
434 
435  SubAuthorities[0] = SECURITY_REMOTE_LOGON_RID;
437  1,
438  SubAuthorities,
439  szAccountName,
440  szDomainName,
442  NULL);
443 
444  /* This Organization Sid */
445  LsapLoadString(hInstance, IDS_THIS_ORGANIZATION_RID, szAccountName, ARRAYSIZE(szAccountName));
446 
447  SubAuthorities[0] = SECURITY_THIS_ORGANIZATION_RID;
449  1,
450  SubAuthorities,
451  szAccountName,
452  szDomainName,
454  NULL);
455 
456  /* Local System Sid */
457  LsapLoadString(hInstance, IDS_LOCAL_SYSTEM_RID, szAccountName, ARRAYSIZE(szAccountName));
458 
459  SubAuthorities[0] = SECURITY_LOCAL_SYSTEM_RID;
461  1,
462  SubAuthorities,
463  szAccountName,
464  szDomainName,
466  &LsapLocalSystemSid);
467 
468  /* Local Service Sid */
469  LsapLoadString(hInstance, IDS_LOCAL_SERVICE_RID, szAccountName, ARRAYSIZE(szAccountName));
470 
471  SubAuthorities[0] = SECURITY_LOCAL_SERVICE_RID;
473  1,
474  SubAuthorities,
475  szAccountName,
476  szDomainName,
478  NULL);
479 
481  1,
482  SubAuthorities,
483  L"LOCALSERVICE",
484  L"NT AUTHORITY",
486  NULL);
487 
488  /* Network Service Sid */
489  LsapLoadString(hInstance, IDS_NETWORK_SERVICE_RID, szAccountName, ARRAYSIZE(szAccountName));
490 
491  SubAuthorities[0] = SECURITY_NETWORK_SERVICE_RID;
493  1,
494  SubAuthorities,
495  szAccountName,
496  szDomainName,
498  NULL);
499 
501  1,
502  SubAuthorities,
503  L"NETWORKSERVICE",
504  L"NT AUTHORITY",
506  NULL);
507 
508  /* Builtin Domain Sid */
509  LsapLoadString(hInstance, IDS_BUILTIN_DOMAIN_RID, szAccountName, ARRAYSIZE(szAccountName));
510  LsapLoadString(hInstance, IDS_BUILTIN_DOMAIN_RID, szDomainName, ARRAYSIZE(szDomainName));
511 
512  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
514  1,
515  SubAuthorities,
516  szAccountName,
517  szDomainName,
519  NULL);
520 
521  /* Administrators Alias Sid */
522  LsapLoadString(hInstance, IDS_ALIAS_RID_ADMINS, szAccountName, ARRAYSIZE(szAccountName));
523 
524  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
525  SubAuthorities[1] = DOMAIN_ALIAS_RID_ADMINS;
527  2,
528  SubAuthorities,
529  szAccountName,
530  szDomainName,
531  SidTypeAlias,
532  &LsapAdministratorsSid);
533 
534  /* Users Alias Sid */
535  LsapLoadString(hInstance, IDS_ALIAS_RID_USERS, szAccountName, ARRAYSIZE(szAccountName));
536 
537  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
538  SubAuthorities[1] = DOMAIN_ALIAS_RID_USERS;
540  2,
541  SubAuthorities,
542  szAccountName,
543  szDomainName,
544  SidTypeAlias,
545  NULL);
546 
547  /* Guests Alias Sid */
548  LsapLoadString(hInstance, IDS_ALIAS_RID_GUESTS, szAccountName, ARRAYSIZE(szAccountName));
549 
550  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
551  SubAuthorities[1] = DOMAIN_ALIAS_RID_GUESTS;
553  2,
554  SubAuthorities,
555  szAccountName,
556  szDomainName,
557  SidTypeAlias,
558  NULL);
559 
560  /* Power User Alias Sid */
561  LsapLoadString(hInstance, IDS_ALIAS_RID_POWER_USERS, szAccountName, ARRAYSIZE(szAccountName));
562 
563  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
564  SubAuthorities[1] = DOMAIN_ALIAS_RID_POWER_USERS;
566  2,
567  SubAuthorities,
568  szAccountName,
569  szDomainName,
570  SidTypeAlias,
571  NULL);
572 
573  /* Account Operators Alias Sid */
574  LsapLoadString(hInstance, IDS_ALIAS_RID_ACCOUNT_OPS, szAccountName, ARRAYSIZE(szAccountName));
575 
576  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
577  SubAuthorities[1] = DOMAIN_ALIAS_RID_ACCOUNT_OPS;
579  2,
580  SubAuthorities,
581  szAccountName,
582  szDomainName,
583  SidTypeAlias,
584  NULL);
585 
586  /* System Operators Alias Sid */
587  LsapLoadString(hInstance, IDS_ALIAS_RID_SYSTEM_OPS, szAccountName, ARRAYSIZE(szAccountName));
588 
589  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
590  SubAuthorities[1] = DOMAIN_ALIAS_RID_SYSTEM_OPS;
592  2,
593  SubAuthorities,
594  szAccountName,
595  szDomainName,
596  SidTypeAlias,
597  NULL);
598 
599  /* Print Operators Alias Sid */
600  LsapLoadString(hInstance, IDS_ALIAS_RID_PRINT_OPS, szAccountName, ARRAYSIZE(szAccountName));
601 
602  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
603  SubAuthorities[1] = DOMAIN_ALIAS_RID_PRINT_OPS;
605  2,
606  SubAuthorities,
607  szAccountName,
608  szDomainName,
609  SidTypeAlias,
610  NULL);
611 
612  /* Backup Operators Alias Sid */
613  LsapLoadString(hInstance, IDS_ALIAS_RID_BACKUP_OPS, szAccountName, ARRAYSIZE(szAccountName));
614 
615  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
616  SubAuthorities[1] = DOMAIN_ALIAS_RID_BACKUP_OPS;
618  2,
619  SubAuthorities,
620  szAccountName,
621  szDomainName,
622  SidTypeAlias,
623  NULL);
624 
625  /* Replicators Alias Sid */
626  LsapLoadString(hInstance, IDS_ALIAS_RID_REPLICATOR, szAccountName, ARRAYSIZE(szAccountName));
627 
628  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
629  SubAuthorities[1] = DOMAIN_ALIAS_RID_REPLICATOR;
631  2,
632  SubAuthorities,
633  szAccountName,
634  szDomainName,
635  SidTypeAlias,
636  NULL);
637 
638  /* RAS Servers Alias Sid */
639  LsapLoadString(hInstance, IDS_ALIAS_RID_RAS_SERVERS, szAccountName, ARRAYSIZE(szAccountName));
640 
641  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
642  SubAuthorities[1] = DOMAIN_ALIAS_RID_RAS_SERVERS;
644  2,
645  SubAuthorities,
646  szAccountName,
647  szDomainName,
648  SidTypeAlias,
649  NULL);
650 
651  /* Pre-Windows 2000 Compatible Access Alias Sid */
652  LsapLoadString(hInstance, IDS_ALIAS_RID_PREW2KCOMPACCESS, szAccountName, ARRAYSIZE(szAccountName));
653 
654  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
655  SubAuthorities[1] = DOMAIN_ALIAS_RID_PREW2KCOMPACCESS;
657  2,
658  SubAuthorities,
659  szAccountName,
660  szDomainName,
661  SidTypeAlias,
662  NULL);
663 
664  /* Remote Desktop Users Alias Sid */
665  LsapLoadString(hInstance, IDS_ALIAS_RID_REMOTE_DESKTOP_USERS, szAccountName, ARRAYSIZE(szAccountName));
666 
667  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
668  SubAuthorities[1] = DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS;
670  2,
671  SubAuthorities,
672  szAccountName,
673  szDomainName,
674  SidTypeAlias,
675  NULL);
676 
677  /* Network Configuration Operators Alias Sid */
678  LsapLoadString(hInstance, IDS_ALIAS_RID_NETWORK_CONFIGURATION_OPS, szAccountName, ARRAYSIZE(szAccountName));
679 
680  SubAuthorities[0] = SECURITY_BUILTIN_DOMAIN_RID;
681  SubAuthorities[1] = DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS;
683  2,
684  SubAuthorities,
685  szAccountName,
686  szDomainName,
687  SidTypeAlias,
688  NULL);
689 
690  /* FIXME: Add more well known sids */
691 
692  return STATUS_SUCCESS;
693 }
694 
695 
696 PWELL_KNOWN_SID
698 {
699  PLIST_ENTRY ListEntry;
700  PWELL_KNOWN_SID Ptr;
701 
702  ListEntry = WellKnownSidListHead.Flink;
703  while (ListEntry != &WellKnownSidListHead)
704  {
705  Ptr = CONTAINING_RECORD(ListEntry,
707  ListEntry);
708  if (RtlEqualSid(Sid, Ptr->Sid))
709  {
710  return Ptr;
711  }
712 
713  ListEntry = ListEntry->Flink;
714  }
715 
716  return NULL;
717 }
718 
719 
720 PWELL_KNOWN_SID
722 {
723  PLIST_ENTRY ListEntry;
724  PWELL_KNOWN_SID Ptr;
725 
726  ListEntry = WellKnownSidListHead.Flink;
727  while (ListEntry != &WellKnownSidListHead)
728  {
729  Ptr = CONTAINING_RECORD(ListEntry,
731  ListEntry);
732  if (RtlEqualUnicodeString(AccountName, &Ptr->AccountName, TRUE))
733  {
734  return Ptr;
735  }
736 
737  ListEntry = ListEntry->Flink;
738  }
739 
740  return NULL;
741 }
742 
743 
744 PWELL_KNOWN_SID
746  PUNICODE_STRING DomainName)
747 {
748  PLIST_ENTRY ListEntry;
749  PWELL_KNOWN_SID Ptr;
750 
751  ListEntry = WellKnownSidListHead.Flink;
752  while (ListEntry != &WellKnownSidListHead)
753  {
754  Ptr = CONTAINING_RECORD(ListEntry,
756  ListEntry);
757  if (RtlEqualUnicodeString(AccountName, &Ptr->AccountName, TRUE) &&
758  RtlEqualUnicodeString(DomainName, &Ptr->DomainName, TRUE))
759  {
760  return Ptr;
761  }
762 
763  ListEntry = ListEntry->Flink;
764  }
765 
766  return NULL;
767 }
768 
769 
770 static
771 NTSTATUS
774  PRPC_UNICODE_STRING *DomainNames,
775  PRPC_UNICODE_STRING *AccountNames)
776 {
777  PRPC_UNICODE_STRING DomainsBuffer = NULL;
778  PRPC_UNICODE_STRING AccountsBuffer = NULL;
779  ULONG DomainLength;
780  ULONG AccountLength;
781  ULONG i;
782  LPWSTR Ptr;
784 
785  DomainsBuffer = MIDL_user_allocate(Count * sizeof(RPC_UNICODE_STRING));
786  if (DomainsBuffer == NULL)
787  {
789  goto done;
790  }
791 
792  AccountsBuffer = MIDL_user_allocate(Count * sizeof(RPC_UNICODE_STRING));
793  if (AccountsBuffer == NULL)
794  {
796  goto done;
797  }
798 
799  for (i = 0; i < Count; i++)
800  {
801 //TRACE("Name: %wZ\n", &Names[i]);
802 
803  Ptr = wcschr(Names[i].Buffer, L'\\');
804  if (Ptr == NULL)
805  {
806  AccountLength = Names[i].Length / sizeof(WCHAR);
807 
808  AccountsBuffer[i].Length = Names[i].Length;
809  AccountsBuffer[i].MaximumLength = AccountsBuffer[i].Length + sizeof(WCHAR);
810  AccountsBuffer[i].Buffer = MIDL_user_allocate(AccountsBuffer[i].MaximumLength);
811  if (AccountsBuffer[i].Buffer == NULL)
812  {
814  goto done;
815  }
816 
817  CopyMemory(AccountsBuffer[i].Buffer,
818  Names[i].Buffer,
819  AccountsBuffer[i].Length);
820  AccountsBuffer[i].Buffer[AccountLength] = UNICODE_NULL;
821 
822 //TRACE("Account name: %wZ\n", &AccountsBuffer[i]);
823  }
824  else
825  {
826  DomainLength = (ULONG)(ULONG_PTR)(Ptr - Names[i].Buffer);
827  AccountLength = (Names[i].Length / sizeof(WCHAR)) - DomainLength - 1;
828 //TRACE("DomainLength: %u\n", DomainLength);
829 //TRACE("AccountLength: %u\n", AccountLength);
830 
831  if (DomainLength > 0)
832  {
833  DomainsBuffer[i].Length = (USHORT)DomainLength * sizeof(WCHAR);
834  DomainsBuffer[i].MaximumLength = DomainsBuffer[i].Length + sizeof(WCHAR);
835  DomainsBuffer[i].Buffer = MIDL_user_allocate(DomainsBuffer[i].MaximumLength);
836  if (DomainsBuffer[i].Buffer == NULL)
837  {
839  goto done;
840  }
841 
842  CopyMemory(DomainsBuffer[i].Buffer,
843  Names[i].Buffer,
844  DomainsBuffer[i].Length);
845  DomainsBuffer[i].Buffer[DomainLength] = UNICODE_NULL;
846 
847 //TRACE("Domain name: %wZ\n", &DomainsBuffer[i]);
848  }
849 
850  AccountsBuffer[i].Length = (USHORT)AccountLength * sizeof(WCHAR);
851  AccountsBuffer[i].MaximumLength = AccountsBuffer[i].Length + sizeof(WCHAR);
852  AccountsBuffer[i].Buffer = MIDL_user_allocate(AccountsBuffer[i].MaximumLength);
853  if (AccountsBuffer[i].Buffer == NULL)
854  {
856  goto done;
857  }
858 
859  CopyMemory(AccountsBuffer[i].Buffer,
860  &(Names[i].Buffer[DomainLength + 1]),
861  AccountsBuffer[i].Length);
862  AccountsBuffer[i].Buffer[AccountLength] = UNICODE_NULL;
863 
864 //TRACE("Account name: %wZ\n", &AccountsBuffer[i]);
865  }
866  }
867 
868 done:
869  if (!NT_SUCCESS(Status))
870  {
871  if (AccountsBuffer != NULL)
872  {
873  for (i = 0; i < Count; i++)
874  {
875  if (AccountsBuffer[i].Buffer != NULL)
876  MIDL_user_free(AccountsBuffer[i].Buffer);
877  }
878 
879  MIDL_user_free(AccountsBuffer);
880  }
881 
882  if (DomainsBuffer != NULL)
883  {
884  for (i = 0; i < Count; i++)
885  {
886  if (DomainsBuffer[i].Buffer != NULL)
887  MIDL_user_free(DomainsBuffer[i].Buffer);
888  }
889 
890  MIDL_user_free(DomainsBuffer);
891  }
892  }
893  else
894  {
895  *DomainNames = DomainsBuffer;
896  *AccountNames = AccountsBuffer;
897  }
898 
899  return Status;
900 }
901 
902 
903 static NTSTATUS
906  PSID Sid,
907  PULONG Index)
908 {
909  ULONG i;
910 
911  i = 0;
912  while (i < ReferencedDomains->Entries &&
913  ReferencedDomains->Domains[i].Sid != NULL)
914  {
915  if (RtlEqualSid(Sid, ReferencedDomains->Domains[i].Sid))
916  {
917  *Index = i;
918  return STATUS_SUCCESS;
919  }
920 
921  i++;
922  }
923 
924  ReferencedDomains->Domains[i].Sid = MIDL_user_allocate(RtlLengthSid(Sid));
925  if (ReferencedDomains->Domains[i].Sid == NULL)
927 
928  RtlCopySid(RtlLengthSid(Sid), ReferencedDomains->Domains[i].Sid, Sid);
929 
930  ReferencedDomains->Domains[i].Name.Length = Name->Length;
931  ReferencedDomains->Domains[i].Name.MaximumLength = Name->MaximumLength;
932  ReferencedDomains->Domains[i].Name.Buffer = MIDL_user_allocate(Name->MaximumLength);
933  if (ReferencedDomains->Domains[i].Name.Buffer == NULL)
934  {
935  MIDL_user_free(ReferencedDomains->Domains[i].Sid);
936  ReferencedDomains->Domains[i].Sid = NULL;
938  }
939 
940  RtlCopyMemory(ReferencedDomains->Domains[i].Name.Buffer,
941  Name->Buffer,
942  Name->MaximumLength);
943 
944  ReferencedDomains->Entries++;
945  *Index = i;
946 
947  return STATUS_SUCCESS;
948 }
949 
950 
951 static BOOLEAN
953  IN PSID Sid)
954 {
955  PISID Sid1 = PrefixSid, Sid2 = Sid;
956  ULONG i;
957 
958  if (Sid1->Revision != Sid2->Revision)
959  return FALSE;
960 
961  if ((Sid1->IdentifierAuthority.Value[0] != Sid2->IdentifierAuthority.Value[0]) ||
962  (Sid1->IdentifierAuthority.Value[1] != Sid2->IdentifierAuthority.Value[1]) ||
963  (Sid1->IdentifierAuthority.Value[2] != Sid2->IdentifierAuthority.Value[2]) ||
964  (Sid1->IdentifierAuthority.Value[3] != Sid2->IdentifierAuthority.Value[3]) ||
965  (Sid1->IdentifierAuthority.Value[4] != Sid2->IdentifierAuthority.Value[4]) ||
966  (Sid1->IdentifierAuthority.Value[5] != Sid2->IdentifierAuthority.Value[5]))
967  return FALSE;
968 
969  if (Sid1->SubAuthorityCount >= Sid2->SubAuthorityCount)
970  return FALSE;
971 
972  if (Sid1->SubAuthorityCount == 0)
973  return TRUE;
974 
975  for (i = 0; i < Sid1->SubAuthorityCount; i++)
976  {
977  if (Sid1->SubAuthority[i] != Sid2->SubAuthority[i])
978  return FALSE;
979  }
980 
981  return TRUE;
982 }
983 
984 
985 ULONG
987 {
988  PISID Sid = Sid_;
989 
990  if (Sid->SubAuthorityCount != 0)
991  return Sid->SubAuthority[Sid->SubAuthorityCount - 1];
992 
993  return 0;
994 }
995 
996 
997 static PSID
999  ULONG RelativeId)
1000 {
1001  UCHAR RidCount;
1002  PSID DstSid;
1003  ULONG i;
1004  ULONG DstSidSize;
1005  PULONG p, q;
1006 
1007  RidCount = *RtlSubAuthorityCountSid(SrcSid);
1008  if (RidCount >= 8)
1009  return NULL;
1010 
1011  DstSidSize = RtlLengthRequiredSid(RidCount + 1);
1012 
1013  DstSid = MIDL_user_allocate(DstSidSize);
1014  if (DstSid == NULL)
1015  return NULL;
1016 
1017  RtlInitializeSid(DstSid,
1018  RtlIdentifierAuthoritySid(SrcSid),
1019  RidCount + 1);
1020 
1021  for (i = 0; i < (ULONG)RidCount; i++)
1022  {
1023  p = RtlSubAuthoritySid(SrcSid, i);
1024  q = RtlSubAuthoritySid(DstSid, i);
1025  *q = *p;
1026  }
1027 
1028  q = RtlSubAuthoritySid(DstSid, (ULONG)RidCount);
1029  *q = RelativeId;
1030 
1031  return DstSid;
1032 }
1033 
1034 
1035 static PSID
1037 {
1038  UCHAR RidCount;
1039  PSID DomainSid;
1040  ULONG i;
1041  ULONG DstSidSize;
1042  PULONG p, q;
1043 
1044  RidCount = *RtlSubAuthorityCountSid(AccountSid);
1045  if (RidCount > 0)
1046  RidCount--;
1047 
1048  DstSidSize = RtlLengthRequiredSid(RidCount);
1049 
1050  DomainSid = MIDL_user_allocate(DstSidSize);
1051  if (DomainSid == NULL)
1052  return NULL;
1053 
1054  RtlInitializeSid(DomainSid,
1055  RtlIdentifierAuthoritySid(AccountSid),
1056  RidCount);
1057 
1058  for (i = 0; i < (ULONG)RidCount; i++)
1059  {
1060  p = RtlSubAuthoritySid(AccountSid, i);
1061  q = RtlSubAuthoritySid(DomainSid, i);
1062  *q = *p;
1063  }
1064 
1065  return DomainSid;
1066 }
1067 
1068 
1069 static PSID
1071 {
1072  UCHAR RidCount;
1073  PSID DstSid;
1074  ULONG i;
1075  ULONG DstSidSize;
1076  PULONG p, q;
1077 
1078  RidCount = *RtlSubAuthorityCountSid(SrcSid);
1079  DstSidSize = RtlLengthRequiredSid(RidCount);
1080 
1081  DstSid = MIDL_user_allocate(DstSidSize);
1082  if (DstSid == NULL)
1083  return NULL;
1084 
1085  RtlInitializeSid(DstSid,
1086  RtlIdentifierAuthoritySid(SrcSid),
1087  RidCount);
1088 
1089  for (i = 0; i < (ULONG)RidCount; i++)
1090  {
1091  p = RtlSubAuthoritySid(SrcSid, i);
1092  q = RtlSubAuthoritySid(DstSid, i);
1093  *q = *p;
1094  }
1095 
1096  return DstSid;
1097 }
1098 
1099 
1100 static
1101 NTSTATUS
1103  PRPC_UNICODE_STRING DomainNames,
1104  PRPC_UNICODE_STRING AccountNames,
1105  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1106  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1107  PULONG Mapped)
1108 {
1109  UNICODE_STRING EmptyDomainName = RTL_CONSTANT_STRING(L"");
1110  PWELL_KNOWN_SID ptr, ptr2;
1111  PSID DomainSid;
1112  ULONG DomainIndex;
1113  ULONG i;
1115 
1116  for (i = 0; i < Count; i++)
1117  {
1118  /* Ignore names which were already mapped */
1119  if (SidsBuffer[i].Use != SidTypeUnknown)
1120  continue;
1121 
1122  /* Ignore fully qualified account names */
1123  if (DomainNames[i].Length != 0)
1124  continue;
1125 
1126  TRACE("Mapping name: %wZ\n", &AccountNames[i]);
1127 
1128  /* Look-up all well-known names */
1129  ptr = LsapLookupIsolatedWellKnownName((PUNICODE_STRING)&AccountNames[i]);
1130  if (ptr != NULL)
1131  {
1132  SidsBuffer[i].Use = ptr->Use;
1133  SidsBuffer[i].Sid = LsapCopySid(ptr->Sid);
1134  if (SidsBuffer[i].Sid == NULL)
1135  {
1137  goto done;
1138  }
1139 
1140  SidsBuffer[i].DomainIndex = -1;
1141  SidsBuffer[i].Flags = 0;
1142 
1143  if (ptr->Use == SidTypeDomain)
1144  {
1145  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1146  &ptr->AccountName,
1147  ptr->Sid,
1148  &DomainIndex);
1149  if (!NT_SUCCESS(Status))
1150  goto done;
1151 
1152  SidsBuffer[i].DomainIndex = DomainIndex;
1153  }
1154  else
1155  {
1157  if (ptr2 != NULL)
1158  {
1159  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1160  &ptr2->AccountName,
1161  ptr2->Sid,
1162  &DomainIndex);
1163  if (!NT_SUCCESS(Status))
1164  goto done;
1165 
1166  SidsBuffer[i].DomainIndex = DomainIndex;
1167  }
1168  else
1169  {
1170  DomainSid = CreateDomainSidFromAccountSid(ptr->Sid);
1171  if (DomainSid == NULL)
1172  {
1174  goto done;
1175  }
1176 
1177  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1178  &EmptyDomainName,
1179  DomainSid,
1180  &DomainIndex);
1181 
1182  if (DomainSid != NULL)
1183  {
1184  MIDL_user_free(DomainSid);
1185  DomainSid = NULL;
1186  }
1187 
1188  if (!NT_SUCCESS(Status))
1189  goto done;
1190 
1191  SidsBuffer[i].DomainIndex = DomainIndex;
1192  }
1193  }
1194 
1195  (*Mapped)++;
1196  continue;
1197  }
1198 
1199  /* Look-up the built-in domain */
1200  if (RtlEqualUnicodeString((PUNICODE_STRING)&AccountNames[i], &BuiltinDomainName, TRUE))
1201  {
1202  SidsBuffer[i].Use = SidTypeDomain;
1203  SidsBuffer[i].Sid = LsapCopySid(BuiltinDomainSid);
1204  if (SidsBuffer[i].Sid == NULL)
1205  {
1207  goto done;
1208  }
1209 
1210  SidsBuffer[i].DomainIndex = -1;
1211  SidsBuffer[i].Flags = 0;
1212 
1213  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1216  &DomainIndex);
1217  if (!NT_SUCCESS(Status))
1218  goto done;
1219 
1220  SidsBuffer[i].DomainIndex = DomainIndex;
1221 
1222  (*Mapped)++;
1223  continue;
1224  }
1225 
1226  /* Look-up the account domain */
1227  if (RtlEqualUnicodeString((PUNICODE_STRING)&AccountNames[i], &AccountDomainName, TRUE))
1228  {
1229  SidsBuffer[i].Use = SidTypeDomain;
1230  SidsBuffer[i].Sid = LsapCopySid(AccountDomainSid);
1231  if (SidsBuffer[i].Sid == NULL)
1232  {
1234  goto done;
1235  }
1236  SidsBuffer[i].DomainIndex = -1;
1237  SidsBuffer[i].Flags = 0;
1238 
1239  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1242  &DomainIndex);
1243  if (!NT_SUCCESS(Status))
1244  goto done;
1245 
1246  SidsBuffer[i].DomainIndex = DomainIndex;
1247 
1248  (*Mapped)++;
1249  continue;
1250  }
1251 
1252  /* FIXME: Look-up the primary domain */
1253 
1254  /* FIXME: Look-up the trusted domains */
1255 
1256  }
1257 
1258 done:
1259 
1260  return Status;
1261 }
1262 
1263 
1264 static
1265 NTSTATUS
1267  PRPC_UNICODE_STRING DomainNames,
1268  PRPC_UNICODE_STRING AccountNames,
1269  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1270  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1271  PULONG Mapped)
1272 {
1273  SAMPR_HANDLE ServerHandle = NULL;
1274  SAMPR_HANDLE DomainHandle = NULL;
1275  SAMPR_ULONG_ARRAY RelativeIds = {0, NULL};
1276  SAMPR_ULONG_ARRAY Use = {0, NULL};
1277  ULONG DomainIndex;
1278  ULONG i;
1280 
1281  Status = SamrConnect(NULL,
1282  &ServerHandle,
1284  if (!NT_SUCCESS(Status))
1285  {
1286  TRACE("SamrConnect failed (Status %08lx)\n", Status);
1287  goto done;
1288  }
1289 
1290  Status = SamrOpenDomain(ServerHandle,
1291  DOMAIN_LOOKUP,
1293  &DomainHandle);
1294  if (!NT_SUCCESS(Status))
1295  {
1296  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
1297  goto done;
1298  }
1299 
1300  for (i = 0; i < Count; i++)
1301  {
1302  /* Ignore names which were already mapped */
1303  if (SidsBuffer[i].Use != SidTypeUnknown)
1304  continue;
1305 
1306  /* Ignore fully qualified account names */
1307  if (DomainNames[i].Length != 0)
1308  continue;
1309 
1310  TRACE("Mapping name: %wZ\n", &AccountNames[i]);
1311 
1312  Status = SamrLookupNamesInDomain(DomainHandle,
1313  1,
1314  &AccountNames[i],
1315  &RelativeIds,
1316  &Use);
1317  if (NT_SUCCESS(Status))
1318  {
1319  TRACE("Found relative ID: %lu\n", RelativeIds.Element[0]);
1320 
1321  SidsBuffer[i].Use = Use.Element[0];
1323  RelativeIds.Element[0]);
1324  if (SidsBuffer[i].Sid == NULL)
1325  {
1327  goto done;
1328  }
1329 
1330  SidsBuffer[i].DomainIndex = -1;
1331  SidsBuffer[i].Flags = 0;
1332 
1333  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1336  &DomainIndex);
1337  if (!NT_SUCCESS(Status))
1338  goto done;
1339 
1340  SidsBuffer[i].DomainIndex = DomainIndex;
1341 
1342  (*Mapped)++;
1343  }
1344 
1345  SamIFree_SAMPR_ULONG_ARRAY(&RelativeIds);
1347  }
1348 
1349 done:
1350  if (DomainHandle != NULL)
1351  SamrCloseHandle(&DomainHandle);
1352 
1353  if (ServerHandle != NULL)
1354  SamrCloseHandle(&ServerHandle);
1355 
1356  return Status;
1357 }
1358 
1359 
1360 static
1361 NTSTATUS
1363  PRPC_UNICODE_STRING DomainNames,
1364  PRPC_UNICODE_STRING AccountNames,
1365  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1366  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1367  PULONG Mapped)
1368 {
1369  SAMPR_HANDLE ServerHandle = NULL;
1370  SAMPR_HANDLE DomainHandle = NULL;
1371  SAMPR_ULONG_ARRAY RelativeIds = {0, NULL};
1372  SAMPR_ULONG_ARRAY Use = {0, NULL};
1373  ULONG DomainIndex;
1374  ULONG i;
1376 
1377  TRACE("()\n");
1378 
1379  Status = SamrConnect(NULL,
1380  &ServerHandle,
1382  if (!NT_SUCCESS(Status))
1383  {
1384  TRACE("SamrConnect failed (Status %08lx)\n", Status);
1385  goto done;
1386  }
1387 
1388  Status = SamrOpenDomain(ServerHandle,
1389  DOMAIN_LOOKUP,
1391  &DomainHandle);
1392  if (!NT_SUCCESS(Status))
1393  {
1394  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
1395  goto done;
1396  }
1397 
1398  for (i = 0; i < Count; i++)
1399  {
1400  /* Ignore names which were already mapped */
1401  if (SidsBuffer[i].Use != SidTypeUnknown)
1402  continue;
1403 
1404  /* Ignore fully qualified account names */
1405  if (DomainNames[i].Length != 0)
1406  continue;
1407 
1408  TRACE("Mapping name: %wZ\n", &AccountNames[i]);
1409 
1410  Status = SamrLookupNamesInDomain(DomainHandle,
1411  1,
1412  &AccountNames[i],
1413  &RelativeIds,
1414  &Use);
1415  if (NT_SUCCESS(Status))
1416  {
1417  TRACE("Found relative ID: %lu\n", RelativeIds.Element[0]);
1418 
1419  SidsBuffer[i].Use = Use.Element[0];
1421  RelativeIds.Element[0]);
1422  if (SidsBuffer[i].Sid == NULL)
1423  {
1425  goto done;
1426  }
1427 
1428  SidsBuffer[i].DomainIndex = -1;
1429  SidsBuffer[i].Flags = 0;
1430 
1431  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1434  &DomainIndex);
1435  if (!NT_SUCCESS(Status))
1436  goto done;
1437 
1438  SidsBuffer[i].DomainIndex = DomainIndex;
1439 
1440  (*Mapped)++;
1441  }
1442 
1443  SamIFree_SAMPR_ULONG_ARRAY(&RelativeIds);
1445  }
1446 
1447 done:
1448  if (DomainHandle != NULL)
1449  SamrCloseHandle(&DomainHandle);
1450 
1451  if (ServerHandle != NULL)
1452  SamrCloseHandle(&ServerHandle);
1453 
1454  return Status;
1455 }
1456 
1457 
1458 static
1459 NTSTATUS
1461  PRPC_UNICODE_STRING DomainNames,
1462  PRPC_UNICODE_STRING AccountNames,
1463  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1464  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1465  PULONG Mapped)
1466 {
1467  UNICODE_STRING EmptyDomainName = RTL_CONSTANT_STRING(L"");
1468  PWELL_KNOWN_SID ptr, ptr2;
1469  PSID DomainSid;
1470  ULONG DomainIndex;
1471  ULONG i;
1473 
1474  for (i = 0; i < Count; i++)
1475  {
1476  /* Ignore names which were already mapped */
1477  if (SidsBuffer[i].Use != SidTypeUnknown)
1478  continue;
1479 
1480  /* Ignore isolated account names */
1481  if (DomainNames[i].Length == 0)
1482  continue;
1483 
1484  TRACE("Mapping name: %wZ\\%wZ\n", &DomainNames[i], &AccountNames[i]);
1485 
1486  /* Look-up all well-known names */
1488  (PUNICODE_STRING)&DomainNames[i]);
1489  if (ptr != NULL)
1490  {
1491  TRACE("Found it! (%wZ\\%wZ)\n", &ptr->DomainName, &ptr->AccountName);
1492 
1493  SidsBuffer[i].Use = ptr->Use;
1494  SidsBuffer[i].Sid = LsapCopySid(ptr->Sid);
1495  if (SidsBuffer[i].Sid == NULL)
1496  {
1498  goto done;
1499  }
1500 
1501  SidsBuffer[i].DomainIndex = -1;
1502  SidsBuffer[i].Flags = 0;
1503 
1504  if (ptr->Use == SidTypeDomain)
1505  {
1506  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1507  &ptr->AccountName,
1508  ptr->Sid,
1509  &DomainIndex);
1510  if (!NT_SUCCESS(Status))
1511  goto done;
1512 
1513  SidsBuffer[i].DomainIndex = DomainIndex;
1514  }
1515  else
1516  {
1518  if (ptr2 != NULL)
1519  {
1520  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1521  &ptr2->AccountName,
1522  ptr2->Sid,
1523  &DomainIndex);
1524  if (!NT_SUCCESS(Status))
1525  goto done;
1526 
1527  SidsBuffer[i].DomainIndex = DomainIndex;
1528  }
1529  else
1530  {
1531  DomainSid = CreateDomainSidFromAccountSid(ptr->Sid);
1532  if (DomainSid == NULL)
1533  {
1535  goto done;
1536  }
1537 
1538  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1539  &EmptyDomainName,
1540  DomainSid,
1541  &DomainIndex);
1542 
1543  if (DomainSid != NULL)
1544  {
1545  MIDL_user_free(DomainSid);
1546  DomainSid = NULL;
1547  }
1548 
1549  if (!NT_SUCCESS(Status))
1550  goto done;
1551 
1552  SidsBuffer[i].DomainIndex = DomainIndex;
1553  }
1554  }
1555 
1556  (*Mapped)++;
1557  continue;
1558  }
1559  }
1560 
1561 done:
1562  return Status;
1563 }
1564 
1565 
1566 static
1567 NTSTATUS
1569  PRPC_UNICODE_STRING DomainNames,
1570  PRPC_UNICODE_STRING AccountNames,
1571  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1572  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1573  PULONG Mapped)
1574 {
1575  SAMPR_HANDLE ServerHandle = NULL;
1576  SAMPR_HANDLE DomainHandle = NULL;
1577  SAMPR_ULONG_ARRAY RelativeIds = {0, NULL};
1578  SAMPR_ULONG_ARRAY Use = {0, NULL};
1579  ULONG DomainIndex;
1580  ULONG i;
1582 
1583  Status = SamrConnect(NULL,
1584  &ServerHandle,
1586  if (!NT_SUCCESS(Status))
1587  {
1588  TRACE("SamrConnect failed (Status %08lx)\n", Status);
1589  goto done;
1590  }
1591 
1592  Status = SamrOpenDomain(ServerHandle,
1593  DOMAIN_LOOKUP,
1595  &DomainHandle);
1596  if (!NT_SUCCESS(Status))
1597  {
1598  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
1599  goto done;
1600  }
1601 
1602  for (i = 0; i < Count; i++)
1603  {
1604  /* Ignore names which were already mapped */
1605  if (SidsBuffer[i].Use != SidTypeUnknown)
1606  continue;
1607 
1608  /* Ignore isolated account names */
1609  if (DomainNames[i].Length == 0)
1610  continue;
1611 
1612  if (!RtlEqualUnicodeString((PUNICODE_STRING)&DomainNames[i], &BuiltinDomainName, TRUE))
1613  continue;
1614 
1615  TRACE("Mapping name: %wZ\\%wZ\n", &DomainNames[i], &AccountNames[i]);
1616 
1617  Status = SamrLookupNamesInDomain(DomainHandle,
1618  1,
1619  &AccountNames[i],
1620  &RelativeIds,
1621  &Use);
1622  if (NT_SUCCESS(Status))
1623  {
1624  SidsBuffer[i].Use = Use.Element[0];
1626  RelativeIds.Element[0]);
1627  if (SidsBuffer[i].Sid == NULL)
1628  {
1630  goto done;
1631  }
1632 
1633  SidsBuffer[i].DomainIndex = -1;
1634  SidsBuffer[i].Flags = 0;
1635 
1636  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1639  &DomainIndex);
1640  if (!NT_SUCCESS(Status))
1641  goto done;
1642 
1643  SidsBuffer[i].DomainIndex = DomainIndex;
1644 
1645  (*Mapped)++;
1646  }
1647 
1648  SamIFree_SAMPR_ULONG_ARRAY(&RelativeIds);
1650  }
1651 
1652 done:
1653  if (DomainHandle != NULL)
1654  SamrCloseHandle(&DomainHandle);
1655 
1656  if (ServerHandle != NULL)
1657  SamrCloseHandle(&ServerHandle);
1658 
1659  return Status;
1660 }
1661 
1662 
1663 static
1664 NTSTATUS
1666  PRPC_UNICODE_STRING DomainNames,
1667  PRPC_UNICODE_STRING AccountNames,
1668  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
1669  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer,
1670  PULONG Mapped)
1671 {
1672  SAMPR_HANDLE ServerHandle = NULL;
1673  SAMPR_HANDLE DomainHandle = NULL;
1674  SAMPR_ULONG_ARRAY RelativeIds = {0, NULL};
1675  SAMPR_ULONG_ARRAY Use = {0, NULL};
1676  ULONG DomainIndex;
1677  ULONG i;
1679 
1680  Status = SamrConnect(NULL,
1681  &ServerHandle,
1683  if (!NT_SUCCESS(Status))
1684  {
1685  TRACE("SamrConnect failed (Status %08lx)\n", Status);
1686  goto done;
1687  }
1688 
1689  Status = SamrOpenDomain(ServerHandle,
1690  DOMAIN_LOOKUP,
1692  &DomainHandle);
1693  if (!NT_SUCCESS(Status))
1694  {
1695  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
1696  goto done;
1697  }
1698 
1699  for (i = 0; i < Count; i++)
1700  {
1701  /* Ignore names which were already mapped */
1702  if (SidsBuffer[i].Use != SidTypeUnknown)
1703  continue;
1704 
1705  /* Ignore isolated account names */
1706  if (DomainNames[i].Length == 0)
1707  continue;
1708 
1709  if (!RtlEqualUnicodeString((PUNICODE_STRING)&DomainNames[i], &AccountDomainName, TRUE))
1710  continue;
1711 
1712  TRACE("Mapping name: %wZ\\%wZ\n", &DomainNames[i], &AccountNames[i]);
1713 
1714  Status = SamrLookupNamesInDomain(DomainHandle,
1715  1,
1716  &AccountNames[i],
1717  &RelativeIds,
1718  &Use);
1719  if (NT_SUCCESS(Status))
1720  {
1721  SidsBuffer[i].Use = Use.Element[0];
1723  RelativeIds.Element[0]);
1724  if (SidsBuffer[i].Sid == NULL)
1725  {
1727  goto done;
1728  }
1729 
1730  SidsBuffer[i].DomainIndex = -1;
1731  SidsBuffer[i].Flags = 0;
1732 
1733  Status = LsapAddDomainToDomainsList(DomainsBuffer,
1736  &DomainIndex);
1737  if (!NT_SUCCESS(Status))
1738  goto done;
1739 
1740  SidsBuffer[i].DomainIndex = DomainIndex;
1741 
1742  (*Mapped)++;
1743  }
1744 
1745  SamIFree_SAMPR_ULONG_ARRAY(&RelativeIds);
1747  }
1748 
1749 done:
1750  if (DomainHandle != NULL)
1751  SamrCloseHandle(&DomainHandle);
1752 
1753  if (ServerHandle != NULL)
1754  SamrCloseHandle(&ServerHandle);
1755 
1756  return Status;
1757 }
1758 
1759 
1760 NTSTATUS
1763  PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1764  PLSAPR_TRANSLATED_SIDS_EX2 TranslatedSids,
1765  LSAP_LOOKUP_LEVEL LookupLevel,
1766  DWORD *MappedCount,
1767  DWORD LookupOptions,
1768  DWORD ClientRevision)
1769 {
1770  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer = NULL;
1771  PLSAPR_TRANSLATED_SID_EX2 SidsBuffer = NULL;
1772  PRPC_UNICODE_STRING DomainNames = NULL;
1773  PRPC_UNICODE_STRING AccountNames = NULL;
1774  ULONG SidsBufferLength;
1775  ULONG i;
1776  ULONG Mapped = 0;
1778 
1779 //TRACE("()\n");
1780 
1781  TranslatedSids->Entries = 0;
1782  TranslatedSids->Sids = NULL;
1783  *ReferencedDomains = NULL;
1784 
1785  SidsBufferLength = Count * sizeof(LSAPR_TRANSLATED_SID_EX2);
1786  SidsBuffer = MIDL_user_allocate(SidsBufferLength);
1787  if (SidsBuffer == NULL)
1788  {
1789 //TRACE("\n");
1791  goto done;
1792  }
1793 
1794  DomainsBuffer = MIDL_user_allocate(sizeof(LSAPR_REFERENCED_DOMAIN_LIST));
1795  if (DomainsBuffer == NULL)
1796  {
1797 //TRACE("\n");
1799  goto done;
1800  }
1801 
1802  DomainsBuffer->Domains = MIDL_user_allocate(Count * sizeof(LSA_TRUST_INFORMATION));
1803  if (DomainsBuffer->Domains == NULL)
1804  {
1805 //TRACE("\n");
1807  goto done;
1808  }
1809  DomainsBuffer->Entries = 0;
1810  DomainsBuffer->MaxEntries = Count;
1811 
1812  for (i = 0; i < Count; i++)
1813  {
1814  SidsBuffer[i].Use = SidTypeUnknown;
1815  SidsBuffer[i].Sid = NULL;
1816  SidsBuffer[i].DomainIndex = -1;
1817  SidsBuffer[i].Flags = 0;
1818  }
1819 
1820  Status = LsapSplitNames(Count,
1821  Names,
1822  &DomainNames,
1823  &AccountNames);
1824  if (!NT_SUCCESS(Status))
1825  {
1826  TRACE("LsapSplitNames failed! (Status %lx)\n", Status);
1827  goto done;
1828  }
1829 
1830 
1831  Status = LsapLookupIsolatedNames(Count,
1832  DomainNames,
1833  AccountNames,
1834  DomainsBuffer,
1835  SidsBuffer,
1836  &Mapped);
1837  if (!NT_SUCCESS(Status) &&
1838  Status != STATUS_NONE_MAPPED &&
1839  Status != STATUS_SOME_NOT_MAPPED)
1840  {
1841  TRACE("LsapLookupIsolatedNames failed! (Status %lx)\n", Status);
1842  goto done;
1843  }
1844 
1845  if (Mapped == Count)
1846  goto done;
1847 
1848 
1849  Status = LsapLookupIsolatedBuiltinNames(Count,
1850  DomainNames,
1851  AccountNames,
1852  DomainsBuffer,
1853  SidsBuffer,
1854  &Mapped);
1855  if (!NT_SUCCESS(Status) &&
1856  Status != STATUS_NONE_MAPPED &&
1857  Status != STATUS_SOME_NOT_MAPPED)
1858  {
1859  TRACE("LsapLookupIsolatedBuiltinNames failed! (Status %lx)\n", Status);
1860  goto done;
1861  }
1862 
1863  if (Mapped == Count)
1864  goto done;
1865 
1866 
1867  Status = LsapLookupIsolatedAccountNames(Count,
1868  DomainNames,
1869  AccountNames,
1870  DomainsBuffer,
1871  SidsBuffer,
1872  &Mapped);
1873  if (!NT_SUCCESS(Status) &&
1874  Status != STATUS_NONE_MAPPED &&
1875  Status != STATUS_SOME_NOT_MAPPED)
1876  {
1877  TRACE("LsapLookupIsolatedAccountNames failed! (Status %lx)\n", Status);
1878  goto done;
1879  }
1880 
1881  if (Mapped == Count)
1882  goto done;
1883 
1885  DomainNames,
1886  AccountNames,
1887  DomainsBuffer,
1888  SidsBuffer,
1889  &Mapped);
1890  if (!NT_SUCCESS(Status) &&
1891  Status != STATUS_NONE_MAPPED &&
1892  Status != STATUS_SOME_NOT_MAPPED)
1893  {
1894  TRACE("LsapLookupFullyQualifiedWellKnownNames failed! (Status %lx)\n", Status);
1895  goto done;
1896  }
1897 
1898  if (Mapped == Count)
1899  goto done;
1900 
1901  Status = LsapLookupBuiltinNames(Count,
1902  DomainNames,
1903  AccountNames,
1904  DomainsBuffer,
1905  SidsBuffer,
1906  &Mapped);
1907  if (!NT_SUCCESS(Status) &&
1908  Status != STATUS_NONE_MAPPED &&
1909  Status != STATUS_SOME_NOT_MAPPED)
1910  {
1911  TRACE("LsapLookupBuiltinNames failed! (Status %lx)\n", Status);
1912  goto done;
1913  }
1914 
1915  if (Mapped == Count)
1916  goto done;
1917 
1918 
1919  Status = LsapLookupAccountNames(Count,
1920  DomainNames,
1921  AccountNames,
1922  DomainsBuffer,
1923  SidsBuffer,
1924  &Mapped);
1925  if (!NT_SUCCESS(Status) &&
1926  Status != STATUS_NONE_MAPPED &&
1927  Status != STATUS_SOME_NOT_MAPPED)
1928  {
1929  TRACE("LsapLookupAccountNames failed! (Status %lx)\n", Status);
1930  goto done;
1931  }
1932 
1933  if (Mapped == Count)
1934  goto done;
1935 
1936 done:
1937 // TRACE("done: Status %lx\n", Status);
1938 
1939  if (DomainNames != NULL)
1940  {
1941 //TRACE("Free DomainNames\n");
1942  for (i = 0; i < Count; i++)
1943  {
1944  if (DomainNames[i].Buffer != NULL)
1945  MIDL_user_free(DomainNames[i].Buffer);
1946  }
1947 
1948  MIDL_user_free(DomainNames);
1949  }
1950 
1951  if (AccountNames != NULL)
1952  {
1953 //TRACE("Free AccountNames\n");
1954  for (i = 0; i < Count; i++)
1955  {
1956 //TRACE("i: %lu\n", i);
1957  if (AccountNames[i].Buffer != NULL)
1958  {
1959  MIDL_user_free(AccountNames[i].Buffer);
1960  }
1961  }
1962 
1963  MIDL_user_free(AccountNames);
1964  }
1965 
1966  if (!NT_SUCCESS(Status))
1967  {
1968 //TRACE("Failure!\n");
1969 
1970 //TRACE("Free DomainsBuffer\n");
1971  if (DomainsBuffer != NULL)
1972  {
1973  if (DomainsBuffer->Domains != NULL)
1974  MIDL_user_free(DomainsBuffer->Domains);
1975 
1976  MIDL_user_free(DomainsBuffer);
1977  }
1978 
1979 //TRACE("Free SidsBuffer\n");
1980  if (SidsBuffer != NULL)
1981  MIDL_user_free(SidsBuffer);
1982  }
1983  else
1984  {
1985 //TRACE("Success!\n");
1986 
1987  *ReferencedDomains = DomainsBuffer;
1988  TranslatedSids->Entries = Count;
1989  TranslatedSids->Sids = SidsBuffer;
1990  *MappedCount = Mapped;
1991 
1992  if (Mapped == 0)
1993  Status = STATUS_NONE_MAPPED;
1994  else if (Mapped < Count)
1995  Status = STATUS_SOME_NOT_MAPPED;
1996  }
1997 
1998 // TRACE("done: Status %lx\n", Status);
1999 
2000  return Status;
2001 }
2002 
2003 
2004 static NTSTATUS
2006  PLSAPR_TRANSLATED_NAME_EX NamesBuffer,
2007  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
2008  PULONG Mapped)
2009 {
2010  PWELL_KNOWN_SID ptr, ptr2;
2011  LPWSTR SidString = NULL;
2012  ULONG DomainIndex;
2013  ULONG i;
2015 
2016  for (i = 0; i < SidEnumBuffer->Entries; i++)
2017  {
2018  /* Ignore SIDs which are already mapped */
2019  if (NamesBuffer[i].Use != SidTypeUnknown)
2020  continue;
2021 
2022  ConvertSidToStringSidW(SidEnumBuffer->SidInfo[i].Sid, &SidString);
2023  TRACE("Mapping SID: %S\n", SidString);
2024  LocalFree(SidString);
2025  SidString = NULL;
2026 
2027  ptr = LsapLookupWellKnownSid(SidEnumBuffer->SidInfo[i].Sid);
2028  if (ptr != NULL)
2029  {
2030  NamesBuffer[i].Use = ptr->Use;
2031  NamesBuffer[i].Flags = 0;
2032 
2033  NamesBuffer[i].Name.Length = ptr->AccountName.Length;
2034  NamesBuffer[i].Name.MaximumLength = ptr->AccountName.MaximumLength;
2036  if (NamesBuffer[i].Name.Buffer == NULL)
2037  {
2039  goto done;
2040  }
2041 
2042  RtlCopyMemory(NamesBuffer[i].Name.Buffer, ptr->AccountName.Buffer, ptr->AccountName.MaximumLength);
2043 
2045  if (ptr2 != NULL)
2046  {
2047  Status = LsapAddDomainToDomainsList(DomainsBuffer,
2048  &ptr2->AccountName,
2049  ptr2->Sid,
2050  &DomainIndex);
2051  if (!NT_SUCCESS(Status))
2052  goto done;
2053 
2054  NamesBuffer[i].DomainIndex = DomainIndex;
2055  }
2056 
2057  TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);
2058 
2059  (*Mapped)++;
2060  }
2061  }
2062 
2063 done:
2064  return Status;
2065 }
2066 
2067 
2068 static NTSTATUS
2070  PLSAPR_TRANSLATED_NAME_EX NamesBuffer,
2071  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
2072  PULONG Mapped)
2073 {
2074  SAMPR_HANDLE ServerHandle = NULL;
2075  SAMPR_HANDLE DomainHandle = NULL;
2077  SAMPR_ULONG_ARRAY Use = {0, NULL};
2078  LPWSTR SidString = NULL;
2079  ULONG DomainIndex;
2080  ULONG RelativeIds[1];
2081  ULONG i;
2083 
2084  Status = SamrConnect(NULL,
2085  &ServerHandle,
2087  if (!NT_SUCCESS(Status))
2088  {
2089  TRACE("SamrConnect failed (Status %08lx)\n", Status);
2090  goto done;
2091  }
2092 
2093  Status = SamrOpenDomain(ServerHandle,
2094  DOMAIN_LOOKUP,
2096  &DomainHandle);
2097  if (!NT_SUCCESS(Status))
2098  {
2099  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
2100  goto done;
2101  }
2102 
2103  for (i = 0; i < SidEnumBuffer->Entries; i++)
2104  {
2105  /* Ignore SIDs which are already mapped */
2106  if (NamesBuffer[i].Use != SidTypeUnknown)
2107  continue;
2108 
2109  ConvertSidToStringSidW(SidEnumBuffer->SidInfo[i].Sid, &SidString);
2110  TRACE("Mapping SID: %S\n", SidString);
2111  LocalFree(SidString);
2112  SidString = NULL;
2113 
2114  if (RtlEqualSid(BuiltinDomainSid, SidEnumBuffer->SidInfo[i].Sid))
2115  {
2116  TRACE("Found builtin domain!\n");
2117 
2118  NamesBuffer[i].Use = SidTypeDomain;
2119  NamesBuffer[i].Flags = 0;
2120 
2121  NamesBuffer[i].Name.Length = BuiltinDomainName.Length;
2124  if (NamesBuffer[i].Name.Buffer == NULL)
2125  {
2127  goto done;
2128  }
2129 
2131 
2132  Status = LsapAddDomainToDomainsList(DomainsBuffer,
2135  &DomainIndex);
2136  if (!NT_SUCCESS(Status))
2137  goto done;
2138 
2139  NamesBuffer[i].DomainIndex = DomainIndex;
2140 
2141  TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);
2142 
2143  (*Mapped)++;
2144  }
2145  else if (LsapIsPrefixSid(BuiltinDomainSid, SidEnumBuffer->SidInfo[i].Sid))
2146  {
2147  TRACE("Found builtin domain account!\n");
2148 
2149  RelativeIds[0] = LsapGetRelativeIdFromSid(SidEnumBuffer->SidInfo[i].Sid);
2150 
2151  Status = SamrLookupIdsInDomain(DomainHandle,
2152  1,
2153  RelativeIds,
2154  &Names,
2155  &Use);
2156  if (NT_SUCCESS(Status))
2157  {
2158  NamesBuffer[i].Use = Use.Element[0];
2159  NamesBuffer[i].Flags = 0;
2160 
2161  NamesBuffer[i].Name.Length = Names.Element[0].Length;
2162  NamesBuffer[i].Name.MaximumLength = Names.Element[0].MaximumLength;
2163  NamesBuffer[i].Name.Buffer = MIDL_user_allocate(Names.Element[0].MaximumLength);
2164  if (NamesBuffer[i].Name.Buffer == NULL)
2165  {
2168 
2170  goto done;
2171  }
2172 
2173  RtlCopyMemory(NamesBuffer[i].Name.Buffer,
2174  Names.Element[0].Buffer,
2175  Names.Element[0].MaximumLength);
2176 
2179 
2180  Status = LsapAddDomainToDomainsList(DomainsBuffer,
2183  &DomainIndex);
2184  if (!NT_SUCCESS(Status))
2185  goto done;
2186 
2187  NamesBuffer[i].DomainIndex = DomainIndex;
2188 
2189  TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);
2190 
2191  (*Mapped)++;
2192  }
2193  }
2194  }
2195 
2196 done:
2197  if (DomainHandle != NULL)
2198  SamrCloseHandle(&DomainHandle);
2199 
2200  if (ServerHandle != NULL)
2201  SamrCloseHandle(&ServerHandle);
2202 
2203  return Status;
2204 }
2205 
2206 
2207 static NTSTATUS
2209  PLSAPR_TRANSLATED_NAME_EX NamesBuffer,
2210  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer,
2211  PULONG Mapped)
2212 {
2213  SAMPR_HANDLE ServerHandle = NULL;
2214  SAMPR_HANDLE DomainHandle = NULL;
2216  SAMPR_ULONG_ARRAY Use = {0, NULL};
2217  LPWSTR SidString = NULL;
2218  ULONG DomainIndex;
2219  ULONG RelativeIds[1];
2220  ULONG i;
2222 
2223  Status = SamrConnect(NULL,
2224  &ServerHandle,
2226  if (!NT_SUCCESS(Status))
2227  {
2228  TRACE("SamrConnect failed (Status %08lx)\n", Status);
2229  goto done;
2230  }
2231 
2232  Status = SamrOpenDomain(ServerHandle,
2233  DOMAIN_LOOKUP,
2235  &DomainHandle);
2236  if (!NT_SUCCESS(Status))
2237  {
2238  TRACE("SamOpenDomain failed (Status %08lx)\n", Status);
2239  goto done;
2240  }
2241 
2242  for (i = 0; i < SidEnumBuffer->Entries; i++)
2243  {
2244  /* Ignore SIDs which are already mapped */
2245  if (NamesBuffer[i].Use != SidTypeUnknown)
2246  continue;
2247 
2248  ConvertSidToStringSidW(SidEnumBuffer->SidInfo[i].Sid, &SidString);
2249  TRACE("Mapping SID: %S\n", SidString);
2250  LocalFree(SidString);
2251  SidString = NULL;
2252 
2253  if (RtlEqualSid(AccountDomainSid, SidEnumBuffer->SidInfo[i].Sid))
2254  {
2255  TRACE("Found account domain!\n");
2256 
2257  NamesBuffer[i].Use = SidTypeDomain;
2258  NamesBuffer[i].Flags = 0;
2259 
2260  NamesBuffer[i].Name.Length = AccountDomainName.Length;
2263  if (NamesBuffer[i].Name.Buffer == NULL)
2264  {
2266  goto done;
2267  }
2268 
2270 
2271  Status = LsapAddDomainToDomainsList(DomainsBuffer,
2274  &DomainIndex);
2275  if (!NT_SUCCESS(Status))
2276  goto done;
2277 
2278  NamesBuffer[i].DomainIndex = DomainIndex;
2279 
2280  TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);
2281 
2282  (*Mapped)++;
2283  }
2284  else if (LsapIsPrefixSid(AccountDomainSid, SidEnumBuffer->SidInfo[i].Sid))
2285  {
2286  TRACE("Found account domain account!\n");
2287 
2288  RelativeIds[0] = LsapGetRelativeIdFromSid(SidEnumBuffer->SidInfo[i].Sid);
2289 
2290  Status = SamrLookupIdsInDomain(DomainHandle,
2291  1,
2292  RelativeIds,
2293  &Names,
2294  &Use);
2295  if (NT_SUCCESS(Status))
2296  {
2297  NamesBuffer[i].Use = Use.Element[0];
2298  NamesBuffer[i].Flags = 0;
2299 
2300  NamesBuffer[i].Name.Length = Names.Element[0].Length;
2301  NamesBuffer[i].Name.MaximumLength = Names.Element[0].MaximumLength;
2302  NamesBuffer[i].Name.Buffer = MIDL_user_allocate(Names.Element[0].MaximumLength);
2303  if (NamesBuffer[i].Name.Buffer == NULL)
2304  {
2307 
2309  goto done;
2310  }
2311 
2312  RtlCopyMemory(NamesBuffer[i].Name.Buffer,
2313  Names.Element[0].Buffer,
2314  Names.Element[0].MaximumLength);
2315 
2318 
2319  Status = LsapAddDomainToDomainsList(DomainsBuffer,
2322  &DomainIndex);
2323  if (!NT_SUCCESS(Status))
2324  goto done;
2325 
2326  NamesBuffer[i].DomainIndex = DomainIndex;
2327 
2328  TRACE("Mapped to: %wZ\n", &NamesBuffer[i].Name);
2329 
2330  (*Mapped)++;
2331  }
2332  }
2333  }
2334 
2335 done:
2336  if (DomainHandle != NULL)
2337  SamrCloseHandle(&DomainHandle);
2338 
2339  if (ServerHandle != NULL)
2340  SamrCloseHandle(&ServerHandle);
2341 
2342  return Status;
2343 }
2344 
2345 
2346 NTSTATUS
2348  PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
2349  PLSAPR_TRANSLATED_NAMES_EX TranslatedNames,
2350  LSAP_LOOKUP_LEVEL LookupLevel,
2351  DWORD *MappedCount,
2352  DWORD LookupOptions,
2353  DWORD ClientRevision)
2354 {
2355  PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer = NULL;
2356  PLSAPR_TRANSLATED_NAME_EX NamesBuffer = NULL;
2357  ULONG NamesBufferLength;
2358  ULONG i;
2359  ULONG Mapped = 0;
2361 
2362  NamesBufferLength = SidEnumBuffer->Entries * sizeof(LSAPR_TRANSLATED_NAME_EX);
2363  NamesBuffer = MIDL_user_allocate(NamesBufferLength);
2364  if (NamesBuffer == NULL)
2365  {
2367  goto done;
2368  }
2369 
2370  DomainsBuffer = MIDL_user_allocate(sizeof(LSAPR_REFERENCED_DOMAIN_LIST));
2371  if (DomainsBuffer == NULL)
2372  {
2374  goto done;
2375  }
2376 
2377  DomainsBuffer->Domains = MIDL_user_allocate(SidEnumBuffer->Entries * sizeof(LSA_TRUST_INFORMATION));
2378  if (DomainsBuffer->Domains == NULL)
2379  {
2381  goto done;
2382  }
2383 
2384  DomainsBuffer->Entries = 0;
2385  DomainsBuffer->MaxEntries = SidEnumBuffer->Entries;
2386 
2387  /* Initialize all name entries */
2388  for (i = 0; i < SidEnumBuffer->Entries; i++)
2389  {
2390  NamesBuffer[i].Use = SidTypeUnknown;
2391  NamesBuffer[i].Name.Length = 0;
2392  NamesBuffer[i].Name.MaximumLength = 0;
2393  NamesBuffer[i].Name.Buffer = NULL;
2394  NamesBuffer[i].DomainIndex = -1;
2395  NamesBuffer[i].Flags = 0;
2396  }
2397 
2398  /* Look-up well-known SIDs */
2399  Status = LsapLookupWellKnownSids(SidEnumBuffer,
2400  NamesBuffer,
2401  DomainsBuffer,
2402  &Mapped);
2403  if (!NT_SUCCESS(Status) &&
2404  Status != STATUS_NONE_MAPPED &&
2405  Status != STATUS_SOME_NOT_MAPPED)
2406  goto done;
2407 
2408  if (Mapped == SidEnumBuffer->Entries)
2409  goto done;
2410 
2411  /* Look-up builtin domain SIDs */
2412  Status = LsapLookupBuiltinDomainSids(SidEnumBuffer,
2413  NamesBuffer,
2414  DomainsBuffer,
2415  &Mapped);
2416  if (!NT_SUCCESS(Status) &&
2417  Status != STATUS_NONE_MAPPED &&
2418  Status != STATUS_SOME_NOT_MAPPED)
2419  goto done;
2420 
2421  if (Mapped == SidEnumBuffer->Entries)
2422  goto done;
2423 
2424  /* Look-up account domain SIDs */
2425  Status = LsapLookupAccountDomainSids(SidEnumBuffer,
2426  NamesBuffer,
2427  DomainsBuffer,
2428  &Mapped);
2429  if (!NT_SUCCESS(Status) &&
2430  Status != STATUS_NONE_MAPPED &&
2431  Status != STATUS_SOME_NOT_MAPPED)
2432  goto done;
2433 
2434  if (Mapped == SidEnumBuffer->Entries)
2435  goto done;
2436 
2437 done:
2438  TRACE("done Status: %lx Mapped: %lu\n", Status, Mapped);
2439 
2440  if (!NT_SUCCESS(Status))
2441  {
2442  if (DomainsBuffer != NULL)
2443  {
2444  if (DomainsBuffer->Domains != NULL)
2445  MIDL_user_free(DomainsBuffer->Domains);
2446 
2447  MIDL_user_free(DomainsBuffer);
2448  }
2449 
2450  if (NamesBuffer != NULL)
2451  MIDL_user_free(NamesBuffer);
2452  }
2453  else
2454  {
2455  *ReferencedDomains = DomainsBuffer;
2456  TranslatedNames->Entries = SidEnumBuffer->Entries;
2457  TranslatedNames->Names = NamesBuffer;
2458  *MappedCount = Mapped;
2459 
2460  if (Mapped == 0)
2461  Status = STATUS_NONE_MAPPED;
2462  else if (Mapped < SidEnumBuffer->Entries)
2463  Status = STATUS_SOME_NOT_MAPPED;
2464  }
2465 
2466  return Status;
2467 }
2468 
2469 /* EOF */
#define IDS_PRINCIPAL_SELF_RID
Definition: resources.h:28
#define SECURITY_BATCH_RID
Definition: setypes.h:530
unsigned long * Element
Definition: authpackage.c:112
static NTSTATUS LsapLookupAccountDomainSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer, PLSAPR_TRANSLATED_NAME_EX NamesBuffer, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PULONG Mapped)
Definition: lookup.c:2208
static BOOLEAN LsapIsPrefixSid(IN PSID PrefixSid, IN PSID Sid)
Definition: lookup.c:952
SID_IDENTIFIER_AUTHORITY LocalSidAuthority
Definition: database.c:17
#define IDS_ALIAS_RID_USERS
Definition: resources.h:39
#define IDS_ALIAS_RID_RAS_SERVERS
Definition: resources.h:47
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
#define IN
Definition: typedefs.h:38
PWSTR Names[NAMES_COUNT]
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:540
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
INT LsapLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
#define IDS_ALIAS_RID_GUESTS
Definition: resources.h:40
static PSID LsapCopySid(PSID SrcSid)
Definition: lookup.c:1070
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define DOMAIN_ALIAS_RID_GUESTS
Definition: setypes.h:626
RPC_UNICODE_STRING Name
Definition: lsa.idl:105
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define SECURITY_THIS_ORGANIZATION_RID
Definition: setypes.h:544
#define IDS_BATCH_RID
Definition: resources.h:22
VOID NTAPI SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr)
Definition: samsrv.c:515
static PSID CreateDomainSidFromAccountSid(PSID AccountSid)
Definition: lookup.c:1036
enum _SID_NAME_USE SID_NAME_USE
#define SECURITY_TERMINAL_SERVER_RID
Definition: setypes.h:542
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: bidi.c:75
* PSID_IDENTIFIER_AUTHORITY
Definition: setypes.h:436
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _WELL_KNOWN_SID WELL_KNOWN_SID
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define DOMAIN_ALIAS_RID_ACCOUNT_OPS
Definition: setypes.h:629
DWORD SubAuthority[*]
Definition: ms-dtyp.idl:202
#define SECURITY_DIALUP_RID
Definition: setypes.h:528
wchar_t * PSAMPR_SERVER_NAME
Definition: authpackage.c:106
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
struct _SAMPR_RETURNED_USTRING_ARRAY SAMPR_RETURNED_USTRING_ARRAY
#define SECURITY_NETWORK_RID
Definition: setypes.h:529
#define IDS_ALIAS_RID_REPLICATOR
Definition: resources.h:46
PVOID *typedef PWSTR
Definition: winlogon.h:57
#define IDS_CREATOR_OWNER_SERVER_RID
Definition: resources.h:18
#define ARRAYSIZE(array)
Definition: filtermapper.c:28
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
#define IDS_NULL_RID
Definition: resources.h:13
NTSTATUS NTAPI SamrLookupNamesInDomain(IN SAMPR_HANDLE DomainHandle, IN ULONG Count, IN RPC_UNICODE_STRING Names[], OUT PSAMPR_ULONG_ARRAY RelativeIds, OUT PSAMPR_ULONG_ARRAY Use)
Definition: samrpc.c:3568
#define IDS_NETWORK_SERVICE_RID
Definition: resources.h:36
#define IDS_ALIAS_RID_ACCOUNT_OPS
Definition: resources.h:42
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:627
#define SECURITY_INTERACTIVE_RID
Definition: setypes.h:531
#define IDS_ALIAS_RID_BACKUP_OPS
Definition: resources.h:45
VOID NTAPI SamIFree_SAMPR_RETURNED_USTRING_ARRAY(PSAMPR_RETURNED_USTRING_ARRAY Ptr)
Definition: samsrv.c:477
PSID BuiltinDomainSid
Definition: globals.c:16
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:28
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
#define InsertTailList(ListHead, Entry)
SID_IDENTIFIER_AUTHORITY CreatorSidAuthority
Definition: database.c:18
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3249
#define WCHAR
Definition: msvc.h:43
#define IDS_RESTRICTED_CODE_RID
Definition: resources.h:30
NTSTATUS NTAPI SamrCloseHandle(IN OUT SAMPR_HANDLE *SamHandle)
Definition: samrpc.c:173
DWORD DWORD
Definition: winlogon.h:75
PLSAPR_TRANSLATED_NAME_EX Names
Definition: lsa.idl:186
LIST_ENTRY ListEntry
Definition: lookup.c:76
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:337
UNICODE_STRING AccountDomainName
Definition: database.c:24
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IDS_AUTHENTICATED_USER_RID
Definition: resources.h:29
PSID LsapWorldSid
Definition: lookup.c:85
enum _LSAP_LOOKUP_LEVEL LSAP_LOOKUP_LEVEL
NTSTATUS LsapLookupNames(DWORD Count, PRPC_UNICODE_STRING Names, PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains, PLSAPR_TRANSLATED_SIDS_EX2 TranslatedSids, LSAP_LOOKUP_LEVEL LookupLevel, DWORD *MappedCount, DWORD LookupOptions, DWORD ClientRevision)
Definition: lookup.c:1761
#define SECURITY_PRINCIPAL_SELF_RID
Definition: setypes.h:539
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
HINSTANCE hInstance
Definition: charmap.c:19
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
NTSTATUS LsapLookupSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer, PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains, PLSAPR_TRANSLATED_NAMES_EX TranslatedNames, LSAP_LOOKUP_LEVEL LookupLevel, DWORD *MappedCount, DWORD LookupOptions, DWORD ClientRevision)
Definition: lookup.c:2347
struct _LSAPR_TRANSLATED_NAME_EX LSAPR_TRANSLATED_NAME_EX
NTSTATUS NTAPI SamrLookupIdsInDomain(IN SAMPR_HANDLE DomainHandle, IN ULONG Count, IN ULONG *RelativeIds, OUT PSAMPR_RETURNED_USTRING_ARRAY Names, OUT PSAMPR_ULONG_ARRAY Use)
Definition: samrpc.c:3797
static PVOID ptr
Definition: dispmode.c:30
#define IDS_TERMINAL_SERVER_RID
Definition: resources.h:31
void * SAMPR_HANDLE
Definition: lookup.c:17
PRPC_UNICODE_STRING Element
Definition: lookup.c:22
#define IDS_CREATOR_GROUP_SERVER_RID
Definition: resources.h:19
smooth NULL
Definition: ftsmooth.c:557
#define IDS_DIALUP_RID
Definition: resources.h:20
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1104
Definition: bufpool.h:45
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define IDS_REMOTE_LOGON_RID
Definition: resources.h:32
#define SECURITY_LOCAL_SERVICE_RID
Definition: setypes.h:547
unsigned long Count
Definition: authpackage.c:111
PSID LsapBatchSid
Definition: lookup.c:87
static NTSTATUS LsapLookupFullyQualifiedWellKnownNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1460
SID_IDENTIFIER_AUTHORITY WorldSidAuthority
Definition: database.c:16
PWELL_KNOWN_SID LsapLookupFullyQualifiedWellKnownName(PUNICODE_STRING AccountName, PUNICODE_STRING DomainName)
Definition: lookup.c:745
static NTSTATUS LsapLookupIsolatedAccountNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1362
static NTSTATUS LsapLookupIsolatedBuiltinNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1266
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
unsigned char BOOLEAN
struct _WELL_KNOWN_SID * PWELL_KNOWN_SID
#define TRACE(s)
Definition: solgame.cpp:4
#define SECURITY_CREATOR_GROUP_SERVER_RID
Definition: setypes.h:520
#define SECURITY_ENTERPRISE_CONTROLLERS_RID
Definition: setypes.h:537
PSID LsapAdministratorsSid
Definition: lookup.c:91
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define IDS_ALIAS_RID_NETWORK_CONFIGURATION_OPS
Definition: resources.h:50
PSID LsapInteractiveSid
Definition: lookup.c:88
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static NTSTATUS LsapLookupBuiltinDomainSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer, PLSAPR_TRANSLATED_NAME_EX NamesBuffer, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PULONG Mapped)
Definition: lookup.c:2069
UNICODE_STRING BuiltinDomainName
Definition: database.c:23
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
#define DOMAIN_ALIAS_RID_BACKUP_OPS
Definition: setypes.h:632
#define IDS_ALIAS_RID_POWER_USERS
Definition: resources.h:41
PLSAPR_TRANSLATED_SID_EX2 Sids
Definition: lsa.idl:210
#define IDS_NT_AUTHORITY
Definition: resources.h:11
#define IDS_LOCAL_SYSTEM_RID
Definition: resources.h:34
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
#define CopyMemory
Definition: winbase.h:1619
#define DOMAIN_ALIAS_RID_SYSTEM_OPS
Definition: setypes.h:630
ULONG LsapGetRelativeIdFromSid(PSID Sid_)
Definition: lookup.c:986
static NTSTATUS LsapSplitNames(DWORD Count, PRPC_UNICODE_STRING Names, PRPC_UNICODE_STRING *DomainNames, PRPC_UNICODE_STRING *AccountNames)
Definition: lookup.c:772
#define SECURITY_LOCAL_RID
Definition: setypes.h:514
PWELL_KNOWN_SID LsapLookupWellKnownSid(PSID Sid)
Definition: lookup.c:697
RPC_UNICODE_STRING Name
Definition: lsa.idl:179
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static NTSTATUS LsapLookupBuiltinNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1568
struct _SAMPR_ULONG_ARRAY SAMPR_ULONG_ARRAY
#define IDS_ALIAS_RID_REMOTE_DESKTOP_USERS
Definition: resources.h:49
#define IDS_ENTERPRISE_CONTROLLERS_RID
Definition: resources.h:27
#define SECURITY_WORLD_RID
Definition: setypes.h:513
#define SECURITY_PROXY_RID
Definition: setypes.h:536
#define SECURITY_ANONYMOUS_LOGON_RID
Definition: setypes.h:535
BOOLEAN LsapCreateSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, UCHAR SubAuthorityCount, PULONG SubAuthorities, PWSTR AccountName, PWSTR DomainName, SID_NAME_USE Use, PSID *SidPtr)
Definition: lookup.c:97
static NTSTATUS LsapLookupWellKnownSids(PLSAPR_SID_ENUM_BUFFER SidEnumBuffer, PLSAPR_TRANSLATED_NAME_EX NamesBuffer, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PULONG Mapped)
Definition: lookup.c:2005
#define SECURITY_CREATOR_OWNER_RID
Definition: setypes.h:517
HANDLE HINSTANCE
Definition: typedefs.h:75
#define SECURITY_NULL_RID
Definition: setypes.h:512
#define IDS_INTERACTIVE_RID
Definition: resources.h:23
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
PSID LsapServiceSid
Definition: lookup.c:89
SID_NAME_USE Use
Definition: lsa.idl:202
unsigned char UCHAR
Definition: xmlstorage.h:181
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
VOID UINTN Length
Definition: acefiex.h:744
UNICODE_STRING AccountName
Definition: lookup.c:78
SID_NAME_USE Use
Definition: lookup.c:80
#define IDS_LOCAL_SERVICE_RID
Definition: resources.h:35
NTSTATUS LsapInitSids(VOID)
Definition: lookup.c:180
#define IDS_PROXY_RID
Definition: resources.h:26
Definition: typedefs.h:117
NTSTATUS NTAPI SamrOpenDomain(IN SAMPR_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PRPC_SID DomainId, OUT SAMPR_HANDLE *DomainHandle)
Definition: samrpc.c:836
unsigned short Length
Definition: msv1_0.h:53
_In_ PSID_IDENTIFIER_AUTHORITY _In_ UCHAR SubAuthorityCount
Definition: rtlfuncs.h:1487
#define SECURITY_NETWORK_SERVICE_RID
Definition: setypes.h:548
static NTSTATUS LsapAddDomainToDomainsList(PLSAPR_REFERENCED_DOMAIN_LIST ReferencedDomains, PUNICODE_STRING Name, PSID Sid, PULONG Index)
Definition: lookup.c:904
NTSTATUS NTAPI SamrConnect(IN PSAMPR_SERVER_NAME ServerName, OUT SAMPR_HANDLE *ServerHandle, IN ACCESS_MASK DesiredAccess)
Definition: samrpc.c:134
Status
Definition: gdiplustypes.h:24
static NTSTATUS LsapLookupAccountNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1665
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
#define STATUS_SOME_NOT_MAPPED
Definition: ntstatus.h:86
#define SECURITY_CREATOR_GROUP_RID
Definition: setypes.h:518
struct _SAMPR_ULONG_ARRAY * PSAMPR_ULONG_ARRAY
LONG NTSTATUS
Definition: DriverTester.h:11
PSID LsapNetworkSid
Definition: lookup.c:86
#define IDS_LOCAL_RID
Definition: resources.h:15
#define SECURITY_REMOTE_LOGON_RID
Definition: setypes.h:543
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:625
LIST_ENTRY Entries[5]
Definition: ExDoubleList.c:8
unsigned short USHORT
Definition: pedump.c:61
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
SID_NAME_USE Use
Definition: lsa.idl:178
UNICODE_STRING DomainName
Definition: lookup.c:79
#define DOMAIN_ALIAS_RID_REPLICATOR
Definition: setypes.h:634
BYTE SubAuthorityCount
Definition: ms-dtyp.idl:200
unsigned int * PULONG
Definition: retypes.h:1
#define SECURITY_RESTRICTED_CODE_RID
Definition: setypes.h:541
#define IDS_NETWORK_RID
Definition: resources.h:21
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LIST_ENTRY WellKnownSidListHead
Definition: lookup.c:84
#define SECURITY_CREATOR_OWNER_SERVER_RID
Definition: setypes.h:519
struct _SAMPR_RETURNED_USTRING_ARRAY * PSAMPR_RETURNED_USTRING_ARRAY
struct _LSAPR_TRANSLATED_SID_EX2 LSAPR_TRANSLATED_SID_EX2
#define DOMAIN_ALIAS_RID_PRINT_OPS
Definition: setypes.h:631
#define IDS_SERVICE_RID
Definition: resources.h:24
#define OUT
Definition: typedefs.h:39
#define SECURITY_SERVICE_RID
Definition: setypes.h:534
static PSID CreateSidFromSidAndRid(PSID SrcSid, ULONG RelativeId)
Definition: lookup.c:998
#define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS
Definition: setypes.h:636
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:844
PWELL_KNOWN_SID LsapLookupIsolatedWellKnownName(PUNICODE_STRING AccountName)
Definition: lookup.c:721
PSID AccountDomainSid
Definition: database.c:22
SID_IDENTIFIER_AUTHORITY IdentifierAuthority
Definition: ms-dtyp.idl:201
_In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
Definition: rtlfuncs.h:1487
#define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
Definition: setypes.h:638
void *__RPC_USER MIDL_user_allocate(SIZE_T size)
Definition: irotp.c:363
PLSAPR_TRUST_INFORMATION Domains
Definition: lsa.idl:111
BYTE Revision
Definition: ms-dtyp.idl:199
SID_IDENTIFIER_AUTHORITY NullSidAuthority
Definition: database.c:15
#define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
Definition: setypes.h:637
GLfloat GLfloat p
Definition: glext.h:8902
#define IDS_WORLD_RID
Definition: resources.h:14
NTSYSAPI BOOLEAN WINAPI RtlCopySid(DWORD, PSID, PSID)
void __RPC_USER MIDL_user_free(void *p)
Definition: irotp.c:368
#define IDS_ALIAS_RID_ADMINS
Definition: resources.h:38
#define IDS_THIS_ORGANIZATION_RID
Definition: resources.h:33
#define IDS_CREATOR_GROUP_RID
Definition: resources.h:17
#define DOMAIN_ALIAS_RID_RAS_SERVERS
Definition: setypes.h:635
WCHAR * LPWSTR
Definition: xmlstorage.h:184
PLSAPR_SID_INFORMATION SidInfo
Definition: lsa.idl:163
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
#define IDS_CREATOR_OWNER_RID
Definition: resources.h:16
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define IDS_ANONYMOUS_LOGON_RID
Definition: resources.h:25
#define IDS_ALIAS_RID_PRINT_OPS
Definition: resources.h:44
_In_ PSID Sid2
Definition: rtlfuncs.h:1757
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IDS_ALIAS_RID_PREW2KCOMPACCESS
Definition: resources.h:48
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define IDS_ALIAS_RID_SYSTEM_OPS
Definition: resources.h:43
#define IDS_BUILTIN_DOMAIN_RID
Definition: resources.h:37
unsigned short MaximumLength
Definition: msv1_0.h:54
NTSYSAPI BOOLEAN NTAPI RtlEqualSid(_In_ PSID Sid1, _In_ PSID Sid2)
SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: database.c:19
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
static NTSTATUS LsapLookupIsolatedNames(DWORD Count, PRPC_UNICODE_STRING DomainNames, PRPC_UNICODE_STRING AccountNames, PLSAPR_REFERENCED_DOMAIN_LIST DomainsBuffer, PLSAPR_TRANSLATED_SID_EX2 SidsBuffer, PULONG Mapped)
Definition: lookup.c:1102
wchar_t * Buffer
Definition: msv1_0.h:55
wchar_t * PSAMPR_SERVER_NAME
Definition: lookup.c:16
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
PSID LsapLocalSystemSid
Definition: lookup.c:90