Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-ldap Modify phone number

i would like to change mobile phone numbers in an AD with a python(-ldap) script.

This is the Code I tried to use:

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

Unfortunately i get the following error:

ldap.UNWILLING_TO_PERFORM: {'info': u'00000057: LdapErr: DSID-0C090FC7, comment: Error in attribute conversion operation, data 0, v4563', 'desc': u'Server is unwilling to perform'}

I am able to delete the entry by leaving old empty, but when i try to set it, i get the following:

LDAPError - TYPE_OR_VALUE_EXISTS: {'info': u'00002083: AtrErr: DSID-031519F7, #5:\n\t0: 00002083: DSID-031519F7, problem 1006 (ATT_OR_VALUE_EXISTS), data 0, Att 150029 (mobile):len 2\n\t1: 00002083: DSID-031519F7, problem 1006 (ATT_OR_VALUE_EXISTS), data 0, Att 150029 (mobile):len 2\n\t2: 00002083: DSID-031519F7, problem 1006 (ATT_OR_VALUE_EXISTS), data 0, Att 150029 (mobile):len 2\n\t3: 00002083: DSID-031519F7, problem 1006 (ATT_OR_VALUE_EXISTS), data 0, Att 150029 (mobile):len 2\n\t4: 00002083: DSID-031519F7, problem 1006 (ATT_OR_VALUE_EXISTS), data 0, Att 150029 (mobile):len 2\n', 'desc': u'Type or value exists'}

Using the command line tool ldapmodify i was able to do those two:

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

But unable to do this:

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

Following error:

ldap_modify: Constraint violation (19) additional info: 00002081: AtrErr: DSID-03151907, #1: 0: 00002081: DSID-03151907, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 150029 (mobile)

have been trying some time now and would really appreciate some help.

like image 373
valentin Avatar asked Sep 05 '25 02:09

valentin


1 Answers

Nevermind the question. Replaced:

nr1 = '+4712781271232'
nr2 = '+9812391282822'

old = {name:nr1}
new = {name:nr2}

With:

old = {'mobile':["+4712781271232"]}
new = {'mobile':["+9812391282822"]}

Brackets do the trick ;)

like image 157
valentin Avatar answered Sep 07 '25 20:09

valentin