From 96a2daf24fb70507fd7f3654d51ce0c5ce2b57d5 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Mon, 18 Nov 2019 13:51:48 -0800 Subject: [PATCH] Add AnonymousPipeServerStream method that takes an ACL --- .../System.IO.Pipes.AccessControl.sln | 4 +- .../ref/System.IO.Pipes.AccessControl.cs | 5 + .../AnonymousPipeServerStreamAclTests.cs | 148 ++++++++++ .../tests/PipeServerStreamAclTestBase.cs | 59 ++++ ...System.IO.Pipes.AccessControl.Tests.csproj | 2 + .../src/MatchingRefApiCompatBaseline.txt | 1 + .../src/System.IO.Pipes.csproj | 257 +++++------------- .../IO/Pipes/AnonymousPipeClientStream.cs | 3 +- .../Pipes/AnonymousPipeServerStream.Unix.cs | 3 +- .../AnonymousPipeServerStream.Windows.cs | 22 +- .../IO/Pipes/AnonymousPipeServerStream.cs | 3 +- .../IO/Pipes/AnonymousPipeServerStreamAcl.cs | 25 ++ .../AccessControl/NativeObjectSecurity.cs | 4 +- 13 files changed, 328 insertions(+), 208 deletions(-) create mode 100644 src/libraries/System.IO.Pipes.AccessControl/tests/AnonymousPipeTests/AnonymousPipeServerStreamAclTests.cs create mode 100644 src/libraries/System.IO.Pipes.AccessControl/tests/PipeServerStreamAclTestBase.cs create mode 100644 src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStreamAcl.cs diff --git a/src/libraries/System.IO.Pipes.AccessControl/System.IO.Pipes.AccessControl.sln b/src/libraries/System.IO.Pipes.AccessControl/System.IO.Pipes.AccessControl.sln index 5c4a7af158651..8f46da6742754 100644 --- a/src/libraries/System.IO.Pipes.AccessControl/System.IO.Pipes.AccessControl.sln +++ b/src/libraries/System.IO.Pipes.AccessControl/System.IO.Pipes.AccessControl.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27213.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29411.138 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Pipes.AccessControl.Tests", "tests\System.IO.Pipes.AccessControl.Tests.csproj", "{A0356E61-19E1-4722-A53D-5D2616E16312}" ProjectSection(ProjectDependencies) = postProject diff --git a/src/libraries/System.IO.Pipes.AccessControl/ref/System.IO.Pipes.AccessControl.cs b/src/libraries/System.IO.Pipes.AccessControl/ref/System.IO.Pipes.AccessControl.cs index 414a3413ce560..ffce89125016e 100644 --- a/src/libraries/System.IO.Pipes.AccessControl/ref/System.IO.Pipes.AccessControl.cs +++ b/src/libraries/System.IO.Pipes.AccessControl/ref/System.IO.Pipes.AccessControl.cs @@ -66,4 +66,9 @@ public void ResetAccessRule(System.IO.Pipes.PipeAccessRule rule) { } public void SetAccessRule(System.IO.Pipes.PipeAccessRule rule) { } public void SetAuditRule(System.IO.Pipes.PipeAuditRule rule) { } } + + public static class AnonymousPipeServerStreamAcl + { + public static System.IO.Pipes.AnonymousPipeServerStream Create(System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize, System.IO.Pipes.PipeSecurity pipeSecurity) { throw null; } + } } diff --git a/src/libraries/System.IO.Pipes.AccessControl/tests/AnonymousPipeTests/AnonymousPipeServerStreamAclTests.cs b/src/libraries/System.IO.Pipes.AccessControl/tests/AnonymousPipeTests/AnonymousPipeServerStreamAclTests.cs new file mode 100644 index 0000000000000..4443a75f3fbcd --- /dev/null +++ b/src/libraries/System.IO.Pipes.AccessControl/tests/AnonymousPipeTests/AnonymousPipeServerStreamAclTests.cs @@ -0,0 +1,148 @@ +using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; +using System.Security.Principal; +using Xunit; + +namespace System.IO.Pipes.Tests +{ + public class AnonymousPipeServerStreamAclTests : PipeServerStreamAclTestBase + { + private const PipeDirection DefaultPipeDirection = PipeDirection.In; + private const HandleInheritability DefaultInheritability = HandleInheritability.None; + private const int DefaultBufferSize = 1; + + [Fact] + public void Create_NullSecurity() + { + CreateAndVerifyAnonymousPipe(expectedSecurity: null).Dispose(); + } + + [Fact] + public void Create_NotSupportedPipeDirection() + { + Assert.Throws(() => + { + CreateAndVerifyAnonymousPipe(GetBasicPipeSecurity(), PipeDirection.InOut).Dispose(); + }); + } + + [Theory] + [InlineData((PipeDirection)(int.MinValue))] + [InlineData((PipeDirection)0)] + [InlineData((PipeDirection)4)] + [InlineData((PipeDirection)(int.MaxValue))] + public void Create_InvalidPipeDirection(PipeDirection direction) + { + Assert.Throws(() => + { + CreateAndVerifyAnonymousPipe(GetBasicPipeSecurity(), direction).Dispose(); + }); + } + + [Theory] + [InlineData((HandleInheritability)(int.MinValue))] + [InlineData((HandleInheritability)(-1))] + [InlineData((HandleInheritability)2)] + [InlineData((HandleInheritability)(int.MaxValue))] + public void Create_InvalidInheritability(HandleInheritability inheritability) + { + Assert.Throws(() => + { + CreateAndVerifyAnonymousPipe(GetBasicPipeSecurity(), inheritability: inheritability).Dispose(); + }); + } + + [Theory] + [InlineData(int.MinValue)] + [InlineData(-1)] + public void Create_InvalidBufferSize(int bufferSize) + { + Assert.Throws(() => + { + CreateAndVerifyAnonymousPipe(GetBasicPipeSecurity(), bufferSize: bufferSize).Dispose(); + }); + } + + public static IEnumerable Create_ValidParameters_MemberData() => + from direction in new[] { PipeDirection.In, PipeDirection.Out } + from inheritability in Enum.GetValues(typeof(HandleInheritability)).Cast() + from bufferSize in new[] { 0, 1 } + select new object[] { direction, inheritability, bufferSize }; + + [Theory] + [MemberData(nameof(Create_ValidParameters_MemberData))] + public void Create_ValidParameters(PipeDirection direction, HandleInheritability inheritability, int bufferSize) + { + CreateAndVerifyAnonymousPipe(GetBasicPipeSecurity(), direction, inheritability, bufferSize).Dispose(); + } + + public static IEnumerable Create_CombineRightsAndAccessControl_MemberData() => + from rights in Enum.GetValues(typeof(PipeAccessRights)).Cast() + from accessControl in new[] { AccessControlType.Allow, AccessControlType.Deny } + select new object[] { rights, accessControl }; + + // These tests match NetFX behavior + [Theory] + [MemberData(nameof(Create_CombineRightsAndAccessControl_MemberData))] + public void Create_CombineRightsAndAccessControl(PipeAccessRights rights, AccessControlType accessControl) + { + // These are the two cases that create a valid pipe when using Allow + if ((rights == PipeAccessRights.FullControl || rights == PipeAccessRights.ReadWrite) && + accessControl == AccessControlType.Allow) + { + VerifyValidSecurity(rights, accessControl); + } + // When creating the PipeAccessRule for the PipeSecurity, the PipeAccessRule constructor calls AccessMaskFromRights, which explicilty removes the Synchronize bit from rights when AccessControlType is Deny + // and rights is not FullControl, so using Synchronize with Deny is not allowed + else if (rights == PipeAccessRights.Synchronize && accessControl == AccessControlType.Deny) + { + Assert.Throws("accessMask", () => + { + PipeSecurity security = GetPipeSecurity(WellKnownSidType.BuiltinUsersSid, PipeAccessRights.Synchronize, AccessControlType.Deny); + }); + } + // Any other case is not authorized + else + { + PipeSecurity security = GetPipeSecurity(WellKnownSidType.BuiltinUsersSid, rights, accessControl); + Assert.Throws(() => + { + AnonymousPipeServerStreamAcl.Create(DefaultPipeDirection, DefaultInheritability, DefaultBufferSize, security).Dispose(); + }); + } + } + + [Theory] + [InlineData(PipeAccessRights.ReadWrite | PipeAccessRights.Synchronize, AccessControlType.Allow)] + public void Create_ValidBitwiseRightsSecurity(PipeAccessRights rights, AccessControlType accessControl) + { + VerifyValidSecurity(rights, accessControl); + } + + private void VerifyValidSecurity(PipeAccessRights rights, AccessControlType accessControl) + { + PipeSecurity security = GetPipeSecurity(WellKnownSidType.BuiltinUsersSid, rights, accessControl); + CreateAndVerifyAnonymousPipe(security).Dispose(); + } + + private AnonymousPipeServerStream CreateAndVerifyAnonymousPipe( + PipeSecurity expectedSecurity, + PipeDirection direction = DefaultPipeDirection, + HandleInheritability inheritability = DefaultInheritability, + int bufferSize = DefaultBufferSize) + { + AnonymousPipeServerStream pipe = AnonymousPipeServerStreamAcl.Create(direction, inheritability, bufferSize, expectedSecurity); + Assert.NotNull(pipe); + + if (expectedSecurity != null) + { + PipeSecurity actualSecurity = pipe.GetAccessControl(); + VerifyPipeSecurity(expectedSecurity, actualSecurity); + } + + return pipe; + } + + } +} diff --git a/src/libraries/System.IO.Pipes.AccessControl/tests/PipeServerStreamAclTestBase.cs b/src/libraries/System.IO.Pipes.AccessControl/tests/PipeServerStreamAclTestBase.cs new file mode 100644 index 0000000000000..679710e607f4e --- /dev/null +++ b/src/libraries/System.IO.Pipes.AccessControl/tests/PipeServerStreamAclTestBase.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; +using System.Security.Principal; +using Xunit; + +namespace System.IO.Pipes.Tests +{ + public class PipeServerStreamAclTestBase + { + protected PipeSecurity GetBasicPipeSecurity() + { + return GetPipeSecurity( + WellKnownSidType.BuiltinUsersSid, + PipeAccessRights.FullControl, + AccessControlType.Allow); + } + + protected PipeSecurity GetPipeSecurity(WellKnownSidType sid, PipeAccessRights rights, AccessControlType accessControl) + { + var security = new PipeSecurity(); + SecurityIdentifier identity = new SecurityIdentifier(sid, null); + var accessRule = new PipeAccessRule(identity, rights, accessControl); + security.AddAccessRule(accessRule); + return security; + } + + protected void VerifyPipeSecurity(PipeSecurity expectedSecurity, PipeSecurity actualSecurity) + { + Assert.Equal(typeof(PipeAccessRights), expectedSecurity.AccessRightType); + Assert.Equal(typeof(PipeAccessRights), actualSecurity.AccessRightType); + + List expectedAccessRules = expectedSecurity.GetAccessRules(includeExplicit: true, includeInherited: false, typeof(SecurityIdentifier)) + .Cast().ToList(); + + List actualAccessRules = actualSecurity.GetAccessRules(includeExplicit: true, includeInherited: false, typeof(SecurityIdentifier)) + .Cast().ToList(); + + Assert.Equal(expectedAccessRules.Count, actualAccessRules.Count); + if (expectedAccessRules.Count > 0) + { + Assert.All(expectedAccessRules, actualAccessRule => + { + int count = expectedAccessRules.Count(expectedAccessRule => AreAccessRulesEqual(expectedAccessRule, actualAccessRule)); + Assert.True(count > 0); + }); + } + } + + protected bool AreAccessRulesEqual(PipeAccessRule expectedRule, PipeAccessRule actualRule) + { + return + expectedRule.AccessControlType == actualRule.AccessControlType && + expectedRule.PipeAccessRights == actualRule.PipeAccessRights && + expectedRule.InheritanceFlags == actualRule.InheritanceFlags && + expectedRule.PropagationFlags == actualRule.PropagationFlags; + } + } +} diff --git a/src/libraries/System.IO.Pipes.AccessControl/tests/System.IO.Pipes.AccessControl.Tests.csproj b/src/libraries/System.IO.Pipes.AccessControl/tests/System.IO.Pipes.AccessControl.Tests.csproj index ccc371ed5d186..7bd84f26e66ba 100644 --- a/src/libraries/System.IO.Pipes.AccessControl/tests/System.IO.Pipes.AccessControl.Tests.csproj +++ b/src/libraries/System.IO.Pipes.AccessControl/tests/System.IO.Pipes.AccessControl.Tests.csproj @@ -6,8 +6,10 @@ + + diff --git a/src/libraries/System.IO.Pipes/src/MatchingRefApiCompatBaseline.txt b/src/libraries/System.IO.Pipes/src/MatchingRefApiCompatBaseline.txt index 59d47a01e274e..4bf654030707b 100644 --- a/src/libraries/System.IO.Pipes/src/MatchingRefApiCompatBaseline.txt +++ b/src/libraries/System.IO.Pipes/src/MatchingRefApiCompatBaseline.txt @@ -1,4 +1,5 @@ # Exposed public in System.IO.Pipes.AccessControl but implemented in System.IO.Pipes +TypesMustExist : Type 'System.IO.Pipes.AnonymousPipeServerStreamAcl' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'System.IO.Pipes.PipeAccessRights' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'System.IO.Pipes.PipeAccessRule' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'System.IO.Pipes.PipeAuditRule' does not exist in the reference but it does exist in the implementation. diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj index 0a6e5d139b39f..1bd0ed013fff7 100644 --- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -18,120 +18,47 @@ - - System\IO\StreamHelpers.CopyValidation.cs - - - System\Threading\Tasks\TaskToApm.cs - + + - - Common\Interop\Windows\Interop.Libraries.cs - - - Common\Interop\Windows\Interop.CloseHandle.cs - - - Common\Interop\Windows\Interop.Errors.cs - - - Common\Interop\Windows\Interop.FormatMessage.cs - - - Interop\Windows\Interop.FreeLibrary.cs - - - Interop\Windows\Interop.SecurityOptions.cs - - - Microsoft\Win32\SafeLibraryHandle.cs - - - Interop\Windows\Interop.BOOL.cs - - - Interop\Windows\Interop.SECURITY_ATTRIBUTES.cs - - - Common\Interop\Windows\Interop.GenericOperations.cs - - - Common\Interop\Windows\Interop.HandleOptions.cs - - - Common\Interop\Windows\Interop.PipeOptions.cs - - - Common\Interop\Windows\Interop.FileOperations.cs - - - Interop\Windows\Interop.FileTypes.cs - - - Common\Interop\Windows\Interop.GetCurrentProcess.cs - - - Common\Interop\Windows\Interop.DuplicateHandle_IntPtr.cs - - - Interop\Windows\Interop.GetFileType.cs - - - Common\Interop\Windows\Interop.CreatePipe_SafePipeHandle.cs - - - Common\Interop\Windows\Interop.ConnectNamedPipe.cs - - - Common\Interop\Windows\Interop.WaitNamedPipe.cs - - - Common\Interop\Windows\Interop.GetNamedPipeHandleState.cs - - - Common\Interop\Windows\Interop.GetNamedPipeInfo.cs - - - Common\Interop\Windows\Interop.SetNamedPipeHandleState.cs - - - Common\Interop\Windows\Interop.CancelIoEx.cs - - - Common\Interop\Windows\Interop.FlushFileBuffers.cs - - - Common\Interop\Windows\Interop.ReadFile_IntPtr.cs - - - Common\Interop\Windows\Interop.ReadFile_NativeOverlapped.cs - - - Common\Interop\Windows\Interop.WriteFile_IntPtr.cs - - - Common\Interop\Windows\Interop.WriteFile_NativeOverlapped.cs - - - Common\Interop\Windows\Interop.DisconnectNamedPipe.cs - - - Common\Interop\Windows\Interop.CreateNamedPipe.cs - - - Common\Interop\Windows\Interop.MaxLengths.cs - - - Common\Interop\Windows\Interop.RevertToSelf.cs - - - Common\Interop\Windows\Interop.ImpersonateNamedPipeClient.cs - - - System\IO\Win32Marshal.cs - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -147,12 +74,8 @@ - - Common\Interop\Windows\Interop.CreateNamedPipeClient.cs - - - Interop\Windows\Interop.LoadLibraryEx.cs - + + @@ -161,81 +84,31 @@ - - Common\Microsoft\Win32\SafeHandles\SafeFileHandleHelper.Unix.cs - - - Common\Interop\Unix\Interop.Libraries.cs - - - Interop\Unix\Interop.Errors.cs - - - Interop\Unix\Interop.IOErrors.cs - - - Common\Interop\Unix\Interop.Close.cs - - - Common\Interop\Unix\Interop.Fcntl.Pipe.cs - - - Common\Interop\Unix\Interop.Fcntl.cs - - - Common\Interop\Unix\Interop.FLock.cs - - - Common\Interop\Unix\Interop.GetHostName.cs - - - Common\Interop\Unix\Interop.GetPeerUserName.cs - - - Common\Interop\Unix\Interop.MkDir.cs - - - Common\Interop\Unix\Interop.Open.cs - - - Common\Interop\Unix\Interop.OpenFlags.cs - - - Common\Interop\Unix\Interop.Permissions.cs - - - Common\Interop\Unix\Interop.Pipe.cs - - - Common\Interop\Unix\Interop.Poll.cs - - - Common\Interop\Unix\Interop.Read.Pipe.cs - - - Common\Interop\Unix\Interop.Unlink.cs - - - Common\Interop\Unix\Interop.Write.Pipe.cs - - - Common\Interop\Unix\Interop.Stat.cs - - - Common\Interop\Unix\Interop.Stat.Pipe.cs - - - Common\Interop\Unix\Interop.GetPeerID.cs - - - Common\Interop\Unix\Interop.GetEUid.cs - - - Common\Interop\Unix\Interop.SetEUid.cs - - - Common\System\Threading\Tasks\ForceAsyncAwaiter.cs - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeClientStream.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeClientStream.cs index d4b99083022b5..77bd42e4aa6ff 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeClientStream.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeClientStream.cs @@ -2,10 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Security; +using Microsoft.Win32.SafeHandles; namespace System.IO.Pipes { diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Unix.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Unix.cs index f63b4041072da..d81c0c110a1d5 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Unix.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Unix.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; using System.Diagnostics; -using System.Security; +using Microsoft.Win32.SafeHandles; namespace System.IO.Pipes { diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs index 7c632ed7dc863..fc57fdf5972aa 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs @@ -2,11 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; -using System.Security; +using Microsoft.Win32.SafeHandles; namespace System.IO.Pipes { @@ -15,13 +13,27 @@ namespace System.IO.Pipes /// public sealed partial class AnonymousPipeServerStream : PipeStream { - // Creates the anonymous pipe. + internal AnonymousPipeServerStream(PipeDirection direction, HandleInheritability inheritability, int bufferSize, PipeSecurity pipeSecurity) + : base(direction, bufferSize) + { + if (direction == PipeDirection.InOut) + { + throw new NotSupportedException(SR.NotSupported_AnonymousPipeUnidirectional); + } + + if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable) + { + throw new ArgumentOutOfRangeException(nameof(inheritability), SR.ArgumentOutOfRange_HandleInheritabilityNoneOrInheritable); + } + + Create(direction, inheritability, bufferSize, pipeSecurity); + } + private void Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize) { Create(direction, inheritability, bufferSize, null); } - // Creates the anonymous pipe. This overload is used in Mono to implement public constructors. private void Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize, PipeSecurity pipeSecurity) { Debug.Assert(direction != PipeDirection.InOut, "Anonymous pipe direction shouldn't be InOut"); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.cs index 4eed15a21410c..ea0f58f4dacad 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; using System.Diagnostics.CodeAnalysis; -using System.Security; +using Microsoft.Win32.SafeHandles; namespace System.IO.Pipes { diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStreamAcl.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStreamAcl.cs new file mode 100644 index 0000000000000..f63da142d5bc1 --- /dev/null +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStreamAcl.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.IO.Pipes +{ + public static class AnonymousPipeServerStreamAcl + { + /// + /// Creates a new instance of the class with the specified pipe direction, inheritability mode, buffer size, and pipe security. + /// + /// One of the enumeration values that determines the direction of the pipe. Anonymous pipes can only be in one direction, so direction cannot be set to . + /// One of the enumeration values that determines whether the underlying handle can be inherited by child processes. + /// The size of the buffer. This value must be greater than or equal to 0. + /// An object that determines the access control and audit security for the pipe. + /// A new anonymous pipe server stream instance. + /// Setting to is equivalent to calling the `System.IO.Pipes.AnonymousPipeServerStream(System.IO.Pipes.PipeDirection direction, System.IO.HandleInheritability inheritability, int bufferSize)` constructor directly. + /// is . + /// is not set to a valid enum value. + public static AnonymousPipeServerStream Create(PipeDirection direction, HandleInheritability inheritability, int bufferSize, PipeSecurity pipeSecurity) + { + return new AnonymousPipeServerStream(direction, inheritability, bufferSize, pipeSecurity); + } + } +} diff --git a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/NativeObjectSecurity.cs b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/NativeObjectSecurity.cs index 803ac7533a327..7859d21718d50 100644 --- a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/NativeObjectSecurity.cs +++ b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/NativeObjectSecurity.cs @@ -139,9 +139,7 @@ private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType } else if (error == Interop.Errors.ERROR_INVALID_NAME) { - exception = new ArgumentException( - SR.Argument_InvalidName, -nameof(name)); + exception = new ArgumentException(SR.Argument_InvalidName, nameof(name)); } else if (error == Interop.Errors.ERROR_FILE_NOT_FOUND) {