Skip to content

Commit 76e709e

Browse files
richardlauBethGriggs
authored andcommittedJul 5, 2021
win,msi: use localized "Authenticated Users" name
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: #39241 Fixes: #39224 Refs: e817ba7 Refs: https://hackerone.com/reports/1211160 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Beth Griggs <[email protected]>
1 parent e96c896 commit 76e709e

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed
 

‎tools/msvs/msi/custom_actions.cc

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <windows.h>
44
#include <msiquery.h>
55
#include <wcautil.h>
6+
#include <sddl.h>
7+
#include <Lmcons.h>
68

79
#define GUID_BUFFER_SIZE 39 // {8-4-4-4-12}\0
810

@@ -96,6 +98,35 @@ extern "C" UINT WINAPI BroadcastEnvironmentUpdate(MSIHANDLE hInstall) {
9698
return WcaFinalize(er);
9799
}
98100

101+
#define AUTHENTICATED_USERS_SID L"S-1-5-11"
102+
103+
extern "C" UINT WINAPI GetLocalizedUserNames(MSIHANDLE hInstall) {
104+
HRESULT hr = S_OK;
105+
UINT er = ERROR_SUCCESS;
106+
TCHAR userName[UNLEN + 1] = {0};
107+
DWORD userNameSize = UNLEN + 1;
108+
TCHAR domain[DNLEN + 1] = {0};
109+
DWORD domainSize = DNLEN + 1;
110+
PSID sid;
111+
SID_NAME_USE nameUse;
112+
113+
hr = WcaInitialize(hInstall, "GetLocalizedUserNames");
114+
ExitOnFailure(hr, "Failed to initialize");
115+
116+
er = ConvertStringSidToSidW(AUTHENTICATED_USERS_SID, &sid);
117+
ExitOnLastError(er, "Failed to convert security identifier");
118+
119+
er = LookupAccountSidW(NULL, sid, userName, &userNameSize, domain, &domainSize, &nameUse);
120+
ExitOnLastError(er, "Failed to lookup security identifier");
121+
122+
MsiSetProperty(hInstall, L"AUTHENTICATED_USERS", userName);
123+
ExitOnWin32Error(er, hr, "Failed to set localized Authenticated User name");
124+
125+
LExit:
126+
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
127+
LocalFree(sid);
128+
return WcaFinalize(er);
129+
}
99130

100131
extern "C" BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, VOID* dummy) {
101132
switch (ulReason) {

‎tools/msvs/msi/custom_actions.def

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ LIBRARY "custom_actions"
33
EXPORTS
44
SetInstallScope
55
BroadcastEnvironmentUpdate
6+
GetLocalizedUserNames

‎tools/msvs/msi/product.wxs

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"/>
4848

4949
<!-- PropertyRef of the account users for setting InstallDir permission explicitly -->
50-
<Property Id="AUTHENTICATED_USERS" Value="Authenticated Users"/>
51-
5250
<PropertyRef Id="WIX_ACCOUNT_LOCALSYSTEM" />
5351
<PropertyRef Id="WIX_ACCOUNT_USERS" />
5452
<PropertyRef Id="WIX_ACCOUNT_ADMINISTRATORS" />
@@ -329,6 +327,12 @@
329327
Execute="immediate"
330328
Return="check" />
331329

330+
<CustomAction Id="GetLocalizedUserNames"
331+
BinaryKey="CustomActionsDLL"
332+
DllEntry="GetLocalizedUserNames"
333+
Execute="immediate"
334+
Return="check" />
335+
332336
<Property Id="WixShellExecTarget" Value="[#InstallToolsBat]" />
333337
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" />
334338

@@ -338,6 +342,7 @@
338342

339343
<InstallExecuteSequence>
340344
<Custom Action='SetInstallScope' Before='FindRelatedProducts'/>
345+
<Custom Action='GetLocalizedUserNames' After='SetInstallScope'/>
341346
<Custom Action='BroadcastEnvironmentUpdate' After='InstallFinalize'/>
342347
</InstallExecuteSequence>
343348

0 commit comments

Comments
 (0)
Please sign in to comment.