Checking the permissions of a shared folder on another Windows failed with access denied?

一个人想着一个人 提交于 2019-12-08 13:01:48

问题


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;
       }
}

来源:https://stackoverflow.com/questions/11050243/checking-the-permissions-of-a-shared-folder-on-another-windows-failed-with-acces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!