0

Just trying to use the python ldap module to modify the values in LDAP I have given belwo codes the First is working and second one thats i'm trying to be input base and need to take the values from user inputs..

#!/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()

It works as expected:

$ python test.py
Please insert the password: mypass123
$

Secondly, i want this code input based but as a newbie i'm unable to arrange/create the old and new values into dictionary through raw_input while placing plain string values as a 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()

0 Answers0