active directory - How do I add permissions to an OU using C#? -
i want give access permission on ou of active directory. have done part below, removes access of ou. code below:
directoryentry rootentry = new directoryentry("ldap://ou=test ou,dc=test,dc=com"); directorysearcher dsfindous = new directorysearcher(rootentry); dsfindous.filter = "(objectclass=organizationalunit)"; dsfindous.searchscope = searchscope.subtree; searchresult oresults = dsfindous.findone(); directoryentry myou = oresults.getdirectoryentry(); system.security.principal.identityreference newowner = new system.security.principal.ntaccount("yourdomain", "yourusername").translate(typeof(system.security.principal.securityidentifier)); activedirectoryaccessrule newrule = new activedirectoryaccessrule(newowner, activedirectoryrights.genericall, system.security.accesscontrol.accesscontroltype.deny); myou.objectsecurity.setaccessrule(newrule); myou.commitchanges();
now problem if remove permission ad ou how can give permission again(revert permissions again). tried system.security.accesscontrol.accesscontroltype.allow newrule. there no permission ou throws exception on :
searchresult oresults = dsfindous.findone(); directoryentry myou = oresults.getdirectoryentry();
how can give rights again perticualr ou again in c#.
update:
activedirectoryaccessrule(newowner, activedirectoryrights.genericall, system.security.accesscontrol.accesscontroltype.deny);
but problem have removed generic rights, , when try search ou again won't find again. can't apply suggested logic again. can try out:). give me way, how can access ou again.
simply replace line:
activedirectoryaccessrule newrule = new activedirectoryaccessrule(newowner, activedirectoryrights.genericall, system.security.accesscontrol.accesscontroltype.deny);
with this:
activedirectoryaccessrule newrule = new activedirectoryaccessrule(newowner, activedirectoryrights.genericall, system.security.accesscontrol.accesscontroltype.allow);
- change "deny" "allow".
p.s. : please format code lines in question appear code.
Comments
Post a Comment