Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-ldap add_s fails to add attribute for AD user with OBJECT_CLASS_VIOLATION

I get an OBJECT_CLASS_VIOLATION when trying to add an attribute. Modifying an existing attribute works just fine (even this same attribute, if I add it from AD first, then mod it).

First I kinit as a domain admin, then:

import ldap, ldap.sasl
l = ldap.initialize('ldap://TEST.DOM.DE')
auth_tokens = ldap.sasl.gssapi('')
l.sasl_interactive_bind_s('', auth_tokens)
l.add_s('CN=dmulder,CN=Users,DC=test,DC=dom,DC=de', [('gecos', ['something'])])

Which returns this error:

ldap.OBJECT_CLASS_VIOLATION: {'info': '0000207B: UpdErr: DSID-0305124B, problem 6002 (OBJ_CLASS_VIOLATION), data 0\n', 'desc': 'Object class violation'}

This command is successful though, if I create the attribute ahead of time within ADUC:

l.modify_s('CN=dmulder,CN=Users,DC=test,DC=dom,DC=de', [(1, 'gecos', None), (0, 'gecos', ['something'])])

And the add command does work with ldapmodify:

> ldapmodify -x -h TEST.DOM.DE -D [email protected] 
dn:CN=dmulder,CN=Users,DC=test,DC=dom,DC=de
changetype: modify
add: gecos
gecos: something
modifying entry "CN=dmulder,CN=Users,DC=test,DC=dom,DC=de"

Any idea what I'm doing wrong here?

like image 855
David Mulder Avatar asked Aug 10 '17 19:08

David Mulder


2 Answers

l.add_s is used to add an object, not an attribute.

In this case you are attempting to create a new object, and you are missing multiple required attributes for object creation. You ought to be using

l.modify_s('CN=dmulder,CN=Users,DC=test,DC=dom,DC=de', [(0, 'gecos', 'something')])

to just add a new attribute to the object.

To clarify: When the attribute isn't already set, this syntax is wrong: l.modify_s('CN=dmulder,CN=Users,DC=test,DC=dom,DC=de', [(1, 'gidNumber', None), (0, 'gidNumber', ['1000'])]) The above syntax (without a previous value) is correct.

like image 129
Vince Avatar answered Sep 28 '22 22:09

Vince


I follow guide and install the OpenLDAP server daemon in ubuntu 16.and below is my attempt.

import ldap
l = ldap.initialize('ldap://localhost',trace_level=3)
l.simple_bind_s('CN=admin,DC=example,DC=com','381138')#my setting
base_dn = 'DC=example,DC=com'
filter = '(objectclass=person)'
attrs = ['gecos']

add_record = [
('objectclass', ['inetOrgPerson']),
('gecos', ['Bacon'] ),
]
#l.modify_s('CN=dmulder,ou=people,dc=example,dc=com', [(1, 'gecos', None), (0, 'gecos', ['something'])])
l.add_s('cn=dmulder,ou=people,dc=example,dc=com', add_record)
l.search_s( base_dn, ldap.SCOPE_SUBTREE, filter, attrs )

if you are not violate the schema,then it must be a bug of ldapclient.python-ldap just a wrapper.

For example, if no structural object class is specified in the attributes, an OTHER exception will be raised. If a record does not contain the attributes used in the UID, a NAMING_VIOLATION will be raised. If a record is missing an attribute required by a structural object class, an OBJECT_CLASS_VIOLATION will be raised, and so on.

Please use the dump_record.pyprovided bya series of python-ldapto dump the new entry to find what is miss.

like image 26
obgnaw Avatar answered Sep 28 '22 23:09

obgnaw