简体   繁体   中英

How to install a LDAP schema with python-ldap?

I have a LDAP schema in a .ldif file that I would like to use python-ldap to install the schema on my LDAP server. My context is the installation process of a python application that needs some custom LDAP schemas.

There is a bit of documentation about ldif and schemas in python-ldap, but I do not know where to start.

How can I install a schema with python-ldap?

import ldap.modlist
import ldif


with open("myschema.ldif") as fd:
    parser = ldif.LDIFRecordList(fd)
    parser.parse()

for dn, entry in parser.all_records:
    add_modlist = ldap.modlist.addModlist(entry)
    conn.add_s(dn, add_modlist)  # where 'conn' is a LDAP connection

The short answer is what @azmeuk has written before.

The long answer is: it depends on the format of your LDIF file. If it contains modify statements then you cannot easily parse the file with python-ldap.

Please check my question at Process LDIF modify records with python-ldap to see what I'm talking about.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM