https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4407e0aefabb4b2f88628…
commit 4407e0aefabb4b2f8862886719412dfe41ca34d0
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu Sep 21 22:44:20 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Sep 21 22:44:20 2023 +0900
[SHELL32][SDK] Implement SHOpenEffectiveToken and SHGetUserSessionId (#5713)
- Implement SHOpenEffectiveToken and
SHGetUserSessionId functions.
- Add them to <undocshell.h>.
---
dll/win32/shell32/stubs.cpp | 22 -----------------
dll/win32/shell32/utils.cpp | 53 ++++++++++++++++++++++++++++++++++++++++
sdk/include/reactos/undocshell.h | 3 +++
3 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/dll/win32/shell32/stubs.cpp b/dll/win32/shell32/stubs.cpp
index a048e2c5274..ae4ce677e66 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
-SHOpenEffectiveToken(LPVOID Token)
-{
- FIXME("SHOpenEffectiveToken() stub\n");
- return FALSE;
-}
-
/*
* Unimplemented
*/
@@ -1178,17 +1167,6 @@ SHGetProcessDword(DWORD dwUnknown1, DWORD dwUnknown2)
return 0;
}
-/*
- * Unimplemented
- */
-EXTERN_C LPVOID
-WINAPI
-SHGetUserSessionId(HANDLE hHandle)
-{
- FIXME("SHGetUserSessionId() stub\n");
- return NULL;
-}
-
EXTERN_C
DWORD WINAPI CheckStagingArea(VOID)
{
diff --git a/dll/win32/shell32/utils.cpp b/dll/win32/shell32/utils.cpp
index edb1f64b87d..537f23a6504 100644
--- a/dll/win32/shell32/utils.cpp
+++ b/dll/win32/shell32/utils.cpp
@@ -9,6 +9,59 @@
WINE_DEFAULT_DEBUG_CHANNEL(shell);
+static BOOL OpenEffectiveToken(DWORD DesiredAccess, HANDLE *phToken)
+{
+ BOOL ret;
+
+ if (phToken == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ *phToken = NULL;
+
+ ret = OpenThreadToken(GetCurrentThread(), DesiredAccess, FALSE, phToken);
+ if (!ret && GetLastError() == ERROR_NO_TOKEN)
+ ret = OpenProcessToken(GetCurrentProcess(), DesiredAccess, phToken);
+
+ return ret;
+}
+
+/*************************************************************************
+ * SHOpenEffectiveToken (SHELL32.235)
+ */
+EXTERN_C BOOL WINAPI SHOpenEffectiveToken(_Out_ LPHANDLE phToken)
+{
+ TRACE("%p\n", phToken);
+ return OpenEffectiveToken(TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, phToken);
+}
+
+/*************************************************************************
+ * SHGetUserSessionId (SHELL32.248)
+ */
+EXTERN_C DWORD WINAPI SHGetUserSessionId(_In_opt_ HANDLE hToken)
+{
+ DWORD dwSessionId, dwLength;
+ BOOL bOpenToken = FALSE;
+
+ TRACE("%p\n", hToken);
+
+ if (!hToken)
+ bOpenToken = SHOpenEffectiveToken(&hToken);
+
+ if (!hToken ||
+ !GetTokenInformation(hToken, TokenSessionId, &dwSessionId,
sizeof(dwSessionId), &dwLength))
+ {
+ dwSessionId = 0;
+ }
+
+ if (bOpenToken)
+ CloseHandle(hToken);
+
+ return dwSessionId;
+}
+
/*************************************************************************
* SHGetShellStyleHInstance (SHELL32.749)
*/
diff --git a/sdk/include/reactos/undocshell.h b/sdk/include/reactos/undocshell.h
index 93fc4201d8c..9c74f8d9b00 100644
--- a/sdk/include/reactos/undocshell.h
+++ b/sdk/include/reactos/undocshell.h
@@ -684,6 +684,9 @@ LargeIntegerToString(
_In_opt_ const NUMBERFMTW *pNumberFormat,
_In_ DWORD dwNumberFlags);
+BOOL WINAPI SHOpenEffectiveToken(_Out_ LPHANDLE phToken);
+DWORD WINAPI SHGetUserSessionId(_In_opt_ HANDLE hToken);
+
/*****************************************************************************
* Shell32 resources
*/