diff --git a/lib/client.js b/lib/client.js index 92b2793..bd3c069 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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() { diff --git a/lib/errors/index.js b/lib/errors/index.js index d3f1584..43e5877 100644 --- a/lib/errors/index.js +++ b/lib/errors/index.js @@ -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, diff --git a/lib/filters/equality_filter.js b/lib/filters/equality_filter.js index c267f46..f8999fd 100644 --- a/lib/filters/equality_filter.js +++ b/lib/filters/equality_filter.js @@ -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; }; diff --git a/lib/filters/substr_filter.js b/lib/filters/substr_filter.js index 31ed374..e0a29f6 100644 --- a/lib/filters/substr_filter.js +++ b/lib/filters/substr_filter.js @@ -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)); diff --git a/lib/index.js b/lib/index.js index b067445..a3cb425 100644 --- a/lib/index.js +++ b/lib/index.js @@ -67,6 +67,7 @@ module.exports = { log4js: logStub, parseURL: url.parse, + url: url, loadSchema: schema.load, createSchemaAddHandler: schema.createAddHandler, diff --git a/lib/messages/add_request.js b/lib/messages/add_request.js index 344830d..0a73e5e 100644 --- a/lib/messages/add_request.js +++ b/lib/messages/add_request.js @@ -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); } diff --git a/lib/messages/parser.js b/lib/messages/parser.js index 75ba272..f75670b 100644 --- a/lib/messages/parser.js +++ b/lib/messages/parser.js @@ -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; } diff --git a/lib/messages/result.js b/lib/messages/result.js index 1d31e4e..a672080 100644 --- a/lib/messages/result.js +++ b/lib/messages/result.js @@ -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); diff --git a/lib/server.js b/lib/server.js index 7cafdc6..69f62ca 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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));