如何检索 python-ldap 可用的每个对象类?

How to retrieve every objectClass available with python-ldap?

给定有效的 python-ldap 上下文,我如何查询 LDAP 服务器中所有可用的 objectClass?我想结果将是 ldap.schema.models.ObjectClass.

的列表

我终于做到了:

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
]