在Ldap.js中search

我正在尝试在我的node.js代码中使用Ldap.js的search方法。 但它不起作用。 这里是我的代码:

searchFunc : function (){ console.log('inside search'); client.bind('cn=Manager,dc=foo,dc=com', kredito231, function(err) { if (err) { console.log(err); client.unbind(); return; } var opts = { filter: (('Email=*@foo.com')) } ; //This search works correct: //client.search( 'cn=x,ou=users' + ',' + 'dc=foo,dc=com', function(err,res){ //This one doesn't work. But everything is done according api client.search('dc=foo,dc=com', opts, function(err, res) { res.on('searchEntry', function(entry) { console.log('hit'); console.log('entry: ' + JSON.stringify(entry.object)); }); res.on('searchReference', function(referral) { console.log('referral: ' + referral.uris.join()); }); res.on('error', function(err) { console.log('searchFailed') ; console.error('error: ' + err.message); }); res.on('end', function(result) { console.log('4') ; console.log('status: ' + result.status); }); }); }); } 

当我使用dn名称的用户search方法时,它返回正确的对象,它的属性。 (res.on('searchEntry',function(entry)part is executed。因为它可以在Ldap中findlogging)但是当我使用client.search('dc = foo,dc = com',opts,function ,res)与上面定义的opt一样,它总是转到分支4:res.on('end',function(result)并且永不返回错误,status是0,这里是Ldap的api文档: http:// ldapjs .ORG / client.html

这不适用于dc=foo,dc=com因为LDAP目录中的条目没有Email属性,因此您的filter不匹配。 LDAP目录中的条目'cn=x,ou=users,dc=foo,dc=com'可能具有这个属性,这就是它工作的原因。