Skip to content

Commit

Permalink
Make self elevation stable, change to using a limited token as when t…
Browse files Browse the repository at this point in the history
…o use it
  • Loading branch information
JohnMcPMS committed Jan 29, 2025
1 parent 2dc4c07 commit d77b935
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace AppInstaller::CLI::Workflow

IConfigurationSetProcessorFactory factory;

// Since downgrading is not currently supported, only use dynamic if not running as admin.
if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::ConfigureSelfElevation) && !Runtime::IsRunningAsAdmin())
// Since downgrading is not currently supported, only use dynamic if running limited.
if (Runtime::IsRunningWithLimitedToken())
{
factory = ConfigurationRemoting::CreateDynamicRuntimeFactory();
}
Expand Down
4 changes: 0 additions & 4 deletions src/AppInstallerCommonCore/ExperimentalFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace AppInstaller::Settings
return userSettings.Get<Setting::EFResume>();
case ExperimentalFeature::Feature::Configuration03:
return userSettings.Get<Setting::EFConfiguration03>();
case ExperimentalFeature::Feature::ConfigureSelfElevation:
return userSettings.Get<Setting::EFConfigureSelfElevation>();
case ExperimentalFeature::Feature::ConfigureExport:
return userSettings.Get<Setting::EFConfigureExport>();
case ExperimentalFeature::Feature::Font:
Expand Down Expand Up @@ -83,8 +81,6 @@ namespace AppInstaller::Settings
return ExperimentalFeature{ "Resume", "resume", "https://aka.ms/winget-settings", Feature::Resume };
case Feature::Configuration03:
return ExperimentalFeature{ "Configuration Schema 0.3", "configuration03", "https://aka.ms/winget-settings", Feature::Configuration03 };
case Feature::ConfigureSelfElevation:
return ExperimentalFeature{ "Configure Self Elevation", "configureSelfElevate", "https://aka.ms/winget-settings", Feature::ConfigureSelfElevation };
case Feature::ConfigureExport:
return ExperimentalFeature{ "Configure Export", "configureExport", "https://aka.ms/winget-settings", Feature::ConfigureExport };
case Feature::Font:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ namespace AppInstaller::Settings
DirectMSI = 0x1,
Resume = 0x2,
Configuration03 = 0x4,
ConfigureSelfElevation = 0x8,
ConfigureExport = 0x10,
Font = 0x20,
ConfigureExport = 0x8,
Font = 0x10,
Max, // This MUST always be after all experimental features

// Features listed after Max will not be shown with the features command
Expand Down
2 changes: 0 additions & 2 deletions src/AppInstallerCommonCore/Public/winget/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ namespace AppInstaller::Settings
EFDirectMSI,
EFResume,
EFConfiguration03,
EFConfigureSelfElevation,
EFConfigureExport,
EFFonts,
// Telemetry
Expand Down Expand Up @@ -162,7 +161,6 @@ namespace AppInstaller::Settings
SETTINGMAPPING_SPECIALIZATION(Setting::EFDirectMSI, bool, bool, false, ".experimentalFeatures.directMSI"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFResume, bool, bool, false, ".experimentalFeatures.resume"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFConfiguration03, bool, bool, false, ".experimentalFeatures.configuration03"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFConfigureSelfElevation, bool, bool, false, ".experimentalFeatures.configureSelfElevate"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFConfigureExport, bool, bool, false, ".experimentalFeatures.configureExport"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFFonts, bool, bool, false, ".experimentalFeatures.fonts"sv);
// Telemetry
Expand Down
1 change: 0 additions & 1 deletion src/AppInstallerCommonCore/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ namespace AppInstaller::Settings
WINGET_VALIDATE_PASS_THROUGH(EFDirectMSI)
WINGET_VALIDATE_PASS_THROUGH(EFResume)
WINGET_VALIDATE_PASS_THROUGH(EFConfiguration03)
WINGET_VALIDATE_PASS_THROUGH(EFConfigureSelfElevation)
WINGET_VALIDATE_PASS_THROUGH(EFConfigureExport)
WINGET_VALIDATE_PASS_THROUGH(EFFonts)
WINGET_VALIDATE_PASS_THROUGH(AnonymizePathForDisplay)
Expand Down
8 changes: 8 additions & 0 deletions src/AppInstallerSharedLib/Public/winget/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ namespace AppInstaller::Runtime
// Determines whether the process is running with administrator or system privileges.
bool IsRunningAsAdminOrSystem();

// Determines whether the current token can be elevated.
// This only returns true for tokens that are TokenElevationTypeLimited.
// Thus, it will only be true if:
// 1. UAC is enabled
// 2. the user is in the Administrators group
// 3. the token is not already elevated
bool IsRunningWithLimitedToken();

// Returns true if this is a release build; false if not.
inline constexpr bool IsReleaseBuild()
{
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerSharedLib/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,9 @@ namespace AppInstaller::Runtime
{
return IsRunningAsAdmin() || IsRunningAsSystem();
}

bool IsRunningWithLimitedToken()
{
return wil::get_token_information<TOKEN_ELEVATION_TYPE>() == TokenElevationTypeLimited;
}
}

0 comments on commit d77b935

Please sign in to comment.