[英]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.