From ca6e7110f5c05a7a59eb4b1e35ed02abc748594e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 9 Oct 2006 19:19:28 +0000 Subject: [PATCH] - Start NetLogon service (lsass.exe) - Fix lots of problems in error handling - Some general cleanup svn path=/trunk/; revision=24477 --- reactos/base/system/winlogon/sas.c | 59 ++++++++++++++++------ reactos/base/system/winlogon/screensaver.c | 2 +- reactos/base/system/winlogon/setup.c | 2 +- reactos/base/system/winlogon/setup.h | 1 - reactos/base/system/winlogon/winlogon.c | 17 +++---- reactos/base/system/winlogon/winlogon.h | 6 +-- reactos/base/system/winlogon/wlx.c | 17 ++++++- 7 files changed, 72 insertions(+), 32 deletions(-) diff --git a/reactos/base/system/winlogon/sas.c b/reactos/base/system/winlogon/sas.c index 65bc33d958a..ee870bf5c6d 100644 --- a/reactos/base/system/winlogon/sas.c +++ b/reactos/base/system/winlogon/sas.c @@ -28,16 +28,29 @@ static BOOL StartTaskManager( IN OUT PWLSESSION Session) { + LPVOID lpEnvironment; + + if (!Session->Gina.Functions.WlxStartApplication) + return FALSE; + + if (!CreateEnvironmentBlock( + &lpEnvironment, + Session->UserToken, + TRUE)) + { + return FALSE; + } + return Session->Gina.Functions.WlxStartApplication( Session->Gina.Context, L"Default", - NULL, + lpEnvironment, L"taskmgr.exe"); } BOOL SetDefaultLanguage( - IN BOOLEAN UserProfile) + IN BOOL UserProfile) { HKEY BaseKey; LPCWSTR SubKey; @@ -146,11 +159,11 @@ static BOOL HandleLogon( IN OUT PWLSESSION Session) { - PROFILEINFOW ProfileInfo = { 0 }; + PROFILEINFOW ProfileInfo = { 0, }; LPVOID lpEnvironment = NULL; BOOLEAN Old; - if (!(Session->Options & WLX_LOGON_OPT_NO_PROFILE)) + if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE)) { /* Load the user profile */ ProfileInfo.dwSize = sizeof(PROFILEINFOW); @@ -165,7 +178,6 @@ HandleLogon( if (!LoadUserProfileW(Session->UserToken, &ProfileInfo)) { ERR("WL: LoadUserProfileW() failed\n"); - CloseHandle(Session->UserToken); return FALSE; } } @@ -177,9 +189,12 @@ HandleLogon( TRUE)) { ERR("WL: CreateEnvironmentBlock() failed\n"); - if (!(Session->Options & WLX_LOGON_OPT_NO_PROFILE)) + if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE)) + { UnloadUserProfile(WLSession->UserToken, ProfileInfo.hProfile); - CloseHandle(Session->UserToken); + CloseHandle(Session->UserToken); + Session->UserToken = NULL; + } return FALSE; } /* FIXME: use Session->Profile.pszEnvironment */ @@ -195,7 +210,15 @@ HandleLogon( /* Set default language */ if (!SetDefaultLanguage(TRUE)) + { + if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE)) + { + UnloadUserProfile(WLSession->UserToken, ProfileInfo.hProfile); + CloseHandle(Session->UserToken); + Session->UserToken = NULL; + } return FALSE; + } if (!Session->Gina.Functions.WlxActivateUserShell( Session->Gina.Context, @@ -203,6 +226,12 @@ HandleLogon( NULL, /* FIXME */ lpEnvironment)) { + if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE)) + { + UnloadUserProfile(WLSession->UserToken, ProfileInfo.hProfile); + CloseHandle(Session->UserToken); + Session->UserToken = NULL; + } return FALSE; } /*if(!GinaInst->Functions->WlxActivateUserShell(GinaInst->Context, @@ -222,7 +251,7 @@ HandleLogon( */ if (!InitializeScreenSaver(Session)) - ERR("WL: Failed to initialize screen saver\n"); + WARN("WL: Failed to initialize screen saver\n"); return TRUE; } @@ -241,7 +270,7 @@ LogoffShutdownThread(LPVOID Parameter) { PLOGOFF_SHUTDOWN_DATA LSData = (PLOGOFF_SHUTDOWN_DATA)Parameter; - if (LSData->Session->UserToken && !ImpersonateLoggedOnUser(LSData->Session->UserToken)) + if (LSData->Session->UserToken != NULL && !ImpersonateLoggedOnUser(LSData->Session->UserToken)) { ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError()); return 0; @@ -363,7 +392,7 @@ UninitializeSAS( UnregisterClassW(WINLOGON_SAS_CLASS, hAppInstance); } -BOOL +NTSTATUS HandleShutdown( IN OUT PWLSESSION Session, IN DWORD wlxAction) @@ -423,11 +452,11 @@ HandleShutdown( if (FALSE) { /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */ - DialogBox(hAppInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), 0, ShutdownComputerWindowProc); + DialogBox(hAppInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), GetDesktopWindow(), ShutdownComputerWindowProc); } NtShutdownSystem(ShutdownNoReboot); } - return TRUE; + return STATUS_SUCCESS; } static VOID @@ -508,9 +537,9 @@ DispatchSAS( DWORD wlxAction = WLX_SAS_ACTION_NONE; if (Session->LogonStatus == WKSTA_IS_LOGGED_ON) - wlxAction = Session->Gina.Functions.WlxLoggedOnSAS(Session->Gina.Context, dwSasType, NULL); + wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOnSAS(Session->Gina.Context, dwSasType, NULL); else if (Session->LogonStatus == WKSTA_IS_LOCKED) - wlxAction = Session->Gina.Functions.WlxWkstaLockedSAS(Session->Gina.Context, dwSasType); + wlxAction = (DWORD)Session->Gina.Functions.WlxWkstaLockedSAS(Session->Gina.Context, dwSasType); else { /* Display a new dialog (if necessary) */ @@ -528,7 +557,7 @@ DispatchSAS( ZeroMemory(&Session->Profile, sizeof(Session->Profile)); Session->Options = 0; - wlxAction = Session->Gina.Functions.WlxLoggedOutSAS( + wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOutSAS( Session->Gina.Context, Session->SASAction, &Session->LogonId, diff --git a/reactos/base/system/winlogon/screensaver.c b/reactos/base/system/winlogon/screensaver.c index a1c61a8789e..197079af812 100644 --- a/reactos/base/system/winlogon/screensaver.c +++ b/reactos/base/system/winlogon/screensaver.c @@ -244,7 +244,7 @@ StartScreenSaver( PROCESS_INFORMATION ProcessInformation; HANDLE HandleArray[2]; LONG rc; - NTSTATUS Status; + DWORD Status; BOOL ret = FALSE; if (!ImpersonateLoggedOnUser(Session->UserToken)) diff --git a/reactos/base/system/winlogon/setup.c b/reactos/base/system/winlogon/setup.c index c5e41b75376..c076a1ae8fb 100644 --- a/reactos/base/system/winlogon/setup.c +++ b/reactos/base/system/winlogon/setup.c @@ -70,7 +70,7 @@ GetSetupType(VOID) } -BOOL +static BOOL SetSetupType (DWORD dwSetupType) { DWORD dwError; diff --git a/reactos/base/system/winlogon/setup.h b/reactos/base/system/winlogon/setup.h index 5089d11cebf..6a391df3830 100644 --- a/reactos/base/system/winlogon/setup.h +++ b/reactos/base/system/winlogon/setup.h @@ -28,7 +28,6 @@ #define __SETUP_H__ DWORD GetSetupType (VOID); -BOOL SetSetupType (DWORD dwSetupType); BOOL RunSetup (VOID); #endif /* __SETUP_H__ */ diff --git a/reactos/base/system/winlogon/winlogon.c b/reactos/base/system/winlogon/winlogon.c index fbda5936356..81bb593b266 100644 --- a/reactos/base/system/winlogon/winlogon.c +++ b/reactos/base/system/winlogon/winlogon.c @@ -102,10 +102,8 @@ StartCustomService( hService = OpenServiceW(hSCManager, ServiceName, SERVICE_START); if (!hService) goto cleanup; -#if 0 if (!StartServiceW(hService, 0, NULL)) goto cleanup; -#endif ret = TRUE; @@ -140,9 +138,7 @@ StartLsass(VOID) return FALSE; } -#if 0 WaitForSingleObject(LsassInitEvent, INFINITE); -#endif CloseHandle(LsassInitEvent); return TRUE; @@ -360,6 +356,7 @@ WinMain( ULONG AuthenticationPackage; NTSTATUS Status; #endif + ULONG HardErrorResponse; MSG Msg; UNREFERENCED_PARAMETER(hPrevInstance); @@ -377,19 +374,19 @@ WinMain( } WLSession = (PWLSESSION)HeapAlloc(GetProcessHeap(), 0, sizeof(WLSESSION)); - ZeroMemory(WLSession, sizeof(WLSESSION)); if (!WLSession) { ERR("WL: Could not allocate memory for winlogon instance\n"); - NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0); + NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } + ZeroMemory(WLSession, sizeof(WLSESSION)); WLSession->DialogTimeout = 120; /* 2 minutes */ if (!CreateWindowStationAndDesktops(WLSession)) { ERR("WL: Could not create window station and desktops\n"); - NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0); + NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } LockWorkstation(WLSession); @@ -397,7 +394,7 @@ WinMain( if (!StartServicesManager()) { ERR("WL: Could not start services.exe\n"); - NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0); + NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } @@ -420,7 +417,7 @@ WinMain( if (!StartLsass()) { DPRINT1("WL: Failed to start lsass.exe service (error %lu)\n", GetLastError()); - NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0); + NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, OptionOk, &HardErrorResponse); ExitProcess(1); } @@ -428,7 +425,7 @@ WinMain( if (!GinaInit(WLSession)) { ERR("WL: Failed to initialize Gina\n"); - DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_GINALOADFAILED), 0, GinaLoadFailedWindowProc, (LPARAM)L""); + DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_GINALOADFAILED), GetDesktopWindow(), GinaLoadFailedWindowProc, (LPARAM)L""); HandleShutdown(WLSession, WLX_SAS_ACTION_SHUTDOWN_REBOOT); ExitProcess(1); } diff --git a/reactos/base/system/winlogon/winlogon.h b/reactos/base/system/winlogon/winlogon.h index 5e6b5032e6e..82fef70adef 100644 --- a/reactos/base/system/winlogon/winlogon.h +++ b/reactos/base/system/winlogon/winlogon.h @@ -89,7 +89,7 @@ typedef struct _GINAFUNCTIONS /* Functions available if WlxVersion >= WLX_VERSION_1_1 (MS Windows 3.5.1) */ PFWLXSCREENSAVERNOTIFY WlxScreenSaverNotify; /* optional */ - PFWLXSTARTAPPLICATION WlxStartApplication; /* optional, not called ATM */ + PFWLXSTARTAPPLICATION WlxStartApplication; /* optional */ /* Functions available if WlxVersion >= WLX_VERSION_1_2 (MS Windows NT 4.0) */ @@ -179,7 +179,7 @@ UpdatePerUserSystemParameters(DWORD dwUnknown, /* sas.c */ BOOL SetDefaultLanguage( - IN BOOLEAN UserProfile); + IN BOOL UserProfile); BOOL InitializeSAS( @@ -213,7 +213,7 @@ BOOL CreateWindowStationAndDesktops( IN OUT PWLSESSION Session); -BOOL +NTSTATUS HandleShutdown( IN OUT PWLSESSION Session, IN DWORD wlxAction); diff --git a/reactos/base/system/winlogon/wlx.c b/reactos/base/system/winlogon/wlx.c index f81f65f4cea..aa9f0cb4354 100644 --- a/reactos/base/system/winlogon/wlx.c +++ b/reactos/base/system/winlogon/wlx.c @@ -896,7 +896,10 @@ CreateWindowStationAndDesktops( } /* FIXME: big HACK */ - Session->WinlogonDesktop = Session->ApplicationDesktop; + CloseDesktop(Session->WinlogonDesktop); + CloseDesktop(Session->ScreenSaverDesktop); + Session->WinlogonDesktop = OpenDesktopW(L"Default", 0, FALSE, GENERIC_ALL); + Session->ScreenSaverDesktop = OpenDesktopW(L"Default", 0, FALSE, GENERIC_ALL); /* * Switch to winlogon desktop @@ -914,13 +917,25 @@ cleanup: if (!ret) { if (Session->ApplicationDesktop) + { CloseDesktop(Session->ApplicationDesktop); + Session->ApplicationDesktop = NULL; + } if (Session->WinlogonDesktop) + { CloseDesktop(Session->WinlogonDesktop); + Session->WinlogonDesktop = NULL; + } if (Session->ScreenSaverDesktop) + { CloseDesktop(Session->ScreenSaverDesktop); + Session->ScreenSaverDesktop = NULL; + } if (Session->InteractiveWindowStation) + { CloseWindowStation(Session->InteractiveWindowStation); + Session->InteractiveWindowStation = NULL; + } } HeapFree(GetProcessHeap(), 0, pDefaultAcl); HeapFree(GetProcessHeap(), 0, pUserDesktopAcl);