使用python创建ladp目录的条目

2024-09-30 18:19:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python创建LDAP条目,它给了我一个错误{'info':'no global superior knowledge','desc':'Server is laving to perform'} 下面是我的代码

import ldap
import ldap.modlist as modlist
fname="dayanand"
lname="dayanand"
username="dayanand"
employee_num='102'
domain="gmail.com"
base_dn="xyz"
l = ldap.initialize("ldap://localhost")
l.simple_bind_s("cn=admin,dc=somnath,dc=zankar,dc=org","zankar")
user_dn = "cn=admin,dc=somnath,dc=org"
user_attrs = {}
#user_attrs['objectClass'] = \
#          ['top', 'person', 'organizationalPerson', 'user']
user_attrs['cn'] = fname + ' ' + lname
#user_attrs['userPrincipalName'] = username + '@' + domain
#user_attrs['sAMAccountName'] = username
user_attrs['givenName'] = fname
user_attrs['sn'] = lname
user_attrs['displayName'] = fname + ' ' + lname
#user_attrs['userAccountControl'] = '514'
user_attrs['mail'] = username + '@host.com'
#user_attrs['employeeID'] = employee_num
user_attrs['homeDirectory'] = '\\\\server\\' + username
#user_attrs['homeDrive'] = 'H:'
#user_attrs['scriptPath'] = 'logon.vbs'
user_ldif = modlist.addModlist(user_attrs)

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

# Do the actual synchronous add-operation to the ldapserver
try:
   l.add_s(user_dn,ldif)
except ldap.LDAPError, error_message:
    print "Error adding new user: %s" % error_message

Tags: thetoaddusernamedccnldapfname
1条回答
网友
1楼 · 发布于 2024-09-30 18:19:36

LDAP实例中的目录树是什么样子的?我这样问是因为你试图绑定到dc=somnath,dc=zankar,dc=org:

l.simple_bind_s("cn=admin,dc=somnath,dc=zankar,dc=org","zankar")

但是你想给dc=somnath,dc=org添加一些东西:

user_dn = "cn=admin,dc=somnath,dc=org"

当您试图向目录中不存在的部分添加条目时,可以看到错误“no global superior knowledge”。你知道吗

您可以创建dc=somnath,dc=org的新基DN,或者尝试向dc=somnath,dc=zanker,dc=org添加条目。注意尝试添加一个不是cn=admin的条目,因为它可能已经存在,因为您正在使用它将()绑定到服务。你知道吗

相关问题 更多 >