From b1932aac4d5a0f99ce080f756a424ffa8b15572a Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 17 Dec 2013 21:01:18 +0000 Subject: [PATCH] [ADVAPI32] Do not deregister the logon process after logon. Close the port when the DLL is unloaded. svn path=/trunk/; revision=61285 --- reactos/dll/win32/advapi32/advapi32.h | 5 + reactos/dll/win32/advapi32/misc/dllmain.c | 8 +- reactos/dll/win32/advapi32/misc/logon.c | 117 +++++++++++++++------- 3 files changed, 90 insertions(+), 40 deletions(-) diff --git a/reactos/dll/win32/advapi32/advapi32.h b/reactos/dll/win32/advapi32/advapi32.h index c2b57d2b641..a304ec5504d 100644 --- a/reactos/dll/win32/advapi32/advapi32.h +++ b/reactos/dll/win32/advapi32/advapi32.h @@ -56,6 +56,11 @@ #define FN_PROGRESSA FN_PROGRESS #endif +/* logon.c */ + +NTSTATUS +CloseLogonLsaHandle(VOID); + /* rpc.c */ RPC_STATUS EvtBindRpc(LPCWSTR pszMachine, diff --git a/reactos/dll/win32/advapi32/misc/dllmain.c b/reactos/dll/win32/advapi32/misc/dllmain.c index 97ae6d0176b..ae7b29d7db4 100644 --- a/reactos/dll/win32/advapi32/misc/dllmain.c +++ b/reactos/dll/win32/advapi32/misc/dllmain.c @@ -15,8 +15,10 @@ extern BOOL RegInitialize(VOID); extern BOOL RegCleanup(VOID); extern VOID UnloadNtMarta(VOID); -BOOL WINAPI -DllMain(HINSTANCE hinstDll, +BOOL +WINAPI +DllMain( + HINSTANCE hinstDll, DWORD dwReason, LPVOID reserved) { @@ -26,7 +28,9 @@ DllMain(HINSTANCE hinstDll, DisableThreadLibraryCalls(hinstDll); RegInitialize(); break; + case DLL_PROCESS_DETACH: + CloseLogonLsaHandle(); RegCleanup(); UnloadNtMarta(); break; diff --git a/reactos/dll/win32/advapi32/misc/logon.c b/reactos/dll/win32/advapi32/misc/logon.c index b7621795638..d1fa3339268 100644 --- a/reactos/dll/win32/advapi32/misc/logon.c +++ b/reactos/dll/win32/advapi32/misc/logon.c @@ -9,8 +9,83 @@ #include WINE_DEFAULT_DEBUG_CHANNEL(advapi); +/* GLOBALS *****************************************************************/ + +HANDLE LsaHandle = NULL; +ULONG AuthenticationPackage = 0; + /* FUNCTIONS ***************************************************************/ +static +NTSTATUS +OpenLogonLsaHandle(VOID) +{ + LSA_STRING LogonProcessName; + LSA_STRING PackageName; + LSA_OPERATIONAL_MODE SecurityMode = 0; + NTSTATUS Status; + + RtlInitAnsiString((PANSI_STRING)&LogonProcessName, + "User32LogonProcess"); + + Status = LsaRegisterLogonProcess(&LogonProcessName, + &LsaHandle, + &SecurityMode); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status); + goto done; + } + + RtlInitAnsiString((PANSI_STRING)&PackageName, + MSV1_0_PACKAGE_NAME); + + Status = LsaLookupAuthenticationPackage(LsaHandle, + &PackageName, + &AuthenticationPackage); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status); + goto done; + } + + TRACE("AuthenticationPackage: 0x%08lx\n", AuthenticationPackage); + +done: + if (!NT_SUCCESS(Status)) + { + if (LsaHandle != NULL) + { + Status = LsaDeregisterLogonProcess(LsaHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status); + } + } + } + + return Status; +} + + +NTSTATUS +CloseLogonLsaHandle(VOID) +{ + NTSTATUS Status = STATUS_SUCCESS; + + if (LsaHandle != NULL) + { + Status = LsaDeregisterLogonProcess(LsaHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status); + } + } + + return Status; +} + + /* * @implemented */ @@ -224,11 +299,6 @@ LogonUserW(LPWSTR lpszUsername, { SID_IDENTIFIER_AUTHORITY LocalAuthority = {SECURITY_LOCAL_SID_AUTHORITY}; SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; - LSA_STRING LogonProcessName; - LSA_STRING PackageName; - HANDLE LsaHandle = NULL; - LSA_OPERATIONAL_MODE SecurityMode = 0; - ULONG AuthenticationPackage = 0; PSID LogonSid = NULL; PSID LocalSid = NULL; LSA_STRING OriginName; @@ -251,33 +321,13 @@ LogonUserW(LPWSTR lpszUsername, *phToken = NULL; - RtlInitAnsiString((PANSI_STRING)&LogonProcessName, - "User32LogonProcess"); - - Status = LsaRegisterLogonProcess(&LogonProcessName, - &LsaHandle, - &SecurityMode); - if (!NT_SUCCESS(Status)) + if (LsaHandle == NULL) { - TRACE("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status); - goto done; + Status = OpenLogonLsaHandle(); + if (!NT_SUCCESS(Status)) + return Status; } - RtlInitAnsiString((PANSI_STRING)&PackageName, - MSV1_0_PACKAGE_NAME); - - Status = LsaLookupAuthenticationPackage(LsaHandle, - &PackageName, - &AuthenticationPackage); - if (!NT_SUCCESS(Status)) - { - TRACE("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status); - goto done; - } - - TRACE("AuthenticationPackage: 0x%08lx\n", AuthenticationPackage); - - RtlInitAnsiString((PANSI_STRING)&OriginName, "Testapp"); @@ -454,15 +504,6 @@ done: if (AuthInfo != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo); - if (LsaHandle != NULL) - { - Status = LsaDeregisterLogonProcess(LsaHandle); - if (!NT_SUCCESS(Status)) - { - TRACE("LsaDeregisterLogonProcess failed (Status 0x%08lx)\n", Status); - } - } - if (!NT_SUCCESS(Status)) { SetLastError(RtlNtStatusToDosError(Status));