node-ldapjs icon indicating copy to clipboard operation
node-ldapjs copied to clipboard

ldapmodify works, but ldapjs client.modify() does't work as expected and return No Such Object

Open eliellima00 opened this issue 1 year ago • 5 comments

I'm triyng to update, a user. When I use ldapmodify from ldap-utils it works as expected. ldapmodify -x -H ldap://grupoatto.corp:389 -D user -W -f modificacoes.ldif

my file has that content

dn: CN=ALDAIR NATAN BEZERRA DO NASCIMENTO GOMES,OU=Usuários,OU=Tecnologia da Informação,OU=Matriz,OU=GrupoATTO,DC=grupoatto,DC=corp
changetype: modify
replace: telephoneNumber
telephoneNumber: 00000000

But, when I use the same dn with client.modify() I see that error

No Such Object
    at messageCallback (/home/eliel/projetos/password-recovery/password-recovery-api/node_modules/ldapjs/lib/client/client.js:1267:45)
    at Parser.onMessage (/home/eliel/projetos/password-recovery/password-recovery-api/node_modules/ldapjs/lib/client/client.js:925:14)
    at Parser.emit (node:events:513:28)
    at Parser.write (/home/eliel/projetos/password-recovery/password-recovery-api/node_modules/ldapjs/lib/messages/parser.js:135:8)
    at Socket.onData (/home/eliel/projetos/password-recovery/password-recovery-api/node_modules/ldapjs/lib/client/client.js:875:22)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  lde_message: 'No Such Object',
  lde_dn: 'OU=Matriz,OU=GrupoATTO,DC=grupoatto,DC=corp'

I don't know if it's a bug or if I'm making something wrong.

here is my code

    const client = createClient({
      url: ldapUri,
    });

    client.bind(adminDN, adminPassword, (err) => {
      if (err) {
        console.error('Erro ao autenticar como administrador:', err);
        return;
      }

      console.log('Autenticado como administrador');

      const change = new Change({
        operation: 'replace',
        modification: {
          type: 'givenName',
          values: ['ALDAIR'],
        },
      });

      const userDN = 'CN=USER TO MODIFY ,OU=Usuários,OU=Tecnologia da Informação,OU=Matriz,OU=GrupoATTO,DC=grupoatto,DC=corp'

      client.modify(userDN, change, (err) => {
        if (err) {
          console.error('Erro ao atualizar o telefone do usuário:', err);
        } else {
          console.log('Telefone atualizado com sucesso.');
        }

        // Fechar a conexão LDAP
        client.unbind((err) => {
          if (err) {
            console.error('Erro ao fechar a conexão LDAP:', err);
          } else {
            console.log('Conexão LDAP encerrada.');
          }
        });
      });
    });
I know that don't have any problen with tree authorization, because with ldapmodify work's as expected

eliellima00 avatar Oct 30 '23 15:10 eliellima00

This sounds very much like issue #940. We have an integration test that covers it https://github.com/ldapjs/node-ldapjs/blob/bec2ff8e7399155ebdcbf86eec2077a792b8510b/test-integration/client/issue-940.test.js

Can you point out where the integration test is different from what you are trying to accomplish?

jsumners avatar Nov 09 '23 23:11 jsumners

Pudiste resolverlo?. Tengo el mismo problema, desde la utilidad ldap se puede modificaro a los usuarios pero desde el código con la función modify, no se puede. Da ese error

byteAr avatar Apr 03 '24 12:04 byteAr

I couldn't make it work. I ended up using another stack with a different language and framework to solve my problem. Maybe the issue is that my DN contains white spaces, I don't know, I tried everything.

eliellima00 avatar Apr 03 '24 13:04 eliellima00

I'm encountering a similar problem as this and issue #940. I'm able to search and locate the user, but when attempting to modify a attribute of the distinguished name (DN) containing Latin characters, it returns "No Such Object" error. Below are some examples of adjustments made to the DN accurately to modify the user (that have the following characters) in a correct way:

  • č to base c
  • š to base s
  • ė to base e
  • ž to base z

The code tested is more and less https://github.com/ldapjs/node-ldapjs/blob/bec2ff8e7399155ebdcbf86eec2077a792b8510b/test-integration/client/issue-940.test.js but on line 52, I have tried to use both dn directly and dn.toString().

quranc avatar Apr 05 '24 08:04 quranc

The issue is very likely as described in https://github.com/ldapjs/filter/pull/9#discussion_r1401459812

jsumners avatar Apr 05 '24 10:04 jsumners