简体   繁体   English

如何使用 python-ldap 安装 LDAP 架构?

[英]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.我在.ldif文件中有一个 LDAP 架构,我想使用 python-ldap 在我的 LDAP 服务器上安装该架构。 My context is the installation process of a python application that needs some custom LDAP schemas.我的上下文是需要一些自定义 LDAP 模式的 python 应用程序的安装过程。

There is a bit of documentation about ldif and schemas in python-ldap, but I do not know where to start. python-ldap中有一些关于ldif模式的文档,但我不知道从哪里开始。

How can I install a schema with python-ldap?如何使用 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.简短的回答是@azmeuk 之前写过的。

The long answer is: it depends on the format of your LDIF file.长答案是:这取决于 LDIF 文件的格式。 If it contains modify statements then you cannot easily parse the file with python-ldap.如果它包含修改语句,则您无法使用 python-ldap 轻松解析该文件。

Please check my question at Process LDIF modify records with python-ldap to see what I'm talking about.请检查我在Process LDIF modify records with python-ldap 中的问题,看看我在说什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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