0

我有一个类似于Ldapsearch to ldapjs conversion的问题,除了我认为我已经scope正确使用了。

我的代码是这样的:

            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);
                        });
                    }
                );
            });

        });

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

{"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使用like执行相同的搜索

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

正常工作。

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

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

4

0 回答 0