From 4d0798ec6311b48bfe6ee3cb4dd41379b4653528 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 3 Aug 2021 18:09:36 -0500 Subject: Always use user's temp directory as basis for acquisition folder. Fixes #5830 --- src/burn/engine/apply.cpp | 3 ++ src/burn/engine/cache.cpp | 90 ++++++++++++++++++++++++++------------ src/burn/engine/cache.h | 12 +++-- src/burn/engine/core.cpp | 8 ++-- src/burn/engine/core.h | 4 +- src/burn/engine/engine.cpp | 4 +- src/burn/engine/plan.cpp | 2 +- src/burn/engine/userexperience.cpp | 2 +- 8 files changed, 82 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp index 002158b6..8711344d 100644 --- a/src/burn/engine/apply.cpp +++ b/src/burn/engine/apply.cpp @@ -533,6 +533,9 @@ extern "C" HRESULT ApplyCache( hr = UserExperienceOnCacheBegin(pUX); ExitOnRootFailure(hr, "BA aborted cache."); + hr = CacheEnsureAcquisitionFolder(pPlan->pCache); + ExitOnFailure(hr, "Failed to ensure acquisition folder."); + cacheContext.hSourceEngineFile = hSourceEngineFile; cacheContext.pCache = pPlan->pCache; cacheContext.pPayloads = pPlan->pPayloads; 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( ); static HRESULT CalculateBaseWorkingFolder( __in BURN_ENGINE_COMMAND* pInternalCommand, + __in LPCWSTR wzAcquisitionFolder, __inout_z LPWSTR* psczBaseWorkingFolder ); -static HRESULT CalculateWorkingFolder( +static HRESULT CalculateWorkingFolders( __in BURN_CACHE* pCache, __in BURN_ENGINE_COMMAND* pInternalCommand ); @@ -214,7 +215,7 @@ extern "C" HRESULT CacheInitialize( ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-user"); - hr = CalculateWorkingFolder(pCache, pInternalCommand); + hr = CalculateWorkingFolders(pCache, pInternalCommand); pCache->fInitializedCache = TRUE; @@ -309,24 +310,42 @@ LExit: return hr; } -extern "C" HRESULT CacheEnsureWorkingFolder( +extern "C" HRESULT CacheEnsureAcquisitionFolder( + __in BURN_CACHE* pCache + ) +{ + Assert(pCache->fInitializedCache); + + HRESULT hr = S_OK; + + hr = DirEnsureExists(pCache->sczAcquisitionFolder, NULL); + ExitOnFailure(hr, "Failed create acquisition folder."); + + // Best effort to ensure our working folder is not encrypted. + ::DecryptFileW(pCache->sczBaseWorkingFolder, 0); + +LExit: + return hr; +} + +extern "C" HRESULT CacheEnsureBaseWorkingFolder( __in BURN_CACHE* pCache, - __deref_out_z_opt LPWSTR* psczWorkingFolder + __deref_out_z_opt LPWSTR* psczBaseWorkingFolder ) { Assert(pCache->fInitializedCache); HRESULT hr = S_OK; - hr = DirEnsureExists(pCache->sczWorkingFolder, NULL); + hr = DirEnsureExists(pCache->sczBaseWorkingFolder, NULL); ExitOnFailure(hr, "Failed create working folder."); // Best effort to ensure our working folder is not encrypted. - ::DecryptFileW(pCache->sczWorkingFolder, 0); + ::DecryptFileW(pCache->sczBaseWorkingFolder, 0); - if (psczWorkingFolder) + if (psczBaseWorkingFolder) { - hr = StrAllocString(psczWorkingFolder, pCache->sczWorkingFolder, 0); + hr = StrAllocString(psczBaseWorkingFolder, pCache->sczBaseWorkingFolder, 0); ExitOnFailure(hr, "Failed to copy working folder."); } @@ -353,7 +372,7 @@ extern "C" HRESULT CacheCalculateBundleWorkingPath( } else // Otherwise, use the real working folder. { - hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", pCache->sczWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName); + hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", pCache->sczBaseWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName); ExitOnFailure(hr, "Failed to calculate the bundle working path."); } @@ -371,7 +390,7 @@ extern "C" HRESULT CacheCalculateBundleLayoutWorkingPath( HRESULT hr = S_OK; - hr = PathConcat(pCache->sczWorkingFolder, wzBundleId, psczWorkingPath); + hr = PathConcat(pCache->sczAcquisitionFolder, wzBundleId, psczWorkingPath); ExitOnFailure(hr, "Failed to append bundle id for bundle layout working path."); LExit: @@ -388,7 +407,7 @@ extern "C" HRESULT CacheCalculatePayloadWorkingPath( HRESULT hr = S_OK; - hr = PathConcat(pCache->sczWorkingFolder, pPayload->sczKey, psczWorkingPath); + hr = PathConcat(pCache->sczAcquisitionFolder, pPayload->sczKey, psczWorkingPath); ExitOnFailure(hr, "Failed to append Id as payload unverified path."); LExit: @@ -405,7 +424,7 @@ extern "C" HRESULT CacheCalculateContainerWorkingPath( HRESULT hr = S_OK; - hr = PathConcat(pCache->sczWorkingFolder, pContainer->sczHash, psczWorkingPath); + hr = PathConcat(pCache->sczAcquisitionFolder, pContainer->sczHash, psczWorkingPath); ExitOnFailure(hr, "Failed to append hash as container unverified path."); LExit: @@ -1155,7 +1174,7 @@ LExit: return hr; } -extern "C" HRESULT CacheRemoveWorkingFolder( +extern "C" HRESULT CacheRemoveBaseWorkingFolder( __in BURN_CACHE* pCache ) { @@ -1164,7 +1183,7 @@ extern "C" HRESULT CacheRemoveWorkingFolder( if (pCache->fInitializedCacheSources) { // Try to clean out everything in the working folder. - hr = DirEnsureDeleteEx(pCache->sczWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE); + hr = DirEnsureDeleteEx(pCache->sczBaseWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE); TraceError(hr, "Could not delete bundle engine working folder."); } @@ -1275,9 +1294,9 @@ extern "C" void CacheCleanup( if (!fPerMachine) { - if (pCache->sczWorkingFolder) + if (pCache->sczAcquisitionFolder) { - hr = PathConcat(pCache->sczWorkingFolder, L"*.*", &sczFiles); + hr = PathConcat(pCache->sczAcquisitionFolder, L"*.*", &sczFiles); if (SUCCEEDED(hr)) { hFind = ::FindFirstFileW(sczFiles, &wfd); @@ -1299,7 +1318,7 @@ extern "C" void CacheCleanup( continue; } - hr = PathConcatCch(pCache->sczWorkingFolder, 0, wfd.cFileName, cchFileName, &sczDelete); + hr = PathConcatCch(pCache->sczAcquisitionFolder, 0, wfd.cFileName, cchFileName, &sczDelete); if (SUCCEEDED(hr)) { hr = FileEnsureDelete(sczDelete); @@ -1327,7 +1346,8 @@ extern "C" void CacheUninitialize( ReleaseNullStr(pCache->sczCurrentMachinePackageCache); ReleaseNullStr(pCache->sczDefaultMachinePackageCache); ReleaseNullStr(pCache->sczDefaultUserPackageCache); - ReleaseNullStr(pCache->sczWorkingFolder); + ReleaseNullStr(pCache->sczBaseWorkingFolder); + ReleaseNullStr(pCache->sczAcquisitionFolder); ReleaseNullStr(pCache->sczSourceProcessFolder); pCache->fRunningFromCache = FALSE; @@ -1343,6 +1363,7 @@ extern "C" void CacheUninitialize( static HRESULT CalculateBaseWorkingFolder( __in BURN_ENGINE_COMMAND* pInternalCommand, + __in LPCWSTR wzAcquisitionFolder, __inout_z LPWSTR* psczBaseWorkingFolder ) { @@ -1351,10 +1372,10 @@ static HRESULT CalculateBaseWorkingFolder( ReleaseNullStr(*psczBaseWorkingFolder); // The value from the command line takes precedence. - if (pInternalCommand->sczWorkingDirectory) + if (pInternalCommand->sczEngineWorkingDirectory) { - hr = PathExpand(psczBaseWorkingFolder, pInternalCommand->sczWorkingDirectory, PATH_EXPAND_FULLPATH); - ExitOnFailure(hr, "Failed to expand engine working directory from command-line: '%ls'", pInternalCommand->sczWorkingDirectory); + hr = PathExpand(psczBaseWorkingFolder, pInternalCommand->sczEngineWorkingDirectory, PATH_EXPAND_FULLPATH); + ExitOnFailure(hr, "Failed to expand engine working directory from command-line: '%ls'", pInternalCommand->sczEngineWorkingDirectory); ExitFunction(); } @@ -1373,34 +1394,41 @@ static HRESULT CalculateBaseWorkingFolder( } } - // Default to the temp path specified in environment variables, but need to use system temp path for security reasons if running elevated. + // Default to the acquisition folder, but need to use system temp path for security reasons if running elevated. if (pInternalCommand->fInitiallyElevated) { hr = PathGetSystemTempPath(psczBaseWorkingFolder); - ExitOnFailure(hr, "Failed to get system temp folder path for working folder."); + ExitOnFailure(hr, "Failed to get system temp folder path for base working folder."); } else { - hr = PathGetTempPath(psczBaseWorkingFolder); - ExitOnFailure(hr, "Failed to get temp folder path for working folder."); + hr = StrAllocString(psczBaseWorkingFolder, wzAcquisitionFolder, 0); + ExitOnFailure(hr, "Failed to copy acquisition folder path for base working folder."); } LExit: return hr; } -static HRESULT CalculateWorkingFolder( +static HRESULT CalculateWorkingFolders( __in BURN_CACHE* pCache, __in BURN_ENGINE_COMMAND* pInternalCommand ) { HRESULT hr = S_OK; RPC_STATUS rs = RPC_S_OK; + LPWSTR sczBaseAcquisitionPath = NULL; LPWSTR sczTempPath = NULL; UUID guid = {}; WCHAR wzGuid[39]; - hr = CalculateBaseWorkingFolder(pInternalCommand, &sczTempPath); + hr = PathGetTempPath(&sczBaseAcquisitionPath); + ExitOnFailure(hr, "Failed to get temp folder path for acquisition folder base."); + + hr = PathBackslashTerminate(&sczBaseAcquisitionPath); + ExitOnFailure(hr, "Failed to backslashify base engine working directory."); + + hr = CalculateBaseWorkingFolder(pInternalCommand, sczBaseAcquisitionPath, &sczTempPath); ExitOnFailure(hr, "Failed to get base engine working directory."); hr = PathBackslashTerminate(&sczTempPath); @@ -1416,10 +1444,14 @@ static HRESULT CalculateWorkingFolder( ExitOnRootFailure(hr, "Failed to convert working folder guid into string."); } - hr = StrAllocFormatted(&pCache->sczWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid); + hr = StrAllocFormatted(&pCache->sczAcquisitionFolder, L"%ls%ls\\", sczBaseAcquisitionPath, wzGuid); + ExitOnFailure(hr, "Failed to append random guid on to temp path for acquisition folder."); + + hr = StrAllocFormatted(&pCache->sczBaseWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid); ExitOnFailure(hr, "Failed to append random guid on to temp path for working folder."); LExit: + ReleaseStr(sczBaseAcquisitionPath); ReleaseStr(sczTempPath); return hr; @@ -2020,7 +2052,7 @@ static HRESULT CopyEngineToWorkingFolder( LPWSTR sczPayloadSourcePath = NULL; LPWSTR sczPayloadTargetPath = NULL; - hr = CacheEnsureWorkingFolder(pCache, &sczWorkingFolder); + hr = CacheEnsureBaseWorkingFolder(pCache, &sczWorkingFolder); ExitOnFailure(hr, "Failed to create working path to copy engine."); hr = PathConcat(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory); diff --git a/src/burn/engine/cache.h b/src/burn/engine/cache.h index 69d82639..8b038b99 100644 --- a/src/burn/engine/cache.h +++ b/src/burn/engine/cache.h @@ -39,7 +39,8 @@ typedef struct _BURN_CACHE BOOL fInitializedCacheSources; BOOL fRunningFromCache; LPWSTR sczSourceProcessFolder; - LPWSTR sczWorkingFolder; + LPWSTR sczAcquisitionFolder; + LPWSTR sczBaseWorkingFolder; } BURN_CACHE; typedef struct _BURN_CACHE_MESSAGE @@ -80,9 +81,12 @@ HRESULT CacheInitializeSources( __in BURN_VARIABLES* pVariables, __in BURN_ENGINE_COMMAND* pInternalCommand ); -HRESULT CacheEnsureWorkingFolder( +HRESULT CacheEnsureAcquisitionFolder( + __in BURN_CACHE* pCache + ); +HRESULT CacheEnsureBaseWorkingFolder( __in BURN_CACHE* pCache, - __deref_out_z_opt LPWSTR* psczWorkingFolder + __deref_out_z_opt LPWSTR* psczBaseWorkingFolder ); HRESULT CacheCalculateBundleWorkingPath( __in BURN_CACHE* pCache, @@ -228,7 +232,7 @@ HRESULT CacheVerifyPayload( __in LPPROGRESS_ROUTINE pfnProgress, __in LPVOID pContext ); -HRESULT CacheRemoveWorkingFolder( +HRESULT CacheRemoveBaseWorkingFolder( __in BURN_CACHE* pCache ); HRESULT CacheRemoveBundle( diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp index e8c51187..87d748cc 100644 --- a/src/burn/engine/core.cpp +++ b/src/burn/engine/core.cpp @@ -229,7 +229,7 @@ extern "C" HRESULT CoreInitializeConstants( { // Pass along any ancestors and ourself to prevent infinite loops. pPackage->Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; - pPackage->Exe.wzEngineWorkingDirectory = pInternalCommand->sczWorkingDirectory; + pPackage->Exe.wzEngineWorkingDirectory = pInternalCommand->sczEngineWorkingDirectory; } } @@ -1019,7 +1019,7 @@ static HRESULT CoreRecreateCommandLine( ExitOnFailure(hr, "Failed to append ancestors to command-line."); } - hr = CoreAppendEngineWorkingDirectoryToCommandLine(pInternalCommand->sczWorkingDirectory, psczCommandLine, NULL); + hr = CoreAppendEngineWorkingDirectoryToCommandLine(pInternalCommand->sczEngineWorkingDirectory, psczCommandLine, NULL); ExitOnFailure(hr, "Failed to append the custom working directory to command-line."); if (wzRelationTypeCommandLine) @@ -1733,12 +1733,12 @@ extern "C" HRESULT CoreParseCommandLine( else if (L'\0' == wzParam[1]) { // Need to grab the current directory here since this is passed on to other processes. - hr = DirGetCurrent(&pInternalCommand->sczWorkingDirectory); + hr = DirGetCurrent(&pInternalCommand->sczEngineWorkingDirectory); ExitOnFailure(hr, "Failed to get current directory for custom working directory."); } else { - hr = StrAllocString(&pInternalCommand->sczWorkingDirectory, wzParam + 1, 0); + hr = StrAllocString(&pInternalCommand->sczEngineWorkingDirectory, wzParam + 1, 0); ExitOnFailure(hr, "Failed to allocate the custom working directory."); } } diff --git a/src/burn/engine/core.h b/src/burn/engine/core.h index 5361a5c0..ff983d60 100644 --- a/src/burn/engine/core.h +++ b/src/burn/engine/core.h @@ -14,7 +14,7 @@ const LPCWSTR BURN_POLICY_REGISTRY_PATH = L"WiX\\Burn"; const LPCWSTR BURN_COMMANDLINE_SWITCH_PARENT = L"parent"; const LPCWSTR BURN_COMMANDLINE_SWITCH_PARENT_NONE = L"parent:none"; const LPCWSTR BURN_COMMANDLINE_SWITCH_CLEAN_ROOM = L"burn.clean.room"; -const LPCWSTR BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY = L"burn.working.directory"; +const LPCWSTR BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY = L"burn.engine.working.directory"; const LPCWSTR BURN_COMMANDLINE_SWITCH_ELEVATED = L"burn.elevated"; const LPCWSTR BURN_COMMANDLINE_SWITCH_EMBEDDED = L"burn.embedded"; const LPCWSTR BURN_COMMANDLINE_SWITCH_RUNONCE = L"burn.runonce"; @@ -100,7 +100,7 @@ typedef struct _BURN_ENGINE_COMMAND LPWSTR sczSourceProcessPath; LPWSTR sczOriginalSource; - LPWSTR sczWorkingDirectory; + LPWSTR sczEngineWorkingDirectory; DWORD dwLoggingAttributes; LPWSTR sczLogFile; diff --git a/src/burn/engine/engine.cpp b/src/burn/engine/engine.cpp index d5dc0545..1f2dac3c 100644 --- a/src/burn/engine/engine.cpp +++ b/src/burn/engine/engine.cpp @@ -246,7 +246,7 @@ LExit: UserExperienceRemove(&engineState.userExperience); - CacheRemoveWorkingFolder(&engineState.cache); + CacheRemoveBaseWorkingFolder(&engineState.cache); CacheUninitialize(&engineState.cache); // If this is a related bundle (but not an update) suppress restart and return the standard restart error code. @@ -401,7 +401,7 @@ static void UninitializeEngineState( ReleaseStr(pEngineState->internalCommand.sczLogFile); ReleaseStr(pEngineState->internalCommand.sczOriginalSource); ReleaseStr(pEngineState->internalCommand.sczSourceProcessPath); - ReleaseStr(pEngineState->internalCommand.sczWorkingDirectory); + ReleaseStr(pEngineState->internalCommand.sczEngineWorkingDirectory); ReleaseStr(pEngineState->log.sczExtension); ReleaseStr(pEngineState->log.sczPrefix); diff --git a/src/burn/engine/plan.cpp b/src/burn/engine/plan.cpp index 04da2a9d..d78f2846 100644 --- a/src/burn/engine/plan.cpp +++ b/src/burn/engine/plan.cpp @@ -1283,7 +1283,7 @@ extern "C" HRESULT PlanRelatedBundlesBegin( // Pass along any ancestors and ourself to prevent infinite loops. pRelatedBundle->package.Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; - pRelatedBundle->package.Exe.wzEngineWorkingDirectory = pPlan->pInternalCommand->sczWorkingDirectory; + pRelatedBundle->package.Exe.wzEngineWorkingDirectory = pPlan->pInternalCommand->sczEngineWorkingDirectory; hr = PlanDefaultRelatedBundleRequestState(relationType, pRelatedBundle->relationType, pPlan->action, pRegistration->pVersion, pRelatedBundle->pVersion, &pRelatedBundle->package.requested); ExitOnFailure(hr, "Failed to get default request state for related bundle."); diff --git a/src/burn/engine/userexperience.cpp b/src/burn/engine/userexperience.cpp index 69ec6347..f48e60de 100644 --- a/src/burn/engine/userexperience.cpp +++ b/src/burn/engine/userexperience.cpp @@ -168,7 +168,7 @@ extern "C" HRESULT UserExperienceEnsureWorkingFolder( HRESULT hr = S_OK; LPWSTR sczWorkingFolder = NULL; - hr = CacheEnsureWorkingFolder(pCache, &sczWorkingFolder); + hr = CacheEnsureBaseWorkingFolder(pCache, &sczWorkingFolder); ExitOnFailure(hr, "Failed to create working folder."); hr = StrAllocFormatted(psczUserExperienceWorkingFolder, L"%ls%ls\\", sczWorkingFolder, L".ba"); -- cgit v1.2.3-55-g6feb