Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions src/System.Management.Automation/security/wldpNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,52 @@ internal static bool IsFileOnlyEntryEnabled()

private static bool TestBooleanWldpSetting(string settingName)
{
int hr = WldpNativeMethods.WldpGetApplicationSettingBoolean(
AppManifestId,
settingName,
out bool result);
bool result = SafeWldpGetApplicationSettingBoolean(settingName);

PSEtwLog.LogWDACQueryEvent(
"WldpGetApplicationSettingBoolean",
settingName,
hr,
result ? 1 : 0);
if (result)
{
return true;
}

if (hr is not 0)
string debugValue = Environment.GetEnvironmentVariable(
$"__PSLockdownPolicy_{settingName}",
EnvironmentVariableTarget.Machine);

if (debugValue is "1")
{
result = false;
result = true;
}

if (!result)
return result;
}

private static bool SafeWldpGetApplicationSettingBoolean(string settingName)
{
try
{
string debugValue = Environment.GetEnvironmentVariable(
$"__PSLockdownPolicy_{settingName}",
EnvironmentVariableTarget.Machine);
int hr = WldpNativeMethods.WldpGetApplicationSettingBoolean(
AppManifestId,
settingName,
out bool result);

if (debugValue is "1")
{
result = true;
}
PSEtwLog.LogWDACQueryEvent(
"WldpGetApplicationSettingBoolean",
settingName,
hr,
result ? 1 : 0);

return hr is 0 && result;
}
catch (Exception ex) when (ex is DllNotFoundException or EntryPointNotFoundException)
{
PSEtwLog.LogWDACQueryEvent(
"WldpGetApplicationSettingBoolean_Failed",
settingName,
ex.HResult,
0);

return result;
return false;
}
}

/// <summary>
Expand Down
Loading