此代码是否为此命名管道设置任何安全性?
这是我从哪里借来的代码,也许是这里或 codeguru 或 codeproject。
无论如何,我想知道是否可以将 NULL 作为 CreateNamedPipe 中的最后一个参数传递,或者 sa
结构是否执行除 NULL 之外的某种类型的安全性?
// Setup the named pipe with a security attribute so it is open to anyone that enquires.
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE);
sa.nLength = (DWORD) sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = (LPVOID) &sd;
sa.bInheritHandle = TRUE;
do
{
hPipe = CreateNamedPipe(lpszPipename,PIPE_ACCESS_DUPLEX,PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,BUFSIZE,BUFSIZE,5000,&sa);
if (hPipe != INVALID_HANDLE_VALUE)
{
if (ConnectNamedPipe(hPipe, NULL)) {
Here is my code I borrowed from I don't know where, maybe here or codeguru or codeproject.
Anyway, I am wondering if I can just pass NULL as the last parameter in CreateNamedPipe
or is the sa
structure doing some type of security beyond NULL?
// Setup the named pipe with a security attribute so it is open to anyone that enquires.
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE);
sa.nLength = (DWORD) sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = (LPVOID) &sd;
sa.bInheritHandle = TRUE;
do
{
hPipe = CreateNamedPipe(lpszPipename,PIPE_ACCESS_DUPLEX,PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,BUFSIZE,BUFSIZE,5000,&sa);
if (hPipe != INVALID_HANDLE_VALUE)
{
if (ConnectNamedPipe(hPipe, NULL)) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将 NULL 作为 CreateNamedPipe() 的最后一个参数传递,那么您将获得命名管道的默认安全描述符。
http://msdn.microsoft .com/en-us/library/windows/desktop/aa365600%28v=vs.85%29.aspx
您的示例代码设置 NULL 自主访问控制列表 (DACL)。这是危险的,因为它允许每个人完全控制。这意味着任何其他应用程序都可以获取您的命名管道的所有权和/或更改其访问权限。
If you pass NULL as the last parameter of CreateNamedPipe() then you get the default security descriptor for a named pipe.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365600%28v=vs.85%29.aspx
Your sample code sets a NULL Discretionary Access Control List (DACL). This is dangerous because it allows full control to everyone. This means any other application could take ownership of your named pipe and/or change the access permissions on it.