Skip to content

Commit 68e3fc2

Browse files
authored
Fix catalog connection failure due to AppCapability::CreateWithProcessIdForUser throwing E_INVALIDARG when called with a null user on Windows 10 v1903 (#5475)
`AppCapability::CreateWithProcessIdForUser` does not accept a null user on Windows 10 v1903. Treat this case as if the API didn't exist.
1 parent e08cdae commit 68e3fc2

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

src/Microsoft.Management.Deployment/Helpers.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,36 @@ namespace winrt::Microsoft::Management::Deployment::implementation
7878
// Get the caller process id and use it to check if the caller has permissions to access the feature.
7979
winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapabilityAccessStatus status = winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapabilityAccessStatus::DeniedBySystem;
8080

81-
auto capability = winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapability::CreateWithProcessIdForUser(nullptr, GetStringForCapability(requiredCapability), callerProcessId);
82-
status = capability.CheckAccess();
81+
winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapability capability{ nullptr };
8382

84-
allowed = (status == winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapabilityAccessStatus::Allowed);
85-
}
86-
else
87-
{
88-
// If AppCapability is not present, require at least medium IL callers
89-
auto requiredIntegrityLevel = AppInstaller::Security::IntegrityLevel::Medium;
90-
91-
if (callerProcessId != GetCurrentProcessId())
83+
try
84+
{
85+
capability = winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapability::CreateWithProcessIdForUser(nullptr, GetStringForCapability(requiredCapability), callerProcessId);
86+
}
87+
catch (const winrt::hresult_invalid_argument&)
9288
{
93-
allowed = AppInstaller::Security::IsCOMCallerIntegrityLevelAtLeast(requiredIntegrityLevel);
9489
}
95-
else
90+
91+
if (capability)
9692
{
97-
allowed = AppInstaller::Security::IsCurrentIntegrityLevelAtLeast(requiredIntegrityLevel);
93+
status = capability.CheckAccess();
94+
95+
return ((status == winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapabilityAccessStatus::Allowed) ? S_OK : E_ACCESSDENIED);
9896
}
9997
}
10098

99+
// If AppCapability is not present, require at least medium IL callers
100+
auto requiredIntegrityLevel = AppInstaller::Security::IntegrityLevel::Medium;
101+
102+
if (callerProcessId != GetCurrentProcessId())
103+
{
104+
allowed = AppInstaller::Security::IsCOMCallerIntegrityLevelAtLeast(requiredIntegrityLevel);
105+
}
106+
else
107+
{
108+
allowed = AppInstaller::Security::IsCurrentIntegrityLevelAtLeast(requiredIntegrityLevel);
109+
}
110+
101111
return (allowed ? S_OK : E_ACCESSDENIED);
102112
}
103113

0 commit comments

Comments
 (0)