Skip to content

Commit 9117727

Browse files
authored
Block admin uninstall of user package (1.29) (#6344)
## 📖 Description Block admin uninstall of user scope package.
1 parent fe424a1 commit 9117727

13 files changed

Lines changed: 51 additions & 19 deletions

File tree

doc/windows/package-manager/winget/returnCodes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ ms.localizationpriority: low
139139
| 0x8A15007A | -1978335110 | APPINSTALLER_CLI_ERROR_REPAIR_NOT_APPLICABLE | Repair operation is not applicable. |
140140
| 0x8A15007B | -1978335109 | APPINSTALLER_CLI_ERROR_EXEC_REPAIR_FAILED | Repair operation failed. |
141141
| 0x8A15007C | -1978335108 | APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED | The installer technology in use doesn't support repair. |
142-
| 0x8A15007D | -1978335107 | APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED | Repair operations involving administrator privileges are not permitted on packages installed within the user scope. |
142+
| 0x8A15007D | -1978335107 | APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED | The requested operation is not permitted from an administrator context on packages installed within the user scope. |
143143
| 0x8A15007E | -1978335106 | APPINSTALLER_CLI_ERROR_SQLITE_CONNECTION_TERMINATED | The SQLite connection was terminated to prevent corruption. |
144144
| 0x8A15007F | -1978335105 | APPINSTALLER_CLI_ERROR_DISPLAYCATALOG_API_FAILED | Failed to get Microsoft Store package catalog. |
145145
| 0x8A150080 | -1978335104 | APPINSTALLER_CLI_ERROR_NO_APPLICABLE_DISPLAYCATALOG_PACKAGE | No applicable Microsoft Store package found from Microsoft Store package catalog. |

src/AppInstallerCLICore/Resources.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ namespace AppInstaller::CLI::Resource
500500
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSpecified);
501501
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSupported);
502502
WINGET_DEFINE_RESOURCE_STRINGID(NoAdminRepairForUserScopePackage);
503+
WINGET_DEFINE_RESOURCE_STRINGID(NoAdminUninstallForUserScopePackage);
503504
WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers);
504505
WINGET_DEFINE_RESOURCE_STRINGID(NoExperimentalFeaturesMessage);
505506
WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledFontFound);

src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ namespace AppInstaller::CLI::Workflow
386386
if (scopeEnum == ScopeEnum::User)
387387
{
388388
context.Reporter.Error() << Resource::String::NoAdminRepairForUserScopePackage << std::endl;
389-
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED);
389+
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED);
390390
}
391391
}
392392

src/AppInstallerCLICore/Workflows/UninstallFlow.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ namespace AppInstaller::CLI::Workflow
6767

6868
std::vector<Item> Items;
6969
};
70+
71+
bool AdminExecutionShouldBlockUserScopePackages(InstallerTypeEnum installerType)
72+
{
73+
switch (installerType)
74+
{
75+
case InstallerTypeEnum::Exe:
76+
case InstallerTypeEnum::Burn:
77+
case InstallerTypeEnum::Inno:
78+
case InstallerTypeEnum::Nullsoft:
79+
case InstallerTypeEnum::Portable:
80+
return true;
81+
default:
82+
return false;
83+
}
84+
}
7085
}
7186

7287
void UninstallSinglePackage(Execution::Context& context)
@@ -214,16 +229,27 @@ namespace AppInstaller::CLI::Workflow
214229
return;
215230
}
216231

217-
const std::string installedTypeString = installedPackageVersion->GetMetadata()[PackageVersionMetadata::InstalledType];
218-
switch (ConvertToInstallerTypeEnum(installedTypeString))
232+
auto packageMetadata = installedPackageVersion->GetMetadata();
233+
auto installedType = ConvertToInstallerTypeEnum(packageMetadata[PackageVersionMetadata::InstalledType]);
234+
235+
// When running as admin, block attempt to uninstall user scope package to prevent EOP paths.
236+
if (AdminExecutionShouldBlockUserScopePackages(installedType) && Runtime::IsRunningAsAdmin())
237+
{
238+
auto scopeEnum = ConvertToScopeEnum(packageMetadata[PackageVersionMetadata::InstalledScope]);
239+
if (scopeEnum == ScopeEnum::User)
240+
{
241+
context.Reporter.Error() << Resource::String::NoAdminUninstallForUserScopePackage << std::endl;
242+
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED);
243+
}
244+
}
245+
246+
switch (installedType)
219247
{
220248
case InstallerTypeEnum::Exe:
221249
case InstallerTypeEnum::Burn:
222250
case InstallerTypeEnum::Inno:
223251
case InstallerTypeEnum::Nullsoft:
224252
{
225-
IPackageVersion::Metadata packageMetadata = installedPackageVersion->GetMetadata();
226-
227253
// Default to silent unless it is not present or interactivity is requested
228254
auto uninstallCommandItr = packageMetadata.find(PackageVersionMetadata::SilentUninstallCommand);
229255
if (uninstallCommandItr == packageMetadata.end() || context.Args.Contains(Execution::Args::Type::Interactive))
@@ -281,8 +307,8 @@ namespace AppInstaller::CLI::Workflow
281307
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_NO_UNINSTALL_INFO_FOUND);
282308
}
283309

284-
const std::string installedScope = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata()[Repository::PackageVersionMetadata::InstalledScope];
285-
const std::string installedArch = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata()[Repository::PackageVersionMetadata::InstalledArchitecture];
310+
const std::string installedScope = packageMetadata[Repository::PackageVersionMetadata::InstalledScope];
311+
const std::string installedArch = packageMetadata[Repository::PackageVersionMetadata::InstalledArchitecture];
286312

287313
PortableInstaller portableInstaller = PortableInstaller(
288314
Manifest::ConvertToScopeEnum(installedScope),

src/AppInstallerCLIE2ETests/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public class ErrorCode
279279

280280
public const int ERROR_NO_REPAIR_INFO_FOUND = unchecked((int)0x8A150079);
281281
public const int ERROR_REPAIR_NOT_SUPPORTED = unchecked((int)0x8A15007C);
282-
public const int ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED = unchecked((int)0x8A15007D);
282+
public const int ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED = unchecked((int)0x8A15007D);
283283

284284
public const int ERROR_INSTALLER_ZERO_BYTE_FILE = unchecked((int)0x8A150086);
285285
public const int ERROR_FONT_INSTALL_FAILED = unchecked((int)0x8A150087);

src/AppInstallerCLIE2ETests/Interop/RepairInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public async Task RepairBurnInstallerInAdminContextWithUserScopeInstall()
167167
var repairOptions = this.TestFactory.CreateRepairOptions();
168168
repairOptions.PackageRepairMode = PackageRepairMode.Silent;
169169

170-
await this.RepairPackageAndValidateStatus(searchResult.CatalogPackage, repairOptions, RepairResultStatus.RepairError, Constants.ErrorCode.ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED);
170+
await this.RepairPackageAndValidateStatus(searchResult.CatalogPackage, repairOptions, RepairResultStatus.RepairError, Constants.ErrorCode.ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED);
171171

172172
// Cleanup
173173
TestCommon.CleanupTestExeAndDirectory(this.installDir);

src/AppInstallerCLIE2ETests/RepairCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void RepairBurnInstallerInAdminContextWithUserScopeInstall()
134134
Assert.True(result.StdOut.Contains("Successfully installed"));
135135

136136
result = TestCommon.RunAICLICommand("repair", "AppInstallerTest.TestUserScopeInstallRepairInAdminContext");
137-
Assert.AreEqual(Constants.ErrorCode.ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED, result.ExitCode);
137+
Assert.AreEqual(Constants.ErrorCode.ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED, result.ExitCode);
138138
Assert.True(result.StdOut.Contains("The package installed for user scope cannot be repaired when running with administrator privileges."));
139139
TestCommon.CleanupTestExeAndDirectory(installDir);
140140
}

src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,8 +2890,8 @@ Please specify one of them using the --source option to proceed.</value>
28902890
<data name="NoAdminRepairForUserScopePackage" xml:space="preserve">
28912891
<value>The package installed for user scope cannot be repaired when running with administrator privileges.</value>
28922892
</data>
2893-
<data name="APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED" xml:space="preserve">
2894-
<value>Repair operations involving administrator privileges are not permitted on packages installed within the user scope.</value>
2893+
<data name="APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED" xml:space="preserve">
2894+
<value>The requested operation is not permitted from an administrator context on packages installed within the user scope.</value>
28952895
</data>
28962896
<data name="RepairFailedWithCode" xml:space="preserve">
28972897
<value>Repair failed with exit code: {0}</value>
@@ -3649,4 +3649,7 @@ An unlocalized JSON fragment will follow on another line.</comment>
36493649
<data name="WINGET_CONFIG_ERROR_PROCESSOR_HASH_MISMATCH" xml:space="preserve">
36503650
<value>The DSC processor hash provided does not match hash of the target file.</value>
36513651
</data>
3652+
<data name="NoAdminUninstallForUserScopePackage" xml:space="preserve">
3653+
<value>The package installed for user scope cannot be uninstalled when running with administrator privileges.</value>
3654+
</data>
36523655
</root>

src/AppInstallerSharedLib/Errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace AppInstaller
212212
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_REPAIR_NOT_APPLICABLE, "Repair operation is not applicable."),
213213
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_EXEC_REPAIR_FAILED, "Repair operation failed."),
214214
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED, "The installer technology in use doesn't support repair."),
215-
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED, "Repair operations involving administrator privileges are not permitted on packages installed within the user scope."),
215+
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED, "The requested operation is not permitted from an administrator context on packages installed within the user scope."),
216216
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_SQLITE_CONNECTION_TERMINATED, "The SQLite connection was terminated to prevent corruption."),
217217
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_DISPLAYCATALOG_API_FAILED, "Failed to get Microsoft Store package catalog."),
218218
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_NO_APPLICABLE_DISPLAYCATALOG_PACKAGE, "No applicable Microsoft Store package found from Microsoft Store package catalog."),

src/AppInstallerSharedLib/Public/AppInstallerErrors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
#define APPINSTALLER_CLI_ERROR_REPAIR_NOT_APPLICABLE ((HRESULT)0x8A15007A)
146146
#define APPINSTALLER_CLI_ERROR_EXEC_REPAIR_FAILED ((HRESULT)0x8A15007B)
147147
#define APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED ((HRESULT)0x8A15007C)
148-
#define APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_REPAIR_PROHIBITED ((HRESULT)0x8A15007D)
148+
#define APPINSTALLER_CLI_ERROR_ADMIN_CONTEXT_ACTION_PROHIBITED ((HRESULT)0x8A15007D)
149149
#define APPINSTALLER_CLI_ERROR_SQLITE_CONNECTION_TERMINATED ((HRESULT)0x8A15007E)
150150
#define APPINSTALLER_CLI_ERROR_DISPLAYCATALOG_API_FAILED ((HRESULT)0x8A15007F)
151151
#define APPINSTALLER_CLI_ERROR_NO_APPLICABLE_DISPLAYCATALOG_PACKAGE ((HRESULT)0x8A150080)

0 commit comments

Comments
 (0)