Commit 419496d0 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi/tests: Allocate the user token dynamically and unify implementations.

parent c505c0fe
......@@ -1963,28 +1963,28 @@ static BOOL is_process_limited(void)
return FALSE;
}
static LPSTR get_user_sid(LPSTR *usersid)
static char *get_user_sid(void)
{
HANDLE token;
BYTE buf[1024];
DWORD size;
PTOKEN_USER user;
DWORD size = 0;
TOKEN_USER *user;
char *usersid = NULL;
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
GetTokenInformation(token, TokenUser, NULL, size, &size);
user = HeapAlloc(GetProcessHeap(), 0, size);
GetTokenInformation(token, TokenUser, user, size, &size);
pConvertSidToStringSidA(user->User.Sid, &usersid);
HeapFree(GetProcessHeap(), 0, user);
*usersid = NULL;
pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
size = sizeof(buf);
pGetTokenInformation(token, TokenUser, buf, size, &size);
user = (PTOKEN_USER)buf;
pConvertSidToStringSidA(user->User.Sid, usersid);
ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
CloseHandle(token);
return *usersid;
return usersid;
}
static BOOL CDECL get_temp_file(char *pszTempName, int cbTempName, void *pv)
......@@ -2516,7 +2516,7 @@ static void test_register_product(void)
return;
}
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
get_date_str(date);
......@@ -2790,7 +2790,7 @@ static void test_publish_product(void)
return;
}
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
GetTempPath(MAX_PATH, temp);
......@@ -3026,7 +3026,7 @@ static void test_publish_features(void)
return;
}
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
CreateDirectoryA("msitest", NULL);
......@@ -3210,7 +3210,7 @@ static void test_register_user(void)
return;
}
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
get_owner_company(&owner, &company);
......@@ -3308,7 +3308,7 @@ static void test_process_components(void)
return;
}
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
CreateDirectoryA("msitest", NULL);
......
......@@ -542,23 +542,23 @@ static void create_test_guid(LPSTR prodcode, LPSTR squashed)
WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
}
static void get_user_sid(LPSTR *usersid)
static char *get_user_sid(void)
{
HANDLE token;
DWORD size;
PTOKEN_USER user;
DWORD size = 0;
TOKEN_USER *user;
char *usersid = NULL;
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
size = 0;
GetTokenInformation(token, TokenUser, NULL, size, &size);
user = HeapAlloc(GetProcessHeap(), 0, size);
user = HeapAlloc(GetProcessHeap(), 0, size);
GetTokenInformation(token, TokenUser, user, size, &size);
pConvertSidToStringSidA(user->User.Sid, usersid);
pConvertSidToStringSidA(user->User.Sid, &usersid);
HeapFree(GetProcessHeap(), 0, user);
CloseHandle(token);
return usersid;
}
static void test_MsiQueryProductState(void)
......@@ -575,7 +575,7 @@ static void test_MsiQueryProductState(void)
REGSAM access = KEY_ALL_ACCESS;
create_test_guid(prodcode, prod_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -918,7 +918,7 @@ static void test_MsiQueryFeatureState(void)
create_test_guid(prodcode, prod_squashed);
compose_base85_guid(component, comp_base85, comp_squashed);
compose_base85_guid(component, comp_base85 + 20, comp_squashed2);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -1428,7 +1428,7 @@ static void test_MsiQueryComponentState(void)
create_test_guid(prodcode, prod_squashed);
compose_base85_guid(component, comp_base85, comp_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -1804,7 +1804,7 @@ static void test_MsiGetComponentPath(void)
create_test_guid(prodcode, prod_squashed);
compose_base85_guid(component, comp_base85, comp_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -2333,7 +2333,7 @@ static void test_MsiGetProductCode(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(prodcode2, prod2_squashed);
compose_base85_guid(component, comp_base85, comp_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -2600,7 +2600,7 @@ static void test_MsiEnumClients(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(prodcode2, prod2_squashed);
compose_base85_guid(component, comp_base85, comp_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -3049,7 +3049,7 @@ static void test_MsiGetProductInfo(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(packcode, pack_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -4341,7 +4341,7 @@ static void test_MsiGetProductInfoEx(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(packcode, pack_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -7094,7 +7094,7 @@ static void test_MsiGetUserInfo(void)
REGSAM access = KEY_ALL_ACCESS;
create_test_guid(prodcode, prod_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -7681,7 +7681,7 @@ static void test_MsiOpenProduct(void)
lstrcatA(path, "\\");
create_test_guid(prodcode, prod_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -9515,7 +9515,7 @@ static void test_MsiEnumPatchesEx(void)
}
create_test_guid(prodcode, prod_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
/* empty szProductCode */
lstrcpyA(patchcode, "apple");
......@@ -9776,7 +9776,7 @@ static void test_MsiEnumPatches(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(patchcode, patch_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -10482,7 +10482,7 @@ static void test_MsiGetPatchInfoEx(void)
create_test_guid(prodcode, prod_squashed);
create_test_guid(patchcode, patch_squashed);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......@@ -11685,7 +11685,7 @@ static void test_MsiEnumProducts(void)
create_test_guid(product1, product_squashed1);
create_test_guid(product2, product_squashed2);
create_test_guid(product3, product_squashed3);
get_user_sid(&usersid);
usersid = get_user_sid();
if (is_wow64)
access |= KEY_WOW64_64KEY;
......
......@@ -109,28 +109,28 @@ static LONG delete_key( HKEY key, LPCSTR subkey, REGSAM access )
return RegDeleteKeyA( key, subkey );
}
static LPSTR get_user_sid(LPSTR *usersid)
static char *get_user_sid(void)
{
HANDLE token;
BYTE buf[1024];
DWORD size;
PTOKEN_USER user;
DWORD size = 0;
TOKEN_USER *user;
char *usersid = NULL;
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
*usersid = NULL;
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
size = sizeof(buf);
GetTokenInformation(token, TokenUser, buf, size, &size);
user = (PTOKEN_USER)buf;
pConvertSidToStringSidA(user->User.Sid, usersid);
ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
GetTokenInformation(token, TokenUser, NULL, size, &size);
user = HeapAlloc(GetProcessHeap(), 0, size);
GetTokenInformation(token, TokenUser, user, size, &size);
pConvertSidToStringSidA(user->User.Sid, &usersid);
HeapFree(GetProcessHeap(), 0, user);
CloseHandle(token);
return *usersid;
return usersid;
}
/* RegDeleteTreeW from dlls/advapi32/registry.c */
......@@ -7998,7 +7998,7 @@ static void test_appsearch_complocator(void)
DWORD size;
UINT r;
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
return;
if (is_process_limited())
......
......@@ -134,25 +134,28 @@ static void create_test_guid(LPSTR prodcode, LPSTR squashed)
WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
}
static int get_user_sid(LPSTR *usersid)
static char *get_user_sid(void)
{
HANDLE token;
BYTE buf[1024];
DWORD size;
PTOKEN_USER user;
BOOL rc;
DWORD size = 0;
TOKEN_USER *user;
char *usersid = NULL;
if (!pConvertSidToStringSidA)
return 0;
rc=OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
if (!rc && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
return 0;
size = sizeof(buf);
GetTokenInformation(token, TokenUser, buf, size, &size);
user = (PTOKEN_USER)buf;
pConvertSidToStringSidA(user->User.Sid, usersid);
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
GetTokenInformation(token, TokenUser, NULL, size, &size);
user = HeapAlloc(GetProcessHeap(), 0, size);
GetTokenInformation(token, TokenUser, user, size, &size);
pConvertSidToStringSidA(user->User.Sid, &usersid);
HeapFree(GetProcessHeap(), 0, user);
CloseHandle(token);
return 1;
return usersid;
}
static void check_reg_str(HKEY prodkey, LPCSTR name, LPCSTR expected, BOOL bcase, DWORD line)
......@@ -205,7 +208,7 @@ static void test_MsiSourceListGetInfo(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListGetInfoA tests\n");
return;
......@@ -660,7 +663,7 @@ static void test_MsiSourceListAddSourceEx(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListAddSourceExA tests\n");
return;
......@@ -1047,7 +1050,7 @@ static void test_MsiSourceListEnumSources(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListEnumSourcesA tests\n");
return;
......@@ -1664,7 +1667,7 @@ static void test_MsiSourceListSetInfo(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListSetInfoA tests\n");
return;
......@@ -2089,7 +2092,7 @@ static void test_MsiSourceListAddMediaDisk(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListAddMediaDiskA tests\n");
return;
......@@ -2403,7 +2406,7 @@ static void test_MsiSourceListEnumMediaDisks(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListEnumMediaDisksA tests\n");
return;
......@@ -3216,7 +3219,7 @@ static void test_MsiSourceListAddSource(void)
}
create_test_guid(prodcode, prod_squashed);
if (!get_user_sid(&usersid))
if (!(usersid = get_user_sid()))
{
skip("User SID not available -> skipping MsiSourceListAddSourceA tests\n");
return;
......
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