aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/cache.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-08-03 18:09:36 -0500
committerSean Hall <r.sean.hall@gmail.com>2021-08-04 10:03:57 -0500
commit4d0798ec6311b48bfe6ee3cb4dd41379b4653528 (patch)
tree87e3a02f540a206403c5e61b242dabbe87c8363a /src/burn/engine/cache.cpp
parentcdba28de1ee229369b254c62bc58cf2f001899a3 (diff)
downloadwix-4d0798ec6311b48bfe6ee3cb4dd41379b4653528.tar.gz
wix-4d0798ec6311b48bfe6ee3cb4dd41379b4653528.tar.bz2
wix-4d0798ec6311b48bfe6ee3cb4dd41379b4653528.zip
Always use user's temp directory as basis for acquisition folder.
Fixes #5830
Diffstat (limited to 'src/burn/engine/cache.cpp')
-rw-r--r--src/burn/engine/cache.cpp90
1 files changed, 61 insertions, 29 deletions
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp
index 0c5266a0..5d81e1ba 100644
--- a/src/burn/engine/cache.cpp
+++ b/src/burn/engine/cache.cpp
@@ -16,9 +16,10 @@ static HRESULT CacheVerifyPayloadSignature(
16 ); 16 );
17static HRESULT CalculateBaseWorkingFolder( 17static HRESULT CalculateBaseWorkingFolder(
18 __in BURN_ENGINE_COMMAND* pInternalCommand, 18 __in BURN_ENGINE_COMMAND* pInternalCommand,
19 __in LPCWSTR wzAcquisitionFolder,
19 __inout_z LPWSTR* psczBaseWorkingFolder 20 __inout_z LPWSTR* psczBaseWorkingFolder
20 ); 21 );
21static HRESULT CalculateWorkingFolder( 22static HRESULT CalculateWorkingFolders(
22 __in BURN_CACHE* pCache, 23 __in BURN_CACHE* pCache,
23 __in BURN_ENGINE_COMMAND* pInternalCommand 24 __in BURN_ENGINE_COMMAND* pInternalCommand
24 ); 25 );
@@ -214,7 +215,7 @@ extern "C" HRESULT CacheInitialize(
214 ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-user"); 215 ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-user");
215 216
216 217
217 hr = CalculateWorkingFolder(pCache, pInternalCommand); 218 hr = CalculateWorkingFolders(pCache, pInternalCommand);
218 219
219 pCache->fInitializedCache = TRUE; 220 pCache->fInitializedCache = TRUE;
220 221
@@ -309,24 +310,42 @@ LExit:
309 return hr; 310 return hr;
310} 311}
311 312
312extern "C" HRESULT CacheEnsureWorkingFolder( 313extern "C" HRESULT CacheEnsureAcquisitionFolder(
314 __in BURN_CACHE* pCache
315 )
316{
317 Assert(pCache->fInitializedCache);
318
319 HRESULT hr = S_OK;
320
321 hr = DirEnsureExists(pCache->sczAcquisitionFolder, NULL);
322 ExitOnFailure(hr, "Failed create acquisition folder.");
323
324 // Best effort to ensure our working folder is not encrypted.
325 ::DecryptFileW(pCache->sczBaseWorkingFolder, 0);
326
327LExit:
328 return hr;
329}
330
331extern "C" HRESULT CacheEnsureBaseWorkingFolder(
313 __in BURN_CACHE* pCache, 332 __in BURN_CACHE* pCache,
314 __deref_out_z_opt LPWSTR* psczWorkingFolder 333 __deref_out_z_opt LPWSTR* psczBaseWorkingFolder
315 ) 334 )
316{ 335{
317 Assert(pCache->fInitializedCache); 336 Assert(pCache->fInitializedCache);
318 337
319 HRESULT hr = S_OK; 338 HRESULT hr = S_OK;
320 339
321 hr = DirEnsureExists(pCache->sczWorkingFolder, NULL); 340 hr = DirEnsureExists(pCache->sczBaseWorkingFolder, NULL);
322 ExitOnFailure(hr, "Failed create working folder."); 341 ExitOnFailure(hr, "Failed create working folder.");
323 342
324 // Best effort to ensure our working folder is not encrypted. 343 // Best effort to ensure our working folder is not encrypted.
325 ::DecryptFileW(pCache->sczWorkingFolder, 0); 344 ::DecryptFileW(pCache->sczBaseWorkingFolder, 0);
326 345
327 if (psczWorkingFolder) 346 if (psczBaseWorkingFolder)
328 { 347 {
329 hr = StrAllocString(psczWorkingFolder, pCache->sczWorkingFolder, 0); 348 hr = StrAllocString(psczBaseWorkingFolder, pCache->sczBaseWorkingFolder, 0);
330 ExitOnFailure(hr, "Failed to copy working folder."); 349 ExitOnFailure(hr, "Failed to copy working folder.");
331 } 350 }
332 351
@@ -353,7 +372,7 @@ extern "C" HRESULT CacheCalculateBundleWorkingPath(
353 } 372 }
354 else // Otherwise, use the real working folder. 373 else // Otherwise, use the real working folder.
355 { 374 {
356 hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", pCache->sczWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName); 375 hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", pCache->sczBaseWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName);
357 ExitOnFailure(hr, "Failed to calculate the bundle working path."); 376 ExitOnFailure(hr, "Failed to calculate the bundle working path.");
358 } 377 }
359 378
@@ -371,7 +390,7 @@ extern "C" HRESULT CacheCalculateBundleLayoutWorkingPath(
371 390
372 HRESULT hr = S_OK; 391 HRESULT hr = S_OK;
373 392
374 hr = PathConcat(pCache->sczWorkingFolder, wzBundleId, psczWorkingPath); 393 hr = PathConcat(pCache->sczAcquisitionFolder, wzBundleId, psczWorkingPath);
375 ExitOnFailure(hr, "Failed to append bundle id for bundle layout working path."); 394 ExitOnFailure(hr, "Failed to append bundle id for bundle layout working path.");
376 395
377LExit: 396LExit:
@@ -388,7 +407,7 @@ extern "C" HRESULT CacheCalculatePayloadWorkingPath(
388 407
389 HRESULT hr = S_OK; 408 HRESULT hr = S_OK;
390 409
391 hr = PathConcat(pCache->sczWorkingFolder, pPayload->sczKey, psczWorkingPath); 410 hr = PathConcat(pCache->sczAcquisitionFolder, pPayload->sczKey, psczWorkingPath);
392 ExitOnFailure(hr, "Failed to append Id as payload unverified path."); 411 ExitOnFailure(hr, "Failed to append Id as payload unverified path.");
393 412
394LExit: 413LExit:
@@ -405,7 +424,7 @@ extern "C" HRESULT CacheCalculateContainerWorkingPath(
405 424
406 HRESULT hr = S_OK; 425 HRESULT hr = S_OK;
407 426
408 hr = PathConcat(pCache->sczWorkingFolder, pContainer->sczHash, psczWorkingPath); 427 hr = PathConcat(pCache->sczAcquisitionFolder, pContainer->sczHash, psczWorkingPath);
409 ExitOnFailure(hr, "Failed to append hash as container unverified path."); 428 ExitOnFailure(hr, "Failed to append hash as container unverified path.");
410 429
411LExit: 430LExit:
@@ -1155,7 +1174,7 @@ LExit:
1155 return hr; 1174 return hr;
1156} 1175}
1157 1176
1158extern "C" HRESULT CacheRemoveWorkingFolder( 1177extern "C" HRESULT CacheRemoveBaseWorkingFolder(
1159 __in BURN_CACHE* pCache 1178 __in BURN_CACHE* pCache
1160 ) 1179 )
1161{ 1180{
@@ -1164,7 +1183,7 @@ extern "C" HRESULT CacheRemoveWorkingFolder(
1164 if (pCache->fInitializedCacheSources) 1183 if (pCache->fInitializedCacheSources)
1165 { 1184 {
1166 // Try to clean out everything in the working folder. 1185 // Try to clean out everything in the working folder.
1167 hr = DirEnsureDeleteEx(pCache->sczWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE); 1186 hr = DirEnsureDeleteEx(pCache->sczBaseWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE);
1168 TraceError(hr, "Could not delete bundle engine working folder."); 1187 TraceError(hr, "Could not delete bundle engine working folder.");
1169 } 1188 }
1170 1189
@@ -1275,9 +1294,9 @@ extern "C" void CacheCleanup(
1275 1294
1276 if (!fPerMachine) 1295 if (!fPerMachine)
1277 { 1296 {
1278 if (pCache->sczWorkingFolder) 1297 if (pCache->sczAcquisitionFolder)
1279 { 1298 {
1280 hr = PathConcat(pCache->sczWorkingFolder, L"*.*", &sczFiles); 1299 hr = PathConcat(pCache->sczAcquisitionFolder, L"*.*", &sczFiles);
1281 if (SUCCEEDED(hr)) 1300 if (SUCCEEDED(hr))
1282 { 1301 {
1283 hFind = ::FindFirstFileW(sczFiles, &wfd); 1302 hFind = ::FindFirstFileW(sczFiles, &wfd);
@@ -1299,7 +1318,7 @@ extern "C" void CacheCleanup(
1299 continue; 1318 continue;
1300 } 1319 }
1301 1320
1302 hr = PathConcatCch(pCache->sczWorkingFolder, 0, wfd.cFileName, cchFileName, &sczDelete); 1321 hr = PathConcatCch(pCache->sczAcquisitionFolder, 0, wfd.cFileName, cchFileName, &sczDelete);
1303 if (SUCCEEDED(hr)) 1322 if (SUCCEEDED(hr))
1304 { 1323 {
1305 hr = FileEnsureDelete(sczDelete); 1324 hr = FileEnsureDelete(sczDelete);
@@ -1327,7 +1346,8 @@ extern "C" void CacheUninitialize(
1327 ReleaseNullStr(pCache->sczCurrentMachinePackageCache); 1346 ReleaseNullStr(pCache->sczCurrentMachinePackageCache);
1328 ReleaseNullStr(pCache->sczDefaultMachinePackageCache); 1347 ReleaseNullStr(pCache->sczDefaultMachinePackageCache);
1329 ReleaseNullStr(pCache->sczDefaultUserPackageCache); 1348 ReleaseNullStr(pCache->sczDefaultUserPackageCache);
1330 ReleaseNullStr(pCache->sczWorkingFolder); 1349 ReleaseNullStr(pCache->sczBaseWorkingFolder);
1350 ReleaseNullStr(pCache->sczAcquisitionFolder);
1331 ReleaseNullStr(pCache->sczSourceProcessFolder); 1351 ReleaseNullStr(pCache->sczSourceProcessFolder);
1332 1352
1333 pCache->fRunningFromCache = FALSE; 1353 pCache->fRunningFromCache = FALSE;
@@ -1343,6 +1363,7 @@ extern "C" void CacheUninitialize(
1343 1363
1344static HRESULT CalculateBaseWorkingFolder( 1364static HRESULT CalculateBaseWorkingFolder(
1345 __in BURN_ENGINE_COMMAND* pInternalCommand, 1365 __in BURN_ENGINE_COMMAND* pInternalCommand,
1366 __in LPCWSTR wzAcquisitionFolder,
1346 __inout_z LPWSTR* psczBaseWorkingFolder 1367 __inout_z LPWSTR* psczBaseWorkingFolder
1347 ) 1368 )
1348{ 1369{
@@ -1351,10 +1372,10 @@ static HRESULT CalculateBaseWorkingFolder(
1351 ReleaseNullStr(*psczBaseWorkingFolder); 1372 ReleaseNullStr(*psczBaseWorkingFolder);
1352 1373
1353 // The value from the command line takes precedence. 1374 // The value from the command line takes precedence.
1354 if (pInternalCommand->sczWorkingDirectory) 1375 if (pInternalCommand->sczEngineWorkingDirectory)
1355 { 1376 {
1356 hr = PathExpand(psczBaseWorkingFolder, pInternalCommand->sczWorkingDirectory, PATH_EXPAND_FULLPATH); 1377 hr = PathExpand(psczBaseWorkingFolder, pInternalCommand->sczEngineWorkingDirectory, PATH_EXPAND_FULLPATH);
1357 ExitOnFailure(hr, "Failed to expand engine working directory from command-line: '%ls'", pInternalCommand->sczWorkingDirectory); 1378 ExitOnFailure(hr, "Failed to expand engine working directory from command-line: '%ls'", pInternalCommand->sczEngineWorkingDirectory);
1358 1379
1359 ExitFunction(); 1380 ExitFunction();
1360 } 1381 }
@@ -1373,34 +1394,41 @@ static HRESULT CalculateBaseWorkingFolder(
1373 } 1394 }
1374 } 1395 }
1375 1396
1376 // Default to the temp path specified in environment variables, but need to use system temp path for security reasons if running elevated. 1397 // Default to the acquisition folder, but need to use system temp path for security reasons if running elevated.
1377 if (pInternalCommand->fInitiallyElevated) 1398 if (pInternalCommand->fInitiallyElevated)
1378 { 1399 {
1379 hr = PathGetSystemTempPath(psczBaseWorkingFolder); 1400 hr = PathGetSystemTempPath(psczBaseWorkingFolder);
1380 ExitOnFailure(hr, "Failed to get system temp folder path for working folder."); 1401 ExitOnFailure(hr, "Failed to get system temp folder path for base working folder.");
1381 } 1402 }
1382 else 1403 else
1383 { 1404 {
1384 hr = PathGetTempPath(psczBaseWorkingFolder); 1405 hr = StrAllocString(psczBaseWorkingFolder, wzAcquisitionFolder, 0);
1385 ExitOnFailure(hr, "Failed to get temp folder path for working folder."); 1406 ExitOnFailure(hr, "Failed to copy acquisition folder path for base working folder.");
1386 } 1407 }
1387 1408
1388LExit: 1409LExit:
1389 return hr; 1410 return hr;
1390} 1411}
1391 1412
1392static HRESULT CalculateWorkingFolder( 1413static HRESULT CalculateWorkingFolders(
1393 __in BURN_CACHE* pCache, 1414 __in BURN_CACHE* pCache,
1394 __in BURN_ENGINE_COMMAND* pInternalCommand 1415 __in BURN_ENGINE_COMMAND* pInternalCommand
1395 ) 1416 )
1396{ 1417{
1397 HRESULT hr = S_OK; 1418 HRESULT hr = S_OK;
1398 RPC_STATUS rs = RPC_S_OK; 1419 RPC_STATUS rs = RPC_S_OK;
1420 LPWSTR sczBaseAcquisitionPath = NULL;
1399 LPWSTR sczTempPath = NULL; 1421 LPWSTR sczTempPath = NULL;
1400 UUID guid = {}; 1422 UUID guid = {};
1401 WCHAR wzGuid[39]; 1423 WCHAR wzGuid[39];
1402 1424
1403 hr = CalculateBaseWorkingFolder(pInternalCommand, &sczTempPath); 1425 hr = PathGetTempPath(&sczBaseAcquisitionPath);
1426 ExitOnFailure(hr, "Failed to get temp folder path for acquisition folder base.");
1427
1428 hr = PathBackslashTerminate(&sczBaseAcquisitionPath);
1429 ExitOnFailure(hr, "Failed to backslashify base engine working directory.");
1430
1431 hr = CalculateBaseWorkingFolder(pInternalCommand, sczBaseAcquisitionPath, &sczTempPath);
1404 ExitOnFailure(hr, "Failed to get base engine working directory."); 1432 ExitOnFailure(hr, "Failed to get base engine working directory.");
1405 1433
1406 hr = PathBackslashTerminate(&sczTempPath); 1434 hr = PathBackslashTerminate(&sczTempPath);
@@ -1416,10 +1444,14 @@ static HRESULT CalculateWorkingFolder(
1416 ExitOnRootFailure(hr, "Failed to convert working folder guid into string."); 1444 ExitOnRootFailure(hr, "Failed to convert working folder guid into string.");
1417 } 1445 }
1418 1446
1419 hr = StrAllocFormatted(&pCache->sczWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid); 1447 hr = StrAllocFormatted(&pCache->sczAcquisitionFolder, L"%ls%ls\\", sczBaseAcquisitionPath, wzGuid);
1448 ExitOnFailure(hr, "Failed to append random guid on to temp path for acquisition folder.");
1449
1450 hr = StrAllocFormatted(&pCache->sczBaseWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid);
1420 ExitOnFailure(hr, "Failed to append random guid on to temp path for working folder."); 1451 ExitOnFailure(hr, "Failed to append random guid on to temp path for working folder.");
1421 1452
1422LExit: 1453LExit:
1454 ReleaseStr(sczBaseAcquisitionPath);
1423 ReleaseStr(sczTempPath); 1455 ReleaseStr(sczTempPath);
1424 1456
1425 return hr; 1457 return hr;
@@ -2020,7 +2052,7 @@ static HRESULT CopyEngineToWorkingFolder(
2020 LPWSTR sczPayloadSourcePath = NULL; 2052 LPWSTR sczPayloadSourcePath = NULL;
2021 LPWSTR sczPayloadTargetPath = NULL; 2053 LPWSTR sczPayloadTargetPath = NULL;
2022 2054
2023 hr = CacheEnsureWorkingFolder(pCache, &sczWorkingFolder); 2055 hr = CacheEnsureBaseWorkingFolder(pCache, &sczWorkingFolder);
2024 ExitOnFailure(hr, "Failed to create working path to copy engine."); 2056 ExitOnFailure(hr, "Failed to create working path to copy engine.");
2025 2057
2026 hr = PathConcat(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory); 2058 hr = PathConcat(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory);