2017-08-10 94 views
9

尝试添加属性时,我得到一个OBJECT_CLASS_VIOLATION。修改现有的属性可以很好地工作(即使是同一个属性,如果我先从AD中添加它,然后再修改它)。python-ldap add_s无法为AD用户添加属性(使用OBJECT_CLASS_VIOLATION)

首先,我执行kinit如域管理员,然后:

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'])]) 

它返回此错误:

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

这个命令是成功的,虽然,如果我ADUC内提前创建的属性:

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

而add命令可以使用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" 

任何想法我在做什么错在这里?

+0

该模式允许rfc2307属性。显然,由于ldapmodify *能够执行添加,因此只有python模块无法执行相同的操作。 – David

+1

我的异常是'ldap.OBJECT_CLASS_VIOLATION:{'info':'no objectClass attribute','desc':'Object class违反'}',并且可以通过在ubuntu16上添加objectClass.i来修复,所有的包都通过apt来安装。 – obgnaw

+0

@obgnaw你能解释一下你的意思吗?在add_s()操作中包含objectClass属性对我无能为力。如果您找到了解决方案,请在答案中发布详细信息。 – David

回答

2

l.add_s用于添加对象,而不是属性。

在这种情况下,您正在尝试创建一个新对象,并且缺少创建对象所需的多个必需属性。你应该使用

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

只需添加一个新的属性的对象。

澄清: 当属性尚未设置,此语法是错误的: l.modify_s('CN=dmulder,CN=Users,DC=test,DC=dom,DC=de', [(1, 'gidNumber', None), (0, 'gidNumber', ['1000'])]) 上述语法(没有前次值)是正确的。

+0

嗯,我试过了一个修改,失败了一个ldap.NO_SUCH_ATTRIBUTE错误。现在我明白了为什么。我提供了一个以前的值(尽管是空的),这是不正确的。 – David

1

我遵循guide并在Ubuntu 16.安装OpenLDAP服务器守护进程,以下是我的尝试。

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) 

,如果你不违反模式,那么它必须是ldapclient.python,LDAP只是一个包装的错误。

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.

请使用dump_record.py提供由a series of python-ldap转储新条目以找出是什么小姐。

+0

这没有什么区别。另外,我正在使用Active Directory,而不是OpenLDAP。 – David