Problems importing from LDIF file generated with python-ldap
Michael Ströder
michael at stroeder.com
Wed Aug 13 15:28:05 CEST 2008
Lars Erik Kolden wrote:
> ldapmodify: modify operation type is missing at line 26, entry
> "cn=audio,ou=Group,dc=ourdc,dc=no"
> [..]
> When I look in the LDAP docs, this looks reasonable, as it states that
> you ned an "add: memberUid" statement with the changetype: modify. But
> how come it worked before? And when I try to incorporate this into the
> LDIF generator script, which uses python-ldap, it just won't work.
I don't know why it worked in the past. The LDIF generator script is
wrong since it uses module ldif for generating entry records (provided
by a dict) instead of providing a modification list (list type) which
would make LDIFWriter.unparse() to generate a change record.
See __doc__ string in ldif.py:
class LDIFWriter:
[..]
def unparse(self,dn,record):
"""
dn
string-representation of distinguished name
record
Either a dictionary holding the LDAP entry {attrtype:record}
or a list with a modify list like for LDAPObject.modify().
"""
> relevant code looked like this:
>
> #########
> # add the new user to a set of default groups:
> # audio, cdrom, floppy, plugdev, video
>
> entry={ 'changetype' : ['modify'],
> 'memberUid': [username],
> }
> dn='cn=audio,ou=Group,dc=ourdc,dc=no'
> ldif_writer=ldif.LDIFWriter(newusers)
> ldif_writer.unparse(dn,entry)
Should be:
modlist=[(ldap.MOD_ADD,'memberUid',[username])]
ldif_writer.unparse(dn,modlist)
BTW: Anyway I'd recommend to directly use a LDAP connection for this
task, not generate LDIF and then using command-line tools. This would
give you much better control in case of LDAP errors.
Ciao, Michael.
More information about the python-ldap
mailing list