handle objectclass as lower case vals in add/search, error handling cleanup and some minor fixes

This commit is contained in:
Mark Cavage 2011-09-15 14:49:00 -07:00
parent 0e77b69dc0
commit fcec8d626f
9 changed files with 36 additions and 17 deletions

View File

@ -160,7 +160,7 @@ function Client(options) {
});
c.on('connect', function() {
c.ldap.connected = true;
c.ldap.id += ':' + (c.type !== 'unix' ? c.remotePort : c.fd);
c.ldap.id += ':' + c.fd;
self.emit('connect', c.ldap.id);
});
c.on('end', function() {

View File

@ -27,7 +27,7 @@ var CODES = {
LDAP_INAPPROPRIATE_MATCHING: 18,
LDAP_CONSTRAINT_VIOLATION: 19,
LDAP_ATTRIBUTE_OR_VALUE_EXISTS: 20,
LDAP_INVALID_ATTRIUBTE_SYNTAX: 21,
LDAP_INVALID_ATTRIBUTE_SYNTAX: 21,
LDAP_NO_SUCH_OBJECT: 32,
LDAP_ALIAS_PROBLEM: 33,
LDAP_INVALID_DN_SYNTAX: 34,

View File

@ -70,6 +70,9 @@ EqualityFilter.prototype.parse = function(ber) {
this.attribute = ber.readString().toLowerCase();
this.value = ber.readString();
if (this.attribute === 'objectclass')
this.value = this.value.toLowerCase();
return true;
};

View File

@ -94,12 +94,19 @@ SubstringFilter.prototype.parse = function(ber) {
switch (tag) {
case 0x80: // Initial
this.initial = ber.readString(tag);
if (this.attribute === 'objectclass')
this.initial = this.initial.toLowerCase();
break;
case 0x81: // Any
this.any.push(ber.readString(tag));
var anyVal = ber.readString(tag);
if (this.attribute === 'objectclass')
anyVal = anyVal.toLowerCase();
this.any.push(anyVal);
break;
case 0x82: // Final
this['final'] = ber.readString(tag);
if (this.attribute === 'objectclass')
this['final'] = this['final'].toLowerCase();
break;
default:
throw new Error('Invalid substrings filter type: 0x' + tag.toString(16));

View File

@ -67,6 +67,7 @@ module.exports = {
log4js: logStub,
parseURL: url.parse,
url: url,
loadSchema: schema.load,
createSchemaAddHandler: schema.createAddHandler,

View File

@ -63,6 +63,10 @@ AddRequest.prototype._parse = function(ber) {
while (ber.offset < end) {
var a = new Attribute();
a.parse(ber);
if (a.type === 'objectclass') {
for (var i = 0; i < a.vals.length; i++)
a.vals[i] = a.vals[i].toLowerCase();
}
this.attributes.push(a);
}

View File

@ -25,6 +25,8 @@ var SearchEntry = require('./search_entry');
var SearchResponse = require('./search_response');
var UnbindRequest = require('./unbind_request');
var UnbindResponse = require('./unbind_response');
var LDAPResult = require('./result');
var Message = require('./message');
var Protocol = require('../protocol');
@ -90,19 +92,14 @@ Parser.prototype.write = function(data) {
data = data.slice(0, ber.length);
}
if (!this._message.parse(data, ber.length))
this.emit('protocolError', new Error('TODO'));
assert.ok(this._message.parse(data, ber.length));
var message = this._message;
this._reset();
this.emit('message', message);
} catch (e) {
if (e.name === 'InvalidAsn1Error') {
self.emit('protocolError', e, self._message);
} else {
self.emit('error', e);
}
self.emit('error', e, self._message);
return false;
}
@ -224,7 +221,9 @@ Parser.prototype._newMessage = function(ber) {
default:
var e = new Error('protocolOp 0x' + type.toString(16) + ' not supported');
this.emit('protocolError', e, messageID);
this.emit('error', e, new LDAPResult({
messageID: messageID
}));
this._reset();
return false;
}

View File

@ -50,6 +50,8 @@ function LDAPResult(options) {
this.errorMessage = options.errorMessage || '';
this.referrals = options.referrals || [];
this.connection = options.connection || null;
this.__defineGetter__('type', function() { return 'LDAPResult'; });
}
util.inherits(LDAPResult, LDAPMessage);

View File

@ -21,6 +21,7 @@ var BindResponse = require('./messages/bind_response');
var CompareResponse = require('./messages/compare_response');
var DeleteResponse = require('./messages/del_response');
var ExtendedResponse = require('./messages/ext_response');
var LDAPResult = require('./messages/result');
var ModifyResponse = require('./messages/modify_response');
var ModifyDNResponse = require('./messages/moddn_response');
var SearchRequest = require('./messages/search_request');
@ -372,15 +373,17 @@ function Server(options) {
}();
});
c.parser.on('protocolError', function(err, messageID) {
log.warn('%s sent invalid protocol message', c.ldap.id, err);
c.destroy();
});
c.parser.on('error', function(err) {
c.parser.on('error', function(err, message) {
log.error('Exception happened parsing for %s: %s',
c.ldap.id, err.stack);
c.destroy();
var res = getResponse(message);
res.status = 0x02; // protocol error
res.errorMessage = err.toString();
c.end(res.toBer());
});
c.on('data', function(data) {
if (log.isTraceEnabled())
log.trace('data on %s: %s', c.ldap.id, util.inspect(data));