Commit badff7c4 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

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.
parent ca2e1c16
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
static BOOL is_wow64; 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 LONG (WINAPI *pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL); static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
...@@ -217,12 +219,50 @@ static void init_functionpointers(void) ...@@ -217,12 +219,50 @@ static void init_functionpointers(void)
if(!p ## func) \ if(!p ## func) \
trace("GetProcAddress(%s) failed\n", #func); trace("GetProcAddress(%s) failed\n", #func);
GET_PROC(hadvapi32, CheckTokenMembership);
GET_PROC(hadvapi32, OpenProcessToken);
GET_PROC(hadvapi32, RegDeleteKeyExA) GET_PROC(hadvapi32, RegDeleteKeyExA)
GET_PROC(hkernel32, IsWow64Process) GET_PROC(hkernel32, IsWow64Process)
#undef GET_PROC #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 ) static LONG delete_key_portable( HKEY key, LPCSTR subkey, REGSAM access )
{ {
if (pRegDeleteKeyExA) if (pRegDeleteKeyExA)
...@@ -2387,6 +2427,15 @@ static void test_Installer_InstallProduct(void) ...@@ -2387,6 +2427,15 @@ static void test_Installer_InstallProduct(void)
IDispatch *pStringList = NULL; IDispatch *pStringList = NULL;
REGSAM access = KEY_ALL_ACCESS; 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) if (is_wow64)
access |= KEY_WOW64_64KEY; access |= KEY_WOW64_64KEY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment