Reputation: 4506
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?
Upvotes: 1
Views: 312
Reputation: 2942
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.
Upvotes: 0
Reputation: 4506
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
Upvotes: 1