Last active
July 5, 2021 16:09
-
-
Save yellowred/d6cdf7fbedca17ed3b8d667e0fd2f1d9 to your computer and use it in GitHub Desktop.
get all records from LDAP DN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getAllRecords = () => { | |
return new Promise((resolve, reject) => { | |
const ldapClient = ldapjs.createClient(ldapOptions); | |
// 1 | |
ldapClient.bind( | |
ldapConfig.managerUser, | |
ldapConfig.managerUserPassword, | |
err => { | |
if (err) return reject(err); | |
// 2 | |
let options = { | |
attributes: [ | |
"cn", | |
"createTimestamp", | |
"modifyTimestamp", | |
"pwdPolicySubentry" | |
], | |
scope: "sub", | |
filter: "(objectClass=person)" | |
}; | |
// 3 | |
ldapClient.search(ldapConfig.domain, options, (err, res) => { | |
if (err) return reject(err); | |
let entries = []; | |
res.on('searchEntry', function (entry) { | |
var r = entry.object; | |
entries.push(r); | |
}); | |
res.on('error', function (err) { | |
reject(err); | |
}); | |
res.on('end', function (result) { | |
resolve(entries); | |
}); | |
}); | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment