From eee489089a29b3fdce907cafcb71bcc6cc307a6e Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Wed, 23 Oct 2013 21:55:43 -0500 Subject: [PATCH] Fix examples/inmemory.js Fixes mcavage/node-ldapjs#138: user can't bind with inmemory example In addition to fixing the userPassword authentication code, the authorize function has been changed so any user may search after a successful bind. --- examples/inmemory.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/inmemory.js b/examples/inmemory.js index c398ce5..5d90e9b 100644 --- a/examples/inmemory.js +++ b/examples/inmemory.js @@ -4,7 +4,9 @@ var ldap = require('../lib/index'); ///--- Shared handlers function authorize(req, res, next) { - if (!req.connection.ldap.bindDN.equals('cn=root')) + /* Any user may search after bind, only cn=root has full power */ + var isSearch = (req instanceof ldap.SearchRequest); + if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) return next(new ldap.InsufficientAccessRightsError()); return next(); @@ -43,10 +45,10 @@ server.bind(SUFFIX, function(req, res, next) { if (!db[dn]) return next(new ldap.NoSuchObjectError(dn)); - if (!dn[dn].userpassword) + if (!db[dn].userpassword) return next(new ldap.NoSuchAttributeError('userPassword')); - if (db[dn].userpassword !== req.credentials) + if (db[dn].userpassword.indexOf(req.credentials) === -1) return next(new ldap.InvalidCredentialsError()); res.end();