aboutsummaryrefslogtreecommitdiff
path: root/src/engine/cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/cache.cpp')
-rw-r--r--src/engine/cache.cpp68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/engine/cache.cpp b/src/engine/cache.cpp
index 2299d26d..9aa94d1d 100644
--- a/src/engine/cache.cpp
+++ b/src/engine/cache.cpp
@@ -59,11 +59,13 @@ static HRESULT TransferWorkingPathToUnverifiedPath(
59 ); 59 );
60static HRESULT VerifyFileAgainstContainer( 60static HRESULT VerifyFileAgainstContainer(
61 __in BURN_CONTAINER* pContainer, 61 __in BURN_CONTAINER* pContainer,
62 __in_z LPCWSTR wzVerifyPath 62 __in_z LPCWSTR wzVerifyPath,
63 __in BOOL fAlreadyCached
63 ); 64 );
64static HRESULT VerifyFileAgainstPayload( 65static HRESULT VerifyFileAgainstPayload(
65 __in BURN_PAYLOAD* pPayload, 66 __in BURN_PAYLOAD* pPayload,
66 __in_z LPCWSTR wzVerifyPath 67 __in_z LPCWSTR wzVerifyPath,
68 __in BOOL fAlreadyCached
67 ); 69 );
68static HRESULT ResetPathPermissions( 70static HRESULT ResetPathPermissions(
69 __in BOOL fPerMachine, 71 __in BOOL fPerMachine,
@@ -896,19 +898,11 @@ extern "C" HRESULT CacheCompletePayload(
896 ExitOnFailure(hr, "Failed to concat complete cached path."); 898 ExitOnFailure(hr, "Failed to concat complete cached path.");
897 899
898 // If the cached file matches what we expected, we're good. 900 // If the cached file matches what we expected, we're good.
899 hr = VerifyFileAgainstPayload(pPayload, sczCachedPath); 901 hr = VerifyFileAgainstPayload(pPayload, sczCachedPath, TRUE);
900 if (SUCCEEDED(hr)) 902 if (SUCCEEDED(hr))
901 { 903 {
902 ::DecryptFileW(sczCachedPath, 0); // Let's try to make sure it's not encrypted.
903 LogId(REPORT_STANDARD, MSG_VERIFIED_EXISTING_PAYLOAD, pPayload->sczKey, sczCachedPath);
904 ExitFunction(); 904 ExitFunction();
905 } 905 }
906 else if (E_PATHNOTFOUND != hr && E_FILENOTFOUND != hr)
907 {
908 LogErrorId(hr, MSG_FAILED_VERIFY_PAYLOAD, pPayload->sczKey, sczCachedPath, NULL);
909
910 FileEnsureDelete(sczCachedPath); // if the file existed but did not verify correctly, make it go away.
911 }
912 906
913 hr = CreateUnverifiedPath(fPerMachine, pPayload->sczKey, &sczUnverifiedPayloadPath); 907 hr = CreateUnverifiedPath(fPerMachine, pPayload->sczKey, &sczUnverifiedPayloadPath);
914 ExitOnFailure(hr, "Failed to create unverified path."); 908 ExitOnFailure(hr, "Failed to create unverified path.");
@@ -928,14 +922,8 @@ extern "C" HRESULT CacheCompletePayload(
928 hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath); 922 hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath);
929 ExitOnFailure(hr, "Failed to reset permissions on unverified cached payload: %ls", pPayload->sczKey); 923 ExitOnFailure(hr, "Failed to reset permissions on unverified cached payload: %ls", pPayload->sczKey);
930 924
931 hr = VerifyFileAgainstPayload(pPayload, sczUnverifiedPayloadPath); 925 hr = VerifyFileAgainstPayload(pPayload, sczUnverifiedPayloadPath, FALSE);
932 if (FAILED(hr)) 926 LogExitOnFailure(hr, MSG_FAILED_VERIFY_PAYLOAD, "Failed to verify payload: %ls at path: %ls", pPayload->sczKey, sczUnverifiedPayloadPath, NULL);
933 {
934 LogErrorId(hr, MSG_FAILED_VERIFY_PAYLOAD, pPayload->sczKey, sczUnverifiedPayloadPath, NULL);
935
936 FileEnsureDelete(sczUnverifiedPayloadPath); // if the file did not verify correctly, make it go away.
937 ExitFunction();
938 }
939 927
940 LogId(REPORT_STANDARD, MSG_VERIFIED_ACQUIRED_PAYLOAD, pPayload->sczKey, sczUnverifiedPayloadPath, fMove ? "moving" : "copying", sczCachedPath); 928 LogId(REPORT_STANDARD, MSG_VERIFIED_ACQUIRED_PAYLOAD, pPayload->sczKey, sczUnverifiedPayloadPath, fMove ? "moving" : "copying", sczCachedPath);
941 929
@@ -963,7 +951,7 @@ extern "C" HRESULT CacheVerifyContainer(
963 hr = PathConcat(wzCachedDirectory, pContainer->sczFilePath, &sczCachedPath); 951 hr = PathConcat(wzCachedDirectory, pContainer->sczFilePath, &sczCachedPath);
964 ExitOnFailure(hr, "Failed to concat complete cached path."); 952 ExitOnFailure(hr, "Failed to concat complete cached path.");
965 953
966 hr = VerifyFileAgainstContainer(pContainer, sczCachedPath); 954 hr = VerifyFileAgainstContainer(pContainer, sczCachedPath, TRUE);
967 955
968LExit: 956LExit:
969 ReleaseStr(sczCachedPath); 957 ReleaseStr(sczCachedPath);
@@ -982,7 +970,7 @@ extern "C" HRESULT CacheVerifyPayload(
982 hr = PathConcat(wzCachedDirectory, pPayload->sczFilePath, &sczCachedPath); 970 hr = PathConcat(wzCachedDirectory, pPayload->sczFilePath, &sczCachedPath);
983 ExitOnFailure(hr, "Failed to concat complete cached path."); 971 ExitOnFailure(hr, "Failed to concat complete cached path.");
984 972
985 hr = VerifyFileAgainstPayload(pPayload, sczCachedPath); 973 hr = VerifyFileAgainstPayload(pPayload, sczCachedPath, TRUE);
986 974
987LExit: 975LExit:
988 ReleaseStr(sczCachedPath); 976 ReleaseStr(sczCachedPath);
@@ -1460,7 +1448,8 @@ LExit:
1460 1448
1461static HRESULT VerifyFileAgainstContainer( 1449static HRESULT VerifyFileAgainstContainer(
1462 __in BURN_CONTAINER* pContainer, 1450 __in BURN_CONTAINER* pContainer,
1463 __in_z LPCWSTR wzVerifyPath 1451 __in_z LPCWSTR wzVerifyPath,
1452 __in BOOL fAlreadyCached
1464 ) 1453 )
1465{ 1454{
1466 HRESULT hr = S_OK; 1455 HRESULT hr = S_OK;
@@ -1484,15 +1473,32 @@ static HRESULT VerifyFileAgainstContainer(
1484 ExitOnFailure(hr, "Failed to verify hash of container: %ls", pContainer->sczId); 1473 ExitOnFailure(hr, "Failed to verify hash of container: %ls", pContainer->sczId);
1485 } 1474 }
1486 1475
1476 if (fAlreadyCached)
1477 {
1478 LogId(REPORT_STANDARD, MSG_VERIFIED_EXISTING_CONTAINER, pContainer->sczId, wzVerifyPath);
1479 ::DecryptFileW(wzVerifyPath, 0); // Let's try to make sure it's not encrypted.
1480 }
1481
1487LExit: 1482LExit:
1488 ReleaseFileHandle(hFile); 1483 ReleaseFileHandle(hFile);
1489 1484
1485 if (FAILED(hr) && E_PATHNOTFOUND != hr && E_FILENOTFOUND != hr)
1486 {
1487 if (fAlreadyCached)
1488 {
1489 LogErrorId(hr, MSG_FAILED_VERIFY_CONTAINER, pContainer->sczId, wzVerifyPath, NULL);
1490 }
1491
1492 FileEnsureDelete(wzVerifyPath); // if the file existed but did not verify correctly, make it go away.
1493 }
1494
1490 return hr; 1495 return hr;
1491} 1496}
1492 1497
1493static HRESULT VerifyFileAgainstPayload( 1498static HRESULT VerifyFileAgainstPayload(
1494 __in BURN_PAYLOAD* pPayload, 1499 __in BURN_PAYLOAD* pPayload,
1495 __in_z LPCWSTR wzVerifyPath 1500 __in_z LPCWSTR wzVerifyPath,
1501 __in BOOL fAlreadyCached
1496 ) 1502 )
1497{ 1503{
1498 HRESULT hr = S_OK; 1504 HRESULT hr = S_OK;
@@ -1516,9 +1522,25 @@ static HRESULT VerifyFileAgainstPayload(
1516 ExitOnFailure(hr, "Failed to verify hash of payload: %ls", pPayload->sczKey); 1522 ExitOnFailure(hr, "Failed to verify hash of payload: %ls", pPayload->sczKey);
1517 } 1523 }
1518 1524
1525 if (fAlreadyCached)
1526 {
1527 LogId(REPORT_STANDARD, MSG_VERIFIED_EXISTING_PAYLOAD, pPayload->sczKey, wzVerifyPath);
1528 ::DecryptFileW(wzVerifyPath, 0); // Let's try to make sure it's not encrypted.
1529 }
1530
1519LExit: 1531LExit:
1520 ReleaseFileHandle(hFile); 1532 ReleaseFileHandle(hFile);
1521 1533
1534 if (FAILED(hr) && E_PATHNOTFOUND != hr && E_FILENOTFOUND != hr)
1535 {
1536 if (fAlreadyCached)
1537 {
1538 LogErrorId(hr, MSG_FAILED_VERIFY_PAYLOAD, pPayload->sczKey, wzVerifyPath, NULL);
1539 }
1540
1541 FileEnsureDelete(wzVerifyPath); // if the file existed but did not verify correctly, make it go away.
1542 }
1543
1522 return hr; 1544 return hr;
1523} 1545}
1524 1546