I am trying to get all the groups that a certain user is a member of.
I have the following structures in ldap:
o=myOrganization
ou=unit1
cn=admin
cn=guess
and
ou=users
cn=ann
cn=bob
cn=carla
myOrganization
is an instance of Organizationunit1
is an instance of OrganizationUnitadmin
and guess
are both GroupOfNames and have everyone as a memberann
, bob
, and carla
are instances of PersonCurrently, I am using the ldap module on python and this is what I have:
import ldap
l = ldap.initialize("ldap://my_host")
l.simple_bind_s("[my_dn]", "[my_pass]")
ldap_result = l.search("[BASE_DN]", ldap.SCOPE_SUBTREE, "(&(objectClass=Person)(cn=ann))", None)
res_type, data = l.result(ldap_result, 0)
print(data)
And I am able to get the user ann
; but, how do I go about getting the groups Ann
belongs to?
I tried, the following from this page:
search_filter='(|(&(objectClass=*)(member=cn=ann)))'
results = l.search_s([BASE_DN], ldap.SCOPE_SUBTREE, search_filter, ['cn',])
しかし、私は空のリストを手に入れました。クエリのさまざまな組み合わせも試しましたが、すべて空になります。
PS:LinuxマシンでOpenLDAPを使用しています
member=cn=ann
十分ではありません。アンの完全なDNを使用する必要があります。おそらく次のようなものです。
member=cn=ann,ou=users,dc=company,dc=com
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加