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 authored and barnson committed Jan 21, 2024
1 parent cde596e commit dfea447
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
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
60 changes: 60 additions & 0 deletions src/burn/engine/core.cpp
Original file line number Diff line number Diff line change
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
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 @@ -624,6 +624,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 dfea447

Please sign in to comment.