noirello / bonsai

Simple Python 3 module for LDAP, using libldap2 and winldap C libraries.
MIT License
117 stars 33 forks source link

Bonsai sets "deleteoldrdn: 1" on rename #17

Closed xunto closed 6 years ago

xunto commented 6 years ago

Hi. I'm not sure that it is but it seems so. So it raise exception about object class violation ("cn" needed) when I try to rename entry.

Could you please explain how to:

  1. Enable debug mode to see bonsai modification log.
  2. Set "deleteoldrdn: 0" when I rename entry.
noirello commented 6 years ago

Your intuition is right: ldap_rename does set deleteoldrdn to 1 by default. Unfortunately, it's hard coded right now. But I'm willing to change it in the future.

Could you send me a detailed example about what you're trying to achieve? (What's the entry looks like before and after the modification)

xunto commented 6 years ago

Record (ldif):

version: 1

dn: cn=b1d10054-14df-4096-97e1-ea8fb7032040,ou=Users,dc=herzen,dc=spb,dc=ru
objectClass: shadowAccount
objectClass: posixAccount
objectClass: domainRelatedObject
objectClass: inetOrgPerson
associatedDomain: students.ok
cn: b1d10054-14df-4096-97e1-ea8fb7032040
gidNumber: 1000
homeDirectory: /home/100393
sn:: %hidden%
uid: 100393
uidNumber: 330604
description:: Q9GC0YPQtNC10L3RgiAo0J7QkSk=
displayName:: %hidden%
employeeNumber: %hidden%
employeeType: students
givenName:: 0JrQvtC90YHRgtCw0L3RgtC40L0g0J/QsNCy0LvQvtCy0LjRhw==
mail: %hidden%
mobile: %hidden%
userPassword:: %hidden%

Code:

async def rename(connection: AIOLDAPConnection, uid)
       record: LDAPEntry = await connection.search(
            "cn=b1d10054-14df-4096-97e1-ea8fb7032040,ou=Users,dc=herzen,dc=spb,dc=ru",
            bonsai.LDAPSearchScope.BASE,
            attrlist=[],
            sizelimit=1
        )[0]

       await record.rename(f"uid={uid},ou=Users,dc=herzen,dc=spb,dc=ru")

This should work.

noirello commented 6 years ago

Thanks, I'll check out.

xunto commented 6 years ago

@noirello Is there some workaround for now? Like a way to send raw request to ldap?

noirello commented 6 years ago

Sorry, but currently there's no workaround for it. :(

xunto commented 6 years ago

Oh, okay. :(

noirello commented 6 years ago

v1.0.0 is out and LDAPEntry's rename method got a delete_old_rdn param.