Given a valid python-ldap
context, how can I query all the objectClass available in the LDAP server? I suppose the result would be a list of ldap.schema.models.ObjectClass
.
Asked
Active
Viewed 766 times
0

azmeuk
- 4,026
- 3
- 37
- 64
-
1I think https://stackoverflow.com/questions/5026546/get-all-possible-attributes-and-all-objectclasses-from-openldap-in-php answers this question, although the code example is PHP rather than Python. – larsks Aug 07 '20 at 12:20
1 Answers
1
I finally managed to do it with:
import ldap
l = ldap.initialize(ldap_uri)
l.simple_bind_s(ldap_bind_dn, ldap_bind_pw)
res = l.search_s("cn=subschema", ldap.SCOPE_BASE, "(objectclass=*)", ["*", "+"])
subschema_entry = res[0]
subschema_subentry = ldap.cidict.cidict(subschema_entry[1])
subschema = ldap.schema.SubSchema(subschema_subentry)
object_class_oids = subschema.listall(ldap.schema.models.ObjectClass)
object_classes = [
subschema.get_obj(ldap.schema.models.ObjectClass, oid) for oid in object_class_oids
]

azmeuk
- 4,026
- 3
- 37
- 64