Checking the permissions of a shared folder on ano

2019-06-14 17:41发布

i'm writting some c++ code retrieving the permissions of shared folds in another computer, by "permissions" i mean something like which user or group is permitted or denied to this folder.

Here's the function to get the NTFS security descriptor of a shared folder(named strFileName) in a certain remote machine(named strServerName whose ip is strServerIP).The question is when i delete the "Everyone" account in the "Share" tab of the folder, the GetNamedSecurityInfo function would fail with error code 5 which means access denied. But if i keep "Everyone" the function works just fine. I can't guarantee the "Everyone" is reserved or not on some remote shared folder. So how to let this function working (or other method which can check permissions would be ok) without "Everyone"?

PSECURITY_DESCRIPTOR ADDirectorySearch::getNTFSSecDescriptor2(CString strFileName, CString strServerName, CString strServerIP)
{
    //CString strServerNameWithSlash = _T("\\\\") + strServerName;//"\\\\veotax3";
    CString strFilePathName = _T("\\\\") + strServerName + _T("\\") + strFileName;//"\\\\veotax3\\nrdc1001";
    CString strFilePathName2 = _T("\\\\") + strServerIP + _T("\\") + strFileName;//"\\\\192.168.1.7\\nrdc1001";
    _bstr_t bstrFilePathName = strFilePathName;

    BOOL bSuccess = FALSE;
    PSECURITY_DESCRIPTOR pSecDescriptorBuf = NULL;
    DWORD dwSizeNeeded = 0;

label2:;
       bSuccess = GetNamedSecurityInfoW(bstrFilePathName, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL, &pSecDescriptorBuf);
       //bSuccess = GetFileSecurityW(bstrFilePathName, DACL_SECURITY_INFORMATION, NULL, 0, &dwSizeNeeded);
       if (ERROR_SUCCESS != bSuccess)
       {
           if (strFilePathName != strFilePathName2)
           {
               strFilePathName = strFilePathName2;
               bstrFilePathName = strFilePathName2;
               goto label2;
           }
           else
           {
               MyMessageBox_Error(_T("getNTFSSecDescriptor2 Error."), _T("Error"));
               return NULL;
           }
       }
       else
       {
            return pSecDescriptorBuf;
       }
}

0条回答
登录 后发表回答