我想知道是否可以限制远程计算机访问服务器中的命名管道。 我正在按如下方式初始化服务器:
NamedPipeServerStream pipeServer = new NamedPipeServerStream("myPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
远程客户端执行:
using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(serverIP, "myPipe", PipeDirection.InOut))
{
pipeStream.Connect(2000);
}
当然它成功了。 有限制它的方法吗? 谢谢!
答案 0 :(得分:1)
PipeSecurity PipeSecurity = new PipeSecurity();
PipeAccessRule AccessRule = new PipeAccessRule(@"NT AUTHORITY\NETWORK", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Deny);
PipeSecurity.AddAccessRule(AccessRule);
PipeAccessRule AccessRule2 = new PipeAccessRule(string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName), PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
PipeSecurity.AddAccessRule(AccessRule2);
然后将其添加到ctor:
NamedPipeServerStream m_PipeServer = new NamedPipeServerStream("myPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, PipeSecurity);
请注意,在使用管道安全性时,它不足以拒绝网络访问,但您需要允许应该使用该管道的当前用户(或用户)进行访问。
string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName)