Ldap: retrieve parent group from subgroup

别等时光非礼了梦想. 提交于 2020-01-06 12:13:28

问题


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.


回答1:


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"])
{
    ...
}


来源:https://stackoverflow.com/questions/19820855/ldap-retrieve-parent-group-from-subgroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!