Francois Gouget : msi/tests: Check that we have enough privileges to run the automation tests.

Alexandre Julliard julliard at winehq.org
Tue Mar 4 14:08:51 CST 2014


Module: wine
Branch: master
Commit: badff7c43a53d49132db5a5a2fd64dca4589d04c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=badff7c43a53d49132db5a5a2fd64dca4589d04c

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Tue Mar  4 19:04:03 2014 +0100

msi/tests: Check that we have enough privileges to run the automation tests.

Note that we could have enough privileges to do the InstallProduct
tests, but not enough to clean up the registry after them, thus
causing later runs to fail. In that case we skip the tests.

---

 dlls/msi/tests/automation.c |   49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/dlls/msi/tests/automation.c b/dlls/msi/tests/automation.c
index c7cc411..242ec63 100644
--- a/dlls/msi/tests/automation.c
+++ b/dlls/msi/tests/automation.c
@@ -35,6 +35,8 @@
 
 static BOOL is_wow64;
 
+static BOOL (WINAPI *pCheckTokenMembership)(HANDLE,PSID,PBOOL);
+static BOOL (WINAPI *pOpenProcessToken)(HANDLE, DWORD, PHANDLE);
 static LONG (WINAPI *pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
 
@@ -217,12 +219,50 @@ static void init_functionpointers(void)
     if(!p ## func) \
       trace("GetProcAddress(%s) failed\n", #func);
 
+    GET_PROC(hadvapi32, CheckTokenMembership);
+    GET_PROC(hadvapi32, OpenProcessToken);
     GET_PROC(hadvapi32, RegDeleteKeyExA)
     GET_PROC(hkernel32, IsWow64Process)
 
 #undef GET_PROC
 }
 
+static BOOL is_process_limited(void)
+{
+    SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
+    PSID Group;
+    BOOL IsInGroup;
+    HANDLE token;
+
+    if (!pCheckTokenMembership || !pOpenProcessToken) return FALSE;
+
+    if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
+                                  DOMAIN_ALIAS_RID_ADMINS,
+                                  0, 0, 0, 0, 0, 0, &Group) ||
+        !pCheckTokenMembership(NULL, Group, &IsInGroup))
+    {
+        trace("Could not check if the current user is an administrator\n");
+        return FALSE;
+    }
+    if (!IsInGroup)
+    {
+        /* Only administrators have enough privileges for these tests */
+        return TRUE;
+    }
+
+    if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
+    {
+        BOOL ret;
+        TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
+        DWORD size;
+
+        ret = GetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
+        CloseHandle(token);
+        return (ret && type == TokenElevationTypeLimited);
+    }
+    return FALSE;
+}
+
 static LONG delete_key_portable( HKEY key, LPCSTR subkey, REGSAM access )
 {
     if (pRegDeleteKeyExA)
@@ -2387,6 +2427,15 @@ static void test_Installer_InstallProduct(void)
     IDispatch *pStringList = NULL;
     REGSAM access = KEY_ALL_ACCESS;
 
+    if (is_process_limited())
+    {
+        /* In fact InstallProduct would succeed but then Windows XP
+         * would not allow us to clean up the registry!
+         */
+        skip("Installer_InstallProduct (insufficient privileges)\n");
+        return;
+    }
+
     if (is_wow64)
         access |= KEY_WOW64_64KEY;
 




More information about the wine-cvs mailing list