Мне нужно управлять более чем 100 независимыми доменами, поэтому я хочу найти программное решение, которое поможет управлять ими.
Я могу сделать это без проблем в PowerShell, используя следующую команду.
$acl = Get-Acl -Path "DC=mydomain,DC=local" -Audit
$acl.Audit
Это возвращает набор из 5 правил аудита. Однако при попытке выполнить ту же операцию на 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 правил аудита. Как ни странно, правила доступа возвращаются без проблем.
Я пробовал
- Явно применить пароль для инициализации 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;
Подробнее здесь: https://stackoverflow.com/questions/781 ... hough-audi
Мобильная версия