ldapjs / node-ldapjs

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

ldapsearch works but ldapjs doesn't #295

Closed seanzx85 closed 9 years ago

seanzx85 commented 9 years ago

I am having and issue with ldapsearch returning a result, where ldapjs is returning nothing.

Working command:

ldapsearch -hserver.com -p 1234 -D"CN=1112223334,ou=All Businesses,dc=CDIAD,dc=ABC,dc=com" -wpassword -b"OU=Groups,DC=CDIAD,DC=GE,DC=com" "(member=CN=123456789,ou=All Businesses,DC=CDIAD,DC=ABC,DC=com)" name

Returning nothing:

var client = ldap.createClient({
    url: 'ldap://server.com:1234',
});
client.bind('CN=1112223334,ou=All Businesses,dc=CDIAD,dc=ABC,dc=com', 'password', function(err) {
    if (err) {
        return console.log('Error:', err);
    }
    client.search('OU=Groups,DC=CDIAD,DC=ABC,DC=com',
        {
            filter:'member=CN=123456789,OU=All Businesses,DC=CDIAD,DC=ABC,DC=com',
            attribute: 'name'
        },
        function(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);
                process.exit(1);
            });
            res.on('end', function(result) {
                console.log('status: ' + result.status);
                process.exit(0);
            });
        }
    );
});
jon-hall commented 9 years ago

You might need to add the 'scope' property to your search options with a value of 'sub' (the default for ldapsearch), as the default is 'base' in ldapjs - which means it only searches the base level - this caught me out today.

seanzx85 commented 9 years ago

@jon-hall thanks! that worked.

LeapM commented 7 years ago

save my day!

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.