Skip to content

Commit c0062e3

Browse files
committed
elevated
1 parent 7ad49cd commit c0062e3

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,28 @@ namespace AppInstaller::CLI::Workflow
6666

6767
constexpr std::wstring_view s_Setting_PowerShellGet_ModuleName = L"name";
6868

69+
struct PredefinedResourceInfo
70+
{
71+
std::wstring_view UnitType;
72+
bool ElevationRequired = false;
73+
74+
PredefinedResourceInfo(std::wstring_view unitType) : UnitType(unitType) {}
75+
PredefinedResourceInfo(std::wstring_view unitType, bool elevationRequired) : UnitType(unitType), ElevationRequired(elevationRequired) {}
76+
};
77+
6978
struct PredefinedResource
7079
{
7180
// RequiredModule could be empty, meaning no required modules needed.
7281
std::wstring_view RequiredModule;
7382

74-
std::vector<std::wstring_view> UnitTypes;
83+
std::vector<PredefinedResourceInfo> ResourceInfos;
7584
};
7685

7786
std::vector<PredefinedResource> PredefinedResourcesForExport()
7887
{
7988
return {
80-
{ {}, { s_UnitType_WinGetUserSettingsFile_DSCv3 } },
81-
{ L"Microsoft.Windows.Settings", { L"Microsoft.Windows.Settings/WindowsSettings" } },
89+
{ {}, { { s_UnitType_WinGetUserSettingsFile_DSCv3 } } },
90+
{ L"Microsoft.Windows.Settings", { { L"Microsoft.Windows.Settings/WindowsSettings", true } } },
8291
};
8392
}
8493

@@ -1494,6 +1503,14 @@ namespace AppInstaller::CLI::Workflow
14941503
}
14951504
}
14961505

1506+
void AddElevatedEnvironment(std::vector<ConfigurationUnit>& units)
1507+
{
1508+
for (auto& unit : units)
1509+
{
1510+
unit.Environment().Context(SecurityContext::Elevated);
1511+
}
1512+
}
1513+
14971514
std::vector<IConfigurationUnitProcessorDetails> GetAllUnitProcessors(Execution::Context& context)
14981515
{
14991516
ConfigurationContext& configContext = context.Get<Data::ConfigurationContext>();
@@ -1554,16 +1571,24 @@ namespace AppInstaller::CLI::Workflow
15541571
}
15551572
*/
15561573

1557-
for (const auto& resourceType : resources.UnitTypes)
1574+
for (const auto& resourceInfo : resources.ResourceInfos)
15581575
{
1559-
auto resourceUnit = CreateConfigurationUnitFromUnitType(resourceType);
1576+
auto resourceUnit = CreateConfigurationUnitFromUnitType(resourceInfo.UnitType);
15601577
auto exportedUnits = ExportUnit(context, resourceUnit);
15611578

15621579
if (requiredModuleUnit)
15631580
{
15641581
AddDependentUnit(exportedUnits, requiredModuleUnit.value());
15651582
}
15661583

1584+
// The dynamic processor factory does not support operating elevated units without a set.
1585+
// Luckily the Get/Export for all PreDefinedResources do not require elevation.
1586+
// Here we add elevation environment to exported results.
1587+
if (resourceInfo.ElevationRequired)
1588+
{
1589+
AddElevatedEnvironment(exportedUnits);
1590+
}
1591+
15671592
for (auto exportedUnit : exportedUnits)
15681593
{
15691594
configContext.Set().Units().Append(std::move(exportedUnit));

0 commit comments

Comments
 (0)