msi/tests: Prevent crash when ConvertSidToStringSidA is not available.

This commit is contained in:
Paul Vriens 2009-05-27 11:10:07 +02:00 committed by Alexandre Julliard
parent 8921b936a8
commit 45c00da496
2 changed files with 32 additions and 25 deletions

View File

@ -40,6 +40,8 @@ static UINT (WINAPI *pMsiSourceListEnumSourcesA)
static UINT (WINAPI *pMsiSourceListGetInfoA)
(LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, LPCSTR, LPSTR, LPDWORD);
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
static HMODULE hsrclient = 0;
static BOOL (WINAPI *pSRRemoveRestorePoint)(DWORD);
static BOOL (WINAPI *pSRSetRestorePointA)(RESTOREPOINTINFOA*, STATEMGRSTATUS*);
@ -1316,6 +1318,7 @@ static int CDECL fci_delete(char *pszFile, int *err, void *pv)
static void init_functionpointers(void)
{
HMODULE hmsi = GetModuleHandleA("msi.dll");
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
#define GET_PROC(mod, func) \
p ## func = (void*)GetProcAddress(mod, #func); \
@ -1326,6 +1329,8 @@ static void init_functionpointers(void)
GET_PROC(hmsi, MsiSourceListEnumSourcesA);
GET_PROC(hmsi, MsiSourceListGetInfoA);
GET_PROC(hadvapi32, ConvertSidToStringSidA);
hsrclient = LoadLibraryA("srclient.dll");
GET_PROC(hsrclient, SRRemoveRestorePoint);
GET_PROC(hsrclient, SRSetRestorePointA);
@ -1352,21 +1357,14 @@ static LPSTR get_user_sid(LPSTR *usersid)
BYTE buf[1024];
DWORD size;
PTOKEN_USER user;
static HMODULE hadvapi32 = NULL;
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
*usersid = NULL;
if (!hadvapi32)
if (!pConvertSidToStringSidA)
{
hadvapi32 = GetModuleHandleA("advapi32.dll");
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
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);

View File

@ -34,27 +34,38 @@ char CURR_DIR[MAX_PATH];
static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR);
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
static void init_functionpointers(void)
{
HMODULE hmsi = GetModuleHandleA("msi.dll");
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
#define GET_PROC(mod, func) \
p ## func = (void*)GetProcAddress(mod, #func);
GET_PROC(hmsi, MsiApplyMultiplePatchesA);
GET_PROC(hadvapi32, ConvertSidToStringSidA);
#undef GET_PROC
}
static LPSTR get_user_sid(LPSTR *usersid)
{
HANDLE token;
BYTE buf[1024];
DWORD size;
PTOKEN_USER user;
static HMODULE hadvapi32 = NULL;
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
*usersid = NULL;
if (!hadvapi32)
if (!pConvertSidToStringSidA)
{
hadvapi32 = GetModuleHandleA("advapi32.dll");
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA");
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
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);
@ -11622,9 +11633,7 @@ static void test_MsiApplyPatch(void)
START_TEST(package)
{
HMODULE hmsi = GetModuleHandleA("msi.dll");
pMsiApplyMultiplePatchesA = (void *)GetProcAddress(hmsi, "MsiApplyMultiplePatchesA");
init_functionpointers();
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);