Minor cleanup of server handling and null DNs

This commit is contained in:
Mark Cavage 2011-11-07 17:12:59 -08:00
parent 75aba691f1
commit 28ddaaad69
2 changed files with 46 additions and 43 deletions

View File

@ -239,7 +239,7 @@ DN.prototype.parentOf = function(dn) {
if (typeof(dn) !== 'object') if (typeof(dn) !== 'object')
dn = parse(dn); dn = parse(dn);
if (this.rdns.length >= dn.rdns.length) if (!this.rdns.length || this.rdns.length >= dn.rdns.length)
return false; return false;
var diff = dn.rdns.length - this.rdns.length; var diff = dn.rdns.length - this.rdns.length;

View File

@ -367,6 +367,7 @@ function Server(options) {
} }
if (err) { if (err) {
log.trace('%s sending error: %s', req.logId, err.stack || err);
sendError(err); sendError(err);
return after(); return after();
} }
@ -444,7 +445,7 @@ function Server(options) {
}); });
this.__defineGetter__('url', function() { this.__defineGetter__('url', function() {
var str; var str;
if (options.certificate && options.key) { if (this.server instanceof tls.Server) {
str = 'ldaps://'; str = 'ldaps://';
} else { } else {
str = 'ldap://'; str = 'ldap://';
@ -745,54 +746,56 @@ Server.prototype._getHandlerChain = function(req) {
var self = this; var self = this;
var routes = this.routes; var routes = this.routes;
for (var r in routes) { var keys = Object.keys(routes);
if (routes.hasOwnProperty(r)) { for (var i = 0; i < keys.length; i++) {
var route = routes[r]; var r = keys[i];
// Special cases are abandons, exops and unbinds, handle those first. var route = routes[r];
if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) {
if (r !== req.requestName)
continue;
return { // Special cases are abandons, exops and unbinds, handle those first.
backend: routes.backend, if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) {
handlers: route[op] || [noExOpHandler] if (r !== req.requestName)
}; continue;
} else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) {
function getUnbindChain() {
if (routes['unbind'] && routes['unbind'][op])
return routes['unbind'][op];
self.log.debug('%s unbind request %j', req.logId, req.json); return {
return [defaultUnbindHandler]; 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 { self.log.debug('%s unbind request %j', req.logId, req.json);
backend: routes['unbind'] ? routes['unbind'].backend : self, return [defaultUnbindHandler];
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 (r !== req.dn.toString() && (!route.dn.parentOf(req.dn)))
continue;
// We should be good to go.
req.suffix = route.dn;
return { return {
backend: route.backend, backend: routes['unbind'] ? routes['unbind'].backend : self,
handlers: route[op] || [defaultHandler] 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. // We're here, so nothing matched.
@ -801,7 +804,7 @@ Server.prototype._getHandlerChain = function(req) {
handlers: [(req.protocolOp !== Protocol.LDAP_REQ_EXTENSION ? handlers: [(req.protocolOp !== Protocol.LDAP_REQ_EXTENSION ?
noSuffixHandler : noExOpHandler)] noSuffixHandler : noExOpHandler)]
}; };
}; }
Server.prototype._mount = function(op, name, argv, notDN) { Server.prototype._mount = function(op, name, argv, notDN) {