msi/tests: Tweak the get_user_sid() functions to simplify their use.

Now the function deals with all errors and win_skips() itself.
This commit is contained in:
Francois Gouget 2009-05-26 00:41:30 +02:00 committed by Alexandre Julliard
parent 97dea95e41
commit 623dad0963
2 changed files with 34 additions and 40 deletions

View File

@ -1346,26 +1346,35 @@ static BOOL check_win9x(void)
return FALSE; return FALSE;
} }
static void get_user_sid(LPSTR *usersid) static LPSTR get_user_sid(LPSTR *usersid)
{ {
HANDLE token; HANDLE token;
BYTE buf[1024]; BYTE buf[1024];
DWORD size; DWORD size;
PTOKEN_USER user; PTOKEN_USER user;
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); static HMODULE hadvapi32 = NULL;
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
*usersid = NULL; *usersid = NULL;
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); if (!hadvapi32)
if (!pConvertSidToStringSidA) {
return; hadvapi32 = GetModuleHandleA("advapi32.dll");
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
}
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
size = sizeof(buf); size = sizeof(buf);
GetTokenInformation(token, TokenUser, buf, size, &size); GetTokenInformation(token, TokenUser, buf, size, &size);
user = (PTOKEN_USER)buf; user = (PTOKEN_USER)buf;
pConvertSidToStringSidA(user->User.Sid, usersid); pConvertSidToStringSidA(user->User.Sid, usersid);
ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
CloseHandle(token); CloseHandle(token);
return *usersid;
} }
static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val) static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
@ -2511,12 +2520,8 @@ static void test_publish_registerproduct(void)
static const CHAR userugkey[] = "Software\\Microsoft\\Installer\\UpgradeCodes" static const CHAR userugkey[] = "Software\\Microsoft\\Installer\\UpgradeCodes"
"\\51AAE0C44620A5E4788506E91F249BD2"; "\\51AAE0C44620A5E4788506E91F249BD2";
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
get_date_str(date); get_date_str(date);
GetTempPath(MAX_PATH, temp); GetTempPath(MAX_PATH, temp);
@ -2756,12 +2761,8 @@ static void test_publish_publishproduct(void)
static const CHAR machprod[] = "Installer\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB"; static const CHAR machprod[] = "Installer\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB";
static const CHAR machup[] = "Installer\\UpgradeCodes\\51AAE0C44620A5E4788506E91F249BD2"; static const CHAR machup[] = "Installer\\UpgradeCodes\\51AAE0C44620A5E4788506E91F249BD2";
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
GetTempPath(MAX_PATH, temp); GetTempPath(MAX_PATH, temp);
@ -2952,12 +2953,8 @@ static void test_publish_publishfeatures(void)
static const CHAR classfeat[] = "Software\\Classes\\Installer\\Features" static const CHAR classfeat[] = "Software\\Classes\\Installer\\Features"
"\\84A88FD7F6998CE40A22FB59F6B9C2BB"; "\\84A88FD7F6998CE40A22FB59F6B9C2BB";
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
CreateDirectoryA("msitest", NULL); CreateDirectoryA("msitest", NULL);
create_file("msitest\\maximus", 500); create_file("msitest\\maximus", 500);
@ -3114,12 +3111,8 @@ static void test_publish_registeruser(void)
"Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\" "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\"
"UserData\\%s\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB\\InstallProperties"; "UserData\\%s\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB\\InstallProperties";
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
get_owner_company(&owner, &company); get_owner_company(&owner, &company);
@ -3197,12 +3190,8 @@ static void test_publish_processcomponents(void)
static const CHAR compkey[] = static const CHAR compkey[] =
"Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Components"; "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Components";
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
CreateDirectoryA("msitest", NULL); CreateDirectoryA("msitest", NULL);
create_file("msitest\\maximus", 500); create_file("msitest\\maximus", 500);

View File

@ -34,26 +34,35 @@ char CURR_DIR[MAX_PATH];
static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR); static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR);
static void get_user_sid(LPSTR *usersid) static LPSTR get_user_sid(LPSTR *usersid)
{ {
HANDLE token; HANDLE token;
BYTE buf[1024]; BYTE buf[1024];
DWORD size; DWORD size;
PTOKEN_USER user; PTOKEN_USER user;
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); static HMODULE hadvapi32 = NULL;
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
*usersid = NULL; *usersid = NULL;
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); if (!hadvapi32)
if (!pConvertSidToStringSidA) {
return; hadvapi32 = GetModuleHandleA("advapi32.dll");
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
}
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
size = sizeof(buf); size = sizeof(buf);
GetTokenInformation(token, TokenUser, buf, size, &size); GetTokenInformation(token, TokenUser, buf, size, &size);
user = (PTOKEN_USER)buf; user = (PTOKEN_USER)buf;
pConvertSidToStringSidA(user->User.Sid, usersid); pConvertSidToStringSidA(user->User.Sid, usersid);
ok(*usersid != NULL, "pConvertSidToStringSidA failed lre=%d\n", GetLastError());
CloseHandle(token); CloseHandle(token);
return *usersid;
} }
/* RegDeleteTreeW from dlls/advapi32/registry.c */ /* RegDeleteTreeW from dlls/advapi32/registry.c */
@ -7336,12 +7345,8 @@ static void test_appsearch_complocator(void)
DWORD size; DWORD size;
UINT r; UINT r;
get_user_sid(&usersid); if (!get_user_sid(&usersid))
if (!usersid)
{
skip("ConvertSidToStringSidA is not available\n");
return; return;
}
create_test_file("FileName1"); create_test_file("FileName1");
create_test_file("FileName4"); create_test_file("FileName4");