我使用以下代码从SD获取ACL:
...
PACL pDacl = NULL;
BOOL bDaclPresent = TRUE;
BOOL bDaclDefaulted = FALSE;
if(!GetSecurityDescriptorDacl((PSECURITY_DESCRIPTOR)spSecurityDescriptor.get(),
&bDaclPresent,
&pDacl,
&bDaclDefaulted))
{
ReportError(TEXT("Failed to call GetSecurityDescriptorDacl."));
...
}
然后我使用AddAccessAllowedAce附加一个新的ACE:
if(!AddAccessAllowedAce(pDacl,
ACL_REVISION,
MQSEC_QUEUE_GENERIC_ALL,
pAnnySid))
{
dwErrCode = GetLastError();
ReportError(dwErrCode);
ReportError(TEXT("Failed to call AddAccessAllowedAce."));
...
}
我收到错误1344“没有更多内存可用于安全信息更新。”
然后我尝试增加PACL缓冲区的大小并更改了PACL头信息。 但我仍然收到错误1336“访问控制列表(ACL)结构无效。”
有人可以给我一个可行的示例代码吗?
MSDN在此处提供了一个AddAccessAllowedAce示例: http://msdn.microsoft.com/en-us/library/ms707085%28v=vs.85%29.aspx 但它即将创建一个全新的ACL,而不是相同的情况。
我甚至认为从旧的ACL'GetAce'然后'AddAce'到新的ACL,最后我追加我自己的新ACE。 但看起来'AddAce'需要一个参数'nAceListLength';我不知道如何从ACE获得这个价值。
有什么想法吗?
答案 0 :(得分:1)
GetSecurityDescriptorDacl()只是为您提供指向已存在于SECURITY_DESCRIPTOR缓冲区中的DACL的指针。如果要向其添加内容,则需要分配更大的缓冲区,复制现有的DACL,然后添加新的ACE。你需要做类似下面的事情(我头顶的伪代码;可能有错误):
PACL pOldDacl = GetSecurityDescriptorDacl(pSecurityDescriptor);
DWORD cbOldSize = GetAclInformation(pOldDacl, ACL_SIZE_INFORMATION);
DWORD cbNewSize = cbOldSize + sizeof(ACE that you want to add);
PACL pNewDacl = alloc(cbNewSize);
InitializeAcl(pNewDacl, cbNewSize);
for each pAce in pOldDacl // GetAce(pOldDacl)
AddAce(pNewDacl, pAce);
AddAce(pNewDacl, the ACE that you want to add); // or use specialized functions like AddAccessAllowedAce, etc
SetSecurityDescriptorDacl(pSecurityDescriptor, pNewDacl);
Microsoft KB有一个article。