我遇到了使用ldapadd和ldif文件导入用户的问题。 我得到的错误是:
ldap_add: Constraint violation (19) additional info: structuralObjectClass: no user modification allowed
导入的用户都是ou=People,dc=example,dc=org 。 LDAP服务器已经包含此基本DN。
/etc/ldap/slapd.d/cn=config/olcDatabase={1}hdb.ldif文件包含以下ACL条目:
olcAccess: {2}to dn.base="ou=People,dc=example,dc=org" attrs=children by gr oup.exact="cn=Manager,ou=Roles,dc=example,dc=org" manage
ldif文件导入如下:
ldapadd -f import.ldif -xv -D "cn=drupal,ou=Apps,dc=example,dc=org" -h localhost -W
cn=drupal,ou=Apps[...]条目是cn=Manager,ou=Roles,dc=example,dc=org的成员cn=Manager,ou=Roles,dc=example,dc=org因此它应该有足够的权限来写( 因为manage是最高级别权限可用 )。
当我发出ldapadd命令时,导入在第一个ldif入口上失败。 完整的命令输出是:
add objectClass: top person inetOrgPerson add uid: John.Merrell add mail: [email protected] add cn: John D Merrell add structuralObjectClass: inetOrgPerson add entryUUID: 65236c42-09b7-1020-9318-9fca7c043dfc add creatorsName: cn=drupal,ou=Apps,dc=bidnetwork,dc=org add createTimestamp: 20110503095643Z add userPassword: 2678u8yyy add givenName: John D add sn: Merrell add entryCSN: 20110629121956.880164Z#000000#000#000000 add modifiersName: cn=drupal,ou=Apps,dc=bidnetwork,dc=org add modifyTimestamp: 20110629121956Z adding new entry "[email protected],ou=People,dc=example,dc=org" ldap_add: Constraint violation (19) additional info: structuralObjectClass: no user modification allowed
我已经testing了导入用户的LDAP或不存在,我得到上述错误在任何情况下。
有人能解释一下这个问题的起因以及如何绕开这个问题吗?
你是如何生成这些LDIF文件的? structuralObjectClass是OpenLDAP中的一个内部值,用户甚至pipe理员不能正常修改这些值。
从你的LDIF中删除这些structuralObjectClass行,或者用slapadd把条目导回(我打赌你用slapcat生成了LDIF文件)。
如果您使用的工具如http://phpldapadmin.sourceforge.net/wiki/index.php/Main_Page导出数据,请不要select在Web UI中Include system attributes :
下面不是解决问题的方法,而是实用程序代码去除结构元素 。 示例python代码删除结构元素。 使用out.ldif
structural_elements = ["structuralObjectClass","entryUUID", "creatorsName","createTimestamp","entryCSN", "modifiersName","modifyTimestamp"] with open("ldap_data_out.ldif","w+") as outfile: with open("ldap_data_in.ldif", "r") as infile: lines = infile.readlines() for line in lines: print line.split(":")[0] if line.split(":")[0] in structural_elements: print "ignoring ,", line else: outfile.write(line)
您需要删除ldif文件中的以下行:
structuralObjectClass: entryUUID: creatorsName: createTimestamp: entryCSN: modifiersName: modifyTimestamp: