unc*_*ged 14 named-pipes .net-core .net-standard-2.0
我正在将库从 .NET Framework 4.6.1 移植到 .NET Standard 2.0。在 Framework 中,NamedPipeServerStream构造函数可以接受PipeSecurity参数,但这在 Core 中不是一个选项。Core中如何设置a的安全性NamedPipeServerStream?
moo*_*oon 16
Net 6.0引入了NamedPipeServerStreamAcl类。
您可以使用Create方法通过 PipeSecurity 创建流...
using System.IO.Pipes;
using System.Security.AccessControl;
using System.Security.Principal;
if (!System.OperatingSystem.IsWindows())
throw new PlatformNotSupportedException("Windows only");
SecurityIdentifier securityIdentifier = new SecurityIdentifier(
WellKnownSidType.AuthenticatedUserSid, null);
PipeSecurity pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(securityIdentifier,
PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
AccessControlType.Allow));
NamedPipeServerStream stream = NamedPipeServerStreamAcl.Create(
"SecurityTestPipe", PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, pipeSecurity);
Run Code Online (Sandbox Code Playgroud)
显然这是一个已知问题
System.IO.Pipes.AccessControl 包不起作用 #26869。上一篇文章中提到了一个解决方法,建议使用NamedPipeServerStream.NetFrameworkVersion nuget 包,该包将公开NamedPipeServerStreamConstructors.New(...)哪些应该镜像所有完整 .NET Framework 构造函数的行为。
遵循 nuget 的github中的代码示例
using System.IO.Pipes;
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
using var serverStream = NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4422 次 |
| 最近记录: |