ldapjs / node-ldapjs

LDAP Client and Server API for node.js
http://ldapjs.org
MIT License
1.61k stars 442 forks source link

ldapsearch is working, but ldapjs not #588

Closed GRme-zz closed 4 years ago

GRme-zz commented 4 years ago

Hey guys,

I have the following ldapsearch command that is working over commandline: ldapsearch -v -x -D cn=myAdmin,ou=users,dc=crowd -w 'myPassword' -H ldap://localhost:10636 -s sub -b 'cn=myAdmin,ou=users,dc=crowd' '(&(cn=myAdmin)(ou=users))'

But the equivalent ldapjs code returns an empty search result:

EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }

And this is my source code:

            ldapClient.bind(
              "cn=myAdmin,ou=users,dc=crowd",
              "myPassword",
              function(error, result) {
                assert.ifError(error, `ERROR while ldap bind(): ${error}`);
                assert.ok(result != null, "The LDAP client result is null!");

                const searchOptions = {
                  scope: "sub",
                  filter: "(&(cn=myAdmin)(ou=users))"
                };

                ldapClient.search("cn=myAdmin,ou=users,dc=crowd", searchOptions, (error, result) => {
                  assert.ifError(error, `ERROR while ldap search(): ${error}`);

                  result.on("searchEntry", function(entry) {
                    console.log("entry: " + JSON.stringify(entry.object));
                  });
                  result.on("searchReference", function(referral) {
                    console.log("referral: " + referral.uris.join());
                  });
                  result.on("error", function(err) {
                    console.error("error: " + err.message);
                  });
                  result.on("end", function(result) {
                    console.log("status: " + result.status);
                  });
                });
              }
            );

Any ideas? Thanks :)

GRme-zz commented 4 years ago

I found a fix for my issue.

jsumners commented 4 years ago

Can you please post the resolution here for others to learn from it?

lilleng commented 4 years ago

That's the result-object value when it's executed by ldapjs before you attach any on-listeners, so I guess the name result is misleading since the actual search result values are given through the "result.on('searchEntry', ...);"-callback function. Rename the result variable to event and it makes more sense.

jsumners commented 1 year ago

⚠️ This issue has been locked due to age. If you have encountered a recent problem that seems to be covered by this issue, please open a new issue.

Please include a minimal reproducible example when opening a new issue.