Dr Drew
Dr Drew

Reputation: 31

OpenFileById fails with ERROR_ACCESS_DENIED

I'm working on a product where OpenFileById() fails with ERROR_ACCESS_DENIED on files and folders that are otherwise accessible (meaning a CreateFile() on the same file or folder specified by path with the same access level / share mode, etc. succeeds).

I'm using backup semantics so I could also get a handle to folders; SE_BACKUP_NAME and SE_RESTORE_NAME privileges are enabled. This code works everywhere else other than this one machine (Windows 8.1).

The process is running as a service under local system, I tried having them change that to a different account with admin privileges and that didn't work either. Files / folders in question haven't been open for deletion (which is one case when this function will fail with ERROR_ACCESS_DENIED as per documentation).

I don't have physical access to this machine so can't kernel debug or anything like that. Has anyone run into this before?

Here's what I'm trying to do in a nutshell:

hRoot = ::CreateFileA(szRootPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

if (hRoot != INVALID_HANDLE_VALUE)
{
    FILE_ID_DESCRIPTOR  fileId;

    fileId.dwSize = sizeof(fileId);
    fileId.Type = FileIdType;
    fileId.FileId.QuadPart = nId;

    hFile = ::OpenFileById(hRoot, &fileId, SYNCHRONIZE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, FILE_FLAG_BACKUP_SEMANTICS);
    if (hFile != INVALID_HANDLE_VALUE)
    {
        ...
        ::CloseHandle(hFile);
    }
    ::CloseHandle(hRoot);
}

Upvotes: 2

Views: 592

Answers (1)

Dr Drew
Dr Drew

Reputation: 31

Apparently this is caused by a third party software product's kernel components (can't really go into specifics)

Upvotes: 1

Related Questions