[SHELL32] Implement SHTestTokenMembership and forward IsUserAnAdmin to it
authorGed Murphy <ged.murphy@crowdstrike.com>
Mon, 4 Mar 2019 11:02:38 +0000 (11:02 +0000)
committerGed Murphy <ged.murphy@crowdstrike.com>
Mon, 4 Mar 2019 11:54:43 +0000 (11:54 +0000)
Moved to the bottom of the file with the other ros functions to help keep wine syncs easier.

dll/win32/shell32/stubs.cpp
dll/win32/shell32/wine/shellord.c
sdk/include/psdk/shellapi.h

index 8bc2f65..1c7996d 100644 (file)
@@ -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
  */
index e0bfb46..ca737c1 100644 (file)
@@ -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
index 34116c1..b4a5ecb 100644 (file)
@@ -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