XP 上的远程命名管道连接被拒绝
我有一个想要实现的简单设计。
单个基于 C++ 的服务器应用程序创建一个只写命名管道。多个客户端(C++ 或 C#)以只读方式连接并侦听状态消息。
我可以将其用于本地进程,但无法将不同主机上的客户端连接到服务器。
服务器运行在 XP SP2(也许是 SP3)上。客户端运行在Win7上。
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
SID_IDENTIFIER_AUTHORITY siaWorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;
PSID psidWorldSid = (PSID) LocalAlloc (LPTR, GetSidLengthRequired(1));
InitializeSid(psidWorldSid, &siaWorldSidAuthority, 1);
*(GetSidSubAuthority(psidWorldSid, 0)) = SECURITY_WORLD_RID;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorGroup(&sd, psidWorldSid, TRUE);
ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // name
PIPE_ACCESS_OUTBOUND, // write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL /*&sa*/); // no security attribute
在最终参数中将 NULL 替换为 &sa 无效。 C# 客户端代码如下所示。
SafeFileHandle pipeHandle =
CreateFile(
pipeName,
GENERIC_READ,
0,
IntPtr.Zero,
OPEN_EXISTING,
0,
IntPtr.Zero);
我在这里错过了什么愚蠢而明显的事情?
I've got a simple design I'm trying to implement.
A single C++ based server app creates a write-only named pipe. Multiple clients (C++ or C#) connect as read-only and listen for status messages.
I have this working for local processes, but I am unable to connect a client on a different host to the server.
The server is running on XP SP2 (maybe SP3). The client is running on Win7.
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
SID_IDENTIFIER_AUTHORITY siaWorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;
PSID psidWorldSid = (PSID) LocalAlloc (LPTR, GetSidLengthRequired(1));
InitializeSid(psidWorldSid, &siaWorldSidAuthority, 1);
*(GetSidSubAuthority(psidWorldSid, 0)) = SECURITY_WORLD_RID;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorGroup(&sd, psidWorldSid, TRUE);
ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // name
PIPE_ACCESS_OUTBOUND, // write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL /*&sa*/); // no security attribute
replacing the NULL with &sa in the final param has no effect. The C# client code looks like this.
SafeFileHandle pipeHandle =
CreateFile(
pipeName,
GENERIC_READ,
0,
IntPtr.Zero,
OPEN_EXISTING,
0,
IntPtr.Zero);
What stupidly obvious thing am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你检查过你的防火墙吗? 445端口被封了吗?
Have you checked your firewall? Is port 445 blocked?