Skip to content

Commit

Permalink
Fixes wixtoolset/issues#5220: Automatically add logging flag for any …
Browse files Browse the repository at this point in the history
…burn ExePackage, BundlePackage, and related bundles
  • Loading branch information
nirbar committed Jun 14, 2023
1 parent 35d30e0 commit 375c94d
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/burn/engine/bundlepackageengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,9 @@ static HRESULT ExecuteBundle(
ExitOnFailure(hr, "Failed to allocate obfuscated bundle command.");
}

// Append logging to command line if it doesn't contain '-log'
CoreAppendLogToCommandLine(&sczBaseCommand, &sczCommandObfuscated, fRollback, pVariables, pPackage);

// Log obfuscated command, which won't include raw hidden variable values or protocol specific arguments to avoid exposing secrets.
LogId(REPORT_STANDARD, MSG_APPLYING_PACKAGE, LoggingRollbackOrExecute(fRollback), pPackage->sczId, LoggingActionStateToString(action), sczExecutablePath, sczCommandObfuscated ? sczCommandObfuscated : sczBaseCommand);

Expand Down
64 changes: 62 additions & 2 deletions src/burn/engine/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ extern "C" HRESULT CoreInitializeConstants(
hr = StrAllocString(&pRegistration->sczBundlePackageAncestors, pRegistration->sczId, 0);
ExitOnFailure(hr, "Failed to copy self to bundle package ancestors.");
}

for (DWORD i = 0; i < pEngineState->packages.cPackages; ++i)
{
BURN_PACKAGE* pPackage = pEngineState->packages.rgPackages + i;
Expand Down Expand Up @@ -1301,6 +1301,66 @@ extern "C" HRESULT CoreAppendFileHandleSelfToCommandLine(
return hr;
}

HRESULT CoreAppendLogToCommandLine(
__deref_inout_z LPWSTR* psczCommandLine,
__deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine,
__in BOOL fRollback,
__in BURN_VARIABLES* pVariables,
__in BURN_PACKAGE *pPackage
)
{
HRESULT hr = S_OK;
INT ccArgs = 0;
LPWSTR* rgszArgs = nullptr;
LPWSTR szLogArg = nullptr;
LPWSTR szLogArgFormatted = nullptr;
LPCWSTR szLogVar = fRollback ? pPackage->sczRollbackLogPathVariable : pPackage->sczLogPathVariable;

if (!szLogVar || !*szLogVar)
{
ExitFunction1(hr = S_FALSE);
}

hr = AppParseCommandLine(*psczCommandLine, &ccArgs, &rgszArgs);
ExitOnFailure(hr, "Failed parsing command line");

// Log flag already present?
for (INT i = 0; i < ccArgs; ++i)
{
if (rgszArgs[i][0] == L'-' || rgszArgs[i][0] == L'/')
{
// Now looking for 'log' or 'l'
if ((CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &rgszArgs[i][1], -1, L"log", -1))
|| (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &rgszArgs[i][1], -1, L"l", -1)))
{
ExitFunction1(hr = S_FALSE);
}
}
}

hr = StrAllocFormatted(&szLogArg, L" -log \"[%ls]\"", szLogVar);
ExitOnFailure(hr, "Failed creating log argument");

hr = VariableFormatString(pVariables, szLogArg, &szLogArgFormatted, NULL);
ExitOnFailure(hr, "Failed to format argument string.");

hr = StrAllocConcat(psczCommandLine, szLogArgFormatted, 0);
ExitOnFailure(hr, "Failed concatenating '-log' to command line");

hr = StrAllocConcat(psczObfuscatedCommandLine, szLogArgFormatted, 0);
ExitOnFailure(hr, "Failed concatenating '-log' to obfuscated command line");

LExit:
if (rgszArgs)
{
AppFreeCommandLineArgs(rgszArgs);
}
ReleaseStr(szLogArg);
ReleaseStr(szLogArgFormatted);

return hr;
}

extern "C" HRESULT CoreAppendSplashScreenWindowToCommandLine(
__in_opt HWND hwndSplashScreen,
__deref_inout_z LPWSTR* psczCommandLine
Expand Down Expand Up @@ -2285,7 +2345,7 @@ static HRESULT DetectPackage(
{
HRESULT hr = S_OK;
BOOL fBegan = FALSE;

fBegan = TRUE;
hr = UserExperienceOnDetectPackageBegin(&pEngineState->userExperience, pPackage->sczId);
ExitOnRootFailure(hr, "BA aborted detect package begin.");
Expand Down
7 changes: 7 additions & 0 deletions src/burn/engine/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ HRESULT CoreAppendFileHandleSelfToCommandLine(
__deref_inout_z LPWSTR* psczCommandLine,
__deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine
);
HRESULT CoreAppendLogToCommandLine(
__deref_inout_z LPWSTR* psczCommandLine,
__deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine,
__in BOOL fRollback,
__in BURN_VARIABLES* pVariables,
__in BURN_PACKAGE *pPackage
);
HRESULT CoreAppendSplashScreenWindowToCommandLine(
__in_opt HWND hwndSplashScreen,
__deref_inout_z LPWSTR* psczCommandLine
Expand Down
6 changes: 6 additions & 0 deletions src/burn/engine/exeengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,12 @@ extern "C" HRESULT ExeEngineExecutePackage(
ExitOnFailure(hr, "Failed to append %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF);
}

// For bundles, append logging to command line if it doesn't contain '-log'
if (pPackage->Exe.fBundle || BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol)
{
CoreAppendLogToCommandLine(&sczBaseCommand, &sczCommandObfuscated, fRollback, pVariables, pPackage);
}

// build user args
if (sczUnformattedUserArgs && *sczUnformattedUserArgs)
{
Expand Down
13 changes: 13 additions & 0 deletions src/burn/engine/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ extern "C" HRESULT LoggingSetPackageVariable(
ExitFunction();
}

// For burn packages we'll add logging even it it wasn't explictly specified
if (BURN_PACKAGE_TYPE_BUNDLE == pPackage->type || (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol))
{
if (!fRollback && (!pPackage->sczLogPathVariable || !*pPackage->sczLogPathVariable))
{
StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
}
else if (fRollback && (!pPackage->sczRollbackLogPathVariable || !*pPackage->sczRollbackLogPathVariable))
{
StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);
}
}

if ((!fRollback && pPackage->sczLogPathVariable && *pPackage->sczLogPathVariable) ||
(fRollback && pPackage->sczRollbackLogPathVariable && *pPackage->sczRollbackLogPathVariable))
{
Expand Down
14 changes: 13 additions & 1 deletion src/burn/engine/pseudobundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" HRESULT PseudoBundleInitializeRelated(
ExitOnNull(pPackage->payloads.rgItems, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload group inside of related bundle struct");
pPackage->payloads.cItems = 1;

pPayload = (BURN_PAYLOAD*)MemAlloc(sizeof(BURN_PAYLOAD), TRUE);
pPayload = (BURN_PAYLOAD*)MemAlloc(sizeof(BURN_PAYLOAD), TRUE);
ExitOnNull(pPayload, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload inside of related bundle struct");
pPackage->payloads.rgItems[0].pPayload = pPayload;
pPayload->packaging = BURN_PAYLOAD_PACKAGING_EXTERNAL;
Expand Down Expand Up @@ -59,6 +59,10 @@ extern "C" HRESULT PseudoBundleInitializeRelated(
hr = StrAllocString(&pPackage->sczCacheId, wzId, 0);
ExitOnFailure(hr, "Failed to copy cache id for pseudo bundle.");

// Log variables - best effort
StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);

if (pDependencyProvider)
{
pPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE);
Expand Down Expand Up @@ -122,6 +126,10 @@ extern "C" HRESULT PseudoBundleInitializePassthrough(
hr = StrAllocString(&pPassthroughPackage->sczCacheId, pPackage->sczCacheId, 0);
ExitOnFailure(hr, "Failed to copy cache id for passthrough pseudo bundle.");

// Log variables - best effort
StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);

hr = CoreCreatePassthroughBundleCommandLine(&sczArguments, pInternalCommand, pCommand);
ExitOnFailure(hr, "Failed to create command-line arguments.");

Expand Down Expand Up @@ -207,6 +215,10 @@ extern "C" HRESULT PseudoBundleInitializeUpdateBundle(
hr = StrAllocString(&pPackage->sczCacheId, wzCacheId, 0);
ExitOnFailure(hr, "Failed to copy cache id for update bundle.");

// Log variables - best effort
StrAllocFormatted(&pPackage->sczLogPathVariable, L"WixBundleLog_%ls", pPackage->sczId);
StrAllocFormatted(&pPackage->sczRollbackLogPathVariable, L"WixBundleRollbackLog_%ls", pPackage->sczId);

hr = StrAllocString(&pPackage->Exe.sczInstallArguments, wzInstallArguments, 0);
ExitOnFailure(hr, "Failed to copy install arguments for update bundle package");

Expand Down

0 comments on commit 375c94d

Please sign in to comment.