2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/lsasrv/authpackage.c
5 * PURPOSE: Authenticaton package management routines
6 * COPYRIGHT: Copyright 2013 Eric Kohl
9 /* INCLUDES ****************************************************************/
13 WINE_DEFAULT_DEBUG_CHANNEL(lsasrv
);
15 typedef enum _LSA_TOKEN_INFORMATION_TYPE
17 LsaTokenInformationNull
,
19 } LSA_TOKEN_INFORMATION_TYPE
, *PLSA_TOKEN_INFORMATION_TYPE
;
21 typedef struct _LSA_TOKEN_INFORMATION_V1
23 LARGE_INTEGER ExpirationTime
;
26 TOKEN_PRIMARY_GROUP PrimaryGroup
;
27 PTOKEN_PRIVILEGES Privileges
;
29 TOKEN_DEFAULT_DACL DefaultDacl
;
30 } LSA_TOKEN_INFORMATION_V1
, *PLSA_TOKEN_INFORMATION_V1
;
32 typedef PVOID PLSA_CLIENT_REQUEST
;
34 typedef NTSTATUS (NTAPI
*PLSA_CREATE_LOGON_SESSION
)(PLUID
);
35 typedef NTSTATUS (NTAPI
*PLSA_DELETE_LOGON_SESSION
)(PLUID
);
37 typedef PVOID (NTAPI
*PLSA_ALLOCATE_LSA_HEAP
)(ULONG
);
38 typedef VOID (NTAPI
*PLSA_FREE_LSA_HEAP
)(PVOID
);
39 typedef NTSTATUS (NTAPI
*PLSA_ALLOCATE_CLIENT_BUFFER
)(PLSA_CLIENT_REQUEST
, ULONG
, PVOID
*);
40 typedef NTSTATUS (NTAPI
*PLSA_FREE_CLIENT_BUFFER
)(PLSA_CLIENT_REQUEST
, PVOID
);
41 typedef NTSTATUS (NTAPI
*PLSA_COPY_TO_CLIENT_BUFFER
)(PLSA_CLIENT_REQUEST
, ULONG
,
43 typedef NTSTATUS (NTAPI
*PLSA_COPY_FROM_CLIENT_BUFFER
)(PLSA_CLIENT_REQUEST
,
46 typedef struct LSA_DISPATCH_TABLE
48 PLSA_CREATE_LOGON_SESSION CreateLogonSession
;
49 PLSA_DELETE_LOGON_SESSION DeleteLogonSession
;
50 PVOID
/*PLSA_ADD_CREDENTIAL */ AddCredential
;
51 PVOID
/*PLSA_GET_CREDENTIALS */ GetCredentials
;
52 PVOID
/*PLSA_DELETE_CREDENTIAL */ DeleteCredential
;
53 PLSA_ALLOCATE_LSA_HEAP AllocateLsaHeap
;
54 PLSA_FREE_LSA_HEAP FreeLsaHeap
;
55 PLSA_ALLOCATE_CLIENT_BUFFER AllocateClientBuffer
;
56 PLSA_FREE_CLIENT_BUFFER FreeClientBuffer
;
57 PLSA_COPY_TO_CLIENT_BUFFER CopyToClientBuffer
;
58 PLSA_COPY_FROM_CLIENT_BUFFER CopyFromClientBuffer
;
59 } LSA_DISPATCH_TABLE
, *PLSA_DISPATCH_TABLE
;
62 typedef NTSTATUS (NTAPI
*PLSA_AP_INITIALIZE_PACKAGE
)(ULONG
, PLSA_DISPATCH_TABLE
,
63 PLSA_STRING
, PLSA_STRING
, PLSA_STRING
*);
64 typedef NTSTATUS (NTAPI
*PLSA_AP_CALL_PACKAGE_INTERNAL
)(PLSA_CLIENT_REQUEST
, PVOID
, PVOID
,
65 ULONG
, PVOID
*, PULONG
, PNTSTATUS
);
66 typedef NTSTATUS (NTAPI
*PLSA_AP_CALL_PACKAGE_PASSTHROUGH
)(PLSA_CLIENT_REQUEST
,
67 PVOID
, PVOID
, ULONG
, PVOID
*, PULONG
, PNTSTATUS
);
68 typedef NTSTATUS (NTAPI
*PLSA_AP_CALL_PACKAGE_UNTRUSTED
)(PLSA_CLIENT_REQUEST
,
69 PVOID
, PVOID
, ULONG
, PVOID
*, PULONG
, PNTSTATUS
);
70 typedef VOID (NTAPI
*PLSA_AP_LOGON_TERMINATED
)(PLUID
);
71 typedef NTSTATUS (NTAPI
*PLSA_AP_LOGON_USER_EX2
)(PLSA_CLIENT_REQUEST
,
72 SECURITY_LOGON_TYPE
, PVOID
, PVOID
, ULONG
, PVOID
*, PULONG
, PLUID
, PNTSTATUS
,
73 PLSA_TOKEN_INFORMATION_TYPE
, PVOID
*, PUNICODE_STRING
*, PUNICODE_STRING
*,
74 PUNICODE_STRING
*, PVOID
/*PSECPKG_PRIMARY_CRED*/, PVOID
/*PSECPKG_SUPPLEMENTAL_CRED_ARRAY **/);
75 typedef NTSTATUS (NTAPI
*PLSA_AP_LOGON_USER_EX
)(PLSA_CLIENT_REQUEST
,
76 SECURITY_LOGON_TYPE
, PVOID
, PVOID
, ULONG
, PVOID
*, PULONG
, PLUID
, PNTSTATUS
,
77 PLSA_TOKEN_INFORMATION_TYPE
, PVOID
*, PUNICODE_STRING
*, PUNICODE_STRING
*,
80 typedef NTSTATUS (NTAPI
*PLSA_AP_LOGON_USER_INTERNAL
)(PLSA_CLIENT_REQUEST
, SECURITY_LOGON_TYPE
,
81 PVOID
, PVOID
, ULONG
, PVOID
*, PULONG
, PLUID
, PNTSTATUS
, PLSA_TOKEN_INFORMATION_TYPE
,
82 PVOID
*, PUNICODE_STRING
*, PUNICODE_STRING
*);
84 typedef struct _AUTH_PACKAGE
91 PLSA_AP_INITIALIZE_PACKAGE LsaApInitializePackage
;
92 PLSA_AP_CALL_PACKAGE_INTERNAL LsaApCallPackage
;
93 PLSA_AP_CALL_PACKAGE_PASSTHROUGH LsaApCallPackagePassthrough
;
94 PLSA_AP_CALL_PACKAGE_UNTRUSTED LsaApCallPackageUntrusted
;
95 PLSA_AP_LOGON_TERMINATED LsaApLogonTerminated
;
96 PLSA_AP_LOGON_USER_EX2 LsaApLogonUserEx2
;
97 PLSA_AP_LOGON_USER_EX LsaApLogonUserEx
;
98 PLSA_AP_LOGON_USER_INTERNAL LsaApLogonUser
;
99 } AUTH_PACKAGE
, *PAUTH_PACKAGE
;
102 /* GLOBALS *****************************************************************/
104 static LIST_ENTRY PackageListHead
;
105 static ULONG PackageId
;
106 static LSA_DISPATCH_TABLE DispatchTable
;
109 /* FUNCTIONS ***************************************************************/
114 LsapAddAuthPackage(IN PWSTR ValueName
,
117 IN ULONG ValueLength
,
119 IN PVOID EntryContext
)
121 PAUTH_PACKAGE Package
= NULL
;
122 UNICODE_STRING PackageName
;
125 NTSTATUS Status
= STATUS_SUCCESS
;
127 TRACE("LsapAddAuthPackage()\n");
129 PackageName
.Length
= (USHORT
)ValueLength
- sizeof(WCHAR
);
130 PackageName
.MaximumLength
= (USHORT
)ValueLength
;
131 PackageName
.Buffer
= ValueData
;
133 Id
= (PULONG
)Context
;
135 Package
= RtlAllocateHeap(RtlGetProcessHeap(),
137 sizeof(AUTH_PACKAGE
));
139 return STATUS_INSUFFICIENT_RESOURCES
;
141 Status
= LdrLoadDll(NULL
,
144 &Package
->ModuleHandle
);
145 if (!NT_SUCCESS(Status
))
147 TRACE("LdrLoadDll failed (Status 0x%08lx)\n", Status
);
151 RtlInitAnsiString(&ProcName
, "LsaApInitializePackage");
152 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
155 (PVOID
*)&Package
->LsaApInitializePackage
);
156 if (!NT_SUCCESS(Status
))
158 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
162 RtlInitAnsiString(&ProcName
, "LsaApCallPackage");
163 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
166 (PVOID
*)&Package
->LsaApCallPackage
);
167 if (!NT_SUCCESS(Status
))
169 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
173 RtlInitAnsiString(&ProcName
, "LsaApCallPackagePassthrough");
174 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
177 (PVOID
*)&Package
->LsaApCallPackagePassthrough
);
178 if (!NT_SUCCESS(Status
))
180 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
184 RtlInitAnsiString(&ProcName
, "LsaApCallPackageUntrusted");
185 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
188 (PVOID
*)&Package
->LsaApCallPackageUntrusted
);
189 if (!NT_SUCCESS(Status
))
191 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
195 RtlInitAnsiString(&ProcName
, "LsaApLogonTerminated");
196 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
199 (PVOID
*)&Package
->LsaApLogonTerminated
);
200 if (!NT_SUCCESS(Status
))
202 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
206 RtlInitAnsiString(&ProcName
, "LsaApLogonUserEx2");
207 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
210 (PVOID
*)&Package
->LsaApLogonUserEx2
);
211 if (!NT_SUCCESS(Status
))
213 RtlInitAnsiString(&ProcName
, "LsaApLogonUserEx");
214 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
217 (PVOID
*)&Package
->LsaApLogonUserEx
);
218 if (!NT_SUCCESS(Status
))
220 RtlInitAnsiString(&ProcName
, "LsaApLogonUser");
221 Status
= LdrGetProcedureAddress(Package
->ModuleHandle
,
224 (PVOID
*)&Package
->LsaApLogonUser
);
225 if (!NT_SUCCESS(Status
))
227 TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status
);
233 /* Initialize the current package */
234 Status
= Package
->LsaApInitializePackage(*Id
,
239 if (!NT_SUCCESS(Status
))
241 TRACE("Package->LsaApInitializePackage() failed (Status 0x%08lx)\n", Status
);
245 TRACE("Package Name: %s\n", Package
->Name
->Buffer
);
250 InsertTailList(&PackageListHead
, &Package
->Entry
);
253 if (!NT_SUCCESS(Status
))
257 if (Package
->ModuleHandle
!= NULL
)
258 LdrUnloadDll(Package
->ModuleHandle
);
260 if (Package
->Name
!= NULL
)
262 if (Package
->Name
->Buffer
!= NULL
)
263 RtlFreeHeap(RtlGetProcessHeap(), 0, Package
->Name
->Buffer
);
265 RtlFreeHeap(RtlGetProcessHeap(), 0, Package
->Name
);
268 RtlFreeHeap(RtlGetProcessHeap(), 0, Package
);
278 LsapGetAuthenticationPackage(IN ULONG PackageId
)
280 PLIST_ENTRY ListEntry
;
281 PAUTH_PACKAGE Package
;
283 ListEntry
= PackageListHead
.Flink
;
284 while (ListEntry
!= &PackageListHead
)
286 Package
= CONTAINING_RECORD(ListEntry
, AUTH_PACKAGE
, Entry
);
288 if (Package
->Id
== PackageId
)
293 ListEntry
= ListEntry
->Flink
;
303 LsapAllocateHeap(IN ULONG Length
)
305 return RtlAllocateHeap(RtlGetProcessHeap(),
314 LsapFreeHeap(IN PVOID Base
)
316 RtlFreeHeap(RtlGetProcessHeap(),
325 LsapAllocateClientBuffer(IN PLSA_CLIENT_REQUEST ClientRequest
,
326 IN ULONG LengthRequired
,
327 OUT PVOID
*ClientBaseAddress
)
329 PLSAP_LOGON_CONTEXT LogonContext
;
332 *ClientBaseAddress
= NULL
;
334 LogonContext
= (PLSAP_LOGON_CONTEXT
)ClientRequest
;
336 Length
= LengthRequired
;
337 return NtAllocateVirtualMemory(LogonContext
->ClientProcessHandle
,
349 LsapFreeClientBuffer(IN PLSA_CLIENT_REQUEST ClientRequest
,
350 IN PVOID ClientBaseAddress
)
352 PLSAP_LOGON_CONTEXT LogonContext
;
355 if (ClientBaseAddress
== NULL
)
356 return STATUS_SUCCESS
;
358 LogonContext
= (PLSAP_LOGON_CONTEXT
)ClientRequest
;
361 return NtFreeVirtualMemory(LogonContext
->ClientProcessHandle
,
371 LsapCopyToClientBuffer(IN PLSA_CLIENT_REQUEST ClientRequest
,
373 IN PVOID ClientBaseAddress
,
374 IN PVOID BufferToCopy
)
376 PLSAP_LOGON_CONTEXT LogonContext
;
378 LogonContext
= (PLSAP_LOGON_CONTEXT
)ClientRequest
;
380 return NtWriteVirtualMemory(LogonContext
->ClientProcessHandle
,
391 LsapCopyFromClientBuffer(IN PLSA_CLIENT_REQUEST ClientRequest
,
393 IN PVOID BufferToCopy
,
394 IN PVOID ClientBaseAddress
)
396 PLSAP_LOGON_CONTEXT LogonContext
;
398 LogonContext
= (PLSAP_LOGON_CONTEXT
)ClientRequest
;
400 return NtReadVirtualMemory(LogonContext
->ClientProcessHandle
,
409 LsapInitAuthPackages(VOID
)
411 RTL_QUERY_REGISTRY_TABLE AuthPackageTable
[] = {
412 {LsapAddAuthPackage
, 0, L
"Authentication Packages", NULL
, REG_NONE
, NULL
, 0},
413 {NULL
, 0, NULL
, NULL
, REG_NONE
, NULL
, 0}};
417 InitializeListHead(&PackageListHead
);
420 /* Initialize the dispatch table */
421 DispatchTable
.CreateLogonSession
= &LsapCreateLogonSession
;
422 DispatchTable
.DeleteLogonSession
= &LsapDeleteLogonSession
;
423 DispatchTable
.AddCredential
= NULL
;
424 DispatchTable
.GetCredentials
= NULL
;
425 DispatchTable
.DeleteCredential
= NULL
;
426 DispatchTable
.AllocateLsaHeap
= &LsapAllocateHeap
;
427 DispatchTable
.FreeLsaHeap
= &LsapFreeHeap
;
428 DispatchTable
.AllocateClientBuffer
= &LsapAllocateClientBuffer
;
429 DispatchTable
.FreeClientBuffer
= &LsapFreeClientBuffer
;
430 DispatchTable
.CopyToClientBuffer
= &LsapCopyToClientBuffer
;
431 DispatchTable
.CopyFromClientBuffer
= &LsapCopyFromClientBuffer
;
433 /* Add registered authentication packages */
434 Status
= RtlQueryRegistryValues(RTL_REGISTRY_CONTROL
,
445 LsapLookupAuthenticationPackage(PLSA_API_MSG RequestMsg
,
446 PLSAP_LOGON_CONTEXT LogonContext
)
448 PLIST_ENTRY ListEntry
;
449 PAUTH_PACKAGE Package
;
450 ULONG PackageNameLength
;
453 TRACE("(%p %p)\n", RequestMsg
, LogonContext
);
455 PackageNameLength
= RequestMsg
->LookupAuthenticationPackage
.Request
.PackageNameLength
;
456 PackageName
= RequestMsg
->LookupAuthenticationPackage
.Request
.PackageName
;
458 TRACE("PackageName: %s\n", PackageName
);
460 ListEntry
= PackageListHead
.Flink
;
461 while (ListEntry
!= &PackageListHead
)
463 Package
= CONTAINING_RECORD(ListEntry
, AUTH_PACKAGE
, Entry
);
465 if ((PackageNameLength
== Package
->Name
->Length
) &&
466 (_strnicmp(PackageName
, Package
->Name
->Buffer
, Package
->Name
->Length
) == 0))
468 RequestMsg
->LookupAuthenticationPackage
.Reply
.Package
= Package
->Id
;
469 return STATUS_SUCCESS
;
472 ListEntry
= ListEntry
->Flink
;
475 return STATUS_NO_SUCH_PACKAGE
;
480 LsapCallAuthenticationPackage(PLSA_API_MSG RequestMsg
,
481 PLSAP_LOGON_CONTEXT LogonContext
)
483 PAUTH_PACKAGE Package
;
484 PVOID LocalBuffer
= NULL
;
488 TRACE("(%p %p)\n", RequestMsg
, LogonContext
);
490 PackageId
= RequestMsg
->CallAuthenticationPackage
.Request
.AuthenticationPackage
;
492 /* Get the right authentication package */
493 Package
= LsapGetAuthenticationPackage(PackageId
);
496 TRACE("LsapGetAuthenticationPackage() failed to find a package\n");
497 return STATUS_NO_SUCH_PACKAGE
;
500 if (RequestMsg
->CallAuthenticationPackage
.Request
.SubmitBufferLength
> 0)
502 LocalBuffer
= RtlAllocateHeap(RtlGetProcessHeap(),
504 RequestMsg
->CallAuthenticationPackage
.Request
.SubmitBufferLength
);
505 if (LocalBuffer
== NULL
)
507 return STATUS_INSUFFICIENT_RESOURCES
;
510 Status
= NtReadVirtualMemory(LogonContext
->ClientProcessHandle
,
511 RequestMsg
->CallAuthenticationPackage
.Request
.ProtocolSubmitBuffer
,
513 RequestMsg
->CallAuthenticationPackage
.Request
.SubmitBufferLength
,
515 if (!NT_SUCCESS(Status
))
517 TRACE("NtReadVirtualMemory() failed (Status 0x%08lx)\n", Status
);
518 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer
);
523 Status
= Package
->LsaApCallPackage((PLSA_CLIENT_REQUEST
)LogonContext
,
525 RequestMsg
->CallAuthenticationPackage
.Request
.ProtocolSubmitBuffer
,
526 RequestMsg
->CallAuthenticationPackage
.Request
.SubmitBufferLength
,
527 &RequestMsg
->CallAuthenticationPackage
.Reply
.ProtocolReturnBuffer
,
528 &RequestMsg
->CallAuthenticationPackage
.Reply
.ReturnBufferLength
,
529 &RequestMsg
->CallAuthenticationPackage
.Reply
.ProtocolStatus
);
530 if (!NT_SUCCESS(Status
))
532 TRACE("Package->LsaApCallPackage() failed (Status 0x%08lx)\n", Status
);
535 if (LocalBuffer
!= NULL
)
536 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer
);
545 IN PLSAP_LOGON_CONTEXT LogonContext
,
546 IN PTOKEN_GROUPS ClientGroups
,
547 IN ULONG ClientGroupsCount
,
548 OUT PTOKEN_GROUPS
*TokenGroups
)
550 ULONG LocalGroupsLength
= 0;
551 PTOKEN_GROUPS LocalGroups
= NULL
;
554 LocalGroupsLength
= sizeof(TOKEN_GROUPS
) +
555 (ClientGroupsCount
- ANYSIZE_ARRAY
) * sizeof(SID_AND_ATTRIBUTES
);
556 LocalGroups
= RtlAllocateHeap(RtlGetProcessHeap(),
559 if (LocalGroups
== NULL
)
561 TRACE("RtlAllocateHeap() failed\n");
562 return STATUS_INSUFFICIENT_RESOURCES
;
565 Status
= NtReadVirtualMemory(LogonContext
->ClientProcessHandle
,
570 if (!NT_SUCCESS(Status
))
573 *TokenGroups
= LocalGroups
;
576 if (!NT_SUCCESS(Status
))
578 if (LocalGroups
!= NULL
)
580 RtlFreeHeap(RtlGetProcessHeap(),
591 LsapLogonUser(PLSA_API_MSG RequestMsg
,
592 PLSAP_LOGON_CONTEXT LogonContext
)
594 PAUTH_PACKAGE Package
;
595 OBJECT_ATTRIBUTES ObjectAttributes
;
596 SECURITY_QUALITY_OF_SERVICE Qos
;
597 LSA_TOKEN_INFORMATION_TYPE TokenInformationType
;
598 PVOID TokenInformation
= NULL
;
599 PLSA_TOKEN_INFORMATION_V1 TokenInfo1
= NULL
;
600 PUNICODE_STRING AccountName
= NULL
;
601 PUNICODE_STRING AuthenticatingAuthority
= NULL
;
602 PUNICODE_STRING MachineName
= NULL
;
603 PVOID LocalAuthInfo
= NULL
;
604 PTOKEN_GROUPS LocalGroups
= NULL
;
605 HANDLE TokenHandle
= NULL
;
610 TRACE("(%p %p)\n", RequestMsg
, LogonContext
);
612 PackageId
= RequestMsg
->LogonUser
.Request
.AuthenticationPackage
;
614 /* Get the right authentication package */
615 Package
= LsapGetAuthenticationPackage(PackageId
);
618 TRACE("LsapGetAuthenticationPackage() failed to find a package\n");
619 return STATUS_NO_SUCH_PACKAGE
;
622 if (RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
> 0)
624 /* Allocate the local authentication info buffer */
625 LocalAuthInfo
= RtlAllocateHeap(RtlGetProcessHeap(),
627 RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
);
628 if (LocalAuthInfo
== NULL
)
630 TRACE("RtlAllocateHeap() failed\n");
631 return STATUS_INSUFFICIENT_RESOURCES
;
634 /* Read the authentication info from the callers adress space */
635 Status
= NtReadVirtualMemory(LogonContext
->ClientProcessHandle
,
636 RequestMsg
->LogonUser
.Request
.AuthenticationInformation
,
638 RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
,
640 if (!NT_SUCCESS(Status
))
642 TRACE("NtReadVirtualMemory() failed (Status 0x%08lx)\n", Status
);
643 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalAuthInfo
);
648 if (RequestMsg
->LogonUser
.Request
.LocalGroupsCount
> 0)
650 Status
= LsapCopyLocalGroups(LogonContext
,
651 RequestMsg
->LogonUser
.Request
.LocalGroups
,
652 RequestMsg
->LogonUser
.Request
.LocalGroupsCount
,
654 if (!NT_SUCCESS(Status
))
657 TRACE("GroupCount: %lu\n", LocalGroups
->GroupCount
);
660 if (Package
->LsaApLogonUserEx2
!= NULL
)
662 Status
= Package
->LsaApLogonUserEx2((PLSA_CLIENT_REQUEST
)LogonContext
,
663 RequestMsg
->LogonUser
.Request
.LogonType
,
665 RequestMsg
->LogonUser
.Request
.AuthenticationInformation
,
666 RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
,
667 &RequestMsg
->LogonUser
.Reply
.ProfileBuffer
,
668 &RequestMsg
->LogonUser
.Reply
.ProfileBufferLength
,
669 &RequestMsg
->LogonUser
.Reply
.LogonId
,
670 &RequestMsg
->LogonUser
.Reply
.SubStatus
,
671 &TokenInformationType
,
674 &AuthenticatingAuthority
,
676 NULL
, /* FIXME: PSECPKG_PRIMARY_CRED PrimaryCredentials */
677 NULL
); /* FIXME: PSECPKG_SUPPLEMENTAL_CRED_ARRAY *SupplementalCredentials */
679 else if (Package
->LsaApLogonUserEx
!= NULL
)
681 Status
= Package
->LsaApLogonUserEx((PLSA_CLIENT_REQUEST
)LogonContext
,
682 RequestMsg
->LogonUser
.Request
.LogonType
,
684 RequestMsg
->LogonUser
.Request
.AuthenticationInformation
,
685 RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
,
686 &RequestMsg
->LogonUser
.Reply
.ProfileBuffer
,
687 &RequestMsg
->LogonUser
.Reply
.ProfileBufferLength
,
688 &RequestMsg
->LogonUser
.Reply
.LogonId
,
689 &RequestMsg
->LogonUser
.Reply
.SubStatus
,
690 &TokenInformationType
,
693 &AuthenticatingAuthority
,
698 Status
= Package
->LsaApLogonUser((PLSA_CLIENT_REQUEST
)LogonContext
,
699 RequestMsg
->LogonUser
.Request
.LogonType
,
701 RequestMsg
->LogonUser
.Request
.AuthenticationInformation
,
702 RequestMsg
->LogonUser
.Request
.AuthenticationInformationLength
,
703 &RequestMsg
->LogonUser
.Reply
.ProfileBuffer
,
704 &RequestMsg
->LogonUser
.Reply
.ProfileBufferLength
,
705 &RequestMsg
->LogonUser
.Reply
.LogonId
,
706 &RequestMsg
->LogonUser
.Reply
.SubStatus
,
707 &TokenInformationType
,
710 &AuthenticatingAuthority
);
713 if (!NT_SUCCESS(Status
))
715 TRACE("LsaApLogonUser/Ex/2 failed (Status 0x%08lx)\n", Status
);
719 if (TokenInformationType
== LsaTokenInformationV1
)
721 TokenInfo1
= (PLSA_TOKEN_INFORMATION_V1
)TokenInformation
;
723 Qos
.Length
= sizeof(SECURITY_QUALITY_OF_SERVICE
);
724 Qos
.ImpersonationLevel
= SecurityImpersonation
;
725 Qos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
726 Qos
.EffectiveOnly
= FALSE
;
728 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
729 ObjectAttributes
.RootDirectory
= NULL
;
730 ObjectAttributes
.ObjectName
= NULL
;
731 ObjectAttributes
.Attributes
= 0;
732 ObjectAttributes
.SecurityDescriptor
= NULL
;
733 ObjectAttributes
.SecurityQualityOfService
= &Qos
;
735 /* Create the logon token */
736 Status
= NtCreateToken(&TokenHandle
,
740 &RequestMsg
->LogonUser
.Reply
.LogonId
,
741 &TokenInfo1
->ExpirationTime
,
744 TokenInfo1
->Privileges
,
746 &TokenInfo1
->PrimaryGroup
,
747 &TokenInfo1
->DefaultDacl
,
748 &RequestMsg
->LogonUser
.Request
.SourceContext
);
749 if (!NT_SUCCESS(Status
))
751 TRACE("NtCreateToken failed (Status 0x%08lx)\n", Status
);
757 FIXME("TokenInformationType %d is not supported!\n", TokenInformationType
);
758 Status
= STATUS_NOT_IMPLEMENTED
;
762 /* Duplicate the token handle into the client process */
763 Status
= NtDuplicateObject(NtCurrentProcess(),
765 LogonContext
->ClientProcessHandle
,
766 &RequestMsg
->LogonUser
.Reply
.Token
,
769 DUPLICATE_SAME_ACCESS
| DUPLICATE_SAME_ATTRIBUTES
| DUPLICATE_CLOSE_SOURCE
);
770 if (!NT_SUCCESS(Status
))
772 TRACE("NtDuplicateObject failed (Status 0x%08lx)\n", Status
);
779 if (!NT_SUCCESS(Status
))
781 if (TokenHandle
!= NULL
)
782 NtClose(TokenHandle
);
785 /* Free the local groups */
786 if (LocalGroups
!= NULL
)
788 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalGroups
);
791 /* Free the local authentication info buffer */
792 if (LocalAuthInfo
!= NULL
)
793 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalAuthInfo
);
795 /* Free the token information */
796 if (TokenInformation
!= NULL
)
798 if (TokenInformationType
== LsaTokenInformationV1
)
800 TokenInfo1
= (PLSA_TOKEN_INFORMATION_V1
)TokenInformation
;
802 if (TokenInfo1
!= NULL
)
804 if (TokenInfo1
->User
.User
.Sid
!= NULL
)
805 LsapFreeHeap(TokenInfo1
->User
.User
.Sid
);
807 if (TokenInfo1
->Groups
!= NULL
)
809 for (i
= 0; i
< TokenInfo1
->Groups
->GroupCount
; i
++)
811 if (TokenInfo1
->Groups
->Groups
[i
].Sid
!= NULL
)
812 LsapFreeHeap(TokenInfo1
->Groups
->Groups
[i
].Sid
);
815 LsapFreeHeap(TokenInfo1
->Groups
);
818 if (TokenInfo1
->PrimaryGroup
.PrimaryGroup
!= NULL
)
819 LsapFreeHeap(TokenInfo1
->PrimaryGroup
.PrimaryGroup
);
821 if (TokenInfo1
->Privileges
!= NULL
)
822 LsapFreeHeap(TokenInfo1
->Privileges
);
824 if (TokenInfo1
->Owner
.Owner
!= NULL
)
825 LsapFreeHeap(TokenInfo1
->Owner
.Owner
);
827 if (TokenInfo1
->DefaultDacl
.DefaultDacl
!= NULL
)
828 LsapFreeHeap(TokenInfo1
->DefaultDacl
.DefaultDacl
);
830 LsapFreeHeap(TokenInfo1
);
835 FIXME("TokenInformationType %d is not supported!\n", TokenInformationType
);
839 /* Free the account name */
840 if (AccountName
!= NULL
)
842 if (AccountName
->Buffer
!= NULL
)
843 LsapFreeHeap(AccountName
->Buffer
);
845 LsapFreeHeap(AccountName
);
848 /* Free the authentication authority */
849 if (AuthenticatingAuthority
!= NULL
)
851 if (AuthenticatingAuthority
!= NULL
)
852 LsapFreeHeap(AuthenticatingAuthority
->Buffer
);
854 LsapFreeHeap(AuthenticatingAuthority
);
857 /* Free the machine name */
858 if (MachineName
!= NULL
)
860 if (MachineName
->Buffer
!= NULL
)
861 LsapFreeHeap(MachineName
->Buffer
);
863 LsapFreeHeap(MachineName
);
866 TRACE("LsapLogonUser done (Status 0x%08lx)\n", Status
);