How to retrieve every objectClass available with python-ldap?

998 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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
]