windows - CreateNamedPipe() 中的 lpSecurityAttributes 需要多长时间?

标签 windows security named-pipes dacl

  1. 我多久可以销毁传递给 CreateNamedPipe()lpSecurityAttributes 指向的结构?
  2. 是否需要为每个管道实例单独设置一个?

CreateNamedPipe() 的 MSDN 文档说:

lpSecurityAttributes [in, optional]

A pointer to a SECURITY_ATTRIBUTES structure that specifies a security descriptor for the new named pipe...

强调我的。 "new"是指新的命名管道,还是命名管道的新实例?它接着说:

Remarks

To create an instance of a named pipe by using CreateNamedPipe, the user must have FILE_CREATE_PIPE_INSTANCE access to the named pipe object. If a new named pipe is being created, the access control list (ACL) from the security attributes parameter defines the discretionary access control for the named pipe.

(再次强调我的意思。)可以将其理解为 lpSecurityAttributes 仅在创建命名管道的第一个实例( 命名管道)时使用, 并在创建同一命名管道的更多实例 时被忽略。如果是这样,则只需要 lpSecurityAttributes 结构的一个实例。

或者您可能必须为每个实例传递一个有效的 lpSecurityAttributes,但它可以(应该?)是同一个吗?

或者您可能必须为每个管道实例分配一个新的 SECURITY_ATTRIBUTES 结构?

我的相关问题 - 一旦对 CreateNamedPipe() 的调用返回,SECURITY_ATTRIBUTES 结构是否会被销毁,或者它是否必须保持有效直到最后一个句柄(到管道,或只是那个管道)实例?)已关闭 - 甚至没有解决。

有人对这两个问题有明确的答案吗?

最佳答案

您需要将有效的 SECURITY_ATTRIBUTES 结构或 NULL 传递给对 CreateNamedPipe 的每次调用。您可以为其他调用重用相同的结构,也可以使用单独的结构,以更方便的为准。在来自不同线程的多个同时调用中使用相同的结构可能不安全 - 我怀疑它会没问题,但无论如何我会避免它。

"new"是指“新管道”而不是“新实例”。如果命名管道已经存在,则不使用 lpSecurityDescriptor 成员中的 ACL。因此,如果您知道您正在创建现有管道的新实例,并且不需要设置 bInheritHandle,您应该只为 lpSecurityAttributes 传递 NULL。如果确实需要设置 bInheritHandle,请确保 lpSecurityDescriptor 为 NULL 或指向有效的安全描述符。

如前所述,lpSecurityAttributes 中的内容可以在调用返回后立即丢弃(除非您计划在另一个调用中重用它!)是的,其中包括分配给安全描述符的内存。

关于windows - CreateNamedPipe() 中的 lpSecurityAttributes 需要多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7964896/

相关文章:

security - 仅在第一次请求时拥有 Jsessionid 的漏洞是什么

c# - 可以从其输出预测 Random.Next()

c++ - Cygwin-打开命名的fifo时导致阻塞,导致另一个线程在打开常规文件时阻塞

java - 作为 Windows 服务运行时,如何增加 Tomcat 7 的内存?

windows - Ec2在启动时将用户数据传递到Windows实例

c# - 如何在 .Net/WPF 应用程序中存储敏感信息?

c# - IPC——消息队列

c - 如何在内核模式下使用 ZwQuerySystemInformation() 获取线程 ID?

c# - 为 linux 架构发布 .NET Core C# 自包含应用程序

python - 什么条件导致打开的非阻塞命名管道 (fifo) 为 "unavailable"用于读取?