[MSGINA] Do not try to impersonate the user on shutdown when we are already logged off
authorEric Kohl <eric.kohl@reactos.org>
Tue, 22 May 2018 15:35:33 +0000 (17:35 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 22 May 2018 15:35:33 +0000 (17:35 +0200)
dll/win32/msgina/gui.c
dll/win32/msgina/msgina.h
dll/win32/msgina/shutdown.c

index c520f07..1e1069e 100644 (file)
@@ -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;
 }
 
index 19eabf9..e2b6b5b 100644 (file)
@@ -132,12 +132,18 @@ CreateProfile(
 
 /* shutdown.c */
 
+DWORD
+GetDefaultShutdownSelState(VOID);
+
 DWORD
 LoadShutdownSelState(VOID);
 
 VOID
 SaveShutdownSelState(DWORD ShutdownCode);
 
+DWORD
+GetDefaultShutdownOptions(VOID);
+
 DWORD
 GetAllowedShutdownOptions(VOID);
 
index ca2528a..1351eab 100644 (file)
@@ -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