https://git.reactos.org/?p=reactos.git;a=commitdiff;h=47567abf279faefd48ad1…
commit 47567abf279faefd48ad1bec8dc48ffc06eaab61
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Tue May 22 17:35:33 2018 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Tue May 22 17:35:33 2018 +0200
[MSGINA] Do not try to impersonate the user on shutdown when we are already logged
off
---
dll/win32/msgina/gui.c | 39 ++++++++++++++++++++++++---------------
dll/win32/msgina/msgina.h | 6 ++++++
dll/win32/msgina/shutdown.c | 18 ++++++++++++++++++
3 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/dll/win32/msgina/gui.c b/dll/win32/msgina/gui.c
index c520f07b31..1e1069eb27 100644
--- a/dll/win32/msgina/gui.c
+++ b/dll/win32/msgina/gui.c
@@ -624,26 +624,17 @@ OnShutDown(
INT ret;
DWORD ShutdownOptions;
- if (ImpersonateLoggedOnUser(pgContext->UserToken))
- {
- pgContext->nShutdownAction = LoadShutdownSelState();
- ShutdownOptions = GetAllowedShutdownOptions();
- RevertToSelf();
- }
- else
- {
- ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n",
GetLastError());
- pgContext->nShutdownAction = 0;
- ShutdownOptions = 0;
- }
+ TRACE("OnShutDown(%p %p)\n", hwndDlg, pgContext);
- ret = ShutdownDialog(hwndDlg, ShutdownOptions, pgContext);
+ pgContext->nShutdownAction = GetDefaultShutdownSelState();
+ ShutdownOptions = GetDefaultShutdownOptions();
- if (ret == IDOK)
+ if (pgContext->UserToken != NULL)
{
if (ImpersonateLoggedOnUser(pgContext->UserToken))
{
- SaveShutdownSelState(pgContext->nShutdownAction);
+ pgContext->nShutdownAction = LoadShutdownSelState();
+ ShutdownOptions = GetAllowedShutdownOptions();
RevertToSelf();
}
else
@@ -652,6 +643,24 @@ OnShutDown(
}
}
+ ret = ShutdownDialog(hwndDlg, ShutdownOptions, pgContext);
+
+ if (ret == IDOK)
+ {
+ if (pgContext->UserToken != NULL)
+ {
+ if (ImpersonateLoggedOnUser(pgContext->UserToken))
+ {
+ SaveShutdownSelState(pgContext->nShutdownAction);
+ RevertToSelf();
+ }
+ else
+ {
+ ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n",
GetLastError());
+ }
+ }
+ }
+
return ret;
}
diff --git a/dll/win32/msgina/msgina.h b/dll/win32/msgina/msgina.h
index 19eabf9eb3..e2b6b5bfb4 100644
--- a/dll/win32/msgina/msgina.h
+++ b/dll/win32/msgina/msgina.h
@@ -132,12 +132,18 @@ CreateProfile(
/* shutdown.c */
+DWORD
+GetDefaultShutdownSelState(VOID);
+
DWORD
LoadShutdownSelState(VOID);
VOID
SaveShutdownSelState(DWORD ShutdownCode);
+DWORD
+GetDefaultShutdownOptions(VOID);
+
DWORD
GetAllowedShutdownOptions(VOID);
diff --git a/dll/win32/msgina/shutdown.c b/dll/win32/msgina/shutdown.c
index ca2528a7bb..1351eabc14 100644
--- a/dll/win32/msgina/shutdown.c
+++ b/dll/win32/msgina/shutdown.c
@@ -90,6 +90,11 @@ GetShutdownReasonUI(VOID)
// return (VersionInfo.wProductType == VER_NT_WORKSTATION) ? FALSE : TRUE;
}
+DWORD
+GetDefaultShutdownSelState(VOID)
+{
+ return WLX_SAS_ACTION_SHUTDOWN_POWER_OFF;
+}
DWORD
LoadShutdownSelState(VOID)
@@ -211,6 +216,12 @@ SaveShutdownSelState(
RegCloseKey(hKey);
}
+DWORD
+GetDefaultShutdownOptions(VOID)
+{
+ return WLX_SHUTDOWN_STATE_POWER_OFF | WLX_SHUTDOWN_STATE_REBOOT;
+}
+
DWORD
GetAllowedShutdownOptions(VOID)
{
@@ -271,6 +282,13 @@ UpdateShutdownDesc(
LoadStringW(pContext->pgContext->hDllInstance, DescId, szBuffer,
_countof(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