python ldap-将用户添加到ldap组

时间:2019-05-29 12:10:24

标签: python ldap python-ldap

最终目标是能够连接到我的ldap并传递用户信息,然后将其在组中进行更新

这是我目前的状态

import ldap
import ldap.modlist as modlist

ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)


l = ldap.initialize("ldaps://ldap")
l.set_option(ldap.OPT_REFERRALS, 0)
l.simple_bind_s("cn=admin,ou=users,dc=test,dc=ru","super-secret")

dn="cn=groupname,dc=users,dc=test,dc=ru"

attrs = {}
attrs['member'] = [ 'mail=user123,dc=users,dc=test,dc=ru' ]

# Convert our dict to nice syntax for the add-function using modlist-module
ldif = modlist.addModlist(attrs)

# Do the actual synchronous add-operation to the ldapserver
l.add_s(dn,ldif)

# Its nice to the server to disconnect and free resources when done
l.unbind_s()

执行此代码时,我收到以下错误消息

ldap.REFERRAL: {'info': 'Referral:\nldap://ldap/cn=groupname,dc=users,dc=test,dc=ru', 'desc': 'Referral'}

如果我删除此行

l.set_option(ldap.OPT_REFERRALS, 0)

我收到此错误

ldap.STRONG_AUTH_REQUIRED: {'info': 'modifications require authentication', 'desc': 'Strong(er) authentication required'}

0 个答案:

没有答案