Minor cleanup of server handling and null DNs
This commit is contained in:
parent
75aba691f1
commit
28ddaaad69
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue