[3/3] msi/tests: Skip tests if UAC is enabled and the process is not running elevated.

Hans Leidekker hans at codeweavers.com
Mon Jul 26 05:09:57 CDT 2010


---
 dlls/msi/tests/install.c |  362 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/msi/tests/package.c |   35 +++++
 dlls/msi/tests/patch.c   |   40 +++++
 3 files changed, 437 insertions(+), 0 deletions(-)

diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c
index 39d5754..72b16de 100644
--- a/dlls/msi/tests/install.c
+++ b/dlls/msi/tests/install.c
@@ -44,6 +44,8 @@ static UINT (WINAPI *pMsiSourceListGetInfoA)
     (LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, LPCSTR, LPSTR, LPDWORD);
 
 static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
+static BOOL (WINAPI *pGetTokenInformation)( HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD );
+static BOOL (WINAPI *pOpenProcessToken)( HANDLE, DWORD, PHANDLE );
 static LONG (WINAPI *pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
 
@@ -3226,6 +3228,8 @@ static void init_functionpointers(void)
     GET_PROC(hmsi, MsiSourceListGetInfoA);
 
     GET_PROC(hadvapi32, ConvertSidToStringSidA);
+    GET_PROC(hadvapi32, GetTokenInformation);
+    GET_PROC(hadvapi32, OpenProcessToken);
     GET_PROC(hadvapi32, RegDeleteKeyExA)
     GET_PROC(hkernel32, IsWow64Process)
 
@@ -3236,6 +3240,25 @@ static void init_functionpointers(void)
 #undef GET_PROC
 }
 
+static BOOL is_process_limited(void)
+{
+    HANDLE token;
+
+    if (!pOpenProcessToken || !pGetTokenInformation) return FALSE;
+
+    if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
+    {
+        BOOL ret;
+        TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
+        DWORD size;
+
+        ret = pGetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
+        CloseHandle(token);
+        return (ret && type == TokenElevationTypeLimited);
+    }
+    return FALSE;
+}
+
 static BOOL check_win9x(void)
 {
     SC_HANDLE scm;
@@ -3659,6 +3682,11 @@ static void test_MsiInstallProduct(void)
         win_skip("Services are not implemented on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     if (pIsWow64Process && pIsWow64Process(GetCurrentProcess(), &wow64) && wow64)
         access |= KEY_WOW64_64KEY;
@@ -4106,6 +4134,12 @@ static void test_continuouscabs(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_cc_test_files();
     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
 
@@ -4237,6 +4271,12 @@ static void test_mixedmedia(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
     create_file("msitest\\augustus", 500);
@@ -4339,6 +4379,12 @@ static void test_readonlyfile(void)
     HANDLE file;
     CHAR path[MAX_PATH];
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
     create_database(msifile, rof_tables, sizeof(rof_tables) / sizeof(msi_table));
@@ -4382,6 +4428,12 @@ static void test_readonlyfile_cab(void)
     CHAR path[MAX_PATH];
     CHAR buf[16];
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("maximus", 500);
     create_cab_file("test1.cab", MEDIA_SIZE, "maximus\0");
@@ -4603,6 +4655,12 @@ static void test_setdirproperty(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
     create_database(msifile, sdp_tables, sizeof(sdp_tables) / sizeof(msi_table));
@@ -4630,6 +4688,12 @@ static void test_cabisextracted(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\gaius", 500);
     create_file("maximus", 500);
@@ -4673,6 +4737,12 @@ static void test_concurrentinstall(void)
     UINT r;
     CHAR path[MAX_PATH];
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     CreateDirectoryA("msitest\\msitest", NULL);
     create_file("msitest\\maximus", 500);
@@ -4721,6 +4791,12 @@ static void test_setpropertyfolder(void)
     CHAR path[MAX_PATH];
     DWORD attr;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     lstrcpyA(path, PROG_FILES_DIR);
     lstrcatA(path, "\\msitest\\added");
 
@@ -4943,6 +5019,12 @@ static void test_publish_registerproduct(void)
     static const CHAR userugkey[] = "Software\\Microsoft\\Installer\\UpgradeCodes"
                                     "\\51AAE0C44620A5E4788506E91F249BD2";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     if (!get_user_sid(&usersid))
         return;
 
@@ -5195,6 +5277,12 @@ static void test_publish_publishproduct(void)
     static const CHAR machprod[] = "Installer\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB";
     static const CHAR machup[] = "Installer\\UpgradeCodes\\51AAE0C44620A5E4788506E91F249BD2";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     if (!get_user_sid(&usersid))
         return;
 
@@ -5418,6 +5506,12 @@ static void test_publish_publishfeatures(void)
     static const CHAR classfeat[] = "Software\\Classes\\Installer\\Features"
                                     "\\84A88FD7F6998CE40A22FB59F6B9C2BB";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     if (!get_user_sid(&usersid))
         return;
 
@@ -5592,6 +5686,12 @@ static void test_publish_registeruser(void)
         "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\"
         "UserData\\%s\\Products\\84A88FD7F6998CE40A22FB59F6B9C2BB\\InstallProperties";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     if (!get_user_sid(&usersid))
         return;
 
@@ -5681,6 +5781,12 @@ static void test_publish_processcomponents(void)
     static const CHAR compkey[] =
         "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Components";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     if (!get_user_sid(&usersid))
         return;
 
@@ -5812,6 +5918,11 @@ static void test_publish(void)
         win_skip("MsiQueryComponentStateA is not available\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     get_date_str(date);
     GetTempPath(MAX_PATH, temp);
@@ -6300,6 +6411,11 @@ static void test_publishsourcelist(void)
         win_skip("MsiSourceListEnumSourcesA and/or MsiSourceListGetInfoA are not available\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
@@ -6652,6 +6768,12 @@ static void test_transformprop(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -6694,6 +6816,12 @@ static void test_currentworkingdir(void)
     CHAR drive[MAX_PATH], path[MAX_PATH];
     LPSTR ptr;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -6850,6 +6978,12 @@ static void test_adminprops(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -6895,6 +7029,12 @@ static void test_removefiles(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\hydrogen", 500);
     create_file("msitest\\helium", 500);
@@ -7024,6 +7164,12 @@ static void test_movefiles(void)
     UINT r;
     char props[MAX_PATH];
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 100);
     create_file("cameroon", 100);
@@ -7164,6 +7310,12 @@ static void test_missingcab(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
     create_file("maximus", 500);
@@ -7224,6 +7376,12 @@ static void test_duplicatefiles(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\maximus", 500);
     create_database(msifile, df_tables, sizeof(df_tables) / sizeof(msi_table));
@@ -7263,6 +7421,12 @@ static void test_writeregistryvalues(void)
     REGSAM access = KEY_ALL_ACCESS;
     BOOL wow64;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -7307,6 +7471,12 @@ static void test_sourcefolder(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("augustus", 500);
 
@@ -7348,6 +7518,12 @@ static void test_customaction51(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -7375,6 +7551,12 @@ static void test_installstate(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\alpha", 500);
     create_file("msitest\\beta", 500);
@@ -7866,6 +8048,11 @@ static void test_MsiConfigureProductEx(void)
         win_skip("Different registry keys on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\hydrogen", 500);
@@ -8123,6 +8310,12 @@ static void test_missingcomponent(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\hydrogen", 500);
     create_file("msitest\\helium", 500);
@@ -8168,6 +8361,12 @@ static void test_sourcedirprop(void)
     UINT r;
     CHAR props[MAX_PATH];
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -8213,6 +8412,12 @@ static void test_adminimage(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     CreateDirectoryA("msitest\\first", NULL);
     CreateDirectoryA("msitest\\second", NULL);
@@ -8271,6 +8476,12 @@ static void test_propcase(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     CreateDirectoryA("msitest", NULL);
     create_file("msitest\\augustus", 500);
 
@@ -8359,6 +8570,12 @@ static void test_shortcut(void)
     UINT r;
     HRESULT hr;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, sc_tables, sizeof(sc_tables) / sizeof(msi_table));
 
@@ -8419,6 +8636,11 @@ static void test_envvar(void)
         win_skip("Environment variables are handled differently on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     create_test_files();
     create_database(msifile, env_tables, sizeof(env_tables) / sizeof(msi_table));
@@ -8531,6 +8753,12 @@ static void test_preselected(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, ps_tables, sizeof(ps_tables) / sizeof(msi_table));
 
@@ -8581,6 +8809,12 @@ static void test_installed_prop(void)
     static char prodcode[] = "{7df88a48-996f-4ec8-a022-bf956f9b2cbb}";
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, ip_tables, sizeof(ip_tables) / sizeof(msi_table));
 
@@ -8625,6 +8859,12 @@ static void test_allusers_prop(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, aup_tables, sizeof(aup_tables) / sizeof(msi_table));
 
@@ -8850,6 +9090,11 @@ static void test_file_in_use(void)
         win_skip("Pending file renaming is implemented differently on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     RegOpenKeyExA(HKEY_LOCAL_MACHINE, session_manager, 0, KEY_ALL_ACCESS, &hkey);
 
@@ -8909,6 +9154,11 @@ static void test_file_in_use_cab(void)
         win_skip("Pending file renaming is implemented differently on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     RegOpenKeyExA(HKEY_LOCAL_MACHINE, session_manager, 0, KEY_ALL_ACCESS, &hkey);
 
@@ -9044,6 +9294,12 @@ static void test_feature_override(void)
     REGSAM access = KEY_ALL_ACCESS;
     BOOL wow64;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\override.txt", 1000);
     create_file("msitest\\preselected.txt", 1000);
@@ -9308,6 +9564,11 @@ static void test_delete_services(void)
         win_skip("Services are not implemented on Win9x and WinMe\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     create_test_files();
     create_database(msifile, sds_tables, sizeof(sds_tables) / sizeof(msi_table));
@@ -9347,6 +9608,12 @@ static void test_self_registration(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, sr_tables, sizeof(sr_tables) / sizeof(msi_table));
 
@@ -9388,6 +9655,12 @@ static void test_register_font(void)
     REGSAM access = KEY_ALL_ACCESS;
     BOOL wow64;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\font.ttf", 1000);
     create_database(msifile, font_tables, sizeof(font_tables) / sizeof(msi_table));
@@ -9433,6 +9706,12 @@ static void test_validate_product_id(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_database(msifile, vp_tables, sizeof(vp_tables) / sizeof(msi_table));
 
@@ -9477,6 +9756,12 @@ static void test_install_remove_odbc(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\ODBCdriver.dll", 1000);
     create_file("msitest\\ODBCdriver2.dll", 1000);
@@ -9525,6 +9810,12 @@ static void test_register_typelib(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\typelib.dll", 1000);
     create_database(msifile, tl_tables, sizeof(tl_tables) / sizeof(msi_table));
@@ -9558,6 +9849,12 @@ static void test_create_remove_shortcut(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\target.txt", 1000);
     create_database(msifile, crs_tables, sizeof(crs_tables) / sizeof(msi_table));
@@ -9597,6 +9894,12 @@ static void test_publish_components(void)
     LONG res;
     HKEY key;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\english.txt", 1000);
     create_database(msifile, pub_tables, sizeof(pub_tables) / sizeof(msi_table));
@@ -9637,6 +9940,12 @@ static void test_remove_duplicate_files(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\original.txt", 1000);
     create_file("msitest\\original2.txt", 1000);
@@ -9685,6 +9994,12 @@ static void test_remove_registry_values(void)
     REGSAM access = KEY_ALL_ACCESS;
     BOOL wow64;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\registry.txt", 1000);
     create_database(msifile, rrv_tables, sizeof(rrv_tables) / sizeof(msi_table));
@@ -9771,6 +10086,12 @@ static void test_find_related_products(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\product.txt", 1000);
     create_database(msifile, frp_tables, sizeof(frp_tables) / sizeof(msi_table));
@@ -9809,6 +10130,12 @@ static void test_remove_ini_values(void)
     HANDLE file;
     BOOL ret;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\inifile.txt", 1000);
     create_database(msifile, riv_tables, sizeof(riv_tables) / sizeof(msi_table));
@@ -9874,6 +10201,11 @@ static void test_remove_env_strings(void)
         win_skip("Environment variables are handled differently on win9x and winme\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     create_test_files();
     create_file("msitest\\envvar.txt", 1000);
@@ -10000,6 +10332,12 @@ static void test_register_class_info(void)
     LONG res;
     HKEY hkey;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\class.txt", 1000);
     create_database(msifile, rci_tables, sizeof(rci_tables) / sizeof(msi_table));
@@ -10053,6 +10391,12 @@ static void test_register_extension_info(void)
     LONG res;
     HKEY hkey;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\extension.txt", 1000);
     create_database(msifile, rei_tables, sizeof(rei_tables) / sizeof(msi_table));
@@ -10099,6 +10443,12 @@ static void test_register_mime_info(void)
     LONG res;
     HKEY hkey;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\mime.txt", 1000);
     create_database(msifile, rmi_tables, sizeof(rmi_tables) / sizeof(msi_table));
@@ -10140,6 +10490,12 @@ static void test_icon_table(void)
     CHAR path[MAX_PATH], win9xpath[MAX_PATH];
     static const char prodcode[] = "{7DF88A49-996F-4EC8-A022-BF956F9B2CBB}";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_database(msifile, icon_base_tables, sizeof(icon_base_tables) / sizeof(msi_table));
 
     res = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb);
@@ -10216,6 +10572,12 @@ static void test_sourcedir_props(void)
 {
     UINT r;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_files();
     create_file("msitest\\sourcedir.txt", 1000);
     create_database(msifile, sd_tables, sizeof(sd_tables) / sizeof(msi_table));
diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index c9e0d65..b326617 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -36,6 +36,8 @@ char CURR_DIR[MAX_PATH];
 static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR);
 
 static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
+static BOOL (WINAPI *pGetTokenInformation)( HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD );
+static BOOL (WINAPI *pOpenProcessToken)( HANDLE, DWORD, PHANDLE );
 static LONG (WINAPI *pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
 static LONG (WINAPI *pRegDeleteKeyExW)(HKEY, LPCWSTR, REGSAM, DWORD);
 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
@@ -56,6 +58,8 @@ static void init_functionpointers(void)
     GET_PROC(hmsi, MsiApplyMultiplePatchesA);
 
     GET_PROC(hadvapi32, ConvertSidToStringSidA);
+    GET_PROC(hadvapi32, GetTokenInformation);
+    GET_PROC(hadvapi32, OpenProcessToken);
     GET_PROC(hadvapi32, RegDeleteKeyExA)
     GET_PROC(hadvapi32, RegDeleteKeyExW)
     GET_PROC(hkernel32, IsWow64Process)
@@ -66,6 +70,25 @@ static void init_functionpointers(void)
 #undef GET_PROC
 }
 
+static BOOL is_process_limited(void)
+{
+    HANDLE token;
+
+    if (!pOpenProcessToken || !pGetTokenInformation) return FALSE;
+
+    if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
+    {
+        BOOL ret;
+        TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
+        DWORD size;
+
+        ret = pGetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
+        CloseHandle(token);
+        return (ret && type == TokenElevationTypeLimited);
+    }
+    return FALSE;
+}
+
 static LONG delete_key( HKEY key, LPCSTR subkey, REGSAM access )
 {
     if (pRegDeleteKeyExA)
@@ -2440,6 +2463,12 @@ static void test_states(void)
     static const CHAR msifile3[] = "winetest3-package.msi";
     static const CHAR msifile4[] = "winetest4-package.msi";
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     hdb = create_package_db();
     ok ( hdb, "failed to create package database\n" );
 
@@ -7538,6 +7567,12 @@ static void test_appsearch_complocator(void)
     if (!get_user_sid(&usersid))
         return;
 
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
+
     create_test_file("FileName1");
     create_test_file("FileName4");
     set_component_path("FileName1", MSIINSTALLCONTEXT_MACHINE,
diff --git a/dlls/msi/tests/patch.c b/dlls/msi/tests/patch.c
index 2453e99..998dc4b 100644
--- a/dlls/msi/tests/patch.c
+++ b/dlls/msi/tests/patch.c
@@ -35,6 +35,8 @@ static UINT (WINAPI *pMsiGetPatchInfoExA)( LPCSTR, LPCSTR, LPCSTR, MSIINSTALLCON
                                            LPCSTR, LPSTR, DWORD * );
 static UINT (WINAPI *pMsiEnumPatchesExA)( LPCSTR, LPCSTR, DWORD, DWORD, DWORD, LPSTR,
                                           LPSTR, MSIINSTALLCONTEXT *, LPSTR, LPDWORD );
+static BOOL (WINAPI *pGetTokenInformation)( HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD );
+static BOOL (WINAPI *pOpenProcessToken)( HANDLE, DWORD, PHANDLE );
 
 static const char *msifile = "winetest-patch.msi";
 static const char *mspfile = "winetest-patch.msp";
@@ -138,6 +140,7 @@ static const struct msi_table tables[] =
 static void init_function_pointers( void )
 {
     HMODULE hmsi = GetModuleHandleA( "msi.dll" );
+    HMODULE hadvapi32 = GetModuleHandleA( "advapi32.dll" );
 
 #define GET_PROC( mod, func ) \
     p ## func = (void *)GetProcAddress( mod, #func ); \
@@ -147,9 +150,31 @@ static void init_function_pointers( void )
     GET_PROC( hmsi, MsiApplyPatchA );
     GET_PROC( hmsi, MsiGetPatchInfoExA );
     GET_PROC( hmsi, MsiEnumPatchesExA );
+
+    GET_PROC( hadvapi32, GetTokenInformation );
+    GET_PROC( hadvapi32, OpenProcessToken );
 #undef GET_PROC
 }
 
+static BOOL is_process_limited(void)
+{
+    HANDLE token;
+
+    if (!pOpenProcessToken || !pGetTokenInformation) return FALSE;
+
+    if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
+    {
+        BOOL ret;
+        TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
+        DWORD size;
+
+        ret = pGetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
+        CloseHandle(token);
+        return (ret && type == TokenElevationTypeLimited);
+    }
+    return FALSE;
+}
+
 static BOOL get_program_files_dir( char *buf, char *buf2 )
 {
     HKEY hkey;
@@ -690,6 +715,11 @@ static void test_simple_patch( void )
         win_skip("MsiApplyPatchA is not available\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     CreateDirectoryA( "msitest", NULL );
     create_file( "msitest\\patch.txt", 1000 );
@@ -937,6 +967,11 @@ static void test_system_tables( void )
         win_skip("MsiApplyPatchA is not available\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     CreateDirectoryA( "msitest", NULL );
     create_file( "msitest\\patch.txt", 1000 );
@@ -1097,6 +1132,11 @@ static void test_patch_registration( void )
         win_skip("required functions not available\n");
         return;
     }
+    if (is_process_limited())
+    {
+        skip("process is limited\n");
+        return;
+    }
 
     CreateDirectoryA( "msitest", NULL );
     create_file( "msitest\\patch.txt", 1000 );
-- 
1.7.0.4






More information about the wine-patches mailing list