winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 508ad2bc29c5d5ce037912b486cc953d300de513
parent 70efd46ad29033cdbb86ac956619714989d2faee
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Sat, 27 Jun 2020 00:36:29 -0700

Add user specific directory for secure settings (#465)


Diffstat:
Msrc/AppInstallerCommonCore/Runtime.cpp | 21++++++++++++++++++---
Msrc/AppInstallerCommonCore/pch.h | 1+
2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/AppInstallerCommonCore/Runtime.cpp b/src/AppInstallerCommonCore/Runtime.cpp @@ -17,7 +17,8 @@ namespace AppInstaller::Runtime constexpr std::string_view s_DefaultTempDirectory = "WinGet"sv; constexpr std::string_view s_AppDataDir_Settings = "Settings"sv; constexpr std::string_view s_AppDataDir_State = "State"sv; - constexpr std::string_view s_SecureSettings_Relative = "Microsoft/WinGet/settings"sv; + constexpr std::string_view s_SecureSettings_Base = "Microsoft/WinGet"sv; + constexpr std::string_view s_SecureSettings_UserRelative = "settings"sv; constexpr std::string_view s_SecureSettings_Relative_Packaged = "pkg"sv; constexpr std::string_view s_SecureSettings_Relative_Unpackaged = "win"sv; @@ -108,6 +109,16 @@ namespace AppInstaller::Runtime return result; } + + // Gets the current user's SID for use in paths. + std::filesystem::path GetUserSID() + { + auto userToken = wil::get_token_information<TOKEN_USER>(); + + wil::unique_hlocal_string sidString; + THROW_IF_WIN32_BOOL_FALSE(ConvertSidToStringSidW(userToken->User.Sid, &sidString)); + return { sidString.get() }; + } } bool IsRunningInPackagedContext() @@ -224,7 +235,9 @@ namespace AppInstaller::Runtime break; case PathName::SecureSettings: result = GetKnownFolderPath(FOLDERID_ProgramData); - result /= s_SecureSettings_Relative; + result /= s_SecureSettings_Base; + result /= GetUserSID(); + result /= s_SecureSettings_UserRelative; result /= s_SecureSettings_Relative_Packaged; result /= GetPackageName(); create = false; @@ -256,7 +269,9 @@ namespace AppInstaller::Runtime break; case PathName::SecureSettings: result = GetKnownFolderPath(FOLDERID_ProgramData); - result /= s_SecureSettings_Relative; + result /= s_SecureSettings_Base; + result /= GetUserSID(); + result /= s_SecureSettings_UserRelative; result /= s_SecureSettings_Relative_Unpackaged; create = false; break; diff --git a/src/AppInstallerCommonCore/pch.h b/src/AppInstallerCommonCore/pch.h @@ -6,6 +6,7 @@ #include <Windows.h> #include <appmodel.h> #include <WinInet.h> +#include <sddl.h> #include <Shlobj.h> #include <Shlwapi.h>