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

NoSuchObjectError returned when i perform a search in starttls mode

Open Oladapo opened this issue 8 years ago • 3 comments

Hello, I'm sort of stuck. Having successfully binded and performed search queries in simple bind mode i get an error when i perform the same queries after binding in starttls mode. Here's a snippet of the code

var ou = 'ou=foo,dc=example,dc=bar'
var opts = { scope : 'sub' }
var dosomething  = function(err, res) {
  assert.ifError(err) 
  console.log(res);
}
var executeSearch = function(base,searchoptions,fn) {
  //NOTE: cli binded and starttls called in bind callback
  cli.search(base,searchoptions,[],function(err,res) {
    var arr = [];
    if(err) return fn(err);


res.on('searchEntry', function(entry) {
  arr.push(entry.object);
});

res.on('error', function(err) {
   console.error('the following error occured: \n' + err);
   fn(err);
});

res.on('end', function(result) {
   fn(null,arr)
});


   });

}

executeSearch(abase,opts, dosomething)

here's the error stack:

NoSuchObjectError: No Such Object
    at messageCallback (/home/dani/Dev/projects/eaglepost/src/eaglepost-admin/node_modules/ldapjs/lib/client/client.js:1419:45)
    at Parser.onMessage (/home/dani/Dev/projects/eaglepost/src/eaglepost-admin/node_modules/ldapjs/lib/client/client.js:1089:14)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Parser.write (/home/dani/Dev/projects/eaglepost/src/eaglepost-admin/node_modules/ldapjs/lib/messages/parser.js:117:8)
    at TLSSocket.onData (/home/dani/Dev/projects/eaglepost/src/eaglepost-admin/node_modules/ldapjs/lib/client/client.js:927:32)
    at emitOne (events.js:77:13)
    at TLSSocket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at TLSSocket.Readable.push (_stream_readable.js:110:10)

Oladapo avatar Mar 10 '16 12:03 Oladapo

I am having this same issue, running the query without StartTLS works flawlessly, however once i use StartTLS it claims it can't find the exact same object.

Destreyf avatar Nov 02 '16 17:11 Destreyf

After playing with this, i was able to get it working using this.

var ldap = require('ldapjs');
var client = ldap.createClient({url: 'ldap://ldap.example.com'});

client.starttls({},[],function(start_err,start_res){
    client.bind('dc=example,dc=com','secret',function(err){
        client.search('ou=Users,dc=example,dc=com', {scope: 'sub'}, [], function(search_err,res){
            res.on('searchEntry', function(entry) {
                console.log('entry: ' + JSON.stringify(entry.object));
            });
            res.on('searchReference', function(referral) {
                console.log('referral: ' + referral.uris.join());
            });
            res.on('error', function(err) {
                console.error('error: ' + err.message);
            });
            res.on('end', function(result) {
                console.log('status: ' + result.status);
            });
        });
    });
});

So this appears to be an issue with calling starttls -after- binding, rather than before, i also had some trouble with nested callbacks that would make wrapper.js freak out, so i just inlined all my code for my project.

Destreyf avatar Nov 02 '16 17:11 Destreyf

client.starttls would be something you perform immediately after creating the client and before performing any other operations. So at the least, this could use some better documentation. A PR would be welcome.

jsumners avatar Aug 27 '19 22:08 jsumners

👋

On February 22, 2023, we released version 3 of this library. As a result, we are closing this issue/pull request.

Please see issue #839 for more information, including how to proceed if you feel this closure is in error.

jsumners avatar Feb 22 '23 19:02 jsumners