Reputation: 86
I want to ask you if there is a solution to get parent group from subgroups in LDAP? I did a little search and we can use the filter like &(objectClass=group)(memberof:1.2.840.113556.1.4.1941:=PATH_TO_GROUP1) to get the child groups of the group, but I want to know if there is a way to get parent group from child group.
Thank you in advance.
Upvotes: 0
Views: 3906
Reputation: 3960
All you should need is query AD for the group, and get the memberof
property, to get all groups that subgroup is part of. The below should be what you need.
// assuming your domain is "my.ad.domain.com"
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=my,DC=ad,DC=domain,DC=com");
// the subgroup you want to find the parents for is "ChildGroup"
DirectorySearcher searcher = new DirectorySearcher(entry, "(&(objectcategory=group)(cn=ChildGroup))", new string[] { "memberof" });
SearchResult result = searcher.FindOne();
// then you can access its groups the usual way
foreach (var group in result.Properties["memberof"])
{
...
}
Upvotes: 2