From 4ba6fde7c8e542707be3d619daab392837e2dbbf Mon Sep 17 00:00:00 2001 From: "kts of kettek(MindFire)" Date: Fri, 10 Jul 2020 19:05:06 -0700 Subject: [PATCH] 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. --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index eb15c15..84285c6 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,6 @@ module.exports = function(plugin) { } }); - var client = ldap.createClient(plugin.conf.options) function requestAuth(res) { res.set('WWW-Authenticate', 'Basic realm="Auth"'); @@ -41,6 +40,9 @@ module.exports = function(plugin) { 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) { if (err) { console.log('E: ldap.bind: ', err) @@ -51,8 +53,8 @@ module.exports = function(plugin) { if (err) { console.log('E: ldap.unbind: ', err) } - next(); }) + next(); } }) });