我正在try 创建一个C#控制台应用程序来管理域(而不是文件系统)上的审核权限.我的问题是我无法读取C#中现有的审计规则,我只得到一个空集合,即使我确信域中有审计规则.
我需要管理100多个独立域,所以我想拿出一个程序化的解决方案来帮助管理它们.
我可以在PowerShell中使用以下命令完成此操作,而不会出现问题.
$acl = Get-Acl -Path "DC=mydomain,DC=local" -Audit
$acl.Audit
这将返回5个审计规则的集合.但是,当try 在C#中执行相同的操作时,审计规则不会返回.
string path = "LDAP://mydomain.local/DC=mydomain,DC=local";
DirectoryEntry domain = new DirectoryEntry(path);
AuthorizationRuleCollection authorizationRuleList1 = domain.ObjectSecurity.GetAuditRules(true, true, typeof(NTAccount));
AuthorizationRuleCollection authorizationRuleList2 = domain.ObjectSecurity.GetAuditRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));
Console.WriteLine("Authorization Rules 1: " + authorizationRuleList1.Count);
Console.WriteLine("Authorization Rules 2: " + authorizationRuleList2.Count);
运行上面的操作显示0个审计规则.奇怪的是,访问规则没有问题地返回.
我已经try
- 解释为
DirectoryEntry
初始化应用密码 - 运行"以管理员身份运行"
- 使用LDAP资源管理器判断存在的审核权限
如有任何建议,我们将不胜感激.
更新了使用ActiveDs获取安全描述符的代码.
string path = "LDAP://demo.local/DC=demo,DC=local";
DirectoryEntry domain = new DirectoryEntry(path);
var ntSecurityDescriptor = domain.Properties["ntSecurityDescriptor"];
ActiveDs.ADsSecurityUtility secUtility = new ActiveDs.ADsSecurityUtility();
ActiveDs.IADsSecurityDescriptor sd = (IADsSecurityDescriptor)ntSecurityDescriptor[0];
ActiveDs.IADsAccessControlList aclList = ActiveDs.IADsAccessControlList)sd.DiscretionaryAcl;