diff options
Diffstat (limited to 'src/burn')
-rw-r--r-- | src/burn/engine/approvedexe.cpp | 105 | ||||
-rw-r--r-- | src/burn/engine/approvedexe.h | 4 | ||||
-rw-r--r-- | src/burn/engine/bundlepackageengine.cpp | 4 | ||||
-rw-r--r-- | src/burn/engine/cache.cpp | 6 | ||||
-rw-r--r-- | src/burn/engine/core.h | 2 | ||||
-rw-r--r-- | src/burn/engine/elevation.cpp | 2 | ||||
-rw-r--r-- | src/burn/engine/exeengine.cpp | 29 | ||||
-rw-r--r-- | src/burn/engine/registration.cpp | 14 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/ApprovedExeTest.cpp | 312 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj | 1 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters | 5 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/PlanTest.cpp | 12 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/precomp.h | 1 |
13 files changed, 471 insertions, 26 deletions
diff --git a/src/burn/engine/approvedexe.cpp b/src/burn/engine/approvedexe.cpp index 28b26d6d..383ee7fa 100644 --- a/src/burn/engine/approvedexe.cpp +++ b/src/burn/engine/approvedexe.cpp | |||
@@ -3,6 +3,13 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | 5 | ||
6 | // internal function declarations | ||
7 | |||
8 | static HRESULT IsRunDll32( | ||
9 | __in BURN_VARIABLES* pVariables, | ||
10 | __in LPCWSTR wzExecutablePath | ||
11 | ); | ||
12 | |||
6 | // function definitions | 13 | // function definitions |
7 | 14 | ||
8 | extern "C" HRESULT ApprovedExesParseFromXml( | 15 | extern "C" HRESULT ApprovedExesParseFromXml( |
@@ -221,12 +228,15 @@ LExit: | |||
221 | extern "C" HRESULT ApprovedExesVerifySecureLocation( | 228 | extern "C" HRESULT ApprovedExesVerifySecureLocation( |
222 | __in BURN_CACHE* pCache, | 229 | __in BURN_CACHE* pCache, |
223 | __in BURN_VARIABLES* pVariables, | 230 | __in BURN_VARIABLES* pVariables, |
224 | __in LPCWSTR wzExecutablePath | 231 | __in LPCWSTR wzExecutablePath, |
232 | __in int argc, | ||
233 | __in LPCWSTR* argv | ||
225 | ) | 234 | ) |
226 | { | 235 | { |
227 | HRESULT hr = S_OK; | 236 | HRESULT hr = S_OK; |
228 | LPWSTR scz = NULL; | 237 | LPWSTR scz = NULL; |
229 | LPWSTR sczSecondary = NULL; | 238 | LPWSTR sczSecondary = NULL; |
239 | LPWSTR sczRunDll32Param = NULL; | ||
230 | 240 | ||
231 | const LPCWSTR vrgSecureFolderVariables[] = { | 241 | const LPCWSTR vrgSecureFolderVariables[] = { |
232 | L"ProgramFiles64Folder", | 242 | L"ProgramFiles64Folder", |
@@ -273,11 +283,104 @@ extern "C" HRESULT ApprovedExesVerifySecureLocation( | |||
273 | ExitFunction(); | 283 | ExitFunction(); |
274 | } | 284 | } |
275 | 285 | ||
286 | // Test if executable is rundll32.exe, and it's target is in a secure location | ||
287 | // Example for CUDA UninstallString: "C:\WINDOWS\SysWOW64\RunDll32.EXE" "C:\Program Files\NVIDIA Corporation\Installer2\InstallerCore\NVI2.DLL",UninstallPackage CUDAToolkit_12.8 | ||
288 | if (argc && argv && argv[0] && *argv[0]) | ||
289 | { | ||
290 | hr = IsRunDll32(pVariables, wzExecutablePath); | ||
291 | ExitOnFailure(hr, "Failed to test whether executable is rundll32"); | ||
292 | |||
293 | if (hr == S_OK) | ||
294 | { | ||
295 | LPCWSTR szComma = wcschr(argv[0], L','); | ||
296 | if (szComma && *szComma) | ||
297 | { | ||
298 | hr = StrAllocString(&sczRunDll32Param, argv[0], szComma - argv[0]); | ||
299 | ExitOnFailure(hr, "Failed to allocate string"); | ||
300 | } | ||
301 | else | ||
302 | { | ||
303 | hr = StrAllocString(&sczRunDll32Param, argv[0], 0); | ||
304 | ExitOnFailure(hr, "Failed to allocate string"); | ||
305 | } | ||
306 | |||
307 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, sczRunDll32Param, 0, NULL); | ||
308 | ExitOnFailure(hr, "Failed to test whether rundll32's parameter, '%ls', is in a secure location", sczRunDll32Param); | ||
309 | if (hr == S_OK) | ||
310 | { | ||
311 | ExitFunction(); | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | |||
276 | hr = S_FALSE; | 316 | hr = S_FALSE; |
277 | 317 | ||
278 | LExit: | 318 | LExit: |
279 | ReleaseStr(scz); | 319 | ReleaseStr(scz); |
280 | ReleaseStr(sczSecondary); | 320 | ReleaseStr(sczSecondary); |
321 | ReleaseStr(sczRunDll32Param); | ||
322 | |||
323 | return hr; | ||
324 | } | ||
325 | |||
326 | static HRESULT IsRunDll32( | ||
327 | __in BURN_VARIABLES* pVariables, | ||
328 | __in LPCWSTR wzExecutablePath | ||
329 | ) | ||
330 | { | ||
331 | HRESULT hr = S_OK; | ||
332 | LPWSTR sczFolder = NULL; | ||
333 | LPWSTR sczFullPath = NULL; | ||
334 | BOOL fEqual = FALSE; | ||
335 | |||
336 | hr = VariableGetString(pVariables, L"SystemFolder", &sczFolder); | ||
337 | ExitOnFailure(hr, "Failed to get the variable: SystemFolder"); | ||
338 | |||
339 | hr = PathConcat(sczFolder, L"rundll32.exe", &sczFullPath); | ||
340 | ExitOnFailure(hr, "Failed to combine paths"); | ||
341 | |||
342 | hr = PathCompareCanonicalized(wzExecutablePath, sczFullPath, &fEqual); | ||
343 | ExitOnFailure(hr, "Failed to compare paths"); | ||
344 | if (fEqual) | ||
345 | { | ||
346 | hr = S_OK; | ||
347 | ExitFunction(); | ||
348 | } | ||
349 | |||
350 | hr = VariableGetString(pVariables, L"System64Folder", &sczFolder); | ||
351 | ExitOnFailure(hr, "Failed to get the variable: System64Folder"); | ||
352 | |||
353 | hr = PathConcat(sczFolder, L"rundll32.exe", &sczFullPath); | ||
354 | ExitOnFailure(hr, "Failed to combine paths"); | ||
355 | |||
356 | hr = PathCompareCanonicalized(wzExecutablePath, sczFullPath, &fEqual); | ||
357 | ExitOnFailure(hr, "Failed to compare paths"); | ||
358 | if (fEqual) | ||
359 | { | ||
360 | hr = S_OK; | ||
361 | ExitFunction(); | ||
362 | } | ||
363 | |||
364 | // Sysnative | ||
365 | hr = PathSystemWindowsSubdirectory(L"SysNative\\", &sczFolder); | ||
366 | ExitOnFailure(hr, "Failed to append SysNative directory."); | ||
367 | |||
368 | hr = PathConcat(sczFolder, L"rundll32.exe", &sczFullPath); | ||
369 | ExitOnFailure(hr, "Failed to combine paths"); | ||
370 | |||
371 | hr = PathCompareCanonicalized(wzExecutablePath, sczFullPath, &fEqual); | ||
372 | ExitOnFailure(hr, "Failed to compare paths"); | ||
373 | if (fEqual) | ||
374 | { | ||
375 | hr = S_OK; | ||
376 | ExitFunction(); | ||
377 | } | ||
378 | |||
379 | hr = S_FALSE; | ||
380 | |||
381 | LExit: | ||
382 | ReleaseStr(sczFolder); | ||
383 | ReleaseStr(sczFullPath); | ||
281 | 384 | ||
282 | return hr; | 385 | return hr; |
283 | } | 386 | } |
diff --git a/src/burn/engine/approvedexe.h b/src/burn/engine/approvedexe.h index 7a68c174..0f441485 100644 --- a/src/burn/engine/approvedexe.h +++ b/src/burn/engine/approvedexe.h | |||
@@ -58,7 +58,9 @@ HRESULT ApprovedExesLaunch( | |||
58 | HRESULT ApprovedExesVerifySecureLocation( | 58 | HRESULT ApprovedExesVerifySecureLocation( |
59 | __in BURN_CACHE* pCache, | 59 | __in BURN_CACHE* pCache, |
60 | __in BURN_VARIABLES* pVariables, | 60 | __in BURN_VARIABLES* pVariables, |
61 | __in LPCWSTR wzExecutablePath | 61 | __in LPCWSTR wzExecutablePath, |
62 | __in int argc, | ||
63 | __in LPCWSTR* argv | ||
62 | ); | 64 | ); |
63 | 65 | ||
64 | 66 | ||
diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index 612da389..db433918 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp | |||
@@ -817,7 +817,7 @@ static HRESULT ExecuteBundle( | |||
817 | 817 | ||
818 | if (pPackage->fPerMachine) | 818 | if (pPackage->fPerMachine) |
819 | { | 819 | { |
820 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, sczExecutablePath); | 820 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, sczExecutablePath, argcArp - 1, (argcArp > 1) ? const_cast<LPCWSTR*>(argvArp + 1) : NULL); |
821 | ExitOnFailure(hr, "Failed to verify the QuietUninstallString executable path is in a secure location: %ls", sczExecutablePath); | 821 | ExitOnFailure(hr, "Failed to verify the QuietUninstallString executable path is in a secure location: %ls", sczExecutablePath); |
822 | if (S_FALSE == hr) | 822 | if (S_FALSE == hr) |
823 | { | 823 | { |
@@ -940,7 +940,7 @@ static HRESULT ExecuteBundle( | |||
940 | 940 | ||
941 | if (wzRelationTypeCommandLine) | 941 | if (wzRelationTypeCommandLine) |
942 | { | 942 | { |
943 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" -%ls", wzRelationTypeCommandLine); | 943 | hr = StrAllocConcatFormatted(&sczBaseCommand, L" -quiet -%ls", wzRelationTypeCommandLine); |
944 | ExitOnFailure(hr, "Failed to append relation type argument."); | 944 | ExitOnFailure(hr, "Failed to append relation type argument."); |
945 | } | 945 | } |
946 | 946 | ||
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp index 16db4a81..e432df69 100644 --- a/src/burn/engine/cache.cpp +++ b/src/burn/engine/cache.cpp | |||
@@ -260,6 +260,9 @@ extern "C" HRESULT CacheInitializeSources( | |||
260 | hr = PathForCurrentProcess(&sczCurrentPath, NULL); | 260 | hr = PathForCurrentProcess(&sczCurrentPath, NULL); |
261 | ExitOnFailure(hr, "Failed to get current process path."); | 261 | ExitOnFailure(hr, "Failed to get current process path."); |
262 | 262 | ||
263 | hr = VariableSetString(pVariables, BURN_BUNDLE_SOURCE_PROCESS_PATH, sczCurrentPath, FALSE, FALSE); | ||
264 | ExitOnFailure(hr, "Failed to set %ls variable.", BURN_BUNDLE_SOURCE_PROCESS_PATH); | ||
265 | |||
263 | // Determine if we are running from the package cache or not. | 266 | // Determine if we are running from the package cache or not. |
264 | hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczCode, &sczCompletedFolder); | 267 | hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczCode, &sczCompletedFolder); |
265 | ExitOnFailure(hr, "Failed to get completed path for bundle."); | 268 | ExitOnFailure(hr, "Failed to get completed path for bundle."); |
@@ -275,6 +278,9 @@ extern "C" HRESULT CacheInitializeSources( | |||
275 | hr = PathGetDirectory(sczCurrentPath, &pCache->sczSourceProcessFolder); | 278 | hr = PathGetDirectory(sczCurrentPath, &pCache->sczSourceProcessFolder); |
276 | ExitOnFailure(hr, "Failed to initialize cache source folder."); | 279 | ExitOnFailure(hr, "Failed to initialize cache source folder."); |
277 | 280 | ||
281 | hr = VariableSetString(pVariables, BURN_BUNDLE_SOURCE_PROCESS_FOLDER, pCache->sczSourceProcessFolder, FALSE, FALSE); | ||
282 | ExitOnFailure(hr, "Failed to set %ls variable.", BURN_BUNDLE_SOURCE_PROCESS_FOLDER); | ||
283 | |||
278 | // If we're not running from the cache, ensure the original source is set. | 284 | // If we're not running from the cache, ensure the original source is set. |
279 | if (!pCache->fRunningFromCache) | 285 | if (!pCache->fRunningFromCache) |
280 | { | 286 | { |
diff --git a/src/burn/engine/core.h b/src/burn/engine/core.h index c5d0a370..cf615e35 100644 --- a/src/burn/engine/core.h +++ b/src/burn/engine/core.h | |||
@@ -46,6 +46,8 @@ const LPCWSTR BURN_BUNDLE_FORCED_RESTART_PACKAGE = L"WixBundleForcedRestartPacka | |||
46 | const LPCWSTR BURN_BUNDLE_INSTALLED = L"WixBundleInstalled"; | 46 | const LPCWSTR BURN_BUNDLE_INSTALLED = L"WixBundleInstalled"; |
47 | const LPCWSTR BURN_BUNDLE_ELEVATED = L"WixBundleElevated"; | 47 | const LPCWSTR BURN_BUNDLE_ELEVATED = L"WixBundleElevated"; |
48 | const LPCWSTR BURN_BUNDLE_PROVIDER_KEY = L"WixBundleProviderKey"; | 48 | const LPCWSTR BURN_BUNDLE_PROVIDER_KEY = L"WixBundleProviderKey"; |
49 | const LPCWSTR BURN_BUNDLE_SOURCE_PROCESS_PATH = L"WixBundleSourceProcessPath"; | ||
50 | const LPCWSTR BURN_BUNDLE_SOURCE_PROCESS_FOLDER = L"WixBundleSourceProcessFolder"; | ||
49 | const LPCWSTR BURN_BUNDLE_TAG = L"WixBundleTag"; | 51 | const LPCWSTR BURN_BUNDLE_TAG = L"WixBundleTag"; |
50 | const LPCWSTR BURN_BUNDLE_UILEVEL = L"WixBundleUILevel"; | 52 | const LPCWSTR BURN_BUNDLE_UILEVEL = L"WixBundleUILevel"; |
51 | const LPCWSTR BURN_BUNDLE_VERSION = L"WixBundleVersion"; | 53 | const LPCWSTR BURN_BUNDLE_VERSION = L"WixBundleVersion"; |
diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index 90e9db01..f208efc9 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp | |||
@@ -3876,7 +3876,7 @@ static HRESULT OnLaunchApprovedExe( | |||
3876 | hr = RegReadString(hKey, pApprovedExe->sczValueName, &pLaunchApprovedExe->sczExecutablePath); | 3876 | hr = RegReadString(hKey, pApprovedExe->sczValueName, &pLaunchApprovedExe->sczExecutablePath); |
3877 | ExitOnFailure(hr, "Failed to read the value for the approved exe path."); | 3877 | ExitOnFailure(hr, "Failed to read the value for the approved exe path."); |
3878 | 3878 | ||
3879 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, pLaunchApprovedExe->sczExecutablePath); | 3879 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, pLaunchApprovedExe->sczExecutablePath, 0, NULL); |
3880 | ExitOnFailure(hr, "Failed to verify the executable path is in a secure location: %ls", pLaunchApprovedExe->sczExecutablePath); | 3880 | ExitOnFailure(hr, "Failed to verify the executable path is in a secure location: %ls", pLaunchApprovedExe->sczExecutablePath); |
3881 | if (S_FALSE == hr) | 3881 | if (S_FALSE == hr) |
3882 | { | 3882 | { |
diff --git a/src/burn/engine/exeengine.cpp b/src/burn/engine/exeengine.cpp index 85168943..3a2816dd 100644 --- a/src/burn/engine/exeengine.cpp +++ b/src/burn/engine/exeengine.cpp | |||
@@ -489,29 +489,30 @@ extern "C" HRESULT ExeEngineExecutePackage( | |||
489 | } | 489 | } |
490 | else if (BURN_EXE_DETECTION_TYPE_ARP == pPackage->Exe.detectionType && BOOTSTRAPPER_ACTION_STATE_UNINSTALL == pExecuteAction->exePackage.action) | 490 | else if (BURN_EXE_DETECTION_TYPE_ARP == pPackage->Exe.detectionType && BOOTSTRAPPER_ACTION_STATE_UNINSTALL == pExecuteAction->exePackage.action) |
491 | { | 491 | { |
492 | ExitOnNull(sczArpUninstallString, hr, E_INVALIDARG, "%hs is null.", pPackage->Exe.fArpUseUninstallString ? "UninstallString" : "QuietUninstallString"); | 492 | LPCWSTR szRegName = pPackage->Exe.fArpUseUninstallString ? L"UninstallString" : L"QuietUninstallString"; |
493 | ExitOnNull(sczArpUninstallString, hr, E_INVALIDARG, "%ls is null.", szRegName); | ||
493 | 494 | ||
494 | hr = AppParseCommandLine(sczArpUninstallString, &argcArp, &argvArp); | 495 | hr = AppParseCommandLine(sczArpUninstallString, &argcArp, &argvArp); |
495 | ExitOnFailure(hr, "Failed to parse QuietUninstallString: %ls.", sczArpUninstallString); | 496 | ExitOnFailure(hr, "Failed to parse %ls: %ls.", szRegName, sczArpUninstallString); |
496 | 497 | ||
497 | ExitOnNull(argcArp, hr, E_INVALIDARG, "QuietUninstallString must contain an executable path."); | 498 | ExitOnNull(argcArp, hr, E_INVALIDARG, "%ls must contain an executable path.", szRegName); |
498 | 499 | ||
499 | hr = StrAllocString(&sczExecutablePath, argvArp[0], 0); | 500 | hr = StrAllocString(&sczExecutablePath, argvArp[0], 0); |
500 | ExitOnFailure(hr, "Failed to copy executable path."); | 501 | ExitOnFailure(hr, "Failed to copy executable path."); |
501 | 502 | ||
502 | if (pPackage->fPerMachine) | 503 | if (pPackage->fPerMachine) |
503 | { | 504 | { |
504 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, sczExecutablePath); | 505 | hr = ApprovedExesVerifySecureLocation(pCache, pVariables, sczExecutablePath, argcArp - 1, (argcArp > 1) ? const_cast<LPCWSTR*>(argvArp + 1) : NULL); |
505 | ExitOnFailure(hr, "Failed to verify the QuietUninstallString executable path is in a secure location: %ls", sczExecutablePath); | 506 | ExitOnFailure(hr, "Failed to verify the %ls executable path is in a secure location: %ls", szRegName, sczExecutablePath); |
506 | if (S_FALSE == hr) | 507 | if (S_FALSE == hr) |
507 | { | 508 | { |
508 | LogStringLine(REPORT_STANDARD, "The QuietUninstallString executable path is not in a secure location: %ls", sczExecutablePath); | 509 | LogStringLine(REPORT_STANDARD, "The %ls executable path is not in a secure location: %ls", szRegName, sczExecutablePath); |
509 | ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); | 510 | ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); |
510 | } | 511 | } |
511 | } | 512 | } |
512 | 513 | ||
513 | hr = PathGetDirectory(sczExecutablePath, &sczCachedDirectory); | 514 | hr = PathGetDirectory(sczExecutablePath, &sczCachedDirectory); |
514 | ExitOnFailure(hr, "Failed to get parent directory for QuietUninstallString executable path: %ls", sczExecutablePath); | 515 | ExitOnFailure(hr, "Failed to get parent directory for %ls executable path: %ls", szRegName, sczExecutablePath); |
515 | } | 516 | } |
516 | else | 517 | else |
517 | { | 518 | { |
@@ -587,13 +588,15 @@ extern "C" HRESULT ExeEngineExecutePackage( | |||
587 | } | 588 | } |
588 | 589 | ||
589 | // build base command | 590 | // build base command |
590 | hr = StrAllocFormatted(&sczBaseCommand, L"\"%ls\"", sczExecutablePath); | 591 | if (sczArpUninstallString && *sczArpUninstallString) |
591 | ExitOnFailure(hr, "Failed to allocate base command."); | 592 | { |
592 | 593 | hr = StrAllocString(&sczBaseCommand, sczArpUninstallString, 0); | |
593 | for (int i = 1; i < argcArp; ++i) | 594 | ExitOnFailure(hr, "Failed to allocate base command."); |
595 | } | ||
596 | else | ||
594 | { | 597 | { |
595 | hr = AppAppendCommandLineArgument(&sczBaseCommand, argvArp[i]); | 598 | hr = StrAllocFormatted(&sczBaseCommand, L"\"%ls\"", sczExecutablePath); |
596 | ExitOnFailure(hr, "Failed to append argument from ARP."); | 599 | ExitOnFailure(hr, "Failed to allocate base command."); |
597 | } | 600 | } |
598 | 601 | ||
599 | if (pPackage->Exe.fBundle) | 602 | if (pPackage->Exe.fBundle) |
diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index 85c006f7..966fc849 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp | |||
@@ -808,13 +808,6 @@ extern "C" HRESULT RegistrationSessionBegin( | |||
808 | ExitOnFailure(hr, "Failed to write software tags."); | 808 | ExitOnFailure(hr, "Failed to write software tags."); |
809 | } | 809 | } |
810 | 810 | ||
811 | // Update registration. | ||
812 | if (pRegistration->update.fRegisterUpdate) | ||
813 | { | ||
814 | hr = WriteUpdateRegistration(pRegistration, pVariables); | ||
815 | ExitOnFailure(hr, "Failed to write update registration."); | ||
816 | } | ||
817 | |||
818 | // Only set install date and initial estimated size here for the first time. | 811 | // Only set install date and initial estimated size here for the first time. |
819 | // Estimated size will always get updated at the end of the session. | 812 | // Estimated size will always get updated at the end of the session. |
820 | if (fCreated) | 813 | if (fCreated) |
@@ -904,6 +897,13 @@ extern "C" HRESULT RegistrationSessionEnd( | |||
904 | 897 | ||
905 | hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize); | 898 | hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize); |
906 | ExitOnFailure(hr, "Failed to update estimated size."); | 899 | ExitOnFailure(hr, "Failed to update estimated size."); |
900 | |||
901 | // Update registration. | ||
902 | if (pRegistration->update.fRegisterUpdate) | ||
903 | { | ||
904 | hr = WriteUpdateRegistration(pRegistration, pVariables); | ||
905 | ExitOnFailure(hr, "Failed to write update registration."); | ||
906 | } | ||
907 | } | 907 | } |
908 | 908 | ||
909 | // Update resume mode. | 909 | // Update resume mode. |
diff --git a/src/burn/test/BurnUnitTest/ApprovedExeTest.cpp b/src/burn/test/BurnUnitTest/ApprovedExeTest.cpp new file mode 100644 index 00000000..da51f1f8 --- /dev/null +++ b/src/burn/test/BurnUnitTest/ApprovedExeTest.cpp | |||
@@ -0,0 +1,312 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | namespace Microsoft | ||
6 | { | ||
7 | namespace Tools | ||
8 | { | ||
9 | namespace WindowsInstallerXml | ||
10 | { | ||
11 | namespace Test | ||
12 | { | ||
13 | namespace Bootstrapper | ||
14 | { | ||
15 | using namespace System; | ||
16 | using namespace System::IO; | ||
17 | using namespace Xunit; | ||
18 | |||
19 | public ref class ApprovedExeTest : BurnUnitTest | ||
20 | { | ||
21 | public: | ||
22 | ApprovedExeTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | [Fact] | ||
27 | void ApprovedExesVerifyPFilesTest() | ||
28 | { | ||
29 | HRESULT hr = S_OK; | ||
30 | BURN_CACHE cache = { }; | ||
31 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
32 | BURN_VARIABLES variables = { }; | ||
33 | LPWSTR scz = NULL; | ||
34 | LPWSTR scz2 = NULL; | ||
35 | |||
36 | try | ||
37 | { | ||
38 | hr = VariableInitialize(&variables); | ||
39 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
40 | |||
41 | hr = CacheInitialize(&cache, &internalCommand); | ||
42 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
43 | |||
44 | hr = VariableGetString(&variables, L"ProgramFilesFolder", &scz); | ||
45 | NativeAssert::Succeeded(hr, "Failed to get variable ProgramFilesFolder."); | ||
46 | |||
47 | hr = PathConcat(scz, L"a.exe", &scz2); | ||
48 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
49 | |||
50 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 0, NULL); | ||
51 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFilesFolder"); | ||
52 | Assert::True((hr == S_OK), "Path under ProgramFilesFolder was expected to be safe"); | ||
53 | } | ||
54 | finally | ||
55 | { | ||
56 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
57 | ReleaseStr(scz); | ||
58 | ReleaseStr(scz2); | ||
59 | |||
60 | CacheUninitialize(&cache); | ||
61 | VariablesUninitialize(&variables); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | [Fact] | ||
66 | void ApprovedExesVerifyPFilesWithRelativeTest() | ||
67 | { | ||
68 | HRESULT hr = S_OK; | ||
69 | BURN_CACHE cache = { }; | ||
70 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
71 | BURN_VARIABLES variables = { }; | ||
72 | LPWSTR scz = NULL; | ||
73 | LPWSTR scz2 = NULL; | ||
74 | |||
75 | try | ||
76 | { | ||
77 | hr = VariableInitialize(&variables); | ||
78 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
79 | |||
80 | hr = CacheInitialize(&cache, &internalCommand); | ||
81 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
82 | cache.fPerMachineCacheRootVerified = TRUE; | ||
83 | cache.fOriginalPerMachineCacheRootVerified = TRUE; | ||
84 | |||
85 | hr = VariableGetString(&variables, L"ProgramFilesFolder", &scz); | ||
86 | NativeAssert::Succeeded(hr, "Failed to get variable ProgramFilesFolder."); | ||
87 | |||
88 | hr = PathConcat(scz, L"..\\a.exe", &scz2); | ||
89 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
90 | |||
91 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 0, NULL); | ||
92 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFilesFolder"); | ||
93 | Assert::True((hr == S_FALSE), "Path pretending to be under ProgramFilesFolder was expected to be unsafe"); | ||
94 | } | ||
95 | finally | ||
96 | { | ||
97 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
98 | ReleaseStr(scz); | ||
99 | ReleaseStr(scz2); | ||
100 | |||
101 | CacheUninitialize(&cache); | ||
102 | VariablesUninitialize(&variables); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | [Fact] | ||
107 | void ApprovedExesVerifyPFiles64Test() | ||
108 | { | ||
109 | HRESULT hr = S_OK; | ||
110 | BURN_CACHE cache = { }; | ||
111 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
112 | BURN_VARIABLES variables = { }; | ||
113 | LPWSTR scz = NULL; | ||
114 | LPWSTR scz2 = NULL; | ||
115 | |||
116 | try | ||
117 | { | ||
118 | hr = VariableInitialize(&variables); | ||
119 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
120 | |||
121 | hr = CacheInitialize(&cache, &internalCommand); | ||
122 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
123 | |||
124 | hr = VariableGetString(&variables, L"ProgramFiles64Folder", &scz); | ||
125 | NativeAssert::Succeeded(hr, "Failed to get variable ProgramFiles64Folder."); | ||
126 | |||
127 | hr = PathConcat(scz, L"a.exe", &scz2); | ||
128 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
129 | |||
130 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 0, NULL); | ||
131 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFiles64Folder"); | ||
132 | Assert::True((hr == S_OK), "Path under ProgramFiles64Folder was expected to be safe"); | ||
133 | } | ||
134 | finally | ||
135 | { | ||
136 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
137 | ReleaseStr(scz); | ||
138 | ReleaseStr(scz2); | ||
139 | |||
140 | CacheUninitialize(&cache); | ||
141 | VariablesUninitialize(&variables); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | [Fact] | ||
146 | void ApprovedExesVerifySys64FolderTest() | ||
147 | { | ||
148 | HRESULT hr = S_OK; | ||
149 | BURN_CACHE cache = { }; | ||
150 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
151 | BURN_VARIABLES variables = { }; | ||
152 | LPWSTR scz = NULL; | ||
153 | LPWSTR scz2 = NULL; | ||
154 | |||
155 | try | ||
156 | { | ||
157 | hr = VariableInitialize(&variables); | ||
158 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
159 | |||
160 | hr = CacheInitialize(&cache, &internalCommand); | ||
161 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
162 | cache.fPerMachineCacheRootVerified = TRUE; | ||
163 | cache.fOriginalPerMachineCacheRootVerified = TRUE; | ||
164 | |||
165 | hr = VariableGetString(&variables, L"System64Folder", &scz); | ||
166 | NativeAssert::Succeeded(hr, "Failed to get variable System64Folder."); | ||
167 | |||
168 | hr = PathConcat(scz, L"a.exe", &scz2); | ||
169 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
170 | |||
171 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 0, NULL); | ||
172 | NativeAssert::Succeeded(hr, "Failed to test secure location under System64Folder"); | ||
173 | Assert::True((hr == S_FALSE), "Path under System64Folder was expected to be unsafe"); | ||
174 | } | ||
175 | finally | ||
176 | { | ||
177 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
178 | ReleaseStr(scz); | ||
179 | ReleaseStr(scz2); | ||
180 | |||
181 | CacheUninitialize(&cache); | ||
182 | VariablesUninitialize(&variables); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | [Fact] | ||
187 | void ApprovedExesVerifySys64Rundll32UnsafeTest() | ||
188 | { | ||
189 | HRESULT hr = S_OK; | ||
190 | BURN_CACHE cache = { }; | ||
191 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
192 | BURN_VARIABLES variables = { }; | ||
193 | LPWSTR scz = NULL; | ||
194 | LPWSTR scz2 = NULL; | ||
195 | LPWSTR szArgs = NULL; | ||
196 | |||
197 | try | ||
198 | { | ||
199 | hr = VariableInitialize(&variables); | ||
200 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
201 | |||
202 | hr = CacheInitialize(&cache, &internalCommand); | ||
203 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
204 | cache.fPerMachineCacheRootVerified = TRUE; | ||
205 | cache.fOriginalPerMachineCacheRootVerified = TRUE; | ||
206 | |||
207 | hr = VariableGetString(&variables, L"System64Folder", &scz); | ||
208 | NativeAssert::Succeeded(hr, "Failed to get variable System64Folder."); | ||
209 | |||
210 | hr = PathConcat(scz, L"rundll32.exe", &scz2); | ||
211 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
212 | |||
213 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 1, const_cast<LPCWSTR*>(&scz2)); | ||
214 | NativeAssert::Succeeded(hr, "Failed to test secure location under System64Folder"); | ||
215 | Assert::True((hr == S_FALSE), "Path under System64Folder was expected to be unsafe for rundll32 target"); | ||
216 | } | ||
217 | finally | ||
218 | { | ||
219 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
220 | ReleaseStr(scz); | ||
221 | ReleaseStr(scz2); | ||
222 | ReleaseStr(szArgs); | ||
223 | |||
224 | CacheUninitialize(&cache); | ||
225 | VariablesUninitialize(&variables); | ||
226 | } | ||
227 | } | ||
228 | |||
229 | [Fact] | ||
230 | void ApprovedExesVerifySys64Rundll32SafeTest() | ||
231 | { | ||
232 | HRESULT hr = S_OK; | ||
233 | BURN_CACHE cache = { }; | ||
234 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
235 | BURN_VARIABLES variables = { }; | ||
236 | LPWSTR scz = NULL; | ||
237 | LPWSTR scz2 = NULL; | ||
238 | LPWSTR scz3 = NULL; | ||
239 | |||
240 | try | ||
241 | { | ||
242 | hr = VariableInitialize(&variables); | ||
243 | NativeAssert::Succeeded(hr, L"Failed to initialize variables."); | ||
244 | |||
245 | hr = CacheInitialize(&cache, &internalCommand); | ||
246 | NativeAssert::Succeeded(hr, "Failed to initialize cache."); | ||
247 | cache.fPerMachineCacheRootVerified = TRUE; | ||
248 | cache.fOriginalPerMachineCacheRootVerified = TRUE; | ||
249 | |||
250 | // System64Folder | ||
251 | hr = VariableGetString(&variables, L"System64Folder", &scz); | ||
252 | NativeAssert::Succeeded(hr, "Failed to get variable System64Folder."); | ||
253 | |||
254 | hr = PathConcat(scz, L"rundll32.exe", &scz2); | ||
255 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
256 | |||
257 | hr = VariableGetString(&variables, L"ProgramFiles64Folder", &scz); | ||
258 | NativeAssert::Succeeded(hr, "Failed to get variable ProgramFiles64Folder."); | ||
259 | |||
260 | hr = PathConcat(scz, L"a.dll", &scz3); | ||
261 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
262 | |||
263 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 1, const_cast<LPCWSTR*>(&scz3)); | ||
264 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFiles64Folder for System64Folder/rundll32 target"); | ||
265 | Assert::True((hr == S_OK), "Path under ProgramFiles64Folder was expected to be safe for System64Folder/rundll32 target"); | ||
266 | |||
267 | hr = PathConcat(scz, L"a.dll,somthing else", &scz3); | ||
268 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
269 | |||
270 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 1, const_cast<LPCWSTR*>(&scz3)); | ||
271 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFiles64Folder for rundll32 target"); | ||
272 | Assert::True((hr == S_OK), "Path under ProgramFiles64Folder was expected to be safe for System64Folder/rundll32 target"); | ||
273 | |||
274 | // SystemFolder | ||
275 | hr = VariableGetString(&variables, L"SystemFolder", &scz); | ||
276 | NativeAssert::Succeeded(hr, "Failed to get variable System64Folder."); | ||
277 | |||
278 | hr = PathConcat(scz, L"rundll32.exe", &scz2); | ||
279 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
280 | |||
281 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 1, const_cast<LPCWSTR*>(&scz3)); | ||
282 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFiles64Folder for SystemFolder/rundll32 target"); | ||
283 | Assert::True((hr == S_OK), "Path under ProgramFiles64Folder was expected to be safe for SystemFolder/rundll32 target"); | ||
284 | |||
285 | // Sysnative | ||
286 | hr = PathSystemWindowsSubdirectory(L"SysNative\\", &scz); | ||
287 | NativeAssert::Succeeded(hr, "Failed to get SysNative Folder."); | ||
288 | |||
289 | hr = PathConcat(scz, L"rundll32.exe", &scz2); | ||
290 | NativeAssert::Succeeded(hr, "Failed to combine paths"); | ||
291 | |||
292 | hr = ApprovedExesVerifySecureLocation(&cache, &variables, scz2, 1, const_cast<LPCWSTR*>(&scz3)); | ||
293 | NativeAssert::Succeeded(hr, "Failed to test secure location under ProgramFiles64Folder for Sysnative/rundll32 target"); | ||
294 | Assert::True((hr == S_OK), "Path under ProgramFiles64Folder was expected to be safe for Sysnative/rundll32 target"); | ||
295 | } | ||
296 | finally | ||
297 | { | ||
298 | ReleaseStr(internalCommand.sczEngineWorkingDirectory); | ||
299 | ReleaseStr(scz); | ||
300 | ReleaseStr(scz2); | ||
301 | ReleaseStr(scz3); | ||
302 | |||
303 | CacheUninitialize(&cache); | ||
304 | VariablesUninitialize(&variables); | ||
305 | } | ||
306 | } | ||
307 | }; | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | } | ||
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj index 331d237b..63d089e4 100644 --- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj +++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj | |||
@@ -45,6 +45,7 @@ | |||
45 | 45 | ||
46 | <ItemGroup> | 46 | <ItemGroup> |
47 | <ClCompile Include="AssemblyInfo.cpp" /> | 47 | <ClCompile Include="AssemblyInfo.cpp" /> |
48 | <ClCompile Include="ApprovedExeTest.cpp" /> | ||
48 | <ClCompile Include="CacheTest.cpp" /> | 49 | <ClCompile Include="CacheTest.cpp" /> |
49 | <ClCompile Include="ElevationTest.cpp" /> | 50 | <ClCompile Include="ElevationTest.cpp" /> |
50 | <ClCompile Include="EmbeddedTest.cpp" /> | 51 | <ClCompile Include="EmbeddedTest.cpp" /> |
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters index 82725436..59aea6e9 100644 --- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters +++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters | |||
@@ -66,6 +66,9 @@ | |||
66 | <ClCompile Include="VariantTest.cpp"> | 66 | <ClCompile Include="VariantTest.cpp"> |
67 | <Filter>Source Files</Filter> | 67 | <Filter>Source Files</Filter> |
68 | </ClCompile> | 68 | </ClCompile> |
69 | <ClCompile Include="ApprovedExeTest.cpp"> | ||
70 | <Filter>Source Files</Filter> | ||
71 | </ClCompile> | ||
69 | </ItemGroup> | 72 | </ItemGroup> |
70 | <ItemGroup> | 73 | <ItemGroup> |
71 | <ClInclude Include="BurnTestException.h"> | 74 | <ClInclude Include="BurnTestException.h"> |
@@ -95,4 +98,4 @@ | |||
95 | <Filter>Resource Files</Filter> | 98 | <Filter>Resource Files</Filter> |
96 | </ResourceCompile> | 99 | </ResourceCompile> |
97 | </ItemGroup> | 100 | </ItemGroup> |
98 | </Project> \ No newline at end of file | 101 | </Project> |
diff --git a/src/burn/test/BurnUnitTest/PlanTest.cpp b/src/burn/test/BurnUnitTest/PlanTest.cpp index e426cb09..25a0cb35 100644 --- a/src/burn/test/BurnUnitTest/PlanTest.cpp +++ b/src/burn/test/BurnUnitTest/PlanTest.cpp | |||
@@ -2990,6 +2990,18 @@ namespace Bootstrapper | |||
2990 | ValidateNonPermanentPackageExpectedStates(&pEngineState->packages.rgPackages[1], L"PackageA", BURN_PACKAGE_REGISTRATION_STATE_PRESENT, BURN_PACKAGE_REGISTRATION_STATE_PRESENT); | 2990 | ValidateNonPermanentPackageExpectedStates(&pEngineState->packages.rgPackages[1], L"PackageA", BURN_PACKAGE_REGISTRATION_STATE_PRESENT, BURN_PACKAGE_REGISTRATION_STATE_PRESENT); |
2991 | } | 2991 | } |
2992 | 2992 | ||
2993 | [Fact] | ||
2994 | void ValidateCacheVariables() | ||
2995 | { | ||
2996 | BURN_ENGINE_STATE engineState = { }; | ||
2997 | BURN_ENGINE_STATE* pEngineState = &engineState; | ||
2998 | |||
2999 | InitializeEngineStateForCorePlan(wzSlipstreamModifiedManifestFileName, pEngineState); | ||
3000 | |||
3001 | Assert::EndsWith(gcnew String(L".exe"), VariableGetStringHelper(&pEngineState->variables, BURN_BUNDLE_SOURCE_PROCESS_PATH)); | ||
3002 | Assert::EndsWith(gcnew String(L"\\"), VariableGetStringHelper(&pEngineState->variables, BURN_BUNDLE_SOURCE_PROCESS_FOLDER)); | ||
3003 | } | ||
3004 | |||
2993 | private: | 3005 | private: |
2994 | // This doesn't initialize everything, just enough for CorePlan to work. | 3006 | // This doesn't initialize everything, just enough for CorePlan to work. |
2995 | void InitializeEngineStateForCorePlan(LPCWSTR wzManifestFileName, BURN_ENGINE_STATE* pEngineState) | 3007 | void InitializeEngineStateForCorePlan(LPCWSTR wzManifestFileName, BURN_ENGINE_STATE* pEngineState) |
diff --git a/src/burn/test/BurnUnitTest/precomp.h b/src/burn/test/BurnUnitTest/precomp.h index f07f5968..ec6fb7d1 100644 --- a/src/burn/test/BurnUnitTest/precomp.h +++ b/src/burn/test/BurnUnitTest/precomp.h | |||
@@ -74,6 +74,7 @@ | |||
74 | #include "splashscreen.h" | 74 | #include "splashscreen.h" |
75 | #include "detect.h" | 75 | #include "detect.h" |
76 | #include "externalengine.h" | 76 | #include "externalengine.h" |
77 | #include "approvedexe.h" | ||
77 | 78 | ||
78 | #include "engine.version.h" | 79 | #include "engine.version.h" |
79 | 80 | ||