1
0
mirror of https://github.com/wine-mirror/wine synced 2024-06-29 06:14:34 +00:00

winetest: Elevate test processes on Wine.

This commit is contained in:
Zebediah Figura 2024-02-20 21:55:59 -06:00 committed by Alexandre Julliard
parent 4860be4747
commit 3103adb6a6

View File

@ -687,6 +687,21 @@ extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
CloseHandle(hfile);
}
static HANDLE get_admin_token(void)
{
TOKEN_ELEVATION_TYPE type;
TOKEN_LINKED_TOKEN linked;
DWORD size;
if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenElevationType, &type, sizeof(type), &size)
|| type == TokenElevationTypeFull)
return NULL;
if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenLinkedToken, &linked, sizeof(linked), &size))
return NULL;
return linked.LinkedToken;
}
static DWORD wait_process( HANDLE process, DWORD timeout )
{
DWORD wait, diff = 0, start = GetTickCount();
@ -722,6 +737,7 @@ run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritic
PROCESS_INFORMATION pi;
DWORD wait, status, flags;
UINT old_errmode;
HANDLE token = NULL;
GetStartupInfoA (&si);
si.dwFlags = STARTF_USESTDHANDLES;
@ -737,8 +753,16 @@ run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritic
else
flags = CREATE_DEFAULT_ERROR_MODE;
if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, flags,
NULL, tempdir, &si, &pi))
/* Some tests cause a UAC prompt on Windows if the user is not elevated,
* so to allow them to run unattended the relevant test units need to skip
* the tests if so.
*
* However, we still want Wine to run as many tests as possible, so always
* elevate ourselves. On Wine elevation isn't interactive. */
if (running_under_wine())
token = get_admin_token();
if (!CreateProcessAsUserA(token, NULL, cmd, NULL, NULL, TRUE, flags, NULL, tempdir, &si, &pi))
{
if (nocritical) SetErrorMode(old_errmode);
if (pid) *pid = 0;