diff options
Diffstat (limited to 'src/burn/engine/cache.cpp')
| -rw-r--r-- | src/burn/engine/cache.cpp | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp index d1999a0d..02cad4a5 100644 --- a/src/burn/engine/cache.cpp +++ b/src/burn/engine/cache.cpp | |||
| @@ -29,7 +29,8 @@ static HRESULT SecurePerMachineCacheRoot(); | |||
| 29 | static HRESULT CreateCompletedPath( | 29 | static HRESULT CreateCompletedPath( |
| 30 | __in BOOL fPerMachine, | 30 | __in BOOL fPerMachine, |
| 31 | __in LPCWSTR wzCacheId, | 31 | __in LPCWSTR wzCacheId, |
| 32 | __out_z LPWSTR* psczCacheDirectory | 32 | __in LPCWSTR wzFilePath, |
| 33 | __out_z LPWSTR* psczCachePath | ||
| 33 | ); | 34 | ); |
| 34 | static HRESULT CreateUnverifiedPath( | 35 | static HRESULT CreateUnverifiedPath( |
| 35 | __in BOOL fPerMachine, | 36 | __in BOOL fPerMachine, |
| @@ -750,6 +751,20 @@ extern "C" BOOL CacheBundleRunningFromCache() | |||
| 750 | return vfRunningFromCache; | 751 | return vfRunningFromCache; |
| 751 | } | 752 | } |
| 752 | 753 | ||
| 754 | HRESULT CachePreparePackage( | ||
| 755 | __in BURN_PACKAGE* pPackage | ||
| 756 | ) | ||
| 757 | { | ||
| 758 | HRESULT hr = S_OK; | ||
| 759 | |||
| 760 | if (!pPackage->sczCacheFolder) | ||
| 761 | { | ||
| 762 | hr = CreateCompletedPath(pPackage->fPerMachine, pPackage->sczCacheId, NULL, &pPackage->sczCacheFolder); | ||
| 763 | } | ||
| 764 | |||
| 765 | return hr; | ||
| 766 | } | ||
| 767 | |||
| 753 | extern "C" HRESULT CacheBundleToCleanRoom( | 768 | extern "C" HRESULT CacheBundleToCleanRoom( |
| 754 | __in BURN_SECTION* pSection, | 769 | __in BURN_SECTION* pSection, |
| 755 | __deref_out_z_opt LPWSTR* psczCleanRoomBundlePath | 770 | __deref_out_z_opt LPWSTR* psczCleanRoomBundlePath |
| @@ -852,7 +867,7 @@ extern "C" HRESULT CacheCompleteBundle( | |||
| 852 | LPWSTR sczSourceDirectory = NULL; | 867 | LPWSTR sczSourceDirectory = NULL; |
| 853 | LPWSTR sczPayloadSourcePath = NULL; | 868 | LPWSTR sczPayloadSourcePath = NULL; |
| 854 | 869 | ||
| 855 | hr = CreateCompletedPath(fPerMachine, wzBundleId, &sczTargetDirectory); | 870 | hr = CreateCompletedPath(fPerMachine, wzBundleId, NULL, &sczTargetDirectory); |
| 856 | ExitOnFailure(hr, "Failed to create completed cache path for bundle."); | 871 | ExitOnFailure(hr, "Failed to create completed cache path for bundle."); |
| 857 | 872 | ||
| 858 | hr = PathConcat(sczTargetDirectory, wzExecutableName, &sczTargetPath); | 873 | hr = PathConcat(sczTargetDirectory, wzExecutableName, &sczTargetPath); |
| @@ -957,16 +972,12 @@ extern "C" HRESULT CacheCompletePayload( | |||
| 957 | ) | 972 | ) |
| 958 | { | 973 | { |
| 959 | HRESULT hr = S_OK; | 974 | HRESULT hr = S_OK; |
| 960 | LPWSTR sczCachedDirectory = NULL; | ||
| 961 | LPWSTR sczCachedPath = NULL; | 975 | LPWSTR sczCachedPath = NULL; |
| 962 | LPWSTR sczUnverifiedPayloadPath = NULL; | 976 | LPWSTR sczUnverifiedPayloadPath = NULL; |
| 963 | 977 | ||
| 964 | hr = CreateCompletedPath(fPerMachine, wzCacheId, &sczCachedDirectory); | 978 | hr = CreateCompletedPath(fPerMachine, wzCacheId, pPayload->sczFilePath, &sczCachedPath); |
| 965 | ExitOnFailure(hr, "Failed to get cached path for package with cache id: %ls", wzCacheId); | 979 | ExitOnFailure(hr, "Failed to get cached path for package with cache id: %ls", wzCacheId); |
| 966 | 980 | ||
| 967 | hr = PathConcat(sczCachedDirectory, pPayload->sczFilePath, &sczCachedPath); | ||
| 968 | ExitOnFailure(hr, "Failed to concat complete cached path."); | ||
| 969 | |||
| 970 | // If the cached file matches what we expected, we're good. | 981 | // If the cached file matches what we expected, we're good. |
| 971 | hr = VerifyFileAgainstPayload(pPayload, sczCachedPath, TRUE, BURN_CACHE_STEP_HASH_TO_SKIP_VERIFY, pfnCacheMessageHandler, pfnProgress, pContext); | 982 | hr = VerifyFileAgainstPayload(pPayload, sczCachedPath, TRUE, BURN_CACHE_STEP_HASH_TO_SKIP_VERIFY, pfnCacheMessageHandler, pfnProgress, pContext); |
| 972 | if (SUCCEEDED(hr)) | 983 | if (SUCCEEDED(hr)) |
| @@ -1016,7 +1027,6 @@ extern "C" HRESULT CacheCompletePayload( | |||
| 1016 | LExit: | 1027 | LExit: |
| 1017 | ReleaseStr(sczUnverifiedPayloadPath); | 1028 | ReleaseStr(sczUnverifiedPayloadPath); |
| 1018 | ReleaseStr(sczCachedPath); | 1029 | ReleaseStr(sczCachedPath); |
| 1019 | ReleaseStr(sczCachedDirectory); | ||
| 1020 | 1030 | ||
| 1021 | return hr; | 1031 | return hr; |
| 1022 | } | 1032 | } |
| @@ -1403,11 +1413,13 @@ LExit: | |||
| 1403 | static HRESULT CreateCompletedPath( | 1413 | static HRESULT CreateCompletedPath( |
| 1404 | __in BOOL fPerMachine, | 1414 | __in BOOL fPerMachine, |
| 1405 | __in LPCWSTR wzId, | 1415 | __in LPCWSTR wzId, |
| 1406 | __out_z LPWSTR* psczCacheDirectory | 1416 | __in LPCWSTR wzFilePath, |
| 1417 | __out_z LPWSTR* psczCachePath | ||
| 1407 | ) | 1418 | ) |
| 1408 | { | 1419 | { |
| 1409 | HRESULT hr = S_OK; | 1420 | HRESULT hr = S_OK; |
| 1410 | LPWSTR sczCacheDirectory = NULL; | 1421 | LPWSTR sczCacheDirectory = NULL; |
| 1422 | LPWSTR sczCacheFile = NULL; | ||
| 1411 | 1423 | ||
| 1412 | if (fPerMachine) | 1424 | if (fPerMachine) |
| 1413 | { | 1425 | { |
| @@ -1415,22 +1427,38 @@ static HRESULT CreateCompletedPath( | |||
| 1415 | ExitOnFailure(hr, "Failed to secure per-machine cache root."); | 1427 | ExitOnFailure(hr, "Failed to secure per-machine cache root."); |
| 1416 | } | 1428 | } |
| 1417 | 1429 | ||
| 1418 | // Get the cache completed path, ensure it exists, and reset any permissions people | 1430 | // Get the cache completed path. |
| 1419 | // might have tried to set on the directory so we inherit the (correct!) security | ||
| 1420 | // permissions from the parent directory. | ||
| 1421 | hr = CacheGetCompletedPath(fPerMachine, wzId, &sczCacheDirectory); | 1431 | hr = CacheGetCompletedPath(fPerMachine, wzId, &sczCacheDirectory); |
| 1422 | ExitOnFailure(hr, "Failed to get cache directory."); | 1432 | ExitOnFailure(hr, "Failed to get cache directory."); |
| 1423 | 1433 | ||
| 1434 | // Ensure it exists. | ||
| 1424 | hr = DirEnsureExists(sczCacheDirectory, NULL); | 1435 | hr = DirEnsureExists(sczCacheDirectory, NULL); |
| 1425 | ExitOnFailure(hr, "Failed to create cache directory: %ls", sczCacheDirectory); | 1436 | ExitOnFailure(hr, "Failed to create cache directory: %ls", sczCacheDirectory); |
| 1426 | 1437 | ||
| 1427 | ResetPathPermissions(fPerMachine, sczCacheDirectory); | 1438 | if (!wzFilePath) |
| 1439 | { | ||
| 1440 | // Reset any permissions people might have tried to set on the directory | ||
| 1441 | // so we inherit the (correct!) security permissions from the parent directory. | ||
| 1442 | ResetPathPermissions(fPerMachine, sczCacheDirectory); | ||
| 1428 | 1443 | ||
| 1429 | *psczCacheDirectory = sczCacheDirectory; | 1444 | *psczCachePath = sczCacheDirectory; |
| 1430 | sczCacheDirectory = NULL; | 1445 | sczCacheDirectory = NULL; |
| 1446 | } | ||
| 1447 | else | ||
| 1448 | { | ||
| 1449 | // Get the cache completed file path. | ||
| 1450 | hr = PathConcat(sczCacheDirectory, wzFilePath, &sczCacheFile); | ||
| 1451 | ExitOnFailure(hr, "Failed to construct cache file."); | ||
| 1452 | |||
| 1453 | // Don't reset permissions here. The payload's package must reset its cache folder when it starts caching. | ||
| 1454 | |||
| 1455 | *psczCachePath = sczCacheFile; | ||
| 1456 | sczCacheFile = NULL; | ||
| 1457 | } | ||
| 1431 | 1458 | ||
| 1432 | LExit: | 1459 | LExit: |
| 1433 | ReleaseStr(sczCacheDirectory); | 1460 | ReleaseStr(sczCacheDirectory); |
| 1461 | ReleaseStr(sczCacheFile); | ||
| 1434 | return hr; | 1462 | return hr; |
| 1435 | } | 1463 | } |
| 1436 | 1464 | ||
