Create ldap client per login attempt

This seems stupid to not just bind then unbind, but it seems that the
joyent ldap library does not support this, as a second call to bind,
even after an unbind, just hangs.
This commit is contained in:
Ketchetwahmeegwun T. Southall 2020-07-10 19:05:06 -07:00
parent 1095d80a34
commit 4ba6fde7c8

View File

@ -16,7 +16,6 @@ module.exports = function(plugin) {
} }
}); });
var client = ldap.createClient(plugin.conf.options)
function requestAuth(res) { function requestAuth(res) {
res.set('WWW-Authenticate', 'Basic realm="Auth"'); res.set('WWW-Authenticate', 'Basic realm="Auth"');
@ -41,6 +40,9 @@ module.exports = function(plugin) {
return; return;
} }
// It seems stupid to create a client each time, but joyent's ldapjs cannot bind then unbind to the same client multiple times...
var client = ldap.createClient(plugin.conf.options)
client.bind(plugin.conf.bind.dn.replace('%u', login), plugin.conf.bind.password.replace('%p', password), function(err) { client.bind(plugin.conf.bind.dn.replace('%u', login), plugin.conf.bind.password.replace('%p', password), function(err) {
if (err) { if (err) {
console.log('E: ldap.bind: ', err) console.log('E: ldap.bind: ', err)
@ -51,8 +53,8 @@ module.exports = function(plugin) {
if (err) { if (err) {
console.log('E: ldap.unbind: ', err) console.log('E: ldap.unbind: ', err)
} }
next();
}) })
next();
} }
}) })
}); });