Author: hbelusca Date: Sat Feb 14 05:27:55 2015 New Revision: 66252
URL: http://svn.reactos.org/svn/reactos?rev=66252&view=rev Log: [WINLOGON] - Reshuffle a bit some code. - Never fail if the kill-COM-processes thread fails to be created. - WlxLogoff GINA callback *must* be called *after* our logoff handling (with HandleLogoff). This is what happens on Windows (just add breakpoints on ExitWindowsEx and on WlxIsLogoffOk and WlxLogoff, and enable winlogon tracing).
[WIN32K] Rename a flag to something more meaningful, and fix a flag filtering bug: lParams = wParam & something; ---> lParams = lParam & something; (the wParam is used for something else).
Part 12/X CORE-8322
Modified: trunk/reactos/base/system/winlogon/sas.c trunk/reactos/base/system/winlogon/winlogon.c trunk/reactos/include/reactos/undocuser.h trunk/reactos/win32ss/user/ntuser/shutdown.c
Modified: trunk/reactos/base/system/winlogon/sas.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/sas.c?... ============================================================================== --- trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] (original) +++ trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] Sat Feb 14 05:27:55 2015 @@ -483,10 +483,9 @@ HeapFree(GetProcessHeap(), 0, Session->Profile); } Session->Profile = NULL; - if (!ret - && ProfileInfo.hProfile != INVALID_HANDLE_VALUE) - { - UnloadUserProfile(WLSession->UserToken, ProfileInfo.hProfile); + if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE) + { + UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile); } RemoveStatusMessage(Session); if (!ret) @@ -494,6 +493,13 @@ CloseHandle(Session->UserToken); Session->UserToken = NULL; } + + if (ret) + { + SwitchDesktop(Session->ApplicationDesktop); + Session->LogonState = STATE_LOGGED_ON; + } + return ret; }
@@ -504,6 +510,7 @@ LogoffShutdownThread( LPVOID Parameter) { + DWORD ret = 1; PLOGOFF_SHUTDOWN_DATA LSData = (PLOGOFF_SHUTDOWN_DATA)Parameter; UINT uFlags;
@@ -530,14 +537,13 @@ if (!ExitWindowsEx(uFlags, 0)) { ERR("Unable to kill user apps, error %lu\n", GetLastError()); - RevertToSelf(); - return 0; + ret = 0; }
if (LSData->Session->UserToken) RevertToSelf();
- return 1; + return ret; }
static @@ -546,6 +552,7 @@ KillComProcesses( LPVOID Parameter) { + DWORD ret = 1; PLOGOFF_SHUTDOWN_DATA LSData = (PLOGOFF_SHUTDOWN_DATA)Parameter;
ERR("In KillComProcesses\n"); @@ -561,14 +568,13 @@ if (!ExitWindowsEx(EWX_CALLER_WINLOGON | EWX_NONOTIFY | EWX_FORCE | EWX_LOGOFF, 0)) { ERR("Unable to kill COM apps, error %lu\n", GetLastError()); - RevertToSelf(); - return 0; + ret = 0; }
if (LSData->Session->UserToken) RevertToSelf();
- return 1; + return ret; }
static @@ -709,8 +715,6 @@ DWORD exitCode; NTSTATUS Status;
- DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS); - /* Prepare data for logoff thread */ LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA)); if (!LSData) @@ -729,10 +733,8 @@ return Status; }
- /* Run logoff thread */ hThread = CreateThread(psa, 0, LogoffShutdownThread, (LPVOID)LSData, 0, NULL); - if (!hThread) { ERR("Unable to create logoff thread, error %lu\n", GetLastError()); @@ -758,35 +760,28 @@ return STATUS_UNSUCCESSFUL; }
+ SwitchDesktop(Session->WinlogonDesktop); + + // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF); + + // FIXME: Closing network connections! + // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
/* Kill remaining COM apps. Only at logoff! */ hThread = CreateThread(psa, 0, KillComProcesses, (LPVOID)LSData, 0, NULL); + if (hThread) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + }
/* We're done with the SECURITY_DESCRIPTOR */ DestroyLogoffSecurityAttributes(psa); psa = NULL;
- if (!hThread) - { - ERR("Unable to create kill COM apps thread, error %lu\n", GetLastError()); - HeapFree(GetProcessHeap(), 0, LSData); - return STATUS_UNSUCCESSFUL; - } - WaitForSingleObject(hThread, INFINITE); HeapFree(GetProcessHeap(), 0, LSData); - if (!GetExitCodeThread(hThread, &exitCode)) - { - ERR("Unable to get exit code of kill COM apps thread (error %lu)\n", GetLastError()); - CloseHandle(hThread); - return STATUS_UNSUCCESSFUL; - } - CloseHandle(hThread); - if (exitCode == 0) - { - ERR("Kill COM apps thread returned failure\n"); - return STATUS_UNSUCCESSFUL; - } - + + DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
UnloadUserProfile(Session->UserToken, Session->hProfileInfo); CloseHandle(Session->UserToken); @@ -854,6 +849,7 @@ DWORD exitCode; BOOLEAN Old;
+ // SwitchDesktop(Session->WinlogonDesktop); DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISSHUTTINGDOWN);
/* Prepare data for shutdown thread */ @@ -905,13 +901,16 @@ FIXME("FIXME: Call SMSS API #1\n"); RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, TRUE, FALSE, &Old); if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT) + { NtShutdownSystem(ShutdownReboot); + } else { if (FALSE) { /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */ - DialogBox(hAppInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), GetDesktopWindow(), ShutdownComputerWindowProc); + DialogBox(hAppInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), + GetDesktopWindow(), ShutdownComputerWindowProc); } NtShutdownSystem(ShutdownNoReboot); } @@ -930,12 +929,7 @@ case WLX_SAS_ACTION_LOGON: /* 0x01 */ if (Session->LogonState == STATE_LOGGED_OFF_SAS) { - if (HandleLogon(Session)) - { - SwitchDesktop(Session->ApplicationDesktop); - Session->LogonState = STATE_LOGGED_ON; - } - else + if (!HandleLogon(Session)) { Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context); } @@ -960,7 +954,7 @@ case WLX_SAS_ACTION_LOCK_WKSTA: /* 0x03 */ if (Session->Gina.Functions.WlxIsLockOk(Session->Gina.Context)) { - SwitchDesktop(WLSession->WinlogonDesktop); + SwitchDesktop(Session->WinlogonDesktop); Session->LogonState = STATE_LOCKED; Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context); } @@ -973,16 +967,17 @@ { if (!Session->Gina.Functions.WlxIsLogoffOk(Session->Gina.Context)) break; - SwitchDesktop(WLSession->WinlogonDesktop); - Session->Gina.Functions.WlxLogoff(Session->Gina.Context); if (!NT_SUCCESS(HandleLogoff(Session, EWX_LOGOFF))) { RemoveStatusMessage(Session); break; } + Session->Gina.Functions.WlxLogoff(Session->Gina.Context); } if (WLX_SHUTTINGDOWN(wlxAction)) { + // FIXME: WlxShutdown should be done from inside HandleShutdown, + // after having displayed "ReactOS is shutting down" message. Session->Gina.Functions.WlxShutdown(Session->Gina.Context, wlxAction); if (!NT_SUCCESS(HandleShutdown(Session, wlxAction))) { @@ -997,12 +992,12 @@ } break; case WLX_SAS_ACTION_TASKLIST: /* 0x07 */ - SwitchDesktop(WLSession->ApplicationDesktop); + SwitchDesktop(Session->ApplicationDesktop); Session->LogonState = STATE_LOGGED_ON; StartTaskManager(Session); break; case WLX_SAS_ACTION_UNLOCK_WKSTA: /* 0x08 */ - SwitchDesktop(WLSession->ApplicationDesktop); + SwitchDesktop(Session->ApplicationDesktop); Session->LogonState = STATE_LOGGED_ON; break; default:
Modified: trunk/reactos/base/system/winlogon/winlogon.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/winlog... ============================================================================== --- trunk/reactos/base/system/winlogon/winlogon.c [iso-8859-1] (original) +++ trunk/reactos/base/system/winlogon/winlogon.c [iso-8859-1] Sat Feb 14 05:27:55 2015 @@ -438,8 +438,8 @@ ExitProcess(2); }
- //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_PREPARENETWORKCONNECTIONS); - //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGCOMPUTERSETTINGS); + // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_PREPARENETWORKCONNECTIONS); + // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGCOMPUTERSETTINGS);
/* Display logged out screen */ WLSession->LogonState = STATE_INIT;
Modified: trunk/reactos/include/reactos/undocuser.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/undocuser.h... ============================================================================== --- trunk/reactos/include/reactos/undocuser.h [iso-8859-1] (original) +++ trunk/reactos/include/reactos/undocuser.h [iso-8859-1] Sat Feb 14 05:27:55 2015 @@ -90,7 +90,7 @@ // Definitions used by WM_CLIENTSHUTDOWN // // Client Shutdown messages -#define MCS_SHUTDOWNTIMERS 1 +#define MCS_ENDSESSION 1 #define MCS_QUERYENDSESSION 2 // Client Shutdown returns #define MCSR_GOODFORSHUTDOWN 1
Modified: trunk/reactos/win32ss/user/ntuser/shutdown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/shutdow... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/shutdown.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/shutdown.c [iso-8859-1] Sat Feb 14 05:27:55 2015 @@ -30,8 +30,8 @@ LRESULT lResult = MCSR_GOODFORSHUTDOWN; HWND *List;
- lParams = wParam & (ENDSESSION_LOGOFF|ENDSESSION_CRITICAL|ENDSESSION_CLOSEAPP); - KillTimers = wParam & MCS_SHUTDOWNTIMERS ? TRUE : FALSE; + KillTimers = wParam & MCS_ENDSESSION ? TRUE : FALSE; + lParams = lParam & (ENDSESSION_LOGOFF | ENDSESSION_CRITICAL | ENDSESSION_CLOSEAPP);
/* First, send end sessions to children */ List = IntWinListChildren(pWindow);