I'm trying to write an LDAP query which will discover if a user is a member of a group which matches a wildcard query and I'm trying to use the LDAP_MATCHING_RULE_IN_CHAIN OID to do this. I'm basically following example 2 on this page:
http://support.microsoft.com/kb/914828
I've found that this method works well within a domain i.e. if user1 is in group1 and group1 is in group2 then I can write a query matching "*2" and the LDAP query will find the nested relationship and match the user against the group.
However, now I've been asked to support relationships between domains in the same forest. So now I've got:
- user1 is a member of group1 in domain 1
- group1 in domain 1 is a member of group2 in domain 2
And I want to be able to match user1 against group2.... I can't work out how to make LDAP_MATCHING_RULE_IN_CHAIN do this:
I've tried setting the base of the query to the following:
- Domain 1, but this just returns groups in domain 1
- The parent domain of domain 1 and domain 2, but this returns no results.
- The GC, found by querying "rootDSE" property but this just returns groups inside the domain 1 (which is the GC server)
Anyone know how I can make this work?
As far as I understand, one way of doing that is :
crossRef
with an attributenETBIOSName
existing.dnsRoot
andnCName
attributs. A working forest DNS allows you to join a domain controler ofdnsRoot
.nCName
allows to search from the root.Be careful to do this as a member of the enterpreise administrators group.
Here is an example of the code.
This is just a proof of concept, you have to complete with :
using
using(){}
form for disposing DirectoryEntry objectsException management
Edited (2011-10-18 13:25)
Your comment about the way you solve the problem can be found in a method given in System.DirectoryServices.AccountManagement Namespace. It's a kind of recursive solution. This time, I test with a user belonging to group1 (in an other domain) which belongs to group2 (in a third domain) and it seems to work.