ReactOS 0.4.16-dev-1946-g52006dd
logon.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/advapi32/misc/logon.c
5 * PURPOSE: Logon functions
6 * PROGRAMMER: Eric Kohl
7 */
8
9#include <advapi32.h>
11
12/* GLOBALS *****************************************************************/
13
14static const CHAR AdvapiTokenSourceName[] = "Advapi ";
16
19
20/* FUNCTIONS ***************************************************************/
21
22static
25{
26 LSA_STRING LogonProcessName;
27 LSA_STRING PackageName;
30
31 RtlInitAnsiString((PANSI_STRING)&LogonProcessName,
32 "User32LogonProcess");
33
34 Status = LsaRegisterLogonProcess(&LogonProcessName,
35 &LsaHandle,
37 if (!NT_SUCCESS(Status))
38 {
39 TRACE("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status);
40 goto done;
41 }
42
43 RtlInitAnsiString((PANSI_STRING)&PackageName,
45
47 &PackageName,
49 if (!NT_SUCCESS(Status))
50 {
51 TRACE("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status);
52 goto done;
53 }
54
55 TRACE("AuthenticationPackage: 0x%08lx\n", AuthenticationPackage);
56
57done:
58 if (!NT_SUCCESS(Status))
59 {
60 if (LsaHandle != NULL)
61 {
63 if (!NT_SUCCESS(Status))
64 {
65 TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status);
66 }
67 }
68 }
69
70 return Status;
71}
72
73
76{
78
79 if (LsaHandle != NULL)
80 {
82 if (!NT_SUCCESS(Status))
83 {
84 TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status);
85 }
86 }
87
88 return Status;
89}
90
91
127static
128BOOL
132{
135 PACL Dacl;
136 PTOKEN_OWNER OwnerOfToken;
137 PTOKEN_PRIMARY_GROUP PrimaryGroupOfToken;
138 SECURITY_DESCRIPTOR AbsoluteSd;
139 ULONG DaclSize, TokenOwnerSize, PrimaryGroupSize, RelativeSDSize = 0;
140 PSID OwnerSid = NULL, SystemSid = NULL, PrimaryGroupSid = NULL;
141 PSECURITY_DESCRIPTOR RelativeSD = NULL;
143
144 /*
145 * Since we do not know how much space
146 * is needed to allocate the buffer to
147 * hold the token owner, first we must
148 * query the exact size.
149 */
152 NULL,
153 0,
154 &TokenOwnerSize);
156 {
157 ERR("CreateDefaultProcessSecurityCommon(): Unexpected status code returned, must be STATUS_BUFFER_TOO_SMALL (Status 0x%08lx)\n", Status);
158 return FALSE;
159 }
160
161 /* We have the required space size, allocate the buffer now */
162 OwnerOfToken = RtlAllocateHeap(RtlGetProcessHeap(),
164 TokenOwnerSize);
165 if (OwnerOfToken == NULL)
166 {
167 ERR("CreateDefaultProcessSecurityCommon(): Failed to allocate buffer for token owner\n");
168 return FALSE;
169 }
170
171 /* Now query the token owner */
174 OwnerOfToken,
175 TokenOwnerSize,
176 &TokenOwnerSize);
177 if (!NT_SUCCESS(Status))
178 {
179 ERR("CreateDefaultProcessSecurityCommon(): Failed to query the token owner (Status 0x%08lx)\n", Status);
180 Success = FALSE;
181 goto Quit;
182 }
183
184 /* Do the same process but for the primary group now */
187 NULL,
188 0,
191 {
192 ERR("CreateDefaultProcessSecurityCommon(): Unexpected status code returned, must be STATUS_BUFFER_TOO_SMALL (Status 0x%08lx)\n", Status);
193 Success = FALSE;
194 goto Quit;
195 }
196
197 /* Allocate the buffer */
198 PrimaryGroupOfToken = RtlAllocateHeap(RtlGetProcessHeap(),
201 if (PrimaryGroupOfToken == NULL)
202 {
203 ERR("CreateDefaultProcessSecurityCommon(): Failed to allocate buffer for primary group token\n");
204 Success = FALSE;
205 goto Quit;
206 }
207
208 /* Query the primary group now */
211 PrimaryGroupOfToken,
214 if (!NT_SUCCESS(Status))
215 {
216 ERR("CreateDefaultProcessSecurityCommon(): Failed to query the token owner (Status 0x%08lx)\n", Status);
217 Success = FALSE;
218 goto Quit;
219 }
220
221 /* Create the SYSTEM SID */
223 1,
225 0, 0, 0, 0, 0, 0, 0,
226 &SystemSid))
227 {
228 ERR("CreateDefaultProcessSecurityCommon(): Failed to create Local System SID (error %lu)\n", GetLastError());
229 Success = FALSE;
230 goto Quit;
231 }
232
233 /* Cache the token owner and primary group SID */
234 OwnerSid = OwnerOfToken->Owner;
235 PrimaryGroupSid = PrimaryGroupOfToken->PrimaryGroup;
236
237 /* Set up the DACL size */
238 DaclSize = sizeof(ACL) +
239 sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(OwnerSid) +
240 sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(SystemSid);
241
242 /* Allocate buffer for the DACL */
243 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
245 DaclSize);
246 if (Dacl == NULL)
247 {
248 ERR("CreateDefaultProcessSecurityCommon(): Failed to allocate buffer for DACL\n");
249 Success = FALSE;
250 goto Quit;
251 }
252
253 /* Initialize the DACL */
255 {
256 ERR("CreateDefaultProcessSecurityCommon(): Failed to initialize DACL (error %lu)\n", GetLastError());
257 Success = FALSE;
258 goto Quit;
259 }
260
261 /* Give full powers to the owner */
265 OwnerSid))
266 {
267 ERR("CreateDefaultProcessSecurityCommon(): Failed to set up ACE for owner (error %lu)\n", GetLastError());
268 Success = FALSE;
269 goto Quit;
270 }
271
272 /* Give full powers to SYSTEM as well */
276 SystemSid))
277 {
278 ERR("CreateDefaultProcessSecurityCommon(): Failed to set up ACE for SYSTEM (error %lu)\n", GetLastError());
279 Success = FALSE;
280 goto Quit;
281 }
282
283 /* Initialize the descriptor in absolute format */
285 {
286 ERR("CreateDefaultProcessSecurityCommon(): Failed to initialize absolute security descriptor (error %lu)\n", GetLastError());
287 Success = FALSE;
288 goto Quit;
289 }
290
291 /* Set the DACL to the security descriptor */
292 if (!SetSecurityDescriptorDacl(&AbsoluteSd, TRUE, Dacl, FALSE))
293 {
294 ERR("CreateDefaultProcessSecurityCommon(): Failed to set up DACL to absolute security descriptor (error %lu)\n", GetLastError());
295 Success = FALSE;
296 goto Quit;
297 }
298
299 /* Set the owner for this descriptor */
300 if (!SetSecurityDescriptorOwner(&AbsoluteSd, OwnerSid, FALSE))
301 {
302 ERR("CreateDefaultProcessSecurityCommon(): Failed to set up owner to absolute security descriptor (error %lu)\n", GetLastError());
303 Success = FALSE;
304 goto Quit;
305 }
306
307 /* Set the primary group for this descriptor */
308 if (!SetSecurityDescriptorGroup(&AbsoluteSd, PrimaryGroupSid, FALSE))
309 {
310 ERR("CreateDefaultProcessSecurityCommon(): Failed to set up group to absolute security descriptor (error %lu)\n", GetLastError());
311 Success = FALSE;
312 goto Quit;
313 }
314
315 /*
316 * Determine the exact size space of the absolute
317 * descriptor so that we can allocate a buffer
318 * to hold the descriptor in a converted self
319 * relative format.
320 */
321 if (MakeSelfRelativeSD(&AbsoluteSd, NULL, &RelativeSDSize) ||
323 {
324 ERR("CreateDefaultProcessSecurityCommon(): error %lu, expected ERROR_INSUFFICIENT_BUFFER\n", GetLastError());
325 Success = FALSE;
326 goto Quit;
327 }
328
329 /* Allocate the buffer */
330 RelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
332 RelativeSDSize);
333 if (RelativeSD == NULL)
334 {
335 ERR("CreateDefaultProcessSecurityCommon(): Failed to allocate relative SD\n");
336 Success = FALSE;
337 goto Quit;
338 }
339
340 /* Convert to a self relative format now */
341 if (!MakeSelfRelativeSD(&AbsoluteSd, RelativeSD, &RelativeSDSize))
342 {
343 ERR("CreateDefaultProcessSecurityCommon(): Failed to allocate relative SD (error %lu)\n", GetLastError());
344 RtlFreeHeap(RtlGetProcessHeap(), 0, RelativeSD);
345 Success = FALSE;
346 goto Quit;
347 }
348
349 /* Success, give the descriptor to the caller */
350 *Sd = RelativeSD;
351 Success = TRUE;
352
353Quit:
354 /* Free all the stuff we have allocated */
355 if (OwnerOfToken != NULL)
356 RtlFreeHeap(RtlGetProcessHeap(), 0, OwnerOfToken);
357
358 if (PrimaryGroupOfToken != NULL)
359 RtlFreeHeap(RtlGetProcessHeap(), 0, PrimaryGroupOfToken);
360
361 if (SystemSid != NULL)
362 FreeSid(SystemSid);
363
364 if (Dacl != NULL)
365 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
366
367 return Success;
368}
369
370
396static
397BOOL
400 _In_ HANDLE ThreadHandle,
401 _In_ PSECURITY_DESCRIPTOR ProcessSecurity,
402 _In_ PSECURITY_DESCRIPTOR ThreadSecurity)
403{
404 /* Set new security data for the process */
407 ProcessSecurity))
408 {
409 ERR("InsertProcessSecurityCommon(): Failed to set security for process (error %lu)\n", GetLastError());
410 return FALSE;
411 }
412
413 /* Set new security data for the thread */
414 if (!SetKernelObjectSecurity(ThreadHandle,
416 ThreadSecurity))
417 {
418 ERR("InsertProcessSecurityCommon(): Failed to set security for thread (error %lu)\n", GetLastError());
419 return FALSE;
420 }
421
422 return TRUE;
423}
424
425
474static
477 _In_ BOOL ImpersonateAsSelf,
479 _In_ HANDLE ThreadHandle,
480 _In_ HANDLE DuplicatedTokenHandle)
481{
483 PROCESS_ACCESS_TOKEN AccessToken;
484 BOOLEAN PrivilegeSet;
485 BOOLEAN HavePrivilege;
486
487 /*
488 * Assume the SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
489 * privilege hasn't been set.
490 */
491 PrivilegeSet = FALSE;
492
493 /*
494 * The caller asked that we must impersonate as
495 * ourselves, that is, we'll be going to impersonate
496 * the security context of the calling process. If
497 * self impersonation fails then the caller has
498 * to do a "rinse and repeat" approach.
499 */
500 if (ImpersonateAsSelf)
501 {
503 if (!NT_SUCCESS(Status))
504 {
505 ERR("RtlImpersonateSelf(SecurityImpersonation) failed, Status 0x%08x\n", Status);
506 return Status;
507 }
508 }
509
510 /*
511 * Attempt to acquire the process primary token assignment privilege
512 * in case we actually need it.
513 * The call will either succeed or fail when the caller has (or has not)
514 * enough rights.
515 * The last situation may not be dramatic for us. Indeed it may happen
516 * that the user-provided token is a restricted version of the caller's
517 * primary token (aka. a "child" token), or both tokens inherit (i.e. are
518 * children, and are together "siblings") from a common parent token.
519 * In this case the NT kernel allows us to assign the token to the child
520 * process without the need for the assignment privilege, which is fine.
521 * On the contrary, if the user-provided token is completely arbitrary,
522 * then the NT kernel will enforce the presence of the assignment privilege:
523 * because we failed (by assumption) to assign the privilege, the process
524 * token assignment will fail as required. It is then the job of the
525 * caller to manually acquire the necessary privileges.
526 */
528 TRUE, TRUE, &PrivilegeSet);
529 HavePrivilege = NT_SUCCESS(Status);
530 if (!HavePrivilege)
531 {
532 ERR("RtlAdjustPrivilege(SE_ASSIGNPRIMARYTOKEN_PRIVILEGE) failed, Status 0x%08lx, "
533 "attempting to continue without it...\n", Status);
534 }
535
536 /*
537 * Assign the duplicated token and thread
538 * handle to the structure so that we'll
539 * use it to assign the primary token
540 * to process.
541 */
542 AccessToken.Token = DuplicatedTokenHandle;
543 AccessToken.Thread = ThreadHandle;
544
545 /* Set the new process token */
548 (PVOID)&AccessToken,
549 sizeof(AccessToken));
550
551 /* Restore the privilege */
552 if (HavePrivilege)
553 {
555 PrivilegeSet, TRUE, &PrivilegeSet);
556 }
557
558 /*
559 * Check again if the caller wanted to impersonate
560 * as self. If that is the case we must revert this
561 * impersonation back.
562 */
563 if (ImpersonateAsSelf)
564 {
565 RevertToSelf();
566 }
567
568 /*
569 * Finally, check if we actually succeeded on assigning
570 * a primary token to the process. If we failed, oh well,
571 * asta la vista baby e arrivederci. The caller has to do
572 * a rinse and repeat approach.
573 */
574 if (!NT_SUCCESS(Status))
575 {
576 ERR("Failed to assign primary token to the process (Status 0x%08lx)\n", Status);
577 return Status;
578 }
579
580 return STATUS_SUCCESS;
581}
582
637static
638BOOL
640 _In_opt_ HANDLE hToken,
641 _In_ DWORD dwCreationFlags,
642 _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
643 _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
644 _Inout_ LPPROCESS_INFORMATION lpProcessInformation)
645{
646 NTSTATUS Status = STATUS_SUCCESS, StatusOnExit;
651 PSECURITY_DESCRIPTOR DefaultSd = NULL, ProcessSd, ThreadSd;
652 HANDLE hTokenDup = NULL;
653 HANDLE OriginalImpersonationToken = NULL;
654 HANDLE NullToken = NULL;
655
656 if (hToken != NULL)
657 {
658 /* Check whether the user-provided token is a primary token */
659 // GetTokenInformation();
661 TokenType,
662 &Type,
663 sizeof(Type),
664 &ReturnLength);
665 if (!NT_SUCCESS(Status))
666 {
667 ERR("NtQueryInformationToken() failed, Status 0x%08x\n", Status);
668 Success = FALSE;
669 goto Quit;
670 }
671
672 if (Type != TokenPrimary)
673 {
674 ERR("Wrong token type for token 0x%p, expected TokenPrimary, got %ld\n", hToken, Type);
676 Success = FALSE;
677 goto Quit;
678 }
679
680 /*
681 * Open the original token of the calling thread
682 * and halt the impersonation for the moment
683 * being. The opened thread token will be cached
684 * so that we will restore it back when we're done.
685 */
688 TRUE,
689 &OriginalImpersonationToken);
690 if (!NT_SUCCESS(Status))
691 {
692 /* We failed? Does this thread have a token at least? */
693 OriginalImpersonationToken = NULL;
694 if (Status != STATUS_NO_TOKEN)
695 {
696 /*
697 * OK so this thread has a token but we
698 * could not open it for whatever reason.
699 * Bail out then.
700 */
701 ERR("Failed to open thread token with 0x%08lx\n", Status);
702 Success = FALSE;
703 goto Quit;
704 }
705 }
706 else
707 {
708 /* We succeeded, stop the impersonation for now */
711 &NullToken,
712 sizeof(NullToken));
713 if (!NT_SUCCESS(Status))
714 {
715 ERR("Failed to stop impersonation with 0x%08lx\n", Status);
716 Success = FALSE;
717 goto Quit;
718 }
719 }
720
721 /*
722 * Create a security descriptor that will be common for the
723 * newly created process on behalf of the context user.
724 */
725 if (!CreateDefaultProcessSecurityCommon(hToken, &DefaultSd))
726 {
727 ERR("Failed to create common security descriptor for the token for new process\n");
728 Success = FALSE;
729 goto Quit;
730 }
731
732 /*
733 * Duplicate the token for this new process. This token
734 * object will get a default security descriptor that we
735 * have created ourselves in ADVAPI32.
736 */
738 NULL,
739 0,
740 NULL,
741 DefaultSd);
742 Status = NtDuplicateToken(hToken,
743 0,
745 FALSE,
747 &hTokenDup);
748 if (!NT_SUCCESS(Status))
749 {
750 ERR("NtDuplicateToken() failed, Status 0x%08x\n", Status);
751 Success = FALSE;
752 goto Quit;
753 }
754
755 /*
756 * Now it's time to set the primary token into
757 * the process. On the first try, do it by
758 * impersonating the security context of the
759 * calling process (impersonate as self).
760 */
762 lpProcessInformation->hProcess,
763 lpProcessInformation->hThread,
764 hTokenDup);
765 if (!NT_SUCCESS(Status))
766 {
767 /*
768 * OK, we failed. Our second (and last try) is to not
769 * impersonate as self but instead we will try by setting
770 * the original impersonation (thread) token and set the
771 * primary token to the process through this way. This is
772 * what we call -- the "rinse and repeat" approach.
773 */
776 &OriginalImpersonationToken,
777 sizeof(OriginalImpersonationToken));
778 if (!NT_SUCCESS(Status))
779 {
780 ERR("Failed to restore impersonation token for setting process token, Status 0x%08lx\n", Status);
781 NtClose(hTokenDup);
782 Success = FALSE;
783 goto Quit;
784 }
785
786 /* Retry again */
788 lpProcessInformation->hProcess,
789 lpProcessInformation->hThread,
790 hTokenDup);
791 if (!NT_SUCCESS(Status))
792 {
793 /* Even the second try failed, bail out... */
794 ERR("Failed to insert the primary token into process, Status 0x%08lx\n", Status);
795 NtClose(hTokenDup);
796 Success = FALSE;
797 goto Quit;
798 }
799
800 /* All good, now stop impersonation */
803 &NullToken,
804 sizeof(NullToken));
805 if (!NT_SUCCESS(Status))
806 {
807 ERR("Failed to unset impersonationg token after setting process token, Status 0x%08lx\n", Status);
808 NtClose(hTokenDup);
809 Success = FALSE;
810 goto Quit;
811 }
812 }
813
814 /*
815 * FIXME: As we have successfully set up a primary token to
816 * the newly created process, we must set up as well a definite
817 * limit of quota charges for this process on the context of
818 * this user.
819 */
820
821 /*
822 * As we have successfully set the token into the process now
823 * it is time that we set up new security information for both
824 * the process and its thread as well, that is, these securable
825 * objects will grant a security descriptor. The security descriptors
826 * provided by the caller take precedence so we should use theirs
827 * if possible in this case. Otherwise both the process and thread
828 * will receive the default security descriptor that we have created
829 * ourselves.
830 *
831 * BEAR IN MIND!!! AT THE MOMENT when these securable objects get new
832 * security information, the process (and the thread) can't be opened
833 * by the creator anymore as the new owner will take in charge of
834 * the process and future objects that are going to be created within
835 * the process. For further information in regard of the documentation
836 * see https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessasuserw.
837 */
838 if (lpProcessAttributes && lpProcessAttributes->lpSecurityDescriptor)
839 {
840 ProcessSd = lpProcessAttributes->lpSecurityDescriptor;
841 }
842 else
843 {
844 ProcessSd = DefaultSd;
845 }
846
847 if (lpThreadAttributes && lpThreadAttributes->lpSecurityDescriptor)
848 {
849 ThreadSd = lpThreadAttributes->lpSecurityDescriptor;
850 }
851 else
852 {
853 ThreadSd = DefaultSd;
854 }
855
856 /* Set new security info to the process and thread now */
857 if (!InsertProcessSecurityCommon(lpProcessInformation->hProcess,
858 lpProcessInformation->hThread,
859 ProcessSd,
860 ThreadSd))
861 {
862 ERR("Failed to set new security information for process and thread\n");
863 NtClose(hTokenDup);
864 Success = FALSE;
865 goto Quit;
866 }
867
868 /* Close the duplicated token */
869 NtClose(hTokenDup);
870 Success = TRUE;
871 }
872
873 /*
874 * If the caller did not supply a token then just declare
875 * ourselves as job done. The newly created process will use
876 * the default security context at this point anyway.
877 */
878 TRACE("No token supplied, the process will use default security context\n");
879 Success = TRUE;
880
881Quit:
882 /*
883 * If we successfully opened the thread token before
884 * and stopped the impersonation then we have to assign
885 * its original token back and close that token we have
886 * referenced it.
887 */
888 if (OriginalImpersonationToken != NULL)
889 {
892 &OriginalImpersonationToken,
893 sizeof(OriginalImpersonationToken));
894
895 /*
896 * We really must assert ourselves that we successfully
897 * set the original token back, otherwise if we fail
898 * then something is seriously going wrong....
899 * The status code is cached in a separate status
900 * variable because we would not want to tamper
901 * with the original status code that could have been
902 * returned by someone else above in this function code.
903 */
904 ASSERT(NT_SUCCESS(StatusOnExit));
905
906 /* De-reference it */
907 NtClose(OriginalImpersonationToken);
908 }
909
910 /* Terminate the process and set the last error status */
911 if (!NT_SUCCESS(Status))
912 {
913 TerminateProcess(lpProcessInformation->hProcess, Status);
915 }
916
917 /* Resume the main thread */
918 if (!(dwCreationFlags & CREATE_SUSPENDED))
919 {
920 ResumeThread(lpProcessInformation->hThread);
921 }
922
923 /* Free the security descriptor from memory */
924 if (DefaultSd != NULL)
925 {
926 RtlFreeHeap(RtlGetProcessHeap(), 0, DefaultSd);
927 }
928
929 return Success;
930}
931
932
933/*
934 * @implemented
935 */
936BOOL
937WINAPI
940 _In_opt_ HANDLE hToken,
941 _In_opt_ LPCSTR lpApplicationName,
942 _Inout_opt_ LPSTR lpCommandLine,
943 _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
944 _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
945 _In_ BOOL bInheritHandles,
946 _In_ DWORD dwCreationFlags,
947 _In_opt_ LPVOID lpEnvironment,
948 _In_opt_ LPCSTR lpCurrentDirectory,
949 _In_ LPSTARTUPINFOA lpStartupInfo,
950 _Out_ LPPROCESS_INFORMATION lpProcessInformation)
951{
952 TRACE("%p %s %s %p %p %d 0x%08x %p %s %p %p\n", hToken, debugstr_a(lpApplicationName),
953 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
954 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
955
956 /* Create the process with a suspended main thread */
957 if (!CreateProcessA(lpApplicationName,
958 lpCommandLine,
959 lpProcessAttributes,
960 lpThreadAttributes,
961 bInheritHandles,
962 dwCreationFlags | CREATE_SUSPENDED,
963 lpEnvironment,
964 lpCurrentDirectory,
965 lpStartupInfo,
966 lpProcessInformation))
967 {
968 ERR("CreateProcessA failed, last error: %d\n", GetLastError());
969 return FALSE;
970 }
971
972 /* Call the helper function */
973 return CreateProcessAsUserCommon(hToken,
974 dwCreationFlags,
975 lpProcessAttributes,
976 lpThreadAttributes,
977 lpProcessInformation);
978}
979
980
981/*
982 * @implemented
983 */
984BOOL
985WINAPI
988 _In_opt_ HANDLE hToken,
989 _In_opt_ LPCWSTR lpApplicationName,
990 _Inout_opt_ LPWSTR lpCommandLine,
991 _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
992 _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
993 _In_ BOOL bInheritHandles,
994 _In_ DWORD dwCreationFlags,
995 _In_opt_ LPVOID lpEnvironment,
996 _In_opt_ LPCWSTR lpCurrentDirectory,
997 _In_ LPSTARTUPINFOW lpStartupInfo,
998 _Out_ LPPROCESS_INFORMATION lpProcessInformation)
999{
1000 TRACE("%p %s %s %p %p %d 0x%08x %p %s %p %p\n", hToken, debugstr_w(lpApplicationName),
1001 debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
1002 dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
1003
1004 /* Create the process with a suspended main thread */
1005 if (!CreateProcessW(lpApplicationName,
1006 lpCommandLine,
1007 lpProcessAttributes,
1008 lpThreadAttributes,
1009 bInheritHandles,
1010 dwCreationFlags | CREATE_SUSPENDED,
1011 lpEnvironment,
1012 lpCurrentDirectory,
1013 lpStartupInfo,
1014 lpProcessInformation))
1015 {
1016 ERR("CreateProcessW failed, last error: %d\n", GetLastError());
1017 return FALSE;
1018 }
1019
1020 /* Call the helper function */
1021 return CreateProcessAsUserCommon(hToken,
1022 dwCreationFlags,
1023 lpProcessAttributes,
1024 lpThreadAttributes,
1025 lpProcessInformation);
1026}
1027
1028
1029/*
1030 * @implemented
1031 */
1032BOOL
1033WINAPI
1035 _In_ LPSTR lpszUsername,
1041{
1042 return LogonUserExA(lpszUsername,
1043 lpszDomain,
1047 phToken,
1048 NULL,
1049 NULL,
1050 NULL,
1051 NULL);
1052}
1053
1054
1055/*
1056 * @implemented
1057 */
1058BOOL
1059WINAPI
1061 _In_ LPSTR lpszUsername,
1071{
1072 UNICODE_STRING UserName;
1073 UNICODE_STRING Domain;
1075 BOOL ret = FALSE;
1076
1077 UserName.Buffer = NULL;
1078 Domain.Buffer = NULL;
1079 Password.Buffer = NULL;
1080
1081 if (!RtlCreateUnicodeStringFromAsciiz(&UserName, lpszUsername))
1082 {
1084 goto UsernameDone;
1085 }
1086
1088 {
1090 goto DomainDone;
1091 }
1092
1094 {
1096 goto PasswordDone;
1097 }
1098
1099 ret = LogonUserExW(UserName.Buffer,
1100 Domain.Buffer,
1101 Password.Buffer,
1104 phToken,
1105 ppLogonSid,
1108 pQuotaLimits);
1109
1110 if (Password.Buffer != NULL)
1112
1113PasswordDone:
1114 if (Domain.Buffer != NULL)
1115 RtlFreeUnicodeString(&Domain);
1116
1117DomainDone:
1118 if (UserName.Buffer != NULL)
1119 RtlFreeUnicodeString(&UserName);
1120
1121UsernameDone:
1122 return ret;
1123}
1124
1125
1126/*
1127 * @implemented
1128 */
1129BOOL
1130WINAPI
1132 _In_ LPWSTR lpszUsername,
1138{
1139 return LogonUserExW(lpszUsername,
1140 lpszDomain,
1144 phToken,
1145 NULL,
1146 NULL,
1147 NULL,
1148 NULL);
1149}
1150
1151
1152/*
1153 * @implemented
1154 */
1155BOOL
1156WINAPI
1158 _In_ LPWSTR lpszUsername,
1168{
1171 PSID LogonSid = NULL;
1172 PSID LocalSid = NULL;
1174 UNICODE_STRING DomainName;
1175 UNICODE_STRING UserName;
1178 ULONG AuthInfoLength;
1179 ULONG_PTR Ptr;
1184 LUID Luid = {0, 0};
1185 LUID LogonId = {0, 0};
1187 QUOTA_LIMITS QuotaLimits;
1191
1192 if ((ppProfileBuffer != NULL && pdwProfileLength == NULL) ||
1194 {
1196 return FALSE;
1197 }
1198
1200 {
1202 *pdwProfileLength = 0;
1203 }
1204
1205 if (phToken != NULL)
1206 *phToken = NULL;
1207
1208 switch (dwLogonType)
1209 {
1212 break;
1213
1216 break;
1217
1219 LogonType = Batch;
1220 break;
1221
1224 break;
1225
1226 default:
1227 ERR("Invalid logon type: %ul\n", dwLogonType);
1229 goto done;
1230 }
1231
1232 if (LsaHandle == NULL)
1233 {
1235 if (!NT_SUCCESS(Status))
1236 goto done;
1237 }
1238
1240 "Advapi32 Logon");
1241
1242 RtlInitUnicodeString(&DomainName,
1243 lpszDomain);
1244
1245 RtlInitUnicodeString(&UserName,
1246 lpszUsername);
1247
1249 lpszPassword);
1250
1251 AuthInfoLength = sizeof(MSV1_0_INTERACTIVE_LOGON)+
1252 DomainName.MaximumLength +
1253 UserName.MaximumLength +
1254 Password.MaximumLength;
1255
1256 AuthInfo = RtlAllocateHeap(RtlGetProcessHeap(),
1258 AuthInfoLength);
1259 if (AuthInfo == NULL)
1260 {
1262 goto done;
1263 }
1264
1266
1267 Ptr = (ULONG_PTR)AuthInfo + sizeof(MSV1_0_INTERACTIVE_LOGON);
1268
1269 AuthInfo->LogonDomainName.Length = DomainName.Length;
1270 AuthInfo->LogonDomainName.MaximumLength = DomainName.MaximumLength;
1271 AuthInfo->LogonDomainName.Buffer = (DomainName.Buffer == NULL) ? NULL : (PWCHAR)Ptr;
1272 if (DomainName.MaximumLength > 0)
1273 {
1275 DomainName.Buffer,
1276 DomainName.MaximumLength);
1277
1278 Ptr += DomainName.MaximumLength;
1279 }
1280
1281 AuthInfo->UserName.Length = UserName.Length;
1282 AuthInfo->UserName.MaximumLength = UserName.MaximumLength;
1283 AuthInfo->UserName.Buffer = (PWCHAR)Ptr;
1284 if (UserName.MaximumLength > 0)
1285 RtlCopyMemory(AuthInfo->UserName.Buffer,
1286 UserName.Buffer,
1287 UserName.MaximumLength);
1288
1289 Ptr += UserName.MaximumLength;
1290
1291 AuthInfo->Password.Length = Password.Length;
1292 AuthInfo->Password.MaximumLength = Password.MaximumLength;
1293 AuthInfo->Password.Buffer = (PWCHAR)Ptr;
1294 if (Password.MaximumLength > 0)
1295 RtlCopyMemory(AuthInfo->Password.Buffer,
1296 Password.Buffer,
1297 Password.MaximumLength);
1298
1299 /* Create the Logon SID */
1304 LogonId.HighPart,
1305 LogonId.LowPart,
1311 &LogonSid);
1312 if (!NT_SUCCESS(Status))
1313 goto done;
1314
1315 /* Create the Local SID */
1316 Status = RtlAllocateAndInitializeSid(&LocalAuthority,
1317 1,
1326 &LocalSid);
1327 if (!NT_SUCCESS(Status))
1328 goto done;
1329
1330 /* Allocate and set the token groups */
1331 TokenGroups = RtlAllocateHeap(RtlGetProcessHeap(),
1333 sizeof(TOKEN_GROUPS) + ((2 - ANYSIZE_ARRAY) * sizeof(SID_AND_ATTRIBUTES)));
1334 if (TokenGroups == NULL)
1335 {
1337 goto done;
1338 }
1339
1340 TokenGroups->GroupCount = 2;
1341 TokenGroups->Groups[0].Sid = LogonSid;
1342 TokenGroups->Groups[0].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
1344 TokenGroups->Groups[1].Sid = LocalSid;
1345 TokenGroups->Groups[1].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
1347
1348 /* Set the token source */
1349 RtlCopyMemory(TokenSource.SourceName,
1351 sizeof(TokenSource.SourceName));
1352 AllocateLocallyUniqueId(&TokenSource.SourceIdentifier);
1353
1355 &OriginName,
1356 LogonType,
1358 (PVOID)AuthInfo,
1359 AuthInfoLength,
1361 &TokenSource,
1364 &Luid,
1365 &TokenHandle,
1366 &QuotaLimits,
1367 &SubStatus);
1368 if (!NT_SUCCESS(Status))
1369 {
1370 ERR("LsaLogonUser failed (Status 0x%08lx)\n", Status);
1371 goto done;
1372 }
1373
1374 if (ProfileBuffer != NULL)
1375 {
1376 TRACE("ProfileBuffer: %p\n", ProfileBuffer);
1377 TRACE("MessageType: %u\n", ProfileBuffer->MessageType);
1378
1379 TRACE("FullName: %p\n", ProfileBuffer->FullName.Buffer);
1380 TRACE("FullName: %S\n", ProfileBuffer->FullName.Buffer);
1381
1382 TRACE("LogonServer: %p\n", ProfileBuffer->LogonServer.Buffer);
1383 TRACE("LogonServer: %S\n", ProfileBuffer->LogonServer.Buffer);
1384 }
1385
1386 TRACE("Luid: 0x%08lx%08lx\n", Luid.HighPart, Luid.LowPart);
1387
1388 if (TokenHandle != NULL)
1389 {
1390 TRACE("TokenHandle: %p\n", TokenHandle);
1391 }
1392
1393 if (phToken != NULL)
1395
1396 /* FIXME: return ppLogonSid and pQuotaLimits */
1397
1398done:
1399 if (ProfileBuffer != NULL)
1401
1402 if (!NT_SUCCESS(Status))
1403 {
1404 if (TokenHandle != NULL)
1406 }
1407
1408 if (TokenGroups != NULL)
1409 RtlFreeHeap(RtlGetProcessHeap(), 0, TokenGroups);
1410
1411 if (LocalSid != NULL)
1413
1414 if (LogonSid != NULL)
1415 RtlFreeSid(LogonSid);
1416
1417 if (AuthInfo != NULL)
1418 RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo);
1419
1420 if (!NT_SUCCESS(Status))
1421 {
1423 return FALSE;
1424 }
1425
1426 return TRUE;
1427}
1428
1429/* EOF */
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
unsigned char BOOLEAN
Type
Definition: Type.h:7
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
WCHAR SourceName[256]
Definition: arping.c:28
TOKEN_TYPE
Definition: asmpp.cpp:29
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
PSID LocalSid
Definition: globals.c:15
#define ERR(fmt,...)
Definition: precomp.h:57
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:40
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
SIZE_T LPSTARTUPINFOW
Definition: cordebug.idl:85
SIZE_T LPPROCESS_INFORMATION
Definition: cordebug.idl:86
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
@ Network
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static NTSTATUS InsertTokenToProcessCommon(_In_ BOOL ImpersonateAsSelf, _In_ HANDLE ProcessHandle, _In_ HANDLE ThreadHandle, _In_ HANDLE DuplicatedTokenHandle)
Sets a primary token to the newly created process. The primary token that gets assigned to is a token...
Definition: logon.c:476
BOOL WINAPI LogonUserW(_In_ LPWSTR lpszUsername, _In_opt_ LPWSTR lpszDomain, _In_opt_ LPWSTR lpszPassword, _In_ DWORD dwLogonType, _In_ DWORD dwLogonProvider, _Out_opt_ PHANDLE phToken)
Definition: logon.c:1131
HANDLE LsaHandle
Definition: logon.c:17
BOOL WINAPI LogonUserExW(_In_ LPWSTR lpszUsername, _In_opt_ LPWSTR lpszDomain, _In_opt_ LPWSTR lpszPassword, _In_ DWORD dwLogonType, _In_ DWORD dwLogonProvider, _Out_opt_ PHANDLE phToken, _Out_opt_ PSID *ppLogonSid, _Out_opt_ PVOID *ppProfileBuffer, _Out_opt_ LPDWORD pdwProfileLength, _Out_opt_ PQUOTA_LIMITS pQuotaLimits)
Definition: logon.c:1157
static const CHAR AdvapiTokenSourceName[]
Definition: logon.c:14
BOOL WINAPI LogonUserExA(_In_ LPSTR lpszUsername, _In_opt_ LPSTR lpszDomain, _In_opt_ LPSTR lpszPassword, _In_ DWORD dwLogonType, _In_ DWORD dwLogonProvider, _Out_opt_ PHANDLE phToken, _Out_opt_ PSID *ppLogonSid, _Out_opt_ PVOID *ppProfileBuffer, _Out_opt_ LPDWORD pdwProfileLength, _Out_opt_ PQUOTA_LIMITS pQuotaLimits)
Definition: logon.c:1060
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessAsUserA(_In_opt_ HANDLE hToken, _In_opt_ LPCSTR lpApplicationName, _Inout_opt_ LPSTR lpCommandLine, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, _In_opt_ LPCSTR lpCurrentDirectory, _In_ LPSTARTUPINFOA lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation)
Definition: logon.c:939
static BOOL CreateDefaultProcessSecurityCommon(_In_ HANDLE TokenHandle, _Out_ PSECURITY_DESCRIPTOR *Sd)
Creates a default security descriptor that is going to be used by both the newly created process and ...
Definition: logon.c:129
NTSTATUS CloseLogonLsaHandle(VOID)
Definition: logon.c:75
BOOL WINAPI LogonUserA(_In_ LPSTR lpszUsername, _In_opt_ LPSTR lpszDomain, _In_opt_ LPSTR lpszPassword, _In_ DWORD dwLogonType, _In_ DWORD dwLogonProvider, _Out_opt_ PHANDLE phToken)
Definition: logon.c:1034
static BOOL CreateProcessAsUserCommon(_In_opt_ HANDLE hToken, _In_ DWORD dwCreationFlags, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _Inout_ LPPROCESS_INFORMATION lpProcessInformation)
Internal function that serves as a helper for CreateProcessAsUserW/A routines on creating a process w...
Definition: logon.c:639
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessAsUserW(_In_opt_ HANDLE hToken, _In_opt_ LPCWSTR lpApplicationName, _Inout_opt_ LPWSTR lpCommandLine, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, _In_opt_ LPCWSTR lpCurrentDirectory, _In_ LPSTARTUPINFOW lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation)
Definition: logon.c:987
static BOOL InsertProcessSecurityCommon(_In_ HANDLE ProcessHandle, _In_ HANDLE ThreadHandle, _In_ PSECURITY_DESCRIPTOR ProcessSecurity, _In_ PSECURITY_DESCRIPTOR ThreadSecurity)
Changes the object security information of a process and thread that belongs to the process with new ...
Definition: logon.c:398
static NTSTATUS OpenLogonLsaHandle(VOID)
Definition: logon.c:24
ULONG AuthenticationPackage
Definition: logon.c:18
BOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid)
Definition: security.c:674
BOOL WINAPI AllocateLocallyUniqueId(PLUID Luid)
Definition: security.c:1218
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:1006
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:929
BOOL WINAPI AddAccessAllowedAce(PACL pAcl, DWORD dwAceRevision, DWORD AccessMask, PSID pSid)
Definition: security.c:1039
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:919
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:698
BOOL WINAPI SetKernelObjectSecurity(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)
Definition: security.c:1928
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
@ ThreadImpersonationToken
Definition: compat.h:940
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4600
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4749
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1534
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:567
BOOL WINAPI RevertToSelf(void)
Definition: security.c:855
return ret
Definition: mutex.c:146
#define ULONG_PTR
Definition: config.h:101
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
@ ProcessAccessToken
Definition: winternl.h:1891
#define NtCurrentThread()
Definition: winternl.h:5364
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define C_ASSERT(e)
Definition: intsafe.h:73
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
@ SecurityImpersonation
Definition: lsa.idl:57
#define ASSERT(a)
Definition: mode.c:44
@ TokenPrimary
Definition: imports.h:273
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
Definition: security.c:657
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
struct _ACL ACL
struct _ACCESS_ALLOWED_ACE ACCESS_ALLOWED_ACE
static SID_IDENTIFIER_AUTHORITY SystemAuthority
Definition: msgina.c:38
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:727
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1625
NTSYSAPI NTSTATUS NTAPI RtlImpersonateSelf(IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
Definition: priv.c:45
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID _Inout_ PULONG _Out_writes_bytes_to_opt_ PrimaryGroupSize PSID _Inout_ PULONG PrimaryGroupSize
Definition: rtlfuncs.h:1633
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1626
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN _In_ TOKEN_TYPE TokenType
Definition: sefuncs.h:411
#define SE_GROUP_LOGON_ID
Definition: setypes.h:98
#define SE_GROUP_MANDATORY
Definition: setypes.h:90
#define SE_GROUP_ENABLED_BY_DEFAULT
Definition: setypes.h:91
#define SE_GROUP_ENABLED
Definition: setypes.h:92
#define _Out_opt_
Definition: no_sal2.h:214
#define _Inout_
Definition: no_sal2.h:162
#define _Inout_opt_
Definition: no_sal2.h:216
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GENERIC_ALL
Definition: nt_native.h:92
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE LogonType
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS _Out_ PNTSTATUS SubStatus
_IRQL_requires_same_ _Out_ PHANDLE _Out_ PLSA_OPERATIONAL_MODE SecurityMode
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID * ProfileBuffer
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG ProfileBufferLength
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
_IRQL_requires_same_ _In_ PLSA_STRING OriginName
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
NTSTATUS NTAPI NtSetInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _In_reads_bytes_(ProcessInformationLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength)
Definition: query.c:1389
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2268
NTSTATUS NTAPI NtOpenThreadToken(_In_ HANDLE ThreadHandle, _In_ ACCESS_MASK DesiredAccess, _In_ BOOLEAN OpenAsSelf, _Out_ PHANDLE TokenHandle)
Opens a token that is tied to a thread handle.
Definition: token.c:2475
NTSTATUS NTAPI LsaLogonUser(HANDLE, PLSA_STRING, SECURITY_LOGON_TYPE, ULONG, PVOID, ULONG, PTOKEN_GROUPS, PTOKEN_SOURCE, PVOID *, PULONG, PLUID, PHANDLE, PQUOTA_LIMITS, PNTSTATUS)
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
@ Interactive
Definition: ntsecapi.h:289
@ Service
Definition: ntsecapi.h:292
@ Batch
Definition: ntsecapi.h:291
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
enum _SECURITY_LOGON_TYPE SECURITY_LOGON_TYPE
ULONG LSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
NTSTATUS NTAPI LsaDeregisterLogonProcess(HANDLE)
NTSTATUS NTAPI LsaFreeReturnBuffer(PVOID)
struct _MSV1_0_INTERACTIVE_LOGON MSV1_0_INTERACTIVE_LOGON
NTSTATUS NTAPI LsaRegisterLogonProcess(PLSA_STRING, PHANDLE, PLSA_OPERATIONAL_MODE)
@ MsV1_0InteractiveLogon
Definition: ntsecapi.h:199
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_NO_TOKEN
Definition: ntstatus.h:454
#define STATUS_BAD_TOKEN_TYPE
Definition: ntstatus.h:498
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
BOOL WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
Definition: sec.c:312
BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, LPDWORD lpdwBufferLength)
Definition: sec.c:214
BOOL WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pGroup, BOOL bGroupDefaulted)
Definition: sec.c:288
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define TRACE(s)
Definition: solgame.cpp:4
PCHAR Buffer
Definition: ntsecapi.h:174
LONG HighPart
DWORD LowPart
UNICODE_STRING Password
Definition: ntsecapi.h:437
UNICODE_STRING UserName
Definition: ntsecapi.h:436
MSV1_0_LOGON_SUBMIT_TYPE MessageType
Definition: ntsecapi.h:434
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:435
PSID Owner
Definition: setypes.h:1040
USHORT MaximumLength
Definition: env_spec_w32.h:370
@ Password
Definition: telnetd.h:67
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Queries a specific type of information in regard of an access token based upon the information class....
Definition: tokencls.c:473
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtDuplicateToken(_In_ HANDLE ExistingTokenHandle, _In_ ACCESS_MASK DesiredAccess, _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ BOOLEAN EffectiveOnly, _In_ TOKEN_TYPE TokenType, _Out_ PHANDLE NewTokenHandle)
Duplicates a token.
Definition: tokenlif.c:1871
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
uint32_t * LPDWORD
Definition: typedefs.h:59
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD dwLogonType
Definition: winbase.h:2467
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE phToken
Definition: winbase.h:2469
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE _Out_opt_ PSID _Out_opt_ PVOID * ppProfileBuffer
Definition: winbase.h:2471
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE _Out_opt_ PSID * ppLogonSid
Definition: winbase.h:2470
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE _Out_opt_ PSID _Out_opt_ PVOID _Out_opt_ LPDWORD pdwProfileLength
Definition: winbase.h:2472
#define LOGON32_LOGON_NETWORK
Definition: winbase.h:369
#define LOGON32_LOGON_BATCH
Definition: winbase.h:370
#define CREATE_SUSPENDED
Definition: winbase.h:182
#define LOGON32_LOGON_INTERACTIVE
Definition: winbase.h:368
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE _Out_opt_ PSID _Out_opt_ PVOID _Out_opt_ LPDWORD _Out_opt_ PQUOTA_LIMITS pQuotaLimits
Definition: winbase.h:2473
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD dwLogonProvider
Definition: winbase.h:2468
#define LOGON32_LOGON_SERVICE
Definition: winbase.h:371
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2466
_In_opt_ LPSTR lpszDomain
Definition: winbase.h:2465
#define WINAPI
Definition: msvc.h:6
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125
#define SECURITY_LOGON_IDS_RID
Definition: setypes.h:560
#define SECURITY_LOCAL_SID_AUTHORITY
Definition: setypes.h:530
#define SECURITY_LOCAL_RID
Definition: setypes.h:542
#define TOKEN_QUERY
Definition: setypes.h:940
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define OWNER_SECURITY_INFORMATION
Definition: setypes.h:123
#define SECURITY_NULL_RID
Definition: setypes.h:540
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
@ TokenSource
Definition: setypes.h:984
@ TokenGroups
Definition: setypes.h:979
@ TokenPrimaryGroup
Definition: setypes.h:982
@ TokenOwner
Definition: setypes.h:981
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define GROUP_SECURITY_INFORMATION
Definition: setypes.h:124
#define TOKEN_IMPERSONATE
Definition: setypes.h:939
#define ACL_REVISION
Definition: setypes.h:39
#define SECURITY_LOGON_IDS_RID_COUNT
Definition: setypes.h:561
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175