此代码是否为此命名管道设置任何安全性?

发布于 2024-10-21 15:29:19 字数 842 浏览 7 评论 0原文

这是我从哪里借来的代码,也许是这里或 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三人与歌 2024-10-28 15:29:19

如果将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文