Skip to content

Commit

Permalink
[Windows][Installer] Use correct format specifier for WcaLog (#9122)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-lebot authored Sep 23, 2021
1 parent 9b4bd54 commit c0319b7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fix some string logging in the Windows installer.
4 changes: 2 additions & 2 deletions tools/windows/install-help/cal/FinalizeInstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ UINT doFinalizeInstall(CustomActionData &data)
if (!bRet)
{
DWORD lastErr = GetLastError();
std::string lastErrStr = GetErrorMessageStr(lastErr);
WcaLog(LOGMSG_STANDARD, "CreateSymbolicLink: %s (%d)", lastErrStr.c_str(), lastErr);
auto lastErrStr = GetErrorMessageStrW(lastErr);
WcaLog(LOGMSG_STANDARD, "CreateSymbolicLink: %S (%d)", lastErrStr.c_str(), lastErr);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tools/windows/install-help/cal/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ DWORD TargetMachine::DetectDomainInformation()
return nErr;
}
_dcFlags = dcInfo->Flags;
WcaLog(LOGMSG_STANDARD, "Domain Controller is %s", IsReadOnlyDomainController() ? "Read-Only" : "Writable");
WcaLog(LOGMSG_STANDARD, "Domain Controller is %S", IsReadOnlyDomainController() ? L"Read-Only" : L"Writable");
NetApiBufferFree(dcInfo);
}
}
Expand Down
12 changes: 7 additions & 5 deletions tools/windows/install-help/cal/customaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,19 @@ UINT doUninstallAs(UNINSTALL_TYPE t);

// see https://stackoverflow.com/a/45565001/425565
// Template ErrType can be HRESULT (long) or DWORD (unsigned long)
template <class ErrType> std::string GetErrorMessageStr(ErrType errCode)
template<class ErrType> std::wstring GetErrorMessageStrW(ErrType errCode)
{
const int buffsize = 4096;
char buffer[buffsize];
wchar_t buffer[buffsize];
const DWORD len =
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr, // (not used with FORMAT_MESSAGE_FROM_SYSTEM)
errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buffer[0], buffsize, nullptr);
if (len > 0)
{
return std::string(buffer, len);
return std::wstring(buffer, len);
}
return "Failed to retrieve error message string.";
std::wstringstream wsstr;
wsstr << L"Failed to retrieve error message string for code " << errCode;
return wsstr.str();
}
4 changes: 2 additions & 2 deletions tools/windows/install-help/cal/stopservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ int uninstallServices(CustomActionData &data)
DWORD rbret = services[i].destroy(hScManager);
if (rbret != 0)
{
std::string lastErrStr = GetErrorMessageStr(rbret);
WcaLog(LOGMSG_STANDARD, "Failed to uninstall service %s (%d)", lastErrStr.c_str(), rbret);
auto lastErrStr = GetErrorMessageStrW(rbret);
WcaLog(LOGMSG_STANDARD, "Failed to uninstall service %S (%d)", lastErrStr.c_str(), rbret);
}
}
WcaLog(LOGMSG_STANDARD, "done uinstalling services");
Expand Down
6 changes: 2 additions & 4 deletions tools/windows/install-help/cal/userrights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,12 @@ DWORD AddUserToGroup(PSID userSid, wchar_t *groupSidString, wchar_t *defaultGrou
memset(&lmi0, 0, sizeof(LOCALGROUP_MEMBERS_INFO_0));
lmi0.lgrmi0_sid = userSid;

std::string asciiname;

getGroupNameFromSidString(groupSidString, defaultGroupName, groupname);
WcaLog(LOGMSG_STANDARD, "Attempting to add to group %S", groupname.c_str());
nErr = NetLocalGroupAddMembers(NULL, groupname.c_str(), 0, (LPBYTE)&lmi0, 1);
if (nErr == NERR_Success)
{
WcaLog(LOGMSG_STANDARD, "Added ddagentuser to %s", asciiname.c_str());
WcaLog(LOGMSG_STANDARD, "Added user to %S", groupname.c_str());
}
else if (nErr == ERROR_MEMBER_IN_GROUP || nErr == ERROR_MEMBER_IN_ALIAS)
{
Expand All @@ -352,7 +350,7 @@ DWORD DelUserFromGroup(PSID userSid, wchar_t *groupSidString, wchar_t *defaultGr
lmi0.lgrmi0_sid = userSid;

getGroupNameFromSidString(groupSidString, defaultGroupName, groupname);
WcaLog(LOGMSG_STANDARD, "Attempting to remove from group %s", groupname.c_str());
WcaLog(LOGMSG_STANDARD, "Attempting to remove from group %S", groupname.c_str());
nErr = NetLocalGroupDelMembers(NULL, L"Performance Monitor Users", 0, (LPBYTE)&lmi0, 1);
if (nErr == NERR_Success)
{
Expand Down

0 comments on commit c0319b7

Please sign in to comment.