Winapi 未正确检索某些文件的NTFS ACL继承

Winapi 未正确检索某些文件的NTFS ACL继承,winapi,permissions,acl,file-permissions,ntfs,Winapi,Permissions,Acl,File Permissions,Ntfs,我注意到我的应用程序没有正确检索NTFS ACL 继承某些文件。这些文件位于my的子文件夹中 简介。使用ICACLS.EXE时,它会正确输出这些文件的(I)。但是 使用GetFileSecurity()检索ACCESS\u ALLOWED\u ACE->Header.acefags时,这些文件的值始终为零。然而,这对许多其他国家都是有效的 我的系统上的文件。此外,文件夹不受影响,但我的配置文件中的所有文件都受影响 目录及其子文件夹 这里是示例C++代码,允许复制问题: #include <

我注意到我的应用程序没有正确检索NTFS ACL 继承某些文件。这些文件位于my的子文件夹中 简介。使用ICACLS.EXE时,它会正确输出这些文件的(I)。但是 使用
GetFileSecurity()
检索
ACCESS\u ALLOWED\u ACE->Header.acefags
时,这些文件的值始终为零。然而,这对许多其他国家都是有效的 我的系统上的文件。此外,文件夹不受影响,但我的配置文件中的所有文件都受影响 目录及其子文件夹

这里是示例C++代码,允许复制问题:

#include <windows.h>
#include <iostream>
#include <comdef.h>

using namespace std;

int main(int argc, TCHAR** argv)
{
    // Check Input Arguments
    if (2 != argc)
    {
        // Output usage information in case of wrong arguments
        cout << "Usage: ACLInfo.exe <path to file or directory>" << endl;
        return 0;
    }

    // Get the path from supplied arguments
    _bstr_t strPath = argv[1];

    // Find out size of needed buffer for security descriptor with DACL
    // DACL = Discretionary Access Control List
    DWORD dwSizeNeeded = 0;
    BOOL bSuccess = GetFileSecurityW(strPath,
                                DACL_SECURITY_INFORMATION,
                                NULL,
                                0,
                                &dwSizeNeeded);

    if (0 == dwSizeNeeded)
    {
        return E_FAIL;
    }
    BYTE* pSecDescriptorBuf = new BYTE[dwSizeNeeded];

    // Retrieve security descriptor with DACL information
    bSuccess = GetFileSecurityW((BSTR)strPath,
                                DACL_SECURITY_INFORMATION,
                                pSecDescriptorBuf,
                                dwSizeNeeded,
                                &dwSizeNeeded);

    // Check if we successfully retrieved security descriptor with DACL 
information
    if (!bSuccess)
    {
        DWORD dwError = GetLastError();
        cout << "Failed to get file security information (" << dwError << ")\n";
        return E_FAIL;
    }

    // Getting DACL from Security Descriptor
    PACL pacl;
    BOOL bDaclPresent, bDaclDefaulted;
    bSuccess = 
GetSecurityDescriptorDacl((SECURITY_DESCRIPTOR*)pSecDescriptorBuf,
                                         &bDaclPresent, &pacl, &bDaclDefaulted);

    // Check if we successfully retrieved DACL
    if (!bSuccess)
    {
        DWORD dwError = GetLastError();
        cout << "Failed to retrieve DACL from security descriptor (" << dwError 
<< ")\n";
        return E_FAIL;
    }

    // Check if DACL present in security descriptor
    if (!bDaclPresent)
    {
        cout << "DACL was not found.\n";
        return E_FAIL;
    }

    // DACL for specified file was retrieved successfully
    // Now, we should fill in the linked list of ACEs
    // Iterate through ACEs (Access Control Entries) of DACL
    for (USHORT i = 0; i < pacl->AceCount; i++)
    {
        LPVOID pAce;
        bSuccess = GetAce(pacl, i, &pAce);
        if (!bSuccess)
        {
            DWORD dwError = GetLastError();
            cout << "Failed to get ace " << i << " (" << dwError << ")\n";
            continue;
        }
        BYTE AceFlags = ((ACCESS_ALLOWED_ACE*)pAce)->Header.AceFlags;
        BOOL Inherited = (AceFlags && (INHERITED_ACE || OBJECT_INHERIT_ACE || CONTAINER_INHERIT_ACE)) != 0;
        if (!Inherited)  
          cout << "not ";
        cout << "Inherited";

    }

    return 0;
}
#包括
#包括
#包括
使用名称空间std;
内部主(内部argc、TCHAR**argv)
{
//检查输入参数
如果(2!=argc)
{
//在参数错误的情况下输出使用信息

与此同时,微软是否向我证实了这是这些API调用中的一个bug,并建议使用类似于
GetNamedSecurityInfo()