@joebigelow / wix / commits / dfea4478

Fixes wixtoolset/issues#5220: Automatically add logging flag for any burn ExePackage, BundlePackage, and related bundles

Nir Bar committed Jun 5, 2023 at 13:27 UTC dfea4478a4938ce738fd49282350d36c73fb9a35
6 files changed +102 -1
src/burn/engine/bundlepackageengine.cpp
+3
@@ -1000,6 +1000,9 @@ static HRESULT ExecuteBundle(
1000 ExitOnFailure(hr, "Failed to allocate obfuscated bundle command.");
1001 }
1002
1003 + // Append logging to command line if it doesn't contain '-log'
1004 + CoreAppendLogToCommandLine(&sczBaseCommand, &sczCommandObfuscated, fRollback, pVariables, pPackage);
1005 +
1006 // Log obfuscated command, which won't include raw hidden variable values or protocol specific arguments to avoid exposing secrets.
1007 LogId(REPORT_STANDARD, MSG_APPLYING_PACKAGE, LoggingRollbackOrExecute(fRollback), pPackage->sczId, LoggingActionStateToString(action), sczExecutablePath, sczCommandObfuscated ? sczCommandObfuscated : sczBaseCommand);
1008
src/burn/engine/core.cpp
+60
@@ -1301,6 +1301,66 @@ LExit:
1301 return hr;
1302 }
1303
1304 +HRESULT CoreAppendLogToCommandLine(
1305 + __deref_inout_z LPWSTR* psczCommandLine,
1306 + __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine,
1307 + __in BOOL fRollback,
1308 + __in BURN_VARIABLES* pVariables,
1309 + __in BURN_PACKAGE *pPackage
1310 + )
1311 +{
1312 + HRESULT hr = S_OK;
1313 + INT ccArgs = 0;
1314 + LPWSTR* rgszArgs = nullptr;
1315 + LPWSTR szLogArg = nullptr;
1316 + LPWSTR szLogArgFormatted = nullptr;
1317 + LPCWSTR szLogVar = fRollback ? pPackage->sczRollbackLogPathVariable : pPackage->sczLogPathVariable;
1318 +
1319 + if (!szLogVar || !*szLogVar)
1320 + {
1321 + ExitFunction1(hr = S_FALSE);
1322 + }
1323 +
1324 + hr = AppParseCommandLine(*psczCommandLine, &ccArgs, &rgszArgs);
1325 + ExitOnFailure(hr, "Failed parsing command line");
1326 +
1327 + // Log flag already present?
1328 + for (INT i = 0; i < ccArgs; ++i)
1329 + {
1330 + if (rgszArgs[i][0] == L'-' || rgszArgs[i][0] == L'/')
1331 + {
1332 + // Now looking for 'log' or 'l'
1333 + if ((CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &rgszArgs[i][1], -1, L"log", -1))
1334 + || (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &rgszArgs[i][1], -1, L"l", -1)))
1335 + {
1336 + ExitFunction1(hr = S_FALSE);
1337 + }
1338 + }
1339 + }
1340 +
1341 + hr = StrAllocFormatted(&szLogArg, L" -log \"[%ls]\"", szLogVar);
1342 + ExitOnFailure(hr, "Failed creating log argument");
1343 +
1344 + hr = VariableFormatString(pVariables, szLogArg, &szLogArgFormatted, NULL);
1345 + ExitOnFailure(hr, "Failed to format argument string.");
1346 +
1347 + hr = StrAllocConcat(psczCommandLine, szLogArgFormatted, 0);
1348 + ExitOnFailure(hr, "Failed concatenating '-log' to command line");
1349 +
1350 + hr = StrAllocConcat(psczObfuscatedCommandLine, szLogArgFormatted, 0);
1351 + ExitOnFailure(hr, "Failed concatenating '-log' to obfuscated command line");
1352 +
1353 +LExit:
1354 + if (rgszArgs)
1355 + {
1356 + AppFreeCommandLineArgs(rgszArgs);
1357 + }
1358 + ReleaseStr(szLogArg);
1359 + ReleaseStr(szLogArgFormatted);
1360 +
1361 + return hr;
1362 +}
1363 +
1364 extern "C" HRESULT CoreAppendSplashScreenWindowToCommandLine(
1365 __in_opt HWND hwndSplashScreen,
1366 __deref_inout_z LPWSTR* psczCommandLine
src/burn/engine/core.h
+7
@@ -306,6 +306,13 @@ HRESULT CoreAppendFileHandleSelfToCommandLine(
306 __deref_inout_z LPWSTR* psczCommandLine,
307 __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine
308 );
309 +HRESULT CoreAppendLogToCommandLine(
310 + __deref_inout_z LPWSTR* psczCommandLine,
311 + __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine,
312 + __in BOOL fRollback,
313 + __in BURN_VARIABLES* pVariables,
314 + __in BURN_PACKAGE *pPackage
315 + );
316 HRESULT CoreAppendSplashScreenWindowToCommandLine(
317 __in_opt HWND hwndSplashScreen,
318 __deref_inout_z LPWSTR* psczCommandLine
src/burn/engine/exeengine.cpp
+6
@@ -624,6 +624,12 @@ extern "C" HRESULT ExeEngineExecutePackage(
624 ExitOnFailure(hr, "Failed to append %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF);
625 }
626
627 + // For bundles, append logging to command line if it doesn't contain '-log'
628 + if (pPackage->Exe.fBundle || BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol)
629 + {
630 + CoreAppendLogToCommandLine(&sczBaseCommand, &sczCommandObfuscated, fRollback, pVariables, pPackage);
631 + }
632 +
633 // build user args
634 if (sczUnformattedUserArgs && *sczUnformattedUserArgs)
635 {
src/burn/engine/logging.cpp
+13
@@ -325,6 +325,19 @@ extern "C" HRESULT LoggingSetPackageVariable(
325 ExitFunction();
326 }
327
328 + // For burn packages we'll add logging even it it wasn't explictly specified
329 + if (BURN_PACKAGE_TYPE_BUNDLE == pPackage->type || (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol))
330 + {
331 + if (!fRollback && (!pPackage->sczLogPathVariable || !*pPackage->sczLogPathVariable))
332 + {
333 + StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
334 + }
335 + else if (fRollback && (!pPackage->sczRollbackLogPathVariable || !*pPackage->sczRollbackLogPathVariable))
336 + {
337 + StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);
338 + }
339 + }
340 +
341 if ((!fRollback && pPackage->sczLogPathVariable && *pPackage->sczLogPathVariable) ||
342 (fRollback && pPackage->sczRollbackLogPathVariable && *pPackage->sczRollbackLogPathVariable))
343 {
src/burn/engine/pseudobundle.cpp
+13 -1
@@ -27,7 +27,7 @@ extern "C" HRESULT PseudoBundleInitializeRelated(
27 ExitOnNull(pPackage->payloads.rgItems, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload group inside of related bundle struct");
28 pPackage->payloads.cItems = 1;
29
30 - pPayload = (BURN_PAYLOAD*)MemAlloc(sizeof(BURN_PAYLOAD), TRUE);
30 + pPayload = (BURN_PAYLOAD*)MemAlloc(sizeof(BURN_PAYLOAD), TRUE);
31 ExitOnNull(pPayload, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload inside of related bundle struct");
32 pPackage->payloads.rgItems[0].pPayload = pPayload;
33 pPayload->packaging = BURN_PAYLOAD_PACKAGING_EXTERNAL;
@@ -59,6 +59,10 @@ extern "C" HRESULT PseudoBundleInitializeRelated(
59 hr = StrAllocString(&pPackage->sczCacheId, wzId, 0);
60 ExitOnFailure(hr, "Failed to copy cache id for pseudo bundle.");
61
62 + // Log variables - best effort
63 + StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
64 + StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);
65 +
66 if (pDependencyProvider)
67 {
68 pPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE);
@@ -122,6 +126,10 @@ extern "C" HRESULT PseudoBundleInitializePassthrough(
126 hr = StrAllocString(&pPassthroughPackage->sczCacheId, pPackage->sczCacheId, 0);
127 ExitOnFailure(hr, "Failed to copy cache id for passthrough pseudo bundle.");
128
129 + // Log variables - best effort
130 + StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
131 + StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);
132 +
133 hr = CoreCreatePassthroughBundleCommandLine(&sczArguments, pInternalCommand, pCommand);
134 ExitOnFailure(hr, "Failed to create command-line arguments.");
135
@@ -207,6 +215,10 @@ extern "C" HRESULT PseudoBundleInitializeUpdateBundle(
215 hr = StrAllocString(&pPackage->sczCacheId, wzCacheId, 0);
216 ExitOnFailure(hr, "Failed to copy cache id for update bundle.");
217
218 + // Log variables - best effort
219 + StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
220 + StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);
221 +
222 hr = StrAllocString(&pPackage->Exe.sczInstallArguments, wzInstallArguments, 0);
223 ExitOnFailure(hr, "Failed to copy install arguments for update bundle package");
224