diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-08-03 18:06:54 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-08-04 10:03:57 -0500 |
| commit | cdba28de1ee229369b254c62bc58cf2f001899a3 (patch) | |
| tree | 4ae9a7aafd83ff311c5440df2c6d4a8693f8f23b /src/burn/engine/cache.cpp | |
| parent | 75d645c6aec0df0e02bd3aaf2fe2571d83316d4c (diff) | |
| download | wix-cdba28de1ee229369b254c62bc58cf2f001899a3.tar.gz wix-cdba28de1ee229369b254c62bc58cf2f001899a3.tar.bz2 wix-cdba28de1ee229369b254c62bc58cf2f001899a3.zip | |
Add argument and policy setting to set Burn's base working directory.
Fixes #5856
Diffstat (limited to 'src/burn/engine/cache.cpp')
| -rw-r--r-- | src/burn/engine/cache.cpp | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp index 54328091..0c5266a0 100644 --- a/src/burn/engine/cache.cpp +++ b/src/burn/engine/cache.cpp | |||
| @@ -14,6 +14,10 @@ static HRESULT CacheVerifyPayloadSignature( | |||
| 14 | __in_z LPCWSTR wzUnverifiedPayloadPath, | 14 | __in_z LPCWSTR wzUnverifiedPayloadPath, |
| 15 | __in HANDLE hFile | 15 | __in HANDLE hFile |
| 16 | ); | 16 | ); |
| 17 | static HRESULT CalculateBaseWorkingFolder( | ||
| 18 | __in BURN_ENGINE_COMMAND* pInternalCommand, | ||
| 19 | __inout_z LPWSTR* psczBaseWorkingFolder | ||
| 20 | ); | ||
| 17 | static HRESULT CalculateWorkingFolder( | 21 | static HRESULT CalculateWorkingFolder( |
| 18 | __in BURN_CACHE* pCache, | 22 | __in BURN_CACHE* pCache, |
| 19 | __in BURN_ENGINE_COMMAND* pInternalCommand | 23 | __in BURN_ENGINE_COMMAND* pInternalCommand |
| @@ -1337,28 +1341,71 @@ extern "C" void CacheUninitialize( | |||
| 1337 | 1341 | ||
| 1338 | // Internal functions. | 1342 | // Internal functions. |
| 1339 | 1343 | ||
| 1340 | static HRESULT CalculateWorkingFolder( | 1344 | static HRESULT CalculateBaseWorkingFolder( |
| 1341 | __in BURN_CACHE* pCache, | 1345 | __in BURN_ENGINE_COMMAND* pInternalCommand, |
| 1342 | __in BURN_ENGINE_COMMAND* pInternalCommand | 1346 | __inout_z LPWSTR* psczBaseWorkingFolder |
| 1343 | ) | 1347 | ) |
| 1344 | { | 1348 | { |
| 1345 | HRESULT hr = S_OK; | 1349 | HRESULT hr = S_OK; |
| 1346 | RPC_STATUS rs = RPC_S_OK; | ||
| 1347 | LPWSTR sczTempPath = NULL; | ||
| 1348 | UUID guid = {}; | ||
| 1349 | WCHAR wzGuid[39]; | ||
| 1350 | 1350 | ||
| 1351 | ReleaseNullStr(*psczBaseWorkingFolder); | ||
| 1352 | |||
| 1353 | // The value from the command line takes precedence. | ||
| 1354 | if (pInternalCommand->sczWorkingDirectory) | ||
| 1355 | { | ||
| 1356 | hr = PathExpand(psczBaseWorkingFolder, pInternalCommand->sczWorkingDirectory, PATH_EXPAND_FULLPATH); | ||
| 1357 | ExitOnFailure(hr, "Failed to expand engine working directory from command-line: '%ls'", pInternalCommand->sczWorkingDirectory); | ||
| 1358 | |||
| 1359 | ExitFunction(); | ||
| 1360 | } | ||
| 1361 | |||
| 1362 | // The base working folder can be specified through policy, | ||
| 1363 | // but only use it if elevated because it should be secured against non-admin users. | ||
| 1351 | if (pInternalCommand->fInitiallyElevated) | 1364 | if (pInternalCommand->fInitiallyElevated) |
| 1352 | { | 1365 | { |
| 1353 | hr = PathGetSystemTempPath(&sczTempPath); | 1366 | hr = PolcReadString(POLICY_BURN_REGISTRY_PATH, L"EngineWorkingDirectory", NULL, psczBaseWorkingFolder); |
| 1367 | ExitOnFailure(hr, "Failed to read EngineWorkingDirectory policy directory."); | ||
| 1368 | |||
| 1369 | if (*psczBaseWorkingFolder) | ||
| 1370 | { | ||
| 1371 | // PolcReadString is supposed to automatically expand REG_EXPAND_SZ values. | ||
| 1372 | ExitFunction(); | ||
| 1373 | } | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | // Default to the temp path specified in environment variables, but need to use system temp path for security reasons if running elevated. | ||
| 1377 | if (pInternalCommand->fInitiallyElevated) | ||
| 1378 | { | ||
| 1379 | hr = PathGetSystemTempPath(psczBaseWorkingFolder); | ||
| 1354 | ExitOnFailure(hr, "Failed to get system temp folder path for working folder."); | 1380 | ExitOnFailure(hr, "Failed to get system temp folder path for working folder."); |
| 1355 | } | 1381 | } |
| 1356 | else | 1382 | else |
| 1357 | { | 1383 | { |
| 1358 | hr = PathGetTempPath(&sczTempPath); | 1384 | hr = PathGetTempPath(psczBaseWorkingFolder); |
| 1359 | ExitOnFailure(hr, "Failed to get temp folder path for working folder."); | 1385 | ExitOnFailure(hr, "Failed to get temp folder path for working folder."); |
| 1360 | } | 1386 | } |
| 1361 | 1387 | ||
| 1388 | LExit: | ||
| 1389 | return hr; | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | static HRESULT CalculateWorkingFolder( | ||
| 1393 | __in BURN_CACHE* pCache, | ||
| 1394 | __in BURN_ENGINE_COMMAND* pInternalCommand | ||
| 1395 | ) | ||
| 1396 | { | ||
| 1397 | HRESULT hr = S_OK; | ||
| 1398 | RPC_STATUS rs = RPC_S_OK; | ||
| 1399 | LPWSTR sczTempPath = NULL; | ||
| 1400 | UUID guid = {}; | ||
| 1401 | WCHAR wzGuid[39]; | ||
| 1402 | |||
| 1403 | hr = CalculateBaseWorkingFolder(pInternalCommand, &sczTempPath); | ||
| 1404 | ExitOnFailure(hr, "Failed to get base engine working directory."); | ||
| 1405 | |||
| 1406 | hr = PathBackslashTerminate(&sczTempPath); | ||
| 1407 | ExitOnFailure(hr, "Failed to backslashify base engine working directory."); | ||
| 1408 | |||
| 1362 | rs = ::UuidCreate(&guid); | 1409 | rs = ::UuidCreate(&guid); |
| 1363 | hr = HRESULT_FROM_RPC(rs); | 1410 | hr = HRESULT_FROM_RPC(rs); |
| 1364 | ExitOnFailure(hr, "Failed to create working folder guid."); | 1411 | ExitOnFailure(hr, "Failed to create working folder guid."); |
