diff options
Diffstat (limited to 'src/engine/cache.cpp')
| -rw-r--r-- | src/engine/cache.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/src/engine/cache.cpp b/src/engine/cache.cpp index 6ddbfb50..6ac313e0 100644 --- a/src/engine/cache.cpp +++ b/src/engine/cache.cpp | |||
| @@ -57,6 +57,10 @@ static HRESULT TransferWorkingPathToUnverifiedPath( | |||
| 57 | __in_z LPCWSTR wzUnverifiedPayloadPath, | 57 | __in_z LPCWSTR wzUnverifiedPayloadPath, |
| 58 | __in BOOL fMove | 58 | __in BOOL fMove |
| 59 | ); | 59 | ); |
| 60 | static HRESULT VerifyFileAgainstContainer( | ||
| 61 | __in BURN_CONTAINER* pContainer, | ||
| 62 | __in_z LPCWSTR wzVerifyPath | ||
| 63 | ); | ||
| 60 | static HRESULT VerifyFileAgainstPayload( | 64 | static HRESULT VerifyFileAgainstPayload( |
| 61 | __in BURN_PAYLOAD* pPayload, | 65 | __in BURN_PAYLOAD* pPayload, |
| 62 | __in_z LPCWSTR wzVerifyPath | 66 | __in_z LPCWSTR wzVerifyPath |
| @@ -837,7 +841,7 @@ LExit: | |||
| 837 | extern "C" HRESULT CacheCompletePayload( | 841 | extern "C" HRESULT CacheCompletePayload( |
| 838 | __in BOOL fPerMachine, | 842 | __in BOOL fPerMachine, |
| 839 | __in BURN_PAYLOAD* pPayload, | 843 | __in BURN_PAYLOAD* pPayload, |
| 840 | __in_z_opt LPCWSTR wzCacheId, | 844 | __in_z LPCWSTR wzCacheId, |
| 841 | __in_z LPCWSTR wzWorkingPayloadPath, | 845 | __in_z LPCWSTR wzWorkingPayloadPath, |
| 842 | __in BOOL fMove | 846 | __in BOOL fMove |
| 843 | ) | 847 | ) |
| @@ -910,6 +914,44 @@ LExit: | |||
| 910 | return hr; | 914 | return hr; |
| 911 | } | 915 | } |
| 912 | 916 | ||
| 917 | extern "C" HRESULT CacheVerifyContainer( | ||
| 918 | __in BURN_CONTAINER* pContainer, | ||
| 919 | __in_z LPCWSTR wzCachedDirectory | ||
| 920 | ) | ||
| 921 | { | ||
| 922 | HRESULT hr = S_OK; | ||
| 923 | LPWSTR sczCachedPath = NULL; | ||
| 924 | |||
| 925 | hr = PathConcat(wzCachedDirectory, pContainer->sczFilePath, &sczCachedPath); | ||
| 926 | ExitOnFailure(hr, "Failed to concat complete cached path."); | ||
| 927 | |||
| 928 | hr = VerifyFileAgainstContainer(pContainer, sczCachedPath); | ||
| 929 | |||
| 930 | LExit: | ||
| 931 | ReleaseStr(sczCachedPath); | ||
| 932 | |||
| 933 | return hr; | ||
| 934 | } | ||
| 935 | |||
| 936 | extern "C" HRESULT CacheVerifyPayload( | ||
| 937 | __in BURN_PAYLOAD* pPayload, | ||
| 938 | __in_z LPCWSTR wzCachedDirectory | ||
| 939 | ) | ||
| 940 | { | ||
| 941 | HRESULT hr = S_OK; | ||
| 942 | LPWSTR sczCachedPath = NULL; | ||
| 943 | |||
| 944 | hr = PathConcat(wzCachedDirectory, pPayload->sczFilePath, &sczCachedPath); | ||
| 945 | ExitOnFailure(hr, "Failed to concat complete cached path."); | ||
| 946 | |||
| 947 | hr = VerifyFileAgainstPayload(pPayload, sczCachedPath); | ||
| 948 | |||
| 949 | LExit: | ||
| 950 | ReleaseStr(sczCachedPath); | ||
| 951 | |||
| 952 | return hr; | ||
| 953 | } | ||
| 954 | |||
| 913 | extern "C" HRESULT CacheRemoveWorkingFolder( | 955 | extern "C" HRESULT CacheRemoveWorkingFolder( |
| 914 | __in_z_opt LPCWSTR wzBundleId | 956 | __in_z_opt LPCWSTR wzBundleId |
| 915 | ) | 957 | ) |
| @@ -1383,6 +1425,38 @@ LExit: | |||
| 1383 | return hr; | 1425 | return hr; |
| 1384 | } | 1426 | } |
| 1385 | 1427 | ||
| 1428 | static HRESULT VerifyFileAgainstContainer( | ||
| 1429 | __in BURN_CONTAINER* pContainer, | ||
| 1430 | __in_z LPCWSTR wzVerifyPath | ||
| 1431 | ) | ||
| 1432 | { | ||
| 1433 | HRESULT hr = S_OK; | ||
| 1434 | HANDLE hFile = INVALID_HANDLE_VALUE; | ||
| 1435 | |||
| 1436 | // Get the container on disk actual hash. | ||
| 1437 | hFile = ::CreateFileW(wzVerifyPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | ||
| 1438 | if (INVALID_HANDLE_VALUE == hFile) | ||
| 1439 | { | ||
| 1440 | hr = HRESULT_FROM_WIN32(::GetLastError()); | ||
| 1441 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) | ||
| 1442 | { | ||
| 1443 | ExitFunction(); // do not log error when the file was not found. | ||
| 1444 | } | ||
| 1445 | ExitOnRootFailure(hr, "Failed to open container at path: %ls", wzVerifyPath); | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | if (pContainer->pbHash) // the container should have a hash we can use to verify it. | ||
| 1449 | { | ||
| 1450 | hr = VerifyHash(pContainer->pbHash, pContainer->cbHash, pContainer->qwFileSize, wzVerifyPath, hFile); | ||
| 1451 | ExitOnFailure(hr, "Failed to verify hash of container: %ls", pContainer->sczId); | ||
| 1452 | } | ||
| 1453 | |||
| 1454 | LExit: | ||
| 1455 | ReleaseFileHandle(hFile); | ||
| 1456 | |||
| 1457 | return hr; | ||
| 1458 | } | ||
| 1459 | |||
| 1386 | static HRESULT VerifyFileAgainstPayload( | 1460 | static HRESULT VerifyFileAgainstPayload( |
| 1387 | __in BURN_PAYLOAD* pPayload, | 1461 | __in BURN_PAYLOAD* pPayload, |
| 1388 | __in_z LPCWSTR wzVerifyPath | 1462 | __in_z LPCWSTR wzVerifyPath |
