I can't modify the name of ldap3 python

73 views Asked by At

I get the error attribute 'sn' is read only In ldp.exe from this user I can modify other users, I have privileges and their 'sn' attribute isn't read only, but in python is, why?

console result

while True:
            pesel = input("Wprowadź PESEL użytkownika dla którego chcesz zmienić nazwisko: ")
            if not is_valid_serial_number(pesel):
                print("Nieprawidłowy numer PESEL.")
                continue
            break
        
        ldap_connection.search(search_base=f'dc=test,dc=local', search_filter=f'(serialNumber={pesel})', search_scope=SUBTREE, attributes=['sAMAccountName', 'givenName', 'sn', 'serialNumber','cn'])
        entry = ldap_connection.entries[0]
        dn = entry.entry_dn
        print(dn)
        new_last_name = input("Wprowadź nowe nazwisko: ")
        
        print(entry.entry_attributes_as_dict)
        
        old_last_name = entry['sn'].value
        print(f"Potwierdź, czy chcesz zmienić nazwisko dla użytkownika {entry.sAMAccountName.value} z {old_last_name} na {new_last_name}.")

        confirmation = input("1. Tak\n2. Nie\nWybierz opcję: ")
       
        if confirmation == '1':
             entry.sn = new_last_name
             ldap_connection.modify(entry.entry_dn, {'sn': [(MODIFY_REPLACE, [new_last_name])]})
             print("Nazwisko użytkownika zostało zmienione.")
        else:
            print("Anulowano zmianę nazwiska.")

            
        ldap_connection.unbind()`

I checked ldap configuration and ldap privileges for user I tried modify other attributes like description but same resultat I tried to:

but it's not about modifications dn

my goal is to edit an existing user, his last name - sn

1

There are 1 answers

0
godelko ツ On

I found a solution.

if confirmation == '1':
    modifications = {'sn': [(MODIFY_REPLACE, [new_last_name])]}
    if ldap_connection.modify(entry.entry_dn, modifications):
        print("Nazwisko użytkownika zostało zmienione.")
    else:
        print("Wystąpił błąd podczas zmiany nazwiska: ", ldap_connection.result)
else:
    print("Anulowano zmianę nazwiska.")