Author: hbelusca
Date: Sat Sep 17 22:39:54 2016
New Revision: 72719
URL:
http://svn.reactos.org/svn/reactos?rev=72719&view=rev
Log:
[XDK][MSGINA]: Consistency codestyle fixes.
[SHELL32]
- Use explicit unicode functions;
- Use _countof instead of sizeof(foo)/sizeof(foo[0]);
- Enable the shutdown privilege when we need it, and disable as soon as possible (code
taken from taskmgr).
Modified:
trunk/reactos/dll/win32/msgina/msgina.spec
trunk/reactos/dll/win32/shell32/dialogs/dialogs.cpp
trunk/reactos/sdk/include/xdk/setypes.h
Modified: trunk/reactos/dll/win32/msgina/msgina.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msgina/msgina.sp…
==============================================================================
--- trunk/reactos/dll/win32/msgina/msgina.spec [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msgina/msgina.spec [iso-8859-1] Sat Sep 17 22:39:54 2016
@@ -13,7 +13,7 @@
13 stub -noname ShellStatusHostShuttingDown ; ()
14 stub -noname ShellNotifyThemeUserChange ; (long long)
15 stub -noname ShellSwitchWhenInteractiveReady ; (long long)
-16 stdcall -noname ShellDimScreen (ptr ptr)
+16 stdcall -noname ShellDimScreen(ptr ptr)
17 stub -noname ShellInstallAccountFilterData ; ()
18 stub -noname ShellStatusHostBegin ; (long)
19 stub -noname ShellIsUserInteractiveLogonAllowed ; (long)
Modified: trunk/reactos/dll/win32/shell32/dialogs/dialogs.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/dialogs/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/dialogs/dialogs.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/dialogs/dialogs.cpp [iso-8859-1] Sat Sep 17 22:39:54
2016
@@ -802,15 +802,15 @@
*/
static BOOL ConfirmDialog(HWND hWndOwner, UINT PromptId, UINT TitleId)
{
- WCHAR Prompt[256];
- WCHAR Title[256];
-
- LoadStringW(shell32_hInstance, PromptId, Prompt, sizeof(Prompt) / sizeof(WCHAR));
- LoadStringW(shell32_hInstance, TitleId, Title, sizeof(Title) / sizeof(WCHAR));
- return MessageBoxW(hWndOwner, Prompt, Title, MB_YESNO|MB_ICONQUESTION) == IDYES;
-}
-
-typedef HRESULT (__stdcall *tShellDimScreen) (IUnknown** Unknown, HWND* hWindow);
+ WCHAR Prompt[256];
+ WCHAR Title[256];
+
+ LoadStringW(shell32_hInstance, PromptId, Prompt, _countof(Prompt));
+ LoadStringW(shell32_hInstance, TitleId, Title, _countof(Title));
+ return MessageBoxW(hWndOwner, Prompt, Title, MB_YESNO | MB_ICONQUESTION) == IDYES;
+}
+
+typedef HRESULT (WINAPI *tShellDimScreen)(IUnknown** Unknown, HWND* hWindow);
BOOL
CallShellDimScreen(IUnknown** pUnknown, HWND* hWindow)
@@ -819,8 +819,8 @@
static BOOL Initialized = FALSE;
if (!Initialized)
{
- HMODULE mod = LoadLibrary(TEXT("msgina.dll"));
- ShellDimScreen = (tShellDimScreen)GetProcAddress(mod, MAKEINTRESOURCEA(16));
+ HMODULE mod = LoadLibraryW(L"msgina.dll");
+ ShellDimScreen = (tShellDimScreen)GetProcAddress(mod, (LPCSTR)16);
Initialized = TRUE;
}
@@ -831,6 +831,33 @@
}
+/* Used to get the shutdown privilege */
+static BOOL
+EnablePrivilege(LPCWSTR lpszPrivilegeName, BOOL bEnablePrivilege)
+{
+ BOOL Success;
+ HANDLE hToken;
+ TOKEN_PRIVILEGES tp;
+
+ Success = OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES,
+ &hToken);
+ if (!Success) return Success;
+
+ Success = LookupPrivilegeValueW(NULL,
+ lpszPrivilegeName,
+ &tp.Privileges[0].Luid);
+ if (!Success) goto Quit;
+
+ tp.PrivilegeCount = 1;
+ tp.Privileges[0].Attributes = (bEnablePrivilege ? SE_PRIVILEGE_ENABLED : 0);
+
+ Success = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
+
+Quit:
+ CloseHandle(hToken);
+ return Success;
+}
/*************************************************************************
* RestartDialogEx [SHELL32.730]
@@ -842,25 +869,16 @@
CComPtr<IUnknown> fadeHandler;
HWND parent;
+
if (!CallShellDimScreen(&fadeHandler, &parent))
parent = hWndOwner;
/* FIXME: use lpwstrReason */
if (ConfirmDialog(parent, IDS_RESTART_PROMPT, IDS_RESTART_TITLE))
{
- HANDLE hToken;
- TOKEN_PRIVILEGES npr;
-
- /* enable the shutdown privilege for the current process */
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
- {
- LookupPrivilegeValueA(0, "SeShutdownPrivilege",
&npr.Privileges[0].Luid);
- npr.PrivilegeCount = 1;
- npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
- CloseHandle(hToken);
- }
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
ExitWindowsEx(EWX_REBOOT, uReason);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
}
return 0;
@@ -870,21 +888,20 @@
* LogOffDialogProc
*
* NOTES: Used to make the Log Off dialog work
- *
- */
-INT_PTR CALLBACK LogOffDialogProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
-{
- switch(Message)
+ */
+INT_PTR CALLBACK LogOffDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
{
case WM_INITDIALOG:
- {
return TRUE;
- }
+
case WM_CLOSE:
EndDialog(hwnd, IDCANCEL);
break;
+
case WM_COMMAND:
- switch(LOWORD(wParam))
+ switch (LOWORD(wParam))
{
case IDOK:
ExitWindowsEx(EWX_LOGOFF, 0);
@@ -894,12 +911,12 @@
break;
}
break;
+
default:
break;
}
return FALSE;
}
-
/*************************************************************************
* LogoffWindowsDialog [SHELL32.54]
@@ -909,13 +926,13 @@
{
CComPtr<IUnknown> fadeHandler;
HWND parent;
+
if (!CallShellDimScreen(&fadeHandler, &parent))
parent = hWndOwner;
- DialogBox(shell32_hInstance, MAKEINTRESOURCE(IDD_LOG_OFF), parent,
LogOffDialogProc);
+ DialogBoxW(shell32_hInstance, MAKEINTRESOURCEW(IDD_LOG_OFF), parent,
LogOffDialogProc);
return 0;
}
-
/*************************************************************************
* RestartDialog [SHELL32.59]
@@ -924,27 +941,6 @@
int WINAPI RestartDialog(HWND hWndOwner, LPCWSTR lpstrReason, DWORD uFlags)
{
return RestartDialogEx(hWndOwner, lpstrReason, uFlags, 0);
-}
-
- /*************************************************************************
- * Used to get the shutdown privilege
- */
-VOID ExitWindows_GetShutdownPrivilege(VOID)
-{
- HANDLE hToken;
- TOKEN_PRIVILEGES npr;
-
- /* enable shut down privilege for current process */
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
- {
- LookupPrivilegeValueA(0, "SeShutdownPrivilege",
&npr.Privileges[0].Luid);
-
- npr.PrivilegeCount = 1;
- npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
-
- CloseHandle(hToken);
- }
}
/*************************************************************************
@@ -960,8 +956,9 @@
if (ConfirmDialog(hWndOwner, IDS_SHUTDOWN_PROMPT, IDS_SHUTDOWN_TITLE))
{
- ExitWindows_GetShutdownPrivilege();
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
ExitWindowsEx(EWX_SHUTDOWN, 0);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
}
}
@@ -979,7 +976,7 @@
void WINAPI ExitWindowsDialog(HWND hWndOwner)
{
typedef DWORD (WINAPI *ShellShFunc)(HWND hParent, WCHAR *Username, BOOL
bHideLogoff);
- HINSTANCE msginaDll = LoadLibraryA("msgina.dll");
+ HINSTANCE msginaDll = LoadLibraryW(L"msgina.dll");
TRACE("(%p)\n", hWndOwner);
@@ -990,21 +987,21 @@
/* If the DLL cannot be found for any reason, then it simply uses a
dialog box to ask if the user wants to shut down the computer. */
- if(!msginaDll)
+ if (!msginaDll)
{
TRACE("Unable to load msgina.dll.\n");
ExitWindowsDialog_backup(parent);
return;
}
- ShellShFunc pShellShutdownDialog = (ShellShFunc) GetProcAddress(msginaDll,
"ShellShutdownDialog");
-
- if(pShellShutdownDialog)
+ ShellShFunc pShellShutdownDialog = (ShellShFunc)GetProcAddress(msginaDll,
"ShellShutdownDialog");
+
+ if (pShellShutdownDialog)
{
/* Actually call the function */
DWORD returnValue = pShellShutdownDialog(parent, NULL, FALSE);
- switch(returnValue)
+ switch (returnValue)
{
case 0x01: /* Log off user */
{
@@ -1013,8 +1010,9 @@
}
case 0x02: /* Shut down */
{
- ExitWindows_GetShutdownPrivilege();
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
ExitWindowsEx(EWX_SHUTDOWN, 0);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
break;
}
case 0x03: /* Install Updates/Shutdown (?) */
@@ -1023,25 +1021,28 @@
}
case 0x04: /* Reboot */
{
- ExitWindows_GetShutdownPrivilege();
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
ExitWindowsEx(EWX_REBOOT, 0);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
break;
}
case 0x10: /* Sleep */
{
- if(IsPwrSuspendAllowed())
- {
- ExitWindows_GetShutdownPrivilege();
+ if (IsPwrSuspendAllowed())
+ {
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
SetSuspendState(FALSE, FALSE, FALSE);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
}
break;
}
case 0x40: /* Hibernate */
{
- if(IsPwrHibernateAllowed())
- {
- ExitWindows_GetShutdownPrivilege();
+ if (IsPwrHibernateAllowed())
+ {
+ EnablePrivilege(L"SeShutdownPrivilege", TRUE);
SetSuspendState(TRUE, FALSE, TRUE);
+ EnablePrivilege(L"SeShutdownPrivilege", FALSE);
}
break;
}
@@ -1054,7 +1055,8 @@
{
/* If the function cannot be found, then revert to using the backup solution */
TRACE("Unable to find the 'ShellShutdownDialog' function");
- FreeLibrary(msginaDll);
ExitWindowsDialog_backup(parent);
}
-}
+
+ FreeLibrary(msginaDll);
+}
Modified: trunk/reactos/sdk/include/xdk/setypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/include/xdk/setypes.h?…
==============================================================================
--- trunk/reactos/sdk/include/xdk/setypes.h [iso-8859-1] (original)
+++ trunk/reactos/sdk/include/xdk/setypes.h [iso-8859-1] Sat Sep 17 22:39:54 2016
@@ -61,7 +61,7 @@
/* Privilege attributes */
#define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
#define SE_PRIVILEGE_ENABLED (0x00000002L)
-#define SE_PRIVILEGE_REMOVED (0X00000004L)
+#define SE_PRIVILEGE_REMOVED (0x00000004L)
#define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
#define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \