From 5f16c2b7eda0341204ec9b4c19fb0a16ff52a771 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 3 Mar 2013 19:43:33 +0000 Subject: [PATCH] [LSASRV] - Add authentication package loader code. - Load registered authentication packages before the rpc server is started. svn path=/trunk/; revision=58421 --- reactos/dll/win32/lsasrv/CMakeLists.txt | 1 + reactos/dll/win32/lsasrv/authpackage.c | 147 ++++++++++++++++++++++++ reactos/dll/win32/lsasrv/lsasrv.c | 19 ++- reactos/dll/win32/lsasrv/lsasrv.h | 5 + 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 reactos/dll/win32/lsasrv/authpackage.c diff --git a/reactos/dll/win32/lsasrv/CMakeLists.txt b/reactos/dll/win32/lsasrv/CMakeLists.txt index a1a48a799ff..9804adaaca3 100644 --- a/reactos/dll/win32/lsasrv/CMakeLists.txt +++ b/reactos/dll/win32/lsasrv/CMakeLists.txt @@ -8,6 +8,7 @@ add_rpc_files(server ${REACTOS_SOURCE_DIR}/include/reactos/idl/lsa.idl) spec2def(lsasrv.dll lsasrv.spec ADD_IMPORTLIB) list(APPEND SOURCE + authpackage.c authport.c database.c lookup.c diff --git a/reactos/dll/win32/lsasrv/authpackage.c b/reactos/dll/win32/lsasrv/authpackage.c new file mode 100644 index 00000000000..462f053a78f --- /dev/null +++ b/reactos/dll/win32/lsasrv/authpackage.c @@ -0,0 +1,147 @@ +/* + * PROJECT: Local Security Authority Server DLL + * LICENSE: GPL - See COPYING in the top level directory + * FILE: dll/win32/lsasrv/authpackage.c + * PURPOSE: Authenticaton package management routines + * COPYRIGHT: Copyright 2013 Eric Kohl + */ + +/* INCLUDES ****************************************************************/ + +#include "lsasrv.h" + +WINE_DEFAULT_DEBUG_CHANNEL(lsasrv); + + + +typedef NTSTATUS (NTAPI *PLSA_AP_INITIALIZE_PACKAGE)(ULONG, PVOID /*PLSA_DISPATCH_TABLE*/, + PLSA_STRING, PLSA_STRING, PLSA_STRING *); + +typedef struct _AUTH_PACKAGE +{ + LIST_ENTRY Entry; + PSTRING Name; + PVOID ModuleHandle; + + PLSA_AP_INITIALIZE_PACKAGE LsaApInitializePackage; +// PLSA_AP_CALL_PACKAGE LsaApCallPackage; +// PLSA_AP_CALL_PACKAGE_UNTRUSTED LsaApCallPackageUntrusted; +// PLSA_AP_LOGON_TERMINATED LsaApLogonTerminated; +// PLSA_AP_LOGON_USER_EX2 LsaApLogonUserEx2; +// PLSA_AP_LOGON_USER_EX LsaApLogonUserEx; +// PLSA_AP_LOGON_USER LsaApLogonUser; +} AUTH_PACKAGE, *PAUTH_PACKAGE; + +/* GLOBALS *****************************************************************/ + +static LIST_ENTRY PackageListHead; +static ULONG PackageId; + +/* FUNCTIONS ***************************************************************/ + +static +NTSTATUS +NTAPI +LsapAddAuthPackage(IN PWSTR ValueName, + IN ULONG ValueType, + IN PVOID ValueData, + IN ULONG ValueLength, + IN PVOID Context, + IN PVOID EntryContext) +{ + PAUTH_PACKAGE Package = NULL; + UNICODE_STRING PackageName; + STRING ProcName; + PULONG Id; + NTSTATUS Status = STATUS_SUCCESS; + + TRACE("LsapAddAuthPackage()\n"); + + PackageName.Length = (USHORT)ValueLength - sizeof(WCHAR); + PackageName.MaximumLength = (USHORT)ValueLength; + PackageName.Buffer = ValueData; + + Id = (PULONG)Context; + + Package = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(AUTH_PACKAGE)); + if (Package == NULL) + return STATUS_INSUFFICIENT_RESOURCES; + + Status = LdrLoadDll(NULL, + NULL, + &PackageName, + &Package->ModuleHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LdrLoadDll failed (Status 0x%08lx)\n", Status); + goto done; + } + + RtlInitAnsiString(&ProcName, "LsaApInitializePackage"); + Status = LdrGetProcedureAddress(Package->ModuleHandle, + &ProcName, + 0, + (PVOID *)&Package->LsaApInitializePackage); + if (!NT_SUCCESS(Status)) + { + TRACE("LdrGetProcedureAddress() failed (Status 0x%08lx)\n", Status); + goto done; + } + + Status = Package->LsaApInitializePackage(*Id, + NULL, + NULL, + NULL, + &Package->Name); + if (!NT_SUCCESS(Status)) + { + TRACE("Package->LsaApInitializePackage() failed (Status 0x%08lx)\n", Status); + goto done; + } + + *Id++; + + InsertTailList(&PackageListHead, &Package->Entry); + +done: + if (!NT_SUCCESS(Status)) + { + if (Package != NULL) + { + if (Package->ModuleHandle != NULL) + LdrUnloadDll(Package->ModuleHandle); + + RtlFreeHeap(RtlGetProcessHeap(), 0, Package); + } + } + + return Status; +} + + +NTSTATUS +LsapInitAuthPackages(VOID) +{ + RTL_QUERY_REGISTRY_TABLE AuthPackageTable[] = { + {LsapAddAuthPackage, 0, L"Authentication Packages", NULL, REG_NONE, NULL, 0}, + {NULL, 0, NULL, NULL, REG_NONE, NULL, 0}}; + + NTSTATUS Status; + + InitializeListHead(&PackageListHead); + PackageId = 0; + + /* Add registered authentication packages */ + Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL, + L"Lsa", + AuthPackageTable, + &PackageId, + NULL); + + + return STATUS_SUCCESS; +} + +/* EOF */ diff --git a/reactos/dll/win32/lsasrv/lsasrv.c b/reactos/dll/win32/lsasrv/lsasrv.c index 6398e999d5a..53198aa06fc 100644 --- a/reactos/dll/win32/lsasrv/lsasrv.c +++ b/reactos/dll/win32/lsasrv/lsasrv.c @@ -20,6 +20,7 @@ LsapInitLsa(VOID) { HANDLE hEvent; DWORD dwError; + NTSTATUS Status; TRACE("LsapInitLsa() called\n"); @@ -29,6 +30,22 @@ LsapInitLsa(VOID) /* Initialize the LSA database */ LsapInitDatabase(); + /* Initialize registered authentication packages */ + Status = LsapInitAuthPackages(); + if (!NT_SUCCESS(Status)) + { + ERR("LsapInitAuthPackages() failed (Status 0x%08lx)\n", Status); + return Status; + } + + /* Start the authentication port thread */ + Status = StartAuthenticationPort(); + if (!NT_SUCCESS(Status)) + { + ERR("StartAuthenticationPort() failed (Status 0x%08lx)\n", Status); + return Status; + } + /* Start the RPC server */ LsarStartRpcServer(); @@ -61,8 +78,6 @@ LsapInitLsa(VOID) /* NOTE: Do not close the event handle!!!! */ - StartAuthenticationPort(); - return STATUS_SUCCESS; } diff --git a/reactos/dll/win32/lsasrv/lsasrv.h b/reactos/dll/win32/lsasrv/lsasrv.h index b80c2b49b52..25f9bada3aa 100644 --- a/reactos/dll/win32/lsasrv/lsasrv.h +++ b/reactos/dll/win32/lsasrv/lsasrv.h @@ -19,10 +19,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -79,6 +81,9 @@ extern UNICODE_STRING BuiltinDomainName; extern PSID AccountDomainSid; extern UNICODE_STRING AccountDomainName; +/* authpackage.c */ +NTSTATUS +LsapInitAuthPackages(VOID); /* authport.c */ NTSTATUS