我想用python(-ldap(脚本更改AD中的手机号码。
这是我尝试使用的代码:
# import needed modules
import ldap
import ldap.modlist as modlist
# Open a connection
l = ldap.initialize("ldap://host/",trace_level=3)
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("user@domain","pw")
# The dn of our existing entry/object
dn="CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e"
# Some place-holders for old and new values
name = 'mobile'
nr1 = '+4712781271232'
nr2 = '+9812391282822'
old = {name:nr1}
new = {name:nr2}
# Convert place-holders for modify-operation using modlist-module
ldif = modlist.modifyModlist(old,new)
# Do the actual modification
l.modify_s(dn, ldif)
# Its nice to the server to disconnect and free resources when done
l.unbind_s()
不幸的是,我得到了以下错误:
ldap.UNWILLING_TO_PERFORM:{'info':u'00000057:LdapErr:DSID-0C090FC7,注释:属性转换操作出错,数据0,v4563','desc':u'服务器不愿意执行'}
我可以通过将旧条目留空来删除该条目,但当我尝试设置它时,我会得到以下结果:
LDAError-TYPE_OR_VALUE_EXISTS:{'info':u'00002083:AtrErr:DSID-031519F7,#5:\n\t0:000002083:DSID-0315319F7,问题1006(ATT_OR_VALUE_EXISTS(,数据0,ATT 150029(移动电话(:len 2\n\t1:00002083:DSID-031519F7,问题1006(ATT_OR_VALUE_EXISTS(,数据0,收件人150029(手机(:len 2\n\t2:000002083:DSID-031519F7,问题1006(ATT_OR_VALUE_EXISTS(,数据0,ATT 150029(移动电话(:len 2\n\t3:00002083:DSID-031519F7,问题1006(ATT_OR_VALUE_EXISTS(,数据0,收件人150029(手机(:len 2\n\t4:0002083:DSID-031519F7,问题1006(ATT_OR_VALUE_EXISTS(,数据0,ATT 150029(移动(:len 2\n','desc':u'类型或值存在'}
使用命令行工具ldapmodify,我能够做到这两个:
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
add: mobile
mobile: +1 2345 6789
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
delete: mobile
mobile: +1 2345 6789
但无法做到这一点:
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
replace: mobile
mobile: +1 2345 6789
mobile: +4 567 89012345
以下错误:
ldap_modify:违反约束(19(附加信息:00002081:AtrErr:DSID-03151907,#1:0:00002081:DSID-03151907,问题1005(CONSTRAINT_ATT_TYPE(,数据0,ATT 150029(移动(
已经尝试了一段时间,非常感谢您的帮助。
不要回答这个问题。替换:
nr1 = '+4712781271232'
nr2 = '+9812391282822'
old = {name:nr1}
new = {name:nr2}
带有:
old = {'mobile':["+4712781271232"]}
new = {'mobile':["+9812391282822"]}
括号起作用;(