我需要向所有人授予我正在创建的命名管道的访问权限。我知道这样做的方法是创建一个 NULL/空 DACL 并将其传递给 CreateNamedPipe
。
如何创建 NULL DACL?有人告诉我,这与为 LPSECURITY_ATTRIBUTES
传递 NULL 指针不同。
最佳答案
像这样:
SECURITY_DESCRIPTOR SD;
InitializeSecurityDescriptor(&SD, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&SD, TRUE, NULL, FALSE);
为了简洁起见,我省略了错误检查。你不会那样做。
然后当您调用 CreateNamedPipe
时,您可以像这样设置安全属性记录:
SA.nLength = sizeof(SA);
SA.lpSecurityDescriptor = &SD;
SA.bInheritHandle = TRUE;
SetSecurityDescriptorDacl
的文档指出:
When the pDacl parameter does not point to a DACL and the bDaclPresent flag is TRUE, a NULL DACL is specified. All access is allowed. You should not use a NULL DACL with an object because any user can change the DACL and owner of the security descriptor. This will interfere with use of the object.
所以,上面是怎么做的,但是文档确实强调你不应该这样做。
关于c++ - 如何创建 NULL/空 DACL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14502450/