From 28ddaaad6934a4847dff2e14b58c8cc76130c4e4 Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Mon, 7 Nov 2011 17:12:59 -0800 Subject: [PATCH] Minor cleanup of server handling and null DNs --- lib/dn.js | 2 +- lib/server.js | 87 ++++++++++++++++++++++++++------------------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/lib/dn.js b/lib/dn.js index ebc0113..c19659c 100644 --- a/lib/dn.js +++ b/lib/dn.js @@ -239,7 +239,7 @@ DN.prototype.parentOf = function(dn) { if (typeof(dn) !== 'object') dn = parse(dn); - if (this.rdns.length >= dn.rdns.length) + if (!this.rdns.length || this.rdns.length >= dn.rdns.length) return false; var diff = dn.rdns.length - this.rdns.length; diff --git a/lib/server.js b/lib/server.js index 1bf59ab..538f6f1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -367,6 +367,7 @@ function Server(options) { } if (err) { + log.trace('%s sending error: %s', req.logId, err.stack || err); sendError(err); return after(); } @@ -444,7 +445,7 @@ function Server(options) { }); this.__defineGetter__('url', function() { var str; - if (options.certificate && options.key) { + if (this.server instanceof tls.Server) { str = 'ldaps://'; } else { str = 'ldap://'; @@ -745,54 +746,56 @@ Server.prototype._getHandlerChain = function(req) { var self = this; var routes = this.routes; - for (var r in routes) { - if (routes.hasOwnProperty(r)) { - var route = routes[r]; - // Special cases are abandons, exops and unbinds, handle those first. - if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) { - if (r !== req.requestName) - continue; + var keys = Object.keys(routes); + for (var i = 0; i < keys.length; i++) { + var r = keys[i]; + var route = routes[r]; - return { - backend: routes.backend, - handlers: route[op] || [noExOpHandler] - }; - } else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) { - function getUnbindChain() { - if (routes['unbind'] && routes['unbind'][op]) - return routes['unbind'][op]; + // Special cases are abandons, exops and unbinds, handle those first. + if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) { + if (r !== req.requestName) + continue; - self.log.debug('%s unbind request %j', req.logId, req.json); - return [defaultUnbindHandler]; - } + return { + backend: routes.backend, + handlers: route[op] || [noExOpHandler] + }; + } else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) { + function getUnbindChain() { + if (routes['unbind'] && routes['unbind'][op]) + return routes['unbind'][op]; - return { - backend: routes['unbind'] ? routes['unbind'].backend : self, - handlers: getUnbindChain() - }; - } else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) { - return { - backend: self, - handlers: [defaultAbandonHandler] - }; + self.log.debug('%s unbind request %j', req.logId, req.json); + return [defaultUnbindHandler]; } - if (!route[op]) - continue; - - // Otherwise, match via DN rules - assert.ok(req.dn); - assert.ok(route.dn); - if (r !== req.dn.toString() && (!route.dn.parentOf(req.dn))) - continue; - - // We should be good to go. - req.suffix = route.dn; return { - backend: route.backend, - handlers: route[op] || [defaultHandler] + backend: routes['unbind'] ? routes['unbind'].backend : self, + handlers: getUnbindChain() + }; + } else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) { + return { + backend: self, + handlers: [defaultAbandonHandler] }; } + + if (!route[op]) + continue; + + // Otherwise, match via DN rules + assert.ok(req.dn); + assert.ok(route.dn); + + if (!route.dn.equals(req.dn) && !route.dn.parentOf(req.dn)) + continue; + + // We should be good to go. + req.suffix = route.dn; + return { + backend: route.backend, + handlers: route[op] || [defaultHandler] + }; } // We're here, so nothing matched. @@ -801,7 +804,7 @@ Server.prototype._getHandlerChain = function(req) { handlers: [(req.protocolOp !== Protocol.LDAP_REQ_EXTENSION ? noSuffixHandler : noExOpHandler)] }; -}; +} Server.prototype._mount = function(op, name, argv, notDN) {