From 5d5ecb5f34053befbe7e6f756325af07da6189c6 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 23 Oct 2022 21:05:53 +0500 Subject: [PATCH 1/8] Implement Environment.IsPrivilegedProcess --- .../Interop.GetTokenInformation_void.cs | 2 +- .../Advapi32/Interop.TOKEN_ACCESS_LEVELS.cs | 41 +++++++++++++++++++ .../TestUtilities/System/AdminHelpers.cs | 4 +- .../tests/TestUtilities/TestUtilities.csproj | 6 ++- .../System.Private.CoreLib.Shared.projitems | 18 ++++++++ .../src/System/Environment.Unix.cs | 6 +++ .../src/System/Environment.Windows.cs | 25 +++++++++++ .../src/System/Environment.cs | 5 +++ .../System.Runtime.Extensions.Tests.csproj | 3 +- .../System/Environment.IsPrivilegedProcess.cs | 24 +++++++++++ .../System.Runtime/ref/System.Runtime.cs | 1 + 11 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Windows/Advapi32/Interop.TOKEN_ACCESS_LEVELS.cs create mode 100644 src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.GetTokenInformation_void.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.GetTokenInformation_void.cs index e04e831ebe667..e61ce35a91f97 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.GetTokenInformation_void.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.GetTokenInformation_void.cs @@ -12,7 +12,7 @@ internal static partial class Advapi32 [LibraryImport(Interop.Libraries.Advapi32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static unsafe partial bool GetTokenInformation( - SafeAccessTokenHandle TokenHandle, + SafeTokenHandle TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, void* TokenInformation, uint TokenInformationLength, diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.TOKEN_ACCESS_LEVELS.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.TOKEN_ACCESS_LEVELS.cs new file mode 100644 index 0000000000000..2c8cd3cc3ba6b --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.TOKEN_ACCESS_LEVELS.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +internal static partial class Interop +{ + internal static partial class Advapi32 + { + [Flags] + internal enum TOKEN_ACCESS_LEVELS : uint + { + AssignPrimary = 0x00000001, + Duplicate = 0x00000002, + Impersonate = 0x00000004, + Query = 0x00000008, + QuerySource = 0x00000010, + AdjustPrivileges = 0x00000020, + AdjustGroups = 0x00000040, + AdjustDefault = 0x00000080, + AdjustSessionId = 0x00000100, + + Read = 0x00020000 | Query, + + Write = 0x00020000 | AdjustPrivileges | AdjustGroups | AdjustDefault, + + AllAccess = 0x000F0000 | + AssignPrimary | + Duplicate | + Impersonate | + Query | + QuerySource | + AdjustPrivileges | + AdjustGroups | + AdjustDefault | + AdjustSessionId, + + MaximumAllowed = 0x02000000 + } + } +} diff --git a/src/libraries/Common/tests/TestUtilities/System/AdminHelpers.cs b/src/libraries/Common/tests/TestUtilities/System/AdminHelpers.cs index 67c9a0067eedc..bf64c9ffea37a 100644 --- a/src/libraries/Common/tests/TestUtilities/System/AdminHelpers.cs +++ b/src/libraries/Common/tests/TestUtilities/System/AdminHelpers.cs @@ -40,8 +40,8 @@ public static unsafe bool IsProcessElevated() return(userId == 0); } - SafeAccessTokenHandle token; - if (!Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), TokenAccessLevels.Read, out token)) + SafeTokenHandle token; + if (!Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), (int)TokenAccessLevels.Read, out token)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Open process token failed"); } diff --git a/src/libraries/Common/tests/TestUtilities/TestUtilities.csproj b/src/libraries/Common/tests/TestUtilities/TestUtilities.csproj index ad1ab67e89c94..cbb1f4ed69be9 100644 --- a/src/libraries/Common/tests/TestUtilities/TestUtilities.csproj +++ b/src/libraries/Common/tests/TestUtilities/TestUtilities.csproj @@ -64,8 +64,8 @@ Link="Common\Interop\Windows\Kernel32\Interop.SECURITY_ATTRIBUTES.cs" /> - + + diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 9d02fee390685..9b945c800bc64 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1414,9 +1414,15 @@ Common\Interop\Windows\Advapi32\Interop.EventWriteTransfer.cs + + Common\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs + Common\Interop\Windows\Advapi32\Interop.LookupAccountNameW.cs + + Common\Interop\Windows\Advapi32\Interop.OpenProcessToken.cs + Common\Interop\Windows\Advapi32\Interop.RegCloseKey.cs @@ -1450,6 +1456,15 @@ Common\Interop\Windows\Advapi32\Interop.RegSetValueEx.cs + + Common\Interop\Windows\Advapi32\Interop.TOKEN_ACCESS_LEVELS.cs + + + Common\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs + + + Common\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs + Common\Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs @@ -1882,6 +1897,9 @@ Common\Interop\Windows\Kernel32\Interop.GetModuleHandle.cs + + Common\Microsoft\Win32\SafeHandles\SafeTokenHandle.cs + Common\System\IO\FileSystem.Attributes.Windows.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs index 046a8ab06dbed..62148406dd23e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs @@ -26,6 +26,12 @@ public static string MachineName public static string UserName => Interop.Sys.GetUserNameFromPasswd(Interop.Sys.GetEUid()); + private static bool IsAdminProcess() + { + uint userId = Interop.Sys.GetEUid(); + return (userId == 0); + } + [MethodImplAttribute(MethodImplOptions.NoInlining)] // Avoid inlining PInvoke frame into the hot path private static int GetProcessId() => Interop.Sys.GetPid(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs index e95f41a312bea..d3c17767fa0a0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.Win32.SafeHandles; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; @@ -83,6 +84,30 @@ private static string ExpandEnvironmentVariablesCore(string name) return builder.ToString(); } + private static unsafe bool IsAdminProcess() + { + SafeTokenHandle token; + if (Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), (int)Interop.Advapi32.TOKEN_ACCESS_LEVELS.Read, out token)) + { + using (token) + { + Interop.Advapi32.TOKEN_ELEVATION elevation = default; + + if (Interop.Advapi32.GetTokenInformation( + token, + Interop.Advapi32.TOKEN_INFORMATION_CLASS.TokenElevation, + &elevation, + (uint)sizeof(Interop.Advapi32.TOKEN_ELEVATION), + out _)) + { + return elevation.TokenIsElevated != Interop.BOOL.FALSE; + } + } + } + + throw Win32Marshal.GetExceptionForLastWin32Error(); + } + private static bool Is64BitOperatingSystemWhen32BitProcess => Interop.Kernel32.IsWow64Process(Interop.Kernel32.GetCurrentProcess(), out bool isWow64) && isWow64; diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs index a16af2f212c8a..ff767b1e9914b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs @@ -18,6 +18,11 @@ public static partial class Environment /// internal static bool IsSingleProcessor => ProcessorCount == 1; + /// + /// Gets whether the current process is authorized to perform security-relevant functions. + /// + public static bool IsPrivilegedProcess { get; } = IsAdminProcess(); + // Unconditionally return false since .NET Core does not support object finalization during shutdown. public static bool HasShutdownStarted => false; diff --git a/src/libraries/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj b/src/libraries/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj index 3e3e293778105..a9a3ad2802404 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj +++ b/src/libraries/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj @@ -33,6 +33,7 @@ + @@ -82,7 +83,7 @@ - + diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs new file mode 100644 index 0000000000000..6b32b9b0b23b1 --- /dev/null +++ b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; +using Xunit; + +namespace System.Tests +{ + public class Environment_IsPrivilegedProcess + { + [Fact] + public void TestIsPrivilegedProcess() + { + if (AdminHelpers.IsProcessElevated()) + { + Assert.True(Environment.IsPrivilegedProcess); + } + else + { + Assert.False(Environment.IsPrivilegedProcess); + } + } + } +} diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 29442746caff7..1d9e956385a30 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -2384,6 +2384,7 @@ public static partial class Environment public static bool HasShutdownStarted { get { throw null; } } public static bool Is64BitOperatingSystem { get { throw null; } } public static bool Is64BitProcess { get { throw null; } } + public static bool IsPrivilegedProcess { get { throw null; } } public static string MachineName { get { throw null; } } public static string NewLine { get { throw null; } } public static System.OperatingSystem OSVersion { get { throw null; } } From 0e3d26ffe29b9662c9303f9127888e1ddca9a260 Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 24 Oct 2022 11:51:42 +0500 Subject: [PATCH 2/8] Address feedback --- .../src/System/Environment.Windows.cs | 10 +++++++--- .../src/System/Environment.cs | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs index d3c17767fa0a0..37108fd51b8b4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs @@ -86,10 +86,10 @@ private static string ExpandEnvironmentVariablesCore(string name) private static unsafe bool IsAdminProcess() { - SafeTokenHandle token; - if (Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), (int)Interop.Advapi32.TOKEN_ACCESS_LEVELS.Read, out token)) + SafeTokenHandle? token = null; + try { - using (token) + if (Interop.Advapi32.OpenProcessToken(Interop.Kernel32.GetCurrentProcess(), (int)Interop.Advapi32.TOKEN_ACCESS_LEVELS.Read, out token)) { Interop.Advapi32.TOKEN_ELEVATION elevation = default; @@ -104,6 +104,10 @@ private static unsafe bool IsAdminProcess() } } } + finally + { + token?.Dispose(); + } throw Win32Marshal.GetExceptionForLastWin32Error(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs index ff767b1e9914b..0cfafb82b1121 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs @@ -18,10 +18,24 @@ public static partial class Environment /// internal static bool IsSingleProcessor => ProcessorCount == 1; + private static bool s_privilegedProcess; + private static volatile int s_pendingPrivilegedProcess; + /// /// Gets whether the current process is authorized to perform security-relevant functions. /// - public static bool IsPrivilegedProcess { get; } = IsAdminProcess(); + public static bool IsPrivilegedProcess + { + get + { + if (s_pendingPrivilegedProcess == 0) + { + s_privilegedProcess = IsAdminProcess(); + s_pendingPrivilegedProcess = 1; + } + return s_privilegedProcess; + } + } // Unconditionally return false since .NET Core does not support object finalization during shutdown. public static bool HasShutdownStarted => false; From 5b2edfd2b5f472b6962e225b56e2d734a9bed62c Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 24 Oct 2022 17:07:37 +0500 Subject: [PATCH 3/8] Use one static --- .../System.Private.CoreLib/src/System/Environment.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs index 0cfafb82b1121..f0d597cf72193 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs @@ -18,8 +18,7 @@ public static partial class Environment /// internal static bool IsSingleProcessor => ProcessorCount == 1; - private static bool s_privilegedProcess; - private static volatile int s_pendingPrivilegedProcess; + private static volatile sbyte s_privilegedProcess; /// /// Gets whether the current process is authorized to perform security-relevant functions. @@ -28,12 +27,11 @@ public static bool IsPrivilegedProcess { get { - if (s_pendingPrivilegedProcess == 0) + if (s_privilegedProcess == 0) { - s_privilegedProcess = IsAdminProcess(); - s_pendingPrivilegedProcess = 1; + s_privilegedProcess = IsAdminProcess() ? (sbyte)1 : (sbyte)-1; } - return s_privilegedProcess; + return s_privilegedProcess > 0; } } From 499edad12e3bee8cc13e80948289f3410c4ca1ad Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 24 Oct 2022 17:11:36 +0500 Subject: [PATCH 4/8] Fix mono wasm --- .../System.Private.CoreLib/src/System/Environment.Browser.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs index 7ba016ee24ba2..973e759e3b8f8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs @@ -25,6 +25,8 @@ private static OperatingSystem GetOSVersion() return new OperatingSystem(PlatformID.Other, new Version(1, 0, 0, 0)); } + private static bool IsAdminProcess() => false; + private static int GetProcessId() => 42; /// From 25fce3c59f151313c393df08f4d0eb13b6890383 Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 24 Oct 2022 22:14:08 +0500 Subject: [PATCH 5/8] Address feedback 2 --- .../System.Private.CoreLib/src/System/Environment.Windows.cs | 4 ++-- .../tests/System/Environment.IsPrivilegedProcess.cs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs index 37108fd51b8b4..d3b8c16b134fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs @@ -103,13 +103,13 @@ private static unsafe bool IsAdminProcess() return elevation.TokenIsElevated != Interop.BOOL.FALSE; } } + + throw Win32Marshal.GetExceptionForLastWin32Error(); } finally { token?.Dispose(); } - - throw Win32Marshal.GetExceptionForLastWin32Error(); } private static bool Is64BitOperatingSystemWhen32BitProcess => diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs index 6b32b9b0b23b1..83e5b2467dc65 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs @@ -9,6 +9,7 @@ namespace System.Tests public class Environment_IsPrivilegedProcess { [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't support geteuid")] public void TestIsPrivilegedProcess() { if (AdminHelpers.IsProcessElevated()) From 0bf5b3cbf3f3ae36e21f73a0a761e503de6b120a Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 25 Oct 2022 08:23:15 +0500 Subject: [PATCH 6/8] Address feedback 3 --- .../src/System/Environment.Unix.cs | 5 +---- .../src/System/Environment.Windows.cs | 2 +- .../System.Private.CoreLib/src/System/Environment.cs | 7 ++++--- .../tests/System/Environment.IsPrivilegedProcess.cs | 9 +-------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs index 62148406dd23e..7e4f0c3652982 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs @@ -26,10 +26,7 @@ public static string MachineName public static string UserName => Interop.Sys.GetUserNameFromPasswd(Interop.Sys.GetEUid()); - private static bool IsAdminProcess() - { - uint userId = Interop.Sys.GetEUid(); - return (userId == 0); + private static bool IsPrivilegedProcessCore() => Interop.Sys.GetEUid() == 0 ; } [MethodImplAttribute(MethodImplOptions.NoInlining)] // Avoid inlining PInvoke frame into the hot path diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs index d3b8c16b134fd..5934ac451ff36 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs @@ -84,7 +84,7 @@ private static string ExpandEnvironmentVariablesCore(string name) return builder.ToString(); } - private static unsafe bool IsAdminProcess() + private static unsafe bool IsPrivilegedProcessCore() { SafeTokenHandle? token = null; try diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs index f0d597cf72193..cc67fc169bced 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs @@ -27,11 +27,12 @@ public static bool IsPrivilegedProcess { get { - if (s_privilegedProcess == 0) + sbyte privilegedProcess = s_privilegedProcess; + if (privilegedProcess == 0) { - s_privilegedProcess = IsAdminProcess() ? (sbyte)1 : (sbyte)-1; + s_privilegedProcess = privilegedProcess = IsPrivilegedProcessCore() ? (sbyte)1 : (sbyte)-1; } - return s_privilegedProcess > 0; + return privilegedProcess > 0; } } diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs index 83e5b2467dc65..55096f3ad2ab9 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Environment.IsPrivilegedProcess.cs @@ -12,14 +12,7 @@ public class Environment_IsPrivilegedProcess [SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't support geteuid")] public void TestIsPrivilegedProcess() { - if (AdminHelpers.IsProcessElevated()) - { - Assert.True(Environment.IsPrivilegedProcess); - } - else - { - Assert.False(Environment.IsPrivilegedProcess); - } + Assert.Equal(AdminHelpers.IsProcessElevated(), Environment.IsPrivilegedProcess); } } } From 1b07c6120b205e8e7511de663d5ca46d78e6d79b Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 25 Oct 2022 08:47:14 +0500 Subject: [PATCH 7/8] Fix typo. --- .../System.Private.CoreLib/src/System/Environment.Unix.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs index 7e4f0c3652982..5a80fe41990b8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs @@ -26,8 +26,7 @@ public static string MachineName public static string UserName => Interop.Sys.GetUserNameFromPasswd(Interop.Sys.GetEUid()); - private static bool IsPrivilegedProcessCore() => Interop.Sys.GetEUid() == 0 ; - } + private static bool IsPrivilegedProcessCore() => Interop.Sys.GetEUid() == 0; [MethodImplAttribute(MethodImplOptions.NoInlining)] // Avoid inlining PInvoke frame into the hot path private static int GetProcessId() => Interop.Sys.GetPid(); From a94be185b91629d386070cb86818c432de013284 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 25 Oct 2022 09:34:18 +0500 Subject: [PATCH 8/8] Fix wasm --- .../System.Private.CoreLib/src/System/Environment.Browser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs index 973e759e3b8f8..6d3aabb565fba 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs @@ -25,7 +25,7 @@ private static OperatingSystem GetOSVersion() return new OperatingSystem(PlatformID.Other, new Version(1, 0, 0, 0)); } - private static bool IsAdminProcess() => false; + private static bool IsPrivilegedProcessCore() => false; private static int GetProcessId() => 42;