views:

2804

answers:

2

I have an application that pulls user information from an OU in Active Directory. The parameters it takes are a base for the search and a filter string.

I have an OU I want to pull information from, but there is a sub OU I want to avoid:

Wanted: users from OU=People,DC=mydomain,DC=com Not Wanted: users from OU=Evil,OU=People,DC=mydomain,DC=com

I know that this could be done by rewriting the application performing teh import to stop it searching sub-OUs, but is there any way to do this with an LDAP filter on the search? Something like (DistinguishedName !contains "Evil") or similar that will let me exclude users based on the path to the user, rather than filtering on a property of the user.

A: 

What user are you binding as? Why not modify the rights of that user to block its ability to read users in the OU=evil container?

geoffc
That will become a problem for ongoing management, tracking which user accounts can read which OUs; if possible I'd like to do this without having to recode the import tool (that will have a big delay because the requried people are not currently available) or implementing a special workaround (such as a post-import stored procedure that deletes the entries from the DB) and stick to the current config, where the LDAP search filter needs to do the restrictions.
DrStalker
+2  A: 

Well, I'm not entirely sure what you're after but if you use the filter (!(distinguishedName=*,OU=Evil,OU=People,DC=mydomain,DC=com)) along with a Subtree search scope then you won't get any users from the "Evil"-sub-OU returned. However, the entire Evil-sub-OU will still be searched (generally not a problem because of fast LDAP search response times though).

If you're using System.DirectoryServices(.Protocols) in .NET you could also set the SearchScope to OneLevel to only search in the People-OU (and no child-OUs). But that won't work if you have any "OU=Good,OU=People,DC=mydomain,DC=com"...

The third option would be to query the People-OU for all sub-OU:s (objectClass=organizationalUnit) and then issue multiple search requests; one for each of them (except the "Evil" one).

Edit: @geoffc - that will be really difficult to implement. By default all authenticated users have read access to all objects in Active Directory. Just setting a "Deny Read" on the Evil OU won't do the trick because the read right for authenticated users is set on the individual user object (in this case) and thus has precedence over the Deny ACL set on the OU. You will essentially have to set the Deny Read ACL on each of the objects in the Evil-OU and always make sure new objects added to the directory get the same Deny rights set. You could edit the Active Directory schema and remove the rights for Authenticated Users but that will break a lot of other things (including Exchange) and is not supported by Microsoft.

Per Noalt
A for effort, but wildcard searches don't work with data of type `DN`, in particular `distinguishedName`.
Anton Tykhyy