https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d1e9fe13de06e9c6d17e80f2b3dd4804235b9650

commit d1e9fe13de06e9c6d17e80f2b3dd4804235b9650
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Tue Sep 26 07:36:07 2023 +0900
Commit:     GitHub <nore...@github.com>
CommitDate: Tue Sep 26 07:36:07 2023 +0900

    [SHELL32][SDK] Implement SHTestTokenPrivilegeW (#5725)
    
    and modify shell32.spec.
---
 dll/win32/shell32/shell32.spec   |  2 +-
 dll/win32/shell32/stubs.cpp      | 11 --------
 dll/win32/shell32/utils.cpp      | 61 ++++++++++++++++++++++++++++++++++++++++
 sdk/include/reactos/undocshell.h |  3 ++
 4 files changed, 65 insertions(+), 12 deletions(-)

diff --git a/dll/win32/shell32/shell32.spec b/dll/win32/shell32/shell32.spec
index a89d475a913..9cc8bfd8cdc 100644
--- a/dll/win32/shell32/shell32.spec
+++ b/dll/win32/shell32/shell32.spec
@@ -232,7 +232,7 @@
 233 stdcall -noname SHGetUserPicturePathW(wstr long ptr)
 234 stdcall -noname SHSetUserPicturePathW(wstr long ptr)
 235 stdcall -noname SHOpenEffectiveToken(ptr)
-236 stdcall -noname SHTestTokenPrivilegeW(ptr ptr)
+236 stdcall -noname SHTestTokenPrivilegeW(ptr wstr)
 237 stdcall -noname SHShouldShowWizards(ptr)
 238 stdcall InternalExtractIconListW(ptr wstr ptr)
 239 stdcall PathIsSlowW(wstr long)
diff --git a/dll/win32/shell32/stubs.cpp b/dll/win32/shell32/stubs.cpp
index ae4ce677e66..f8518336906 100644
--- a/dll/win32/shell32/stubs.cpp
+++ b/dll/win32/shell32/stubs.cpp
@@ -1099,17 +1099,6 @@ SHSetUserPicturePathW(LPCWSTR lpPath, int csidl, LPVOID 
lpUnknown)
     return E_FAIL;
 }
 
-/*
- * Unimplemented
- */
-EXTERN_C BOOL
-WINAPI
-SHTestTokenPrivilegeW(HANDLE hToken, LPDWORD ReturnLength)
-{
-    FIXME("SHTestTokenPrivilegeW() stub\n");
-    return FALSE;
-}
-
 /*
  * Unimplemented
  */
diff --git a/dll/win32/shell32/utils.cpp b/dll/win32/shell32/utils.cpp
index 5f3e38175ec..57ade40713e 100644
--- a/dll/win32/shell32/utils.cpp
+++ b/dll/win32/shell32/utils.cpp
@@ -103,6 +103,67 @@ SHInvokePrivilegedFunctionW(
     return hr;
 }
 
+/*************************************************************************
+ *                SHTestTokenPrivilegeW (SHELL32.236)
+ *
+ * @see http://undoc.airesoft.co.uk/shell32.dll/SHTestTokenPrivilegeW.php
+ */
+EXTERN_C
+BOOL WINAPI
+SHTestTokenPrivilegeW(_In_opt_ HANDLE hToken, _In_z_ LPCWSTR lpName)
+{
+    LUID Luid;
+    DWORD dwLength;
+    PTOKEN_PRIVILEGES pTokenPriv;
+    HANDLE hNewToken = NULL;
+    BOOL ret = FALSE;
+
+    TRACE("(%p, %s)\n", hToken, debugstr_w(lpName));
+
+    if (!lpName)
+        return FALSE;
+
+    if (!hToken)
+    {
+        if (!SHOpenEffectiveToken(&hNewToken))
+            goto Quit;
+
+        if (!hNewToken)
+            return FALSE;
+
+        hToken = hNewToken;
+    }
+
+    if (!LookupPrivilegeValueW(NULL, lpName, &Luid))
+        return FALSE;
+
+    dwLength = 0;
+    if (!GetTokenInformation(hToken, TokenPrivileges, NULL, 0, &dwLength))
+        goto Quit;
+
+    pTokenPriv = (PTOKEN_PRIVILEGES)LocalAlloc(LPTR, dwLength);
+    if (!pTokenPriv)
+        goto Quit;
+
+    if (GetTokenInformation(hToken, TokenPrivileges, pTokenPriv, dwLength, 
&dwLength))
+    {
+        UINT iPriv, cPrivs;
+        cPrivs = pTokenPriv->PrivilegeCount;
+        for (iPriv = 0; !ret && iPriv < cPrivs; ++iPriv)
+        {
+            ret = RtlEqualLuid(&Luid, &pTokenPriv->Privileges[iPriv].Luid);
+        }
+    }
+
+    LocalFree(pTokenPriv);
+
+Quit:
+    if (hToken == hNewToken)
+        CloseHandle(hNewToken);
+
+    return ret;
+}
+
 /*************************************************************************
  *                SHGetShellStyleHInstance (SHELL32.749)
  */
diff --git a/sdk/include/reactos/undocshell.h b/sdk/include/reactos/undocshell.h
index 312804e7d73..1577466ab9f 100644
--- a/sdk/include/reactos/undocshell.h
+++ b/sdk/include/reactos/undocshell.h
@@ -695,6 +695,9 @@ SHInvokePrivilegedFunctionW(
     _In_ PRIVILEGED_FUNCTION fn,
     _In_opt_ LPARAM lParam);
 
+BOOL WINAPI
+SHTestTokenPrivilegeW(_In_opt_ HANDLE hToken, _In_z_ LPCWSTR lpName);
+
 /*****************************************************************************
  * Shell32 resources
  */

Reply via email to