加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – CreateNamedPipe()中lpSecurityAttributes需要什么生

发布时间:2020-12-14 04:31:04 所属栏目:Windows 来源:网络整理
导读:我多久可以销毁传递给CreateNamedPipe()的lpSecurityAttributes所指向的结构? 我是否需要为每个管道实例单独一个? CreateNamedPipe()的MSDN文档说: lpSecurityAttributes [in,optional] A pointer to a SECURITY_ATTRIBUTES structure that specifies a s
>我多久可以销毁传递给CreateNamedPipe()的lpSecurityAttributes所指向的结构?
>我是否需要为每个管道实例单独一个?

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结构,或者它是否必须保持有效直到最后一个句柄(到管道,或只是那个管道实例?)关闭 – 是不是解决.

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

解决方法

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读