https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0649f25b48753ed057151…
commit 0649f25b48753ed05715104cd83058c6d1d60f48
Author: Ged Murphy <ged.murphy(a)crowdstrike.com>
AuthorDate: Mon Mar 4 11:02:38 2019 +0000
Commit: Ged Murphy <ged.murphy(a)crowdstrike.com>
CommitDate: Mon Mar 4 11:54:43 2019 +0000
[SHELL32] Implement SHTestTokenMembership and forward IsUserAnAdmin to it
Moved to the bottom of the file with the other ros functions to help keep wine syncs
easier.
---
dll/win32/shell32/stubs.cpp | 11 ---
dll/win32/shell32/wine/shellord.c | 143 ++++++++++++++++++--------------------
sdk/include/psdk/shellapi.h | 8 +++
3 files changed, 76 insertions(+), 86 deletions(-)
diff --git a/dll/win32/shell32/stubs.cpp b/dll/win32/shell32/stubs.cpp
index 8bc2f65296..1c7996df8a 100644
--- a/dll/win32/shell32/stubs.cpp
+++ b/dll/win32/shell32/stubs.cpp
@@ -1316,17 +1316,6 @@ SHGetProcessDword(DWORD dwUnknown1, DWORD dwUnknown2)
return 0;
}
-/*
- * Unimplemented
- */
-EXTERN_C BOOL
-WINAPI
-SHTestTokenMembership(HANDLE TokenHandle, ULONG SidToCheck)
-{
- FIXME("SHTestTokenMembership() stub\n");
- return FALSE;
-}
-
/*
* Unimplemented
*/
diff --git a/dll/win32/shell32/wine/shellord.c b/dll/win32/shell32/wine/shellord.c
index e0bfb46bb9..ca737c1665 100644
--- a/dll/win32/shell32/wine/shellord.c
+++ b/dll/win32/shell32/wine/shellord.c
@@ -3,7 +3,7 @@
* (NT uses Unicode strings, 95 uses ASCII strings)
*
* Copyright 1997 Marcus Meissner
- * 1998 J�rgen Schmied
+ * 1998 Jürgen Schmied
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1300,80 +1300,6 @@ BOOL WINAPI FileIconInit(BOOL bFullInit)
return SIC_Initialize();
}
-/*************************************************************************
- * IsUserAnAdmin [SHELL32.680] NT 4.0
- *
- * Checks whether the current user is a member of the Administrators group.
- *
- * PARAMS
- * None
- *
- * RETURNS
- * Success: TRUE
- * Failure: FALSE
- */
-BOOL WINAPI IsUserAnAdmin(VOID)
-{
- SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
- HANDLE hToken;
- DWORD dwSize;
- PTOKEN_GROUPS lpGroups;
- PSID lpSid;
- DWORD i;
- BOOL bResult = FALSE;
-
- TRACE("\n");
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
- {
- return FALSE;
- }
-
- if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
- {
- if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- {
- CloseHandle(hToken);
- return FALSE;
- }
- }
-
- lpGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
- if (lpGroups == NULL)
- {
- CloseHandle(hToken);
- return FALSE;
- }
-
- if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
- {
- HeapFree(GetProcessHeap(), 0, lpGroups);
- CloseHandle(hToken);
- return FALSE;
- }
-
- CloseHandle(hToken);
- if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
- DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
- &lpSid))
- {
- HeapFree(GetProcessHeap(), 0, lpGroups);
- return FALSE;
- }
-
- for (i = 0; i < lpGroups->GroupCount; i++)
- {
- if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
- {
- bResult = TRUE;
- break;
- }
- }
-
- FreeSid(lpSid);
- HeapFree(GetProcessHeap(), 0, lpGroups);
- return bResult;
-}
-
/*************************************************************************
* SetAppStartingCursor [SHELL32.99]
*/
@@ -2149,3 +2075,70 @@ HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pcsfv,
return hRes;
}
#endif
+
+
+/*************************************************************************
+ * SHTestTokenMembership [SHELL32.245]
+ *
+ * Checks whether a given token is a mamber of a local group with the
+ * specified RID.
+ *
+ */
+EXTERN_C BOOL
+WINAPI
+SHTestTokenMembership(HANDLE TokenHandle, ULONG ulRID)
+{
+ SID_IDENTIFIER_AUTHORITY ntAuth = {SECURITY_NT_AUTHORITY};
+ DWORD nSubAuthority0, nSubAuthority1;
+ DWORD nSubAuthorityCount;
+ PSID SidToCheck;
+ BOOL IsMember = FALSE;
+
+ if ((ulRID == SECURITY_SERVICE_RID) || ulRID == SECURITY_LOCAL_SYSTEM_RID)
+ {
+ nSubAuthority0 = ulRID;
+ nSubAuthority1 = 0;
+ nSubAuthorityCount= 1;
+ }
+ else
+ {
+ nSubAuthority0 = SECURITY_BUILTIN_DOMAIN_RID;
+ nSubAuthority1 = ulRID;
+ nSubAuthorityCount= 2;
+ }
+
+ if (!AllocateAndInitializeSid(&ntAuth,
+ nSubAuthorityCount,
+ nSubAuthority0,
+ nSubAuthority1,
+ 0, 0, 0, 0, 0, 0,
+ &SidToCheck))
+ {
+ return FALSE;
+ }
+
+ if (!CheckTokenMembership(TokenHandle, SidToCheck, &IsMember))
+ {
+ IsMember = FALSE;
+ }
+
+ FreeSid(SidToCheck);
+ return IsMember;
+}
+
+/*************************************************************************
+ * IsUserAnAdmin [SHELL32.680] NT 4.0
+ *
+ * Checks whether the current user is a member of the Administrators group.
+ *
+ * PARAMS
+ * None
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+BOOL WINAPI IsUserAnAdmin(VOID)
+{
+ return SHTestTokenMembership(NULL, DOMAIN_ALIAS_RID_ADMINS);
+}
\ No newline at end of file
diff --git a/sdk/include/psdk/shellapi.h b/sdk/include/psdk/shellapi.h
index 34116c1792..b4a5ecb4f7 100644
--- a/sdk/include/psdk/shellapi.h
+++ b/sdk/include/psdk/shellapi.h
@@ -632,6 +632,14 @@ DoEnvironmentSubstW(
_Inout_updates_(cchSrc) LPWSTR pszSrc,
UINT cchSrc);
+#if (_WIN32_IE >= 0x0601)
+BOOL
+WINAPI
+SHTestTokenMembership(
+ _In_opt_ HANDLE hToken,
+ _In_ ULONG ulRID);
+#endif
+
#ifdef UNICODE
#define NOTIFYICONDATA_V1_SIZE NOTIFYICONDATAW_V1_SIZE
#define NOTIFYICONDATA_V2_SIZE NOTIFYICONDATAW_V2_SIZE