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

View file

@ -34,27 +34,38 @@ char CURR_DIR[MAX_PATH];
static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR); 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) 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;
static HMODULE hadvapi32 = NULL;
static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
*usersid = NULL; if (!pConvertSidToStringSidA)
if (!hadvapi32)
{ {
hadvapi32 = GetModuleHandleA("advapi32.dll"); win_skip("ConvertSidToStringSidA is not available\n");
pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); return NULL;
if (!pConvertSidToStringSidA)
{
win_skip("ConvertSidToStringSidA is not available\n");
return NULL;
}
} }
*usersid = 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);
@ -11622,9 +11633,7 @@ static void test_MsiApplyPatch(void)
START_TEST(package) START_TEST(package)
{ {
HMODULE hmsi = GetModuleHandleA("msi.dll"); init_functionpointers();
pMsiApplyMultiplePatchesA = (void *)GetProcAddress(hmsi, "MsiApplyMultiplePatchesA");
GetCurrentDirectoryA(MAX_PATH, CURR_DIR); GetCurrentDirectoryA(MAX_PATH, CURR_DIR);