Remove unelevation code since clean room changes made it unreachable.
Sean Hall committed
Aug 3, 2021 at 15:43 UTC
75d645c6aec0df0e02bd3aaf2fe2571d83316d4c
7 files changed
+61
-170
src/burn/engine/core.cpp
-14
@@ -1086,14 +1086,6 @@ extern "C" HRESULT CoreCreateCleanRoomCommandLine(
1086
ExitOnFailure(hr, "Failed to append /disablesystemrestore.");
1087
}
1088
1089
-#ifdef ENABLE_UNELEVATE
1090
- if (pInternalCommand->fDisableUnelevate)
1091
- {
1092
- hr = StrAllocConcatFormatted(psczCommandLine, L" /%ls", BURN_COMMANDLINE_SWITCH_DISABLE_UNELEVATE);
1093
- ExitOnFailure(hr, "Failed to append switch: %ls.", BURN_COMMANDLINE_SWITCH_DISABLE_UNELEVATE);
1094
- }
1095
-#endif
1096
-
1089
if (pInternalCommand->sczOriginalSource)
1090
{
1091
hr = StrAllocConcat(psczCommandLine, L" /originalsource", 0);
@@ -1646,12 +1638,6 @@ extern "C" HRESULT CoreParseCommandLine(
1638
{
1639
pCommand->fPassthrough = TRUE;
1640
}
1649
- else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_DISABLE_UNELEVATE, -1))
1650
- {
1651
-#ifdef ENABLE_UNELEVATE
1652
- pInternalCommand->fDisableUnelevate = TRUE;
1653
-#endif
1654
- }
1641
else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_RUNONCE, -1))
1642
{
1643
if (BURN_MODE_UNKNOWN != pInternalCommand->mode)
src/burn/engine/core.h
-3
@@ -91,9 +91,6 @@ typedef struct _BURN_ENGINE_COMMAND
91
BURN_MODE mode;
92
BURN_AU_PAUSE_ACTION automaticUpdates;
93
BOOL fDisableSystemRestore;
94
-#ifdef ENABLE_UNELEVATE
95
- BOOL fDisableUnelevate;
96
-#endif
94
BOOL fInitiallyElevated;
95
96
LPWSTR sczActiveParent;
src/burn/engine/elevation.cpp
+41
-1
@@ -100,6 +100,16 @@ typedef struct _BURN_ELEVATION_CHILD_MESSAGE_CONTEXT
100
101
// internal function declarations
102
103
+/*******************************************************************
104
+ LaunchElevatedProcess - Called from the per-user process to create
105
+ the per-machine process and set up the
106
+ communication pipe.
107
+
108
+*******************************************************************/
109
+static HRESULT LaunchElevatedProcess(
110
+ __in BURN_ENGINE_STATE* pEngineState,
111
+ __in_opt HWND hwndParent
112
+ );
113
static DWORD WINAPI ElevatedChildCacheThreadProc(
114
__in LPVOID lpThreadParameter
115
);
@@ -367,7 +377,7 @@ extern "C" HRESULT ElevationElevate(
377
nResult = IDOK;
378
379
// Create the elevated process and if successful, wait for it to connect.
370
- hr = PipeLaunchChildProcess(pEngineState->sczBundleEngineWorkingPath, &pEngineState->companionConnection, TRUE, hwndParent);
380
+ hr = LaunchElevatedProcess(pEngineState, hwndParent);
381
if (SUCCEEDED(hr))
382
{
383
LogId(REPORT_STANDARD, MSG_LAUNCH_ELEVATED_ENGINE_SUCCESS);
@@ -1371,6 +1381,36 @@ LExit:
1381
1382
// internal function definitions
1383
1384
+static HRESULT LaunchElevatedProcess(
1385
+ __in BURN_ENGINE_STATE* pEngineState,
1386
+ __in_opt HWND hwndParent
1387
+ )
1388
+{
1389
+ HRESULT hr = S_OK;
1390
+ DWORD dwCurrentProcessId = ::GetCurrentProcessId();
1391
+ LPWSTR sczParameters = NULL;
1392
+ HANDLE hProcess = NULL;
1393
+ BURN_PIPE_CONNECTION* pConnection = &pEngineState->companionConnection;
1394
+
1395
+ hr = StrAllocFormatted(&sczParameters, L"-q -%ls %ls %ls %u", BURN_COMMANDLINE_SWITCH_ELEVATED, pConnection->sczName, pConnection->sczSecret, dwCurrentProcessId);
1396
+ ExitOnFailure(hr, "Failed to allocate parameters for elevated process.");
1397
+
1398
+ // Since ShellExecuteEx doesn't support passing inherited handles, don't bother with CoreAppendFileHandleSelfToCommandLine.
1399
+ // We could fallback to using ::DuplicateHandle to inject the file handle later if necessary.
1400
+ hr = ShelExec(pEngineState->sczBundleEngineWorkingPath, sczParameters, L"runas", NULL, SW_SHOWNA, hwndParent, &hProcess);
1401
+ ExitOnFailure(hr, "Failed to launch elevated child process: %ls", pEngineState->sczBundleEngineWorkingPath);
1402
+
1403
+ pConnection->dwProcessId = ::GetProcessId(hProcess);
1404
+ pConnection->hProcess = hProcess;
1405
+ hProcess = NULL;
1406
+
1407
+LExit:
1408
+ ReleaseHandle(hProcess);
1409
+ ReleaseStr(sczParameters);
1410
+
1411
+ return hr;
1412
+}
1413
+
1414
static DWORD WINAPI ElevatedChildCacheThreadProc(
1415
__in LPVOID lpThreadParameter
1416
)
src/burn/engine/engine.cpp
+9
-21
@@ -462,31 +462,19 @@ static HRESULT RunUntrusted(
462
hr = CoreCreateCleanRoomCommandLine(&sczParameters, pEngineState, wzCleanRoomBundlePath, sczCurrentProcessPath, &hFileAttached, &hFileSelf);
463
ExitOnFailure(hr, "Failed to create clean room command-line.");
464
465
-#ifdef ENABLE_UNELEVATE
466
- // TODO: Pass file handle to unelevated process if this ever gets reenabled.
467
- if (!pEngineState->internalCommand.fDisableUnelevate)
468
- {
469
- // Try to launch unelevated and if that fails for any reason, we'll launch our process normally (even though that may make it elevated).
470
- hr = ProcExecuteAsInteractiveUser(wzCleanRoomBundlePath, sczParameters, &hProcess);
471
- }
472
-#endif
465
+ hr = StrAllocFormattedSecure(&sczFullCommandLine, L"\"%ls\" %ls", wzCleanRoomBundlePath, sczParameters);
466
+ ExitOnFailure(hr, "Failed to allocate full command-line.");
467
474
- if (!hProcess)
468
+ si.cb = sizeof(si);
469
+ si.wShowWindow = static_cast<WORD>(pEngineState->command.nCmdShow);
470
+ if (!::CreateProcessW(wzCleanRoomBundlePath, sczFullCommandLine, NULL, NULL, TRUE, 0, 0, NULL, &si, &pi))
471
{
476
- hr = StrAllocFormattedSecure(&sczFullCommandLine, L"\"%ls\" %ls", wzCleanRoomBundlePath, sczParameters);
477
- ExitOnFailure(hr, "Failed to allocate full command-line.");
478
-
479
- si.cb = sizeof(si);
480
- si.wShowWindow = static_cast<WORD>(pEngineState->command.nCmdShow);
481
- if (!::CreateProcessW(wzCleanRoomBundlePath, sczFullCommandLine, NULL, NULL, TRUE, 0, 0, NULL, &si, &pi))
482
- {
483
- ExitWithLastError(hr, "Failed to launch clean room process: %ls", sczFullCommandLine);
484
- }
485
-
486
- hProcess = pi.hProcess;
487
- pi.hProcess = NULL;
472
+ ExitWithLastError(hr, "Failed to launch clean room process: %ls", sczFullCommandLine);
473
}
474
475
+ hProcess = pi.hProcess;
476
+ pi.hProcess = NULL;
477
+
478
hr = ProcWaitForCompletion(hProcess, INFINITE, &pEngineState->userExperience.dwExitCode);
479
ExitOnFailure(hr, "Failed to wait for clean room process: %ls", wzCleanRoomBundlePath);
480
src/burn/engine/pipe.cpp
-102
@@ -313,108 +313,6 @@ LExit:
313
return hr;
314
}
315
316
-/*******************************************************************
317
- PipeLaunchParentProcess - Called from the per-machine process to create
318
- a per-user process and set up the
319
- communication pipe.
320
-
321
-*******************************************************************/
322
-const LPCWSTR BURN_COMMANDLINE_SWITCH_UNELEVATED = L"burn.unelevated";
323
-HRESULT PipeLaunchParentProcess(
324
- __in_z LPCWSTR wzCommandLine,
325
- __in int nCmdShow,
326
- __in_z LPWSTR sczConnectionName,
327
- __in_z LPWSTR sczSecret,
328
- __in BOOL /*fDisableUnelevate*/
329
- )
330
-{
331
- HRESULT hr = S_OK;
332
- DWORD dwProcessId = 0;
333
- LPWSTR sczBurnPath = NULL;
334
- LPWSTR sczParameters = NULL;
335
- HANDLE hProcess = NULL;
336
-
337
- dwProcessId = ::GetCurrentProcessId();
338
-
339
- hr = PathForCurrentProcess(&sczBurnPath, NULL);
340
- ExitOnFailure(hr, "Failed to get current process path.");
341
-
342
- hr = StrAllocFormatted(&sczParameters, L"-%ls %ls %ls %u %ls", BURN_COMMANDLINE_SWITCH_UNELEVATED, sczConnectionName, sczSecret, dwProcessId, wzCommandLine);
343
- ExitOnFailure(hr, "Failed to allocate parameters for unelevated process.");
344
-
345
-#ifdef ENABLE_UNELEVATE
346
- if (fDisableUnelevate)
347
- {
348
- hr = ProcExec(sczBurnPath, sczParameters, nCmdShow, &hProcess);
349
- ExitOnFailure(hr, "Failed to launch parent process with unelevate disabled: %ls", sczBurnPath);
350
- }
351
- else
352
- {
353
- // Try to launch unelevated and if that fails for any reason, try launch our process normally (even though that may make it elevated).
354
- hr = ProcExecuteAsInteractiveUser(sczBurnPath, sczParameters, &hProcess);
355
- if (FAILED(hr))
356
- {
357
- hr = ShelExecUnelevated(sczBurnPath, sczParameters, L"open", NULL, nCmdShow);
358
- if (FAILED(hr))
359
- {
360
- hr = ShelExec(sczBurnPath, sczParameters, L"open", NULL, nCmdShow, NULL, NULL);
361
- ExitOnFailure(hr, "Failed to launch parent process: %ls", sczBurnPath);
362
- }
363
- }
364
- }
365
-#else
366
- hr = ProcExec(sczBurnPath, sczParameters, nCmdShow, &hProcess);
367
- ExitOnFailure(hr, "Failed to launch parent process with unelevate disabled: %ls", sczBurnPath);
368
-#endif
369
-
370
-LExit:
371
- ReleaseHandle(hProcess);
372
- ReleaseStr(sczParameters);
373
- ReleaseStr(sczBurnPath);
374
-
375
- return hr;
376
-}
377
-
378
-/*******************************************************************
379
- PipeLaunchChildProcess - Called from the per-user process to create
380
- the per-machine process and set up the
381
- communication pipe.
382
-
383
-*******************************************************************/
384
-extern "C" HRESULT PipeLaunchChildProcess(
385
- __in_z LPCWSTR wzExecutablePath,
386
- __in BURN_PIPE_CONNECTION* pConnection,
387
- __in BOOL fElevate,
388
- __in_opt HWND hwndParent
389
- )
390
-{
391
- HRESULT hr = S_OK;
392
- DWORD dwCurrentProcessId = ::GetCurrentProcessId();
393
- LPWSTR sczParameters = NULL;
394
- LPCWSTR wzVerb = NULL;
395
- HANDLE hProcess = NULL;
396
-
397
- hr = StrAllocFormatted(&sczParameters, L"-q -%ls %ls %ls %u", BURN_COMMANDLINE_SWITCH_ELEVATED, pConnection->sczName, pConnection->sczSecret, dwCurrentProcessId);
398
- ExitOnFailure(hr, "Failed to allocate parameters for elevated process.");
399
-
400
- wzVerb = !fElevate ? L"open" : L"runas";
401
-
402
- // Since ShellExecuteEx doesn't support passing inherited handles, don't bother with CoreAppendFileHandleSelfToCommandLine.
403
- // We could fallback to using ::DuplicateHandle to inject the file handle later if necessary.
404
- hr = ShelExec(wzExecutablePath, sczParameters, wzVerb, NULL, SW_SHOWNA, hwndParent, &hProcess);
405
- ExitOnFailure(hr, "Failed to launch elevated child process: %ls", wzExecutablePath);
406
-
407
- pConnection->dwProcessId = ::GetProcessId(hProcess);
408
- pConnection->hProcess = hProcess;
409
- hProcess = NULL;
410
-
411
-LExit:
412
- ReleaseHandle(hProcess);
413
- ReleaseStr(sczParameters);
414
-
415
- return hr;
416
-}
417
-
316
/*******************************************************************
317
PipeWaitForChildConnect -
318
src/burn/engine/pipe.h
-13
@@ -80,19 +80,6 @@ HRESULT PipeCreatePipes(
80
__in BOOL fCreateCachePipe,
81
__out HANDLE* phEvent
82
);
83
-HRESULT PipeLaunchParentProcess(
84
- __in LPCWSTR wzCommandLine,
85
- __in int nCmdShow,
86
- __in_z LPWSTR sczConnectionName,
87
- __in_z LPWSTR sczSecret,
88
- __in BOOL fDisableUnelevate
89
- );
90
-HRESULT PipeLaunchChildProcess(
91
- __in_z LPCWSTR wzExecutablePath,
92
- __in BURN_PIPE_CONNECTION* pConnection,
93
- __in BOOL fElevate,
94
- __in_opt HWND hwndParent
95
- );
83
HRESULT PipeWaitForChildConnect(
84
__in BURN_PIPE_CONNECTION* pConnection
85
);
src/burn/test/BurnUnitTest/ElevationTest.cpp
+11
-16
@@ -52,38 +52,33 @@ namespace Bootstrapper
52
void ElevateTest()
53
{
54
HRESULT hr = S_OK;
55
- BURN_PIPE_CONNECTION connection = { };
55
+ BURN_ENGINE_STATE engineState = { };
56
+ BURN_PIPE_CONNECTION* pConnection = &engineState.companionConnection;
57
HANDLE hEvent = NULL;
58
DWORD dwResult = S_OK;
59
+
60
+ engineState.sczBundleEngineWorkingPath = L"tests\\ignore\\this\\path\\to\\burn.exe";
61
+
62
try
63
{
64
ShelFunctionOverride(ElevateTest_ShellExecuteExW);
65
62
- PipeConnectionInitialize(&connection);
66
+ PipeConnectionInitialize(pConnection);
67
68
//
69
// per-user side setup
70
//
67
- hr = PipeCreateNameAndSecret(&connection.sczName, &connection.sczSecret);
68
- TestThrowOnFailure(hr, L"Failed to create connection name and secret.");
69
-
70
- hr = PipeCreatePipes(&connection, TRUE, &hEvent);
71
- TestThrowOnFailure(hr, L"Failed to create pipes.");
72
-
73
- hr = PipeLaunchChildProcess(L"tests\\ignore\\this\\path\\to\\burn.exe", &connection, TRUE, NULL);
74
- TestThrowOnFailure(hr, L"Failed to create elevated process.");
75
-
76
- hr = PipeWaitForChildConnect(&connection);
77
- TestThrowOnFailure(hr, L"Failed to wait for child process to connect.");
71
+ hr = ElevationElevate(&engineState, NULL);
72
+ TestThrowOnFailure(hr, L"Failed to elevate.");
73
74
// post execute message
80
- hr = PipeSendMessage(connection.hPipe, TEST_PARENT_SENT_MESSAGE_ID, NULL, 0, ProcessParentMessages, NULL, &dwResult);
75
+ hr = PipeSendMessage(pConnection->hPipe, TEST_PARENT_SENT_MESSAGE_ID, NULL, 0, ProcessParentMessages, NULL, &dwResult);
76
TestThrowOnFailure(hr, "Failed to post execute message to per-machine process.");
77
78
//
79
// initiate termination
80
//
86
- hr = PipeTerminateChildProcess(&connection, 666, FALSE);
81
+ hr = PipeTerminateChildProcess(pConnection, 666, FALSE);
82
TestThrowOnFailure(hr, L"Failed to terminate elevated process.");
83
84
// check flags
@@ -91,7 +86,7 @@ namespace Bootstrapper
86
}
87
finally
88
{
94
- PipeConnectionUninitialize(&connection);
89
+ PipeConnectionUninitialize(pConnection);
90
ReleaseHandle(hEvent);
91
}
92
}