[MSGINA] Do not try to impersonate the user on shutdown when we are already logged off

This commit is contained in:
Eric Kohl 2018-05-22 17:35:33 +02:00
parent 4c4c6e88b3
commit 47567abf27
3 changed files with 50 additions and 17 deletions

View file

@ -624,6 +624,13 @@ OnShutDown(
INT ret; INT ret;
DWORD ShutdownOptions; DWORD ShutdownOptions;
TRACE("OnShutDown(%p %p)\n", hwndDlg, pgContext);
pgContext->nShutdownAction = GetDefaultShutdownSelState();
ShutdownOptions = GetDefaultShutdownOptions();
if (pgContext->UserToken != NULL)
{
if (ImpersonateLoggedOnUser(pgContext->UserToken)) if (ImpersonateLoggedOnUser(pgContext->UserToken))
{ {
pgContext->nShutdownAction = LoadShutdownSelState(); pgContext->nShutdownAction = LoadShutdownSelState();
@ -633,13 +640,14 @@ OnShutDown(
else else
{ {
ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError()); ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
pgContext->nShutdownAction = 0; }
ShutdownOptions = 0;
} }
ret = ShutdownDialog(hwndDlg, ShutdownOptions, pgContext); ret = ShutdownDialog(hwndDlg, ShutdownOptions, pgContext);
if (ret == IDOK) if (ret == IDOK)
{
if (pgContext->UserToken != NULL)
{ {
if (ImpersonateLoggedOnUser(pgContext->UserToken)) if (ImpersonateLoggedOnUser(pgContext->UserToken))
{ {
@ -651,6 +659,7 @@ OnShutDown(
ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError()); ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
} }
} }
}
return ret; return ret;
} }

View file

@ -132,12 +132,18 @@ CreateProfile(
/* shutdown.c */ /* shutdown.c */
DWORD
GetDefaultShutdownSelState(VOID);
DWORD DWORD
LoadShutdownSelState(VOID); LoadShutdownSelState(VOID);
VOID VOID
SaveShutdownSelState(DWORD ShutdownCode); SaveShutdownSelState(DWORD ShutdownCode);
DWORD
GetDefaultShutdownOptions(VOID);
DWORD DWORD
GetAllowedShutdownOptions(VOID); GetAllowedShutdownOptions(VOID);

View file

@ -90,6 +90,11 @@ GetShutdownReasonUI(VOID)
// return (VersionInfo.wProductType == VER_NT_WORKSTATION) ? FALSE : TRUE; // return (VersionInfo.wProductType == VER_NT_WORKSTATION) ? FALSE : TRUE;
} }
DWORD
GetDefaultShutdownSelState(VOID)
{
return WLX_SAS_ACTION_SHUTDOWN_POWER_OFF;
}
DWORD DWORD
LoadShutdownSelState(VOID) LoadShutdownSelState(VOID)
@ -211,6 +216,12 @@ SaveShutdownSelState(
RegCloseKey(hKey); RegCloseKey(hKey);
} }
DWORD
GetDefaultShutdownOptions(VOID)
{
return WLX_SHUTDOWN_STATE_POWER_OFF | WLX_SHUTDOWN_STATE_REBOOT;
}
DWORD DWORD
GetAllowedShutdownOptions(VOID) GetAllowedShutdownOptions(VOID)
{ {
@ -271,6 +282,13 @@ UpdateShutdownDesc(
LoadStringW(pContext->pgContext->hDllInstance, DescId, szBuffer, _countof(szBuffer)); LoadStringW(pContext->pgContext->hDllInstance, DescId, szBuffer, _countof(szBuffer));
SetDlgItemTextW(hDlg, IDC_SHUTDOWN_DESCRIPTION, szBuffer); SetDlgItemTextW(hDlg, IDC_SHUTDOWN_DESCRIPTION, szBuffer);
if (pContext->bReasonUI)
{
EnableWindow(GetDlgItem(hDlg, IDC_REASON_PLANNED), (ShutdownCode != WLX_SAS_ACTION_LOGOFF));
EnableWindow(GetDlgItem(hDlg, IDC_REASON_LIST), (ShutdownCode != WLX_SAS_ACTION_LOGOFF));
EnableWindow(GetDlgItem(hDlg, IDC_REASON_COMMENT), (ShutdownCode != WLX_SAS_ACTION_LOGOFF));
}
} }
static VOID static VOID