只是尝试使用python ldap
模块来修改LDAP中的值
我给了belwo代码,第一个正在工作,第二个是我试图成为输入库,需要从用户输入中获取值。
#!/usr/bin/python
# import needed modules
import ldap
import ldap.modlist as modlist
secret = raw_input("Please insert the password")
# Open a connection
l = ldap.initialize("ldap://testldap.lab.com:389")
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("cn=directory manager", secret)
# The dn of our existing entry/object
dn="cn=testldapgroup1,ou=Group,ou=corp,ou=services,o=lab.com"
# Some place-holders for old and new values
old = {'businessCategory':'Public'}
new = {'businessCategory':'Private'}
# 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()
按预期工作:
$ python test.py
Please insert the password: mypass123
$
其次,我想要基于此代码输入,但作为新手,我无法通过old
将new
和raw_input
值排列/创建到字典中,同时将纯字符串值放置为输入
#!/usr/bin/python
# import needed modules
import ldap
import ldap.modlist as modlist
secret = raw_input("Please insert the password: ")
# Open a connection
l = ldap.initialize("ldap://testldap.lab.com:389")
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("cn=directory manager", secret)
# The dn of our existing entry/object
dn= raw_input("Please Insert the dn value to be modified: ")
# Some place-holders for old and new values
old = {raw_input("Please Insert Key:value")}
new = {raw_input("Please Insert Key:value")}
# 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()