C# 更改命名管道访问权限
我已经使用C# 更改命名管道访问权限,c#,windows,security,named-pipes,C#,Windows,Security,Named Pipes,我已经使用System.IO.Pipes创建了一个命名管道。在我不得不以管理模式运行程序之前,它工作得很好。提升后,客户端无法再连接(客户端未运行提升)。如果我以管理员身份运行客户端,它连接良好,因此看起来像是权限问题。我一直在研究如何解决这个问题,但一直没有成功(我发现处理Windows安全问题令人难以置信)。我的目标是允许任何客户机(无论是否提升)能够连接到管道 我更改的第一件事是使用访问权限打开管道: pipeServer = new NamedPipeServerStream(pipeN
System.IO.Pipes
创建了一个命名管道。在我不得不以管理模式运行程序之前,它工作得很好。提升后,客户端无法再连接(客户端未运行提升)。如果我以管理员身份运行客户端,它连接良好,因此看起来像是权限问题。我一直在研究如何解决这个问题,但一直没有成功(我发现处理Windows安全问题令人难以置信)。我的目标是允许任何客户机(无论是否提升)能够连接到管道
我更改的第一件事是使用访问权限打开管道:
pipeServer = new NamedPipeServerStream(pipeName,
PipeDirection.InOut,
1,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous,
0x4000,
0x400,
null,
HandleInheritability.Inheritable,
PipeAccessRights.ChangePermissions | PipeAccessRights.AccessSystemSecurity);
然后我拼凑了这个代码。在调用SetEntriesInAcl
之前,一切正常,但调用失败:
错误:0x534“未完成帐户名和安全ID之间的映射。”
BuildExplicitAccessWithName
函数不返回值,但似乎成功了。这是通话后的样子:
我将非常感谢您的帮助
(所有Win32函数和数据类型都在pinvoke.net上找到。另外,我正在使用Windows 10。)我最终不必使用任何本机调用。全班都在学习。诀窍是我必须将其传递给构造函数:
// Creates a PipeSecurity that allows users read/write access
PipeSecurity CreateSystemIOPipeSecurity()
{
PipeSecurity pipeSecurity = new PipeSecurity();
var id = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
// Allow Everyone read and write access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule(id, PipeAccessRights.ReadWrite, AccessControlType.Allow));
return pipeSecurity;
}
创建管道时使用该功能:
PipeSecurity pipeSecurity = CreateSystemIOPipeSecurity();
pipeServer = new NamedPipeServerStream(pipeName,
PipeDirection.InOut,
1,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous,
0x4000,
0x400,
pipeSecurity,
HandleInheritability.Inheritable);
再见。@eryksun谢谢。这让我走上了正确的道路。我将键入一个答案供将来参考。请注意,.NET Core中的构造函数不接受PipeSecurity参数,因此我认为您必须使用PipeStream.SetAccessControl方法。
PipeSecurity pipeSecurity = CreateSystemIOPipeSecurity();
pipeServer = new NamedPipeServerStream(pipeName,
PipeDirection.InOut,
1,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous,
0x4000,
0x400,
pipeSecurity,
HandleInheritability.Inheritable);