NTAccount 的 GetAccessControl 错误

发布于 2024-09-05 18:02:43 字数 1564 浏览 2 评论 0原文

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

上面的代码块给我带来了问题。执行 WinPrincipal.IsInRole(rule.IdentityReference.Value) 时,会发生以下异常:

“主域和受信任域之间的信任关系失败。”。

我对使用身份、原则等非常陌生,所以我不知道问题是什么。我假设它与 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:

"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?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够爱げ你 2024-09-12 18:02:43

我可以尝试通过建议您使用 SecurityIdentifier 来解决您的问题,但即使解决了这个问题,这里还有许多其他问题仍然会成为阻碍。我不是在谈论诸如使用 FileInfo 而不是 File 之类的低效率问题,而是在谈论您尝试用来解释 DACL 的基本逻辑。

请查看:http://msdn.microsoft。 com/en-us/library/cc230290(PROT.10).aspx

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. 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文