2

我需要为客户端和服务器(在同一主机中)之间的通信创建一个命名管道,这是代码:

WCHAR wszPipeName[MAX_FILE_LENGTH];
swprintf_s(wszPipeName, MAX_FILE_LENGTH, L"\\\\.\\pipe\\TEST%d", uniqueID);
pipe = CreateNamedPipe(
           wszPipeName, // name of the pipe
           PIPE_ACCESS_DUPLEX,
       PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
       1,
           MAX_MSG_SIZE, 
           MAX_MSG_SIZE , //inbound buffer
           MAX_READ_DATA_TIMEOUT,
           NULL // use default security attributes
       );

处理程序返回的始终是 INVALID_HANDLE_VAULE,错误是 ERROR_ACCESS_DENIED。

这里有什么问题吗?它在 Windows 7/8 上运行。

谢谢

4

2 回答 2

0

这是 Python 代码,但这会为本地用户设置一个安全描述符并拒绝远程:

dacl = ACL()

# Deny NT AUTHORITY\NETWORK SID
sid = CreateWellKnownSid(WinNetworkSid)
dacl.AddAccessDeniedAce(ACL_REVISION, GENERIC_ALL, sid)

# Allow current user SID
token = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY)
sid = GetTokenInformation(token, TokenUser)[0]
dacl.AddAccessAllowedAce(ACL_REVISION, GENERIC_READ | GENERIC_WRITE, sid)

security_descriptor = SECURITY_DESCRIPTOR()
security_descriptor.SetSecurityDescriptorDacl(True, dacl, False)

security_attributes = SECURITY_ATTRIBUTES()
security_attributes.SECURITY_DESCRIPTOR = security_descriptor

pipe = CreateNamedPipe(
    <your other params here>
    security_attributes
)
于 2019-08-01T20:15:03.217 回答
-1

找到原因了,是因为安全限制。提供合适的安全描述符后,它就可以工作了!

于 2013-01-25T20:57:42.010 回答