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

Francois Gouget fgouget at codeweavers.com
Tue Mar 4 12:04:03 CST 2014


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.
---

This should fix the test failures on the fg-win2000-susr and 
fg-winxp-lusr VMs.

 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;
 
-- 
1.8.5.3




More information about the wine-patches mailing list