简体   繁体   English

NTAccount的GetAccessControl错误

[英]GetAccessControl error with NTAccount

    private bool HasRights(FileSystemRights fileSystemRights_, string fileName_, bool isFile_)
    {
        bool hasRights = false;

        WindowsIdentity WinIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
        WindowsPrincipal WinPrincipal = new WindowsPrincipal(WinIdentity);

        AuthorizationRuleCollection arc = null;

        if (isFile_)
        {
            FileInfo fi = new FileInfo(@fileName_);
            arc = fi.GetAccessControl().GetAccessRules(true, true, typeof(NTAccount));
        }
        else
        {
            DirectoryInfo di = new DirectoryInfo(@fileName_);
            arc = di.GetAccessControl().GetAccessRules(true, true, typeof(NTAccount));
        }

        foreach (FileSystemAccessRule rule in arc)
        {
            if (WinPrincipal.IsInRole(rule.IdentityReference.Value))
            {
                if (((int)rule.FileSystemRights & (int)fileSystemRights_) > 0)
                {
                    if (rule.AccessControlType == AccessControlType.Allow)
                        hasRights = true;
                    else if (rule.AccessControlType == AccessControlType.Deny)
                    {
                        hasRights = false;
                        break;
                    }
                }
            }
        }

        return hasRights;
    }

The above code block is causing me problems. 上面的代码块导致我出现问题。 When the WinPrincipal.IsInRole(rule.IdentityReference.Value) is executed the following exception occurs: 当执行WinPrincipal.IsInRole(rule.IdentityReference.Value)时,会发生以下异常:

"The trust relationship between the primary domain and the trusted domain failed.". “主域和可信域之间的信任关系失败。”

I'm very new to using identities, principles and such so I don't know what's the problem. 我对使用身份,原则等还很陌生,所以我不知道出了什么问题。 I'm assuming it's with the use of NTAccount? 我假设它与NTAccount一起使用?

Thanks 谢谢

I could try to address your question by suggesting you use a SecurityIdentifier, but there are many other issues here that would still be show-stoppers even if this were addressed. 我可以尝试通过建议您使用SecurityIdentifier来解决您的问题,但是即使解决了此问题,这里还有许多其他问题仍然是制止因素。 I'm not talking about inefficiencies such as using FileInfo instead of File, but the basic logic you're trying to use to interpret the DACL. 我不是在谈论效率低下的问题,例如使用FileInfo而不是File,而是要尝试用来解释DACL的基本逻辑。

Take a look at: http://msdn.microsoft.com/en-us/library/cc230290(PROT.10).aspx 看看: http : //msdn.microsoft.com/zh-cn/library/cc230290(PROT.10).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模拟后无法GetAccessControl,获取错误 - Can't GetAccessControl After Doing Impersonation, Get Error NTAccount.Translate方法失败并显示错误无法转换部分或全部标识引用 - NTAccount.Translate Method fails with error Some or all identity references could not be translated 使用本地系统帐户运行时,GetAccessControl 方法失败,出现意外错误代码 3 - GetAccessControl Method failed with unexpected error code 3, when run with Local System account 检查两个NTAccount对象的相等性 - Checking the equality of two NTAccount objects 有没有一种方法可以加快GetAccessControl和GetOwner - Is there a way to speed up GetAccessControl and GetOwner GetAccessControl(xxxxxx)返回错误结果 - GetAccessControl(xxxxxx) return false results C# 当我链接到 dll - C# get error Method not found :System.Security.AccessControl.FileSecurity System.IO.File.GetAccessControl(System.String) when I link to dll 按字母顺序订购Directory.GetAccessControl.GetAccessRules - Order Directory.GetAccessControl.GetAccessRules alphabetically GetAccessControl抛出UnauthorizedAccessException访问SystemData目录 - GetAccessControl throws UnauthorizedAccessException accessing SystemData directory DirectoryInfo.GetAccessControl方法始终失败 - DirectoryInfo.GetAccessControl method always fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM