未能使用 AddAccessAllowedAce 将 ACE 附加到现有 ACL 中。

问题描述 投票:0回答:1

我使用下面的代码从SD中获取一个ACL,然后我使用AddAccessAllowedAce来附加一个新的ACE。

...
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.comen-uslibraryms707085%28v=vs.85%29.aspx。 但它即将创建一个全新的ACL,不是同样的情况。

我甚至想从旧的ACL中 "GetAce",然后 "AddAce "到新的ACL中,最后我添加了我自己的新ACE.但看起来 "AddAce "需要一个参数 "nAceListLength";我不知道如何从ACE中获得这个值。

有什么好办法吗?

windows security acl
1个回答
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有一个 文章.

© www.soinside.com 2019 - 2024. All rights reserved.