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