ldapjs不返回任何内容,但是ldapsearch可以正常工作,并且调试日志显示“ SearchEntry”已返回

时间:2019-10-03 13:16:38

标签: node.js ldap ldapjs

除了我认为我已经正确使用了scope以外,我遇到了与Ldapsearch to ldapjs conversion类似的问题。

我的代码是这样的:

            const ldap = require('ldapjs');
            var client = ldap.createClient({
                url: 'ldap://70.70.70.70:389',
                log,
            });
            client.bind('CN=vagrant,CN=Users,DC=perficientads,DC=com' /*'vagrant@perficientads.com'*/, 'vagrant', function(err) {
                if (err) {
                    return console.log('Error:', err);
                }
                client.search('DC=perficientads,DC=com',
                    {
                        //filter:'(&(|(objectClass=user)(objectClass=person))(!(objectClass=computer))(!(objectClass=group))(cn=*vagrant*))',
                        filter: '(sAMAccountName=vagrant)',
                        //filter: '(&(|(objectClass=user)(objectClass=person))(!(objectClass=computer))(!(objectClass=group)))',
                        attributes: [
                            'dn', 'sn', 'cn',
                            "mail",
                        ],
                        scope: 'sub',
                    },
                    function(err, res) {
                        res.on('searchEntry', function(entry) {
                            console.log('entry: ' + JSON.stringify(entry.object));
                            resolve(null);
                        });
                        res.on('searchReference', function(referral) {
                            console.log('referral: ' + referral.uris.join());
                            resolve(null);
                        });
                        res.on('error', function(err) {
                            console.error('error: ' + err.message);
                            resolve(null);

                        });
                        res.on('end', function(result) {
                            console.log('result status: ' + JSON.stringify(result));
                            resolve(null);
                        });
                    }
                );
            });

        });

可通过https://gist.github.com/davidpodhola/b8c851ca3e7c4cf0c66d8981cd250028#file-log-txt-L25访问整个ldapjs调试日志;最重要的部分是它包含

{"name":"oecsc-rental","hostname":"PerficientAD","pid":4992,"clazz":"Client","level":10,"msg":"Parsing done: {\"messageID\":2,\"protocolOp\":\"SearchEntry\",\"objectName\":\"CN=vagrant,CN=Users,DC=perficientads,DC=com\",\"attributes\":[{\"type\":\"cn\",\"vals\":[\"vagrant\"]}],\"controls\":[]}","time":"2019-10-03T12:41:07.524Z","v":0}
{"name":"oecsc-rental","hostname":"PerficientAD","pid":4992,"clazz":"Client","ldap_id":"1__ldap://70.70.70.70:389","level":10,"msg":"response received","time":"2019-10-03T12:41:07.524Z","v":0}

我认为是应该返回SearchEntry

使用ldapsearch进行相同的搜索,例如

ldapsearch -H ldap://70.70.70.70:389 -x -W -D "vagrant@perficientads.com" -b "DC=perficientads,DC=com" "(sAMAccountName=vagrant)" "mail"

正常工作。

问题是'end'事件立即被触发,而没有searchEntry被触发。

我认为我忽略了一些非常简单的事情。请帮忙,谢谢!

0 个答案:

没有答案