简体   繁体   中英

Ldapsearch to ldapjs conversion

I've been trying to convert the following ldapsearch query

ldapsearch -H ldap://ldap.berkeley.edu -x -b 'ou=people,dc=berkeley,dc=edu' objectclass=*

to an ldapjs script:

var ldap = require('ldapjs');
var server = 'ldap://ldap.berkeley.edu';
var searchBase = 'ou=people,dc=berkeley,dc=edu';

var client = ldap.createClient({
  url: server
});

var opts = {
  filter: '(objectclass=*)'
}; 

client.search(searchBase, opts, function(err, res) {
  res.on('searchEntry', function (entry) {
    console.log(entry.toString());
  });
});

The ldapsearch gives me plenty of results but ldapjs doesn't return any users.
You can find some attempts of solving this on GitHub .

ldapjs search scopes are "backwards" of OpenLDAP and (AFAIK) most similar C libraries that are derived from the UMich code. The default scope in ldapjs is "base", as opposed to "sub". Without seeing any of your data, you probably need to make that code look like:

var opts = {
  filter: '(objectclass=*)',
  scope: 'sub'
}; 

client.search(searchBase, opts, function(err, res) {
  res.on('searchEntry', function (entry) {
    console.log(entry.toString());
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM