From 0f00104a2cf7eb5ce9a3e9c4f2d0b45dae26a6c5 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 2 Jul 2021 18:22:20 +0100 Subject: [PATCH] win,msi: use localized "Authenticated Users" name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Well known user account names are localized on Windows. Look up the "Authenticated Users" user by its security identifier to get the localized name. PR-URL: https://github.com/nodejs/node/pull/39241 Fixes: https://github.com/nodejs/node/issues/39224 Refs: https://github.com/nodejs/node/commit/e817ba70f56c4bfd5d4a68dce8b165142312e7b6 Refs: https://hackerone.com/reports/1211160 Reviewed-By: Michaƫl Zasso Reviewed-By: Beth Griggs --- tools/msvs/msi/custom_actions.cc | 31 +++++++++++++++++++++++++++++++ tools/msvs/msi/custom_actions.def | 1 + tools/msvs/msi/product.wxs | 9 +++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/tools/msvs/msi/custom_actions.cc b/tools/msvs/msi/custom_actions.cc index 8a8417ea0b2929..32811dcb19469d 100644 --- a/tools/msvs/msi/custom_actions.cc +++ b/tools/msvs/msi/custom_actions.cc @@ -3,6 +3,8 @@ #include #include #include +#include +#include #define GUID_BUFFER_SIZE 39 // {8-4-4-4-12}\0 @@ -96,6 +98,35 @@ extern "C" UINT WINAPI BroadcastEnvironmentUpdate(MSIHANDLE hInstall) { return WcaFinalize(er); } +#define AUTHENTICATED_USERS_SID L"S-1-5-11" + +extern "C" UINT WINAPI GetLocalizedUserNames(MSIHANDLE hInstall) { + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + TCHAR userName[UNLEN + 1] = {0}; + DWORD userNameSize = UNLEN + 1; + TCHAR domain[DNLEN + 1] = {0}; + DWORD domainSize = DNLEN + 1; + PSID sid; + SID_NAME_USE nameUse; + + hr = WcaInitialize(hInstall, "GetLocalizedUserNames"); + ExitOnFailure(hr, "Failed to initialize"); + + er = ConvertStringSidToSidW(AUTHENTICATED_USERS_SID, &sid); + ExitOnLastError(er, "Failed to convert security identifier"); + + er = LookupAccountSidW(NULL, sid, userName, &userNameSize, domain, &domainSize, &nameUse); + ExitOnLastError(er, "Failed to lookup security identifier"); + + MsiSetProperty(hInstall, L"AUTHENTICATED_USERS", userName); + ExitOnWin32Error(er, hr, "Failed to set localized Authenticated User name"); + +LExit: + er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; + LocalFree(sid); + return WcaFinalize(er); +} extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, VOID* dummy) { switch (ulReason) { diff --git a/tools/msvs/msi/custom_actions.def b/tools/msvs/msi/custom_actions.def index 5f6b25fc423492..93f2a28f45e45e 100644 --- a/tools/msvs/msi/custom_actions.def +++ b/tools/msvs/msi/custom_actions.def @@ -3,3 +3,4 @@ LIBRARY "custom_actions" EXPORTS SetInstallScope BroadcastEnvironmentUpdate +GetLocalizedUserNames diff --git a/tools/msvs/msi/product.wxs b/tools/msvs/msi/product.wxs index 1aaa11d5ac4c55..ed062c3d74729b 100755 --- a/tools/msvs/msi/product.wxs +++ b/tools/msvs/msi/product.wxs @@ -47,8 +47,6 @@ - - @@ -329,6 +327,12 @@ Execute="immediate" Return="check" /> + + @@ -338,6 +342,7 @@ +