diff options
| author | Nir Bar <nir.bar@panel-sw.co.il> | 2021-03-17 14:45:03 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-17 14:49:24 -0500 |
| commit | b7582318f6cb6e166f5ca22128caea2a97551a1f (patch) | |
| tree | f92071000dd33376e6b982b52ed2172278ef4035 /src/engine/elevation.cpp | |
| parent | af68033509730ffe01602f839861a47287bb709f (diff) | |
| download | wix-b7582318f6cb6e166f5ca22128caea2a97551a1f.tar.gz wix-b7582318f6cb6e166f5ca22128caea2a97551a1f.tar.bz2 wix-b7582318f6cb6e166f5ca22128caea2a97551a1f.zip | |
Use wiutil to start/end msi transactions
Release MSI transaction handles immediately
contributes to #5386
Diffstat (limited to 'src/engine/elevation.cpp')
| -rw-r--r-- | src/engine/elevation.cpp | 111 |
1 files changed, 87 insertions, 24 deletions
diff --git a/src/engine/elevation.cpp b/src/engine/elevation.cpp index 7c5dae4b..1737bf5b 100644 --- a/src/engine/elevation.cpp +++ b/src/engine/elevation.cpp | |||
| @@ -246,14 +246,17 @@ static HRESULT OnLaunchApprovedExe( | |||
| 246 | __in DWORD cbData | 246 | __in DWORD cbData |
| 247 | ); | 247 | ); |
| 248 | static HRESULT OnMsiBeginTransaction( | 248 | static HRESULT OnMsiBeginTransaction( |
| 249 | __in BURN_PACKAGES* pPackages, | ||
| 249 | __in BYTE* pbData, | 250 | __in BYTE* pbData, |
| 250 | __in DWORD cbData | 251 | __in DWORD cbData |
| 251 | ); | 252 | ); |
| 252 | static HRESULT OnMsiCommitTransaction( | 253 | static HRESULT OnMsiCommitTransaction( |
| 254 | __in BURN_PACKAGES* pPackages, | ||
| 253 | __in BYTE* pbData, | 255 | __in BYTE* pbData, |
| 254 | __in DWORD cbData | 256 | __in DWORD cbData |
| 255 | ); | 257 | ); |
| 256 | static HRESULT OnMsiRollbackTransaction( | 258 | static HRESULT OnMsiRollbackTransaction( |
| 259 | __in BURN_PACKAGES* pPackages, | ||
| 257 | __in BYTE* pbData, | 260 | __in BYTE* pbData, |
| 258 | __in DWORD cbData | 261 | __in DWORD cbData |
| 259 | ); | 262 | ); |
| @@ -763,7 +766,7 @@ LExit: | |||
| 763 | 766 | ||
| 764 | extern "C" HRESULT ElevationMsiBeginTransaction( | 767 | extern "C" HRESULT ElevationMsiBeginTransaction( |
| 765 | __in HANDLE hPipe, | 768 | __in HANDLE hPipe, |
| 766 | __in LPCWSTR wzName | 769 | __in BURN_ROLLBACK_BOUNDARY* pRollbackBoundary |
| 767 | ) | 770 | ) |
| 768 | { | 771 | { |
| 769 | HRESULT hr = S_OK; | 772 | HRESULT hr = S_OK; |
| @@ -772,9 +775,12 @@ extern "C" HRESULT ElevationMsiBeginTransaction( | |||
| 772 | DWORD dwResult = ERROR_SUCCESS; | 775 | DWORD dwResult = ERROR_SUCCESS; |
| 773 | 776 | ||
| 774 | // serialize message data | 777 | // serialize message data |
| 775 | hr = BuffWriteString(&pbData, &cbData, wzName); | 778 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczId); |
| 776 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); | 779 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); |
| 777 | 780 | ||
| 781 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczLogPath); | ||
| 782 | ExitOnFailure(hr, "Failed to write transaction log path to message buffer."); | ||
| 783 | |||
| 778 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); | 784 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); |
| 779 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION message to per-machine process."); | 785 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION message to per-machine process."); |
| 780 | 786 | ||
| @@ -788,7 +794,7 @@ LExit: | |||
| 788 | 794 | ||
| 789 | extern "C" HRESULT ElevationMsiCommitTransaction( | 795 | extern "C" HRESULT ElevationMsiCommitTransaction( |
| 790 | __in HANDLE hPipe, | 796 | __in HANDLE hPipe, |
| 791 | __in LPCWSTR wzName | 797 | __in BURN_ROLLBACK_BOUNDARY* pRollbackBoundary |
| 792 | ) | 798 | ) |
| 793 | { | 799 | { |
| 794 | HRESULT hr = S_OK; | 800 | HRESULT hr = S_OK; |
| @@ -797,9 +803,12 @@ extern "C" HRESULT ElevationMsiCommitTransaction( | |||
| 797 | DWORD dwResult = ERROR_SUCCESS; | 803 | DWORD dwResult = ERROR_SUCCESS; |
| 798 | 804 | ||
| 799 | // serialize message data | 805 | // serialize message data |
| 800 | hr = BuffWriteString(&pbData, &cbData, wzName); | 806 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczId); |
| 801 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); | 807 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); |
| 802 | 808 | ||
| 809 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczLogPath); | ||
| 810 | ExitOnFailure(hr, "Failed to write transaction log path to message buffer."); | ||
| 811 | |||
| 803 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); | 812 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); |
| 804 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION message to per-machine process."); | 813 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION message to per-machine process."); |
| 805 | 814 | ||
| @@ -811,7 +820,7 @@ LExit: | |||
| 811 | 820 | ||
| 812 | extern "C" HRESULT ElevationMsiRollbackTransaction( | 821 | extern "C" HRESULT ElevationMsiRollbackTransaction( |
| 813 | __in HANDLE hPipe, | 822 | __in HANDLE hPipe, |
| 814 | __in LPCWSTR wzName | 823 | __in BURN_ROLLBACK_BOUNDARY* pRollbackBoundary |
| 815 | ) | 824 | ) |
| 816 | { | 825 | { |
| 817 | HRESULT hr = S_OK; | 826 | HRESULT hr = S_OK; |
| @@ -820,9 +829,12 @@ extern "C" HRESULT ElevationMsiRollbackTransaction( | |||
| 820 | DWORD dwResult = ERROR_SUCCESS; | 829 | DWORD dwResult = ERROR_SUCCESS; |
| 821 | 830 | ||
| 822 | // serialize message data | 831 | // serialize message data |
| 823 | hr = BuffWriteString(&pbData, &cbData, wzName); | 832 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczId); |
| 824 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); | 833 | ExitOnFailure(hr, "Failed to write transaction name to message buffer."); |
| 825 | 834 | ||
| 835 | hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczLogPath); | ||
| 836 | ExitOnFailure(hr, "Failed to write transaction log path to message buffer."); | ||
| 837 | |||
| 826 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); | 838 | hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION, pbData, cbData, NULL, NULL, &dwResult); |
| 827 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION message to per-machine process."); | 839 | ExitOnFailure(hr, "Failed to send BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION message to per-machine process."); |
| 828 | 840 | ||
| @@ -1610,15 +1622,15 @@ static HRESULT ProcessElevatedChildMessage( | |||
| 1610 | switch (pMsg->dwMessage) | 1622 | switch (pMsg->dwMessage) |
| 1611 | { | 1623 | { |
| 1612 | case BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION: | 1624 | case BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION: |
| 1613 | hrResult = OnMsiBeginTransaction((BYTE*)pMsg->pvData, pMsg->cbData); | 1625 | hrResult = OnMsiBeginTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData); |
| 1614 | break; | 1626 | break; |
| 1615 | 1627 | ||
| 1616 | case BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION: | 1628 | case BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION: |
| 1617 | hrResult = OnMsiCommitTransaction((BYTE*)pMsg->pvData, pMsg->cbData); | 1629 | hrResult = OnMsiCommitTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData); |
| 1618 | break; | 1630 | break; |
| 1619 | 1631 | ||
| 1620 | case BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION: | 1632 | case BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION: |
| 1621 | hrResult = OnMsiRollbackTransaction((BYTE*)pMsg->pvData, pMsg->cbData); | 1633 | hrResult = OnMsiRollbackTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData); |
| 1622 | break; | 1634 | break; |
| 1623 | 1635 | ||
| 1624 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE: | 1636 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE: |
| @@ -2824,64 +2836,115 @@ LExit: | |||
| 2824 | } | 2836 | } |
| 2825 | 2837 | ||
| 2826 | static HRESULT OnMsiBeginTransaction( | 2838 | static HRESULT OnMsiBeginTransaction( |
| 2839 | __in BURN_PACKAGES* pPackages, | ||
| 2827 | __in BYTE* pbData, | 2840 | __in BYTE* pbData, |
| 2828 | __in DWORD cbData | 2841 | __in DWORD cbData |
| 2829 | ) | 2842 | ) |
| 2830 | { | 2843 | { |
| 2831 | HRESULT hr = S_OK; | 2844 | HRESULT hr = S_OK; |
| 2832 | SIZE_T iData = 0; | 2845 | SIZE_T iData = 0; |
| 2833 | LPWSTR sczName = NULL; | 2846 | LPWSTR sczId = NULL; |
| 2847 | LPWSTR sczLogPath = NULL; | ||
| 2848 | BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL; | ||
| 2834 | 2849 | ||
| 2835 | // Deserialize message data. | 2850 | // Deserialize message data. |
| 2836 | hr = BuffReadString(pbData, cbData, &iData, &sczName); | 2851 | hr = BuffReadString(pbData, cbData, &iData, &sczId); |
| 2837 | ExitOnFailure(hr, "Failed to read transaction name."); | 2852 | ExitOnFailure(hr, "Failed to read rollback boundary id."); |
| 2838 | 2853 | ||
| 2839 | hr = MsiEngineBeginTransaction(sczName); | 2854 | hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); |
| 2855 | ExitOnFailure(hr, "Failed to read transaction log path."); | ||
| 2856 | |||
| 2857 | PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); | ||
| 2858 | ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); | ||
| 2859 | |||
| 2860 | pRollbackBoundary->sczLogPath = sczLogPath; | ||
| 2861 | |||
| 2862 | hr = MsiEngineBeginTransaction(pRollbackBoundary); | ||
| 2840 | 2863 | ||
| 2841 | LExit: | 2864 | LExit: |
| 2842 | ReleaseStr(sczName); | 2865 | ReleaseStr(sczId); |
| 2866 | ReleaseStr(sczLogPath); | ||
| 2867 | |||
| 2868 | if (pRollbackBoundary) | ||
| 2869 | { | ||
| 2870 | pRollbackBoundary->sczLogPath = NULL; | ||
| 2871 | } | ||
| 2843 | 2872 | ||
| 2844 | return hr; | 2873 | return hr; |
| 2845 | } | 2874 | } |
| 2846 | 2875 | ||
| 2847 | static HRESULT OnMsiCommitTransaction( | 2876 | static HRESULT OnMsiCommitTransaction( |
| 2877 | __in BURN_PACKAGES* pPackages, | ||
| 2848 | __in BYTE* pbData, | 2878 | __in BYTE* pbData, |
| 2849 | __in DWORD cbData | 2879 | __in DWORD cbData |
| 2850 | ) | 2880 | ) |
| 2851 | { | 2881 | { |
| 2852 | HRESULT hr = S_OK; | 2882 | HRESULT hr = S_OK; |
| 2853 | SIZE_T iData = 0; | 2883 | SIZE_T iData = 0; |
| 2854 | LPWSTR sczName = NULL; | 2884 | LPWSTR sczId = NULL; |
| 2885 | LPWSTR sczLogPath = NULL; | ||
| 2886 | BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL; | ||
| 2855 | 2887 | ||
| 2856 | // Deserialize message data. | 2888 | // Deserialize message data. |
| 2857 | hr = BuffReadString(pbData, cbData, &iData, &sczName); | 2889 | hr = BuffReadString(pbData, cbData, &iData, &sczId); |
| 2858 | ExitOnFailure(hr, "Failed to read transaction name."); | 2890 | ExitOnFailure(hr, "Failed to read rollback boundary id."); |
| 2859 | 2891 | ||
| 2860 | hr = MsiEngineCommitTransaction(sczName); | 2892 | hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); |
| 2893 | ExitOnFailure(hr, "Failed to read transaction log path."); | ||
| 2894 | |||
| 2895 | PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); | ||
| 2896 | ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); | ||
| 2897 | |||
| 2898 | pRollbackBoundary->sczLogPath = sczLogPath; | ||
| 2899 | |||
| 2900 | hr = MsiEngineCommitTransaction(pRollbackBoundary); | ||
| 2861 | 2901 | ||
| 2862 | LExit: | 2902 | LExit: |
| 2863 | ReleaseStr(sczName); | 2903 | ReleaseStr(sczId); |
| 2904 | ReleaseStr(sczLogPath); | ||
| 2905 | |||
| 2906 | if (pRollbackBoundary) | ||
| 2907 | { | ||
| 2908 | pRollbackBoundary->sczLogPath = NULL; | ||
| 2909 | } | ||
| 2864 | 2910 | ||
| 2865 | return hr; | 2911 | return hr; |
| 2866 | } | 2912 | } |
| 2867 | 2913 | ||
| 2868 | static HRESULT OnMsiRollbackTransaction( | 2914 | static HRESULT OnMsiRollbackTransaction( |
| 2915 | __in BURN_PACKAGES* pPackages, | ||
| 2869 | __in BYTE* pbData, | 2916 | __in BYTE* pbData, |
| 2870 | __in DWORD cbData | 2917 | __in DWORD cbData |
| 2871 | ) | 2918 | ) |
| 2872 | { | 2919 | { |
| 2873 | HRESULT hr = S_OK; | 2920 | HRESULT hr = S_OK; |
| 2874 | SIZE_T iData = 0; | 2921 | SIZE_T iData = 0; |
| 2875 | LPWSTR sczName = NULL; | 2922 | LPWSTR sczId = NULL; |
| 2923 | LPWSTR sczLogPath = NULL; | ||
| 2924 | BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL; | ||
| 2876 | 2925 | ||
| 2877 | // Deserialize message data. | 2926 | // Deserialize message data. |
| 2878 | hr = BuffReadString(pbData, cbData, &iData, &sczName); | 2927 | hr = BuffReadString(pbData, cbData, &iData, &sczId); |
| 2879 | ExitOnFailure(hr, "Failed to read transaction name."); | 2928 | ExitOnFailure(hr, "Failed to read rollback boundary id."); |
| 2880 | 2929 | ||
| 2881 | hr = MsiEngineRollbackTransaction(sczName); | 2930 | hr = BuffReadString(pbData, cbData, &iData, &sczLogPath); |
| 2931 | ExitOnFailure(hr, "Failed to read transaction log path."); | ||
| 2932 | |||
| 2933 | PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary); | ||
| 2934 | ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId); | ||
| 2935 | |||
| 2936 | pRollbackBoundary->sczLogPath = sczLogPath; | ||
| 2937 | |||
| 2938 | hr = MsiEngineRollbackTransaction(pRollbackBoundary); | ||
| 2882 | 2939 | ||
| 2883 | LExit: | 2940 | LExit: |
| 2884 | ReleaseStr(sczName); | 2941 | ReleaseStr(sczId); |
| 2942 | ReleaseStr(sczLogPath); | ||
| 2943 | |||
| 2944 | if (pRollbackBoundary) | ||
| 2945 | { | ||
| 2946 | pRollbackBoundary->sczLogPath = NULL; | ||
| 2947 | } | ||
| 2885 | 2948 | ||
| 2886 | return hr; | 2949 | return hr; |
| 2887 | } | 2950 | } |
