From cb707764454d99974dcb6602f64d50b4d679bb8c Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 5 Jun 2022 22:01:40 -0400 Subject: [PATCH] Replace protocol with module (#806) --- lib/attribute.js | 8 +-- lib/change.js | 1 - lib/client/client.js | 4 +- lib/client/search_pager.js | 1 - lib/filters/filter.js | 22 ++++---- lib/filters/index.js | 22 ++++---- lib/index.js | 2 +- lib/messages/abandon_request.js | 4 +- lib/messages/abandon_response.js | 1 - lib/messages/add_request.js | 4 +- lib/messages/add_response.js | 4 +- lib/messages/bind_request.js | 4 +- lib/messages/bind_response.js | 4 +- lib/messages/compare_request.js | 4 +- lib/messages/compare_response.js | 4 +- lib/messages/del_request.js | 4 +- lib/messages/del_response.js | 4 +- lib/messages/ext_request.js | 4 +- lib/messages/ext_response.js | 4 +- lib/messages/message.js | 1 - lib/messages/moddn_request.js | 4 +- lib/messages/moddn_response.js | 4 +- lib/messages/modify_request.js | 4 +- lib/messages/modify_response.js | 4 +- lib/messages/parser.js | 44 ++++++++-------- lib/messages/result.js | 6 +-- lib/messages/search_entry.js | 4 +- lib/messages/search_reference.js | 4 +- lib/messages/search_request.js | 18 +++---- lib/messages/search_response.js | 4 +- lib/messages/unbind_request.js | 4 +- lib/messages/unbind_response.js | 1 - lib/protocol.js | 53 -------------------- lib/server.js | 86 ++++++++++++++++---------------- package.json | 1 + 35 files changed, 145 insertions(+), 202 deletions(-) delete mode 100644 lib/protocol.js diff --git a/lib/attribute.js b/lib/attribute.js index 2792296..235cc05 100644 --- a/lib/attribute.js +++ b/lib/attribute.js @@ -4,7 +4,7 @@ const assert = require('assert') const asn1 = require('@ldapjs/asn1') -const Protocol = require('./protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -96,8 +96,8 @@ Attribute.prototype.parse = function parse (ber) { ber.readSequence() this.type = ber.readString() - if (ber.peek() === Protocol.LBER_SET) { - if (ber.readSequence(Protocol.LBER_SET)) { + if (ber.peek() === Protocol.core.LBER_SET) { + if (ber.readSequence(Protocol.core.LBER_SET)) { const end = ber.offset + ber.length while (ber.offset < end) { this._vals.push(ber.readString(asn1.Ber.OctetString, true)) } } @@ -111,7 +111,7 @@ Attribute.prototype.toBer = function toBer (ber) { ber.startSequence() ber.writeString(this.type) - ber.startSequence(Protocol.LBER_SET) + ber.startSequence(Protocol.core.LBER_SET) if (this._vals.length) { this._vals.forEach(function (b) { ber.writeByte(asn1.Ber.OctetString) diff --git a/lib/change.js b/lib/change.js index 6f45dbe..80cf83f 100644 --- a/lib/change.js +++ b/lib/change.js @@ -3,7 +3,6 @@ const assert = require('assert-plus') const Attribute = require('./attribute') -// var Protocol = require('./protocol') /// --- API diff --git a/lib/client/client.js b/lib/client/client.js index b48132e..55aa2af 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -20,7 +20,7 @@ const Change = require('../change') const Control = require('../controls/index').Control const { Control: LdapControl } = require('@ldapjs/controls') const SearchPager = require('./search_pager') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const dn = require('../dn') const errors = require('../errors') const filters = require('../filters') @@ -601,7 +601,7 @@ Client.prototype.search = function search (base, baseObject: baseDN, scope: options.scope || 'base', filter: options.filter, - derefAliases: options.derefAliases || Protocol.NEVER_DEREF_ALIASES, + derefAliases: options.derefAliases || Protocol.search.NEVER_DEREF_ALIASES, sizeLimit: options.sizeLimit || 0, timeLimit: options.timeLimit || 10, typesOnly: options.typesOnly || false, diff --git a/lib/client/search_pager.js b/lib/client/search_pager.js index 6e7d498..81b68a0 100644 --- a/lib/client/search_pager.js +++ b/lib/client/search_pager.js @@ -7,7 +7,6 @@ const assert = require('assert-plus') // var dn = require('../dn') // var messages = require('../messages/index') -// var Protocol = require('../protocol') const { PagedResultsControl } = require('@ldapjs/controls') const CorkedEmitter = require('../corked_emitter.js') diff --git a/lib/filters/filter.js b/lib/filters/filter.js index bfd193c..7327c6a 100644 --- a/lib/filters/filter.js +++ b/lib/filters/filter.js @@ -2,21 +2,21 @@ // var assert = require('assert') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals const TYPES = { - and: Protocol.FILTER_AND, - or: Protocol.FILTER_OR, - not: Protocol.FILTER_NOT, - equal: Protocol.FILTER_EQUALITY, - substring: Protocol.FILTER_SUBSTRINGS, - ge: Protocol.FILTER_GE, - le: Protocol.FILTER_LE, - present: Protocol.FILTER_PRESENT, - approx: Protocol.FILTER_APPROX, - ext: Protocol.FILTER_EXT + and: Protocol.search.FILTER_AND, + or: Protocol.search.FILTER_OR, + not: Protocol.search.FILTER_NOT, + equal: Protocol.search.FILTER_EQUALITY, + substring: Protocol.search.FILTER_SUBSTRINGS, + ge: Protocol.search.FILTER_GE, + le: Protocol.search.FILTER_LE, + present: Protocol.search.FILTER_PRESENT, + approx: Protocol.search.FILTER_APPROX, + ext: Protocol.search.FILTER_EXT } /// --- API diff --git a/lib/filters/index.js b/lib/filters/index.js index 6fd8d52..7cbe9eb 100644 --- a/lib/filters/index.js +++ b/lib/filters/index.js @@ -6,7 +6,7 @@ const asn1 = require('@ldapjs/asn1') const parents = require('ldap-filter') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const Filter = require('./filter') const AndFilter = require('./and_filter') @@ -71,53 +71,53 @@ function _parse (ber) { const type = ber.readSequence() switch (type) { - case Protocol.FILTER_AND: + case Protocol.search.FILTER_AND: f = new AndFilter() parseSet(f) break - case Protocol.FILTER_APPROX: + case Protocol.search.FILTER_APPROX: f = new ApproximateFilter() f.parse(ber) break - case Protocol.FILTER_EQUALITY: + case Protocol.search.FILTER_EQUALITY: f = new EqualityFilter() f.parse(ber) return f - case Protocol.FILTER_EXT: + case Protocol.search.FILTER_EXT: f = new ExtensibleFilter() f.parse(ber) return f - case Protocol.FILTER_GE: + case Protocol.search.FILTER_GE: f = new GreaterThanEqualsFilter() f.parse(ber) return f - case Protocol.FILTER_LE: + case Protocol.search.FILTER_LE: f = new LessThanEqualsFilter() f.parse(ber) return f - case Protocol.FILTER_NOT: + case Protocol.search.FILTER_NOT: f = new NotFilter({ filter: _parse(ber) }) break - case Protocol.FILTER_OR: + case Protocol.search.FILTER_OR: f = new OrFilter() parseSet(f) break - case Protocol.FILTER_PRESENT: + case Protocol.search.FILTER_PRESENT: f = new PresenceFilter() f.parse(ber) break - case Protocol.FILTER_SUBSTRINGS: + case Protocol.search.FILTER_SUBSTRINGS: f = new SubstringFilter() f.parse(ber) break diff --git a/lib/index.js b/lib/index.js index 13664db..e6941f6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,7 +5,7 @@ const logger = require('./logger') const client = require('./client') const Attribute = require('./attribute') const Change = require('./change') -const Protocol = require('./protocol') +const Protocol = require('@ldapjs/protocol') const Server = require('./server') const controls = require('./controls') diff --git a/lib/messages/abandon_request.js b/lib/messages/abandon_request.js index 184164c..0895f16 100644 --- a/lib/messages/abandon_request.js +++ b/lib/messages/abandon_request.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -13,7 +13,7 @@ function AbandonRequest (options) { assert.object(options) assert.optionalNumber(options.abandonID) - options.protocolOp = Protocol.LDAP_REQ_ABANDON + options.protocolOp = Protocol.operations.LDAP_REQ_ABANDON LDAPMessage.call(this, options) this.abandonID = options.abandonID || 0 diff --git a/lib/messages/abandon_response.js b/lib/messages/abandon_response.js index aa3fbc8..1659179 100644 --- a/lib/messages/abandon_response.js +++ b/lib/messages/abandon_response.js @@ -4,7 +4,6 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./result') -// var Protocol = require('../protocol') /// --- API diff --git a/lib/messages/add_request.js b/lib/messages/add_request.js index 2677a01..cc8c56c 100644 --- a/lib/messages/add_request.js +++ b/lib/messages/add_request.js @@ -5,7 +5,7 @@ const util = require('util') const LDAPMessage = require('./message') const Attribute = require('../attribute') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const lassert = require('../assert') /// --- API @@ -16,7 +16,7 @@ function AddRequest (options) { lassert.optionalStringDN(options.entry) lassert.optionalArrayOfAttribute(options.attributes) - options.protocolOp = Protocol.LDAP_REQ_ADD + options.protocolOp = Protocol.operations.LDAP_REQ_ADD LDAPMessage.call(this, options) this.entry = options.entry || null diff --git a/lib/messages/add_response.js b/lib/messages/add_response.js index 31265cd..3cfac98 100644 --- a/lib/messages/add_response.js +++ b/lib/messages/add_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function AddResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_ADD + options.protocolOp = Protocol.operations.LDAP_RES_ADD LDAPResult.call(this, options) } util.inherits(AddResponse, LDAPResult) diff --git a/lib/messages/bind_request.js b/lib/messages/bind_request.js index eb33e8f..993e1d6 100644 --- a/lib/messages/bind_request.js +++ b/lib/messages/bind_request.js @@ -6,7 +6,7 @@ const util = require('util') const asn1 = require('@ldapjs/asn1') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals @@ -20,7 +20,7 @@ function BindRequest (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REQ_BIND + options.protocolOp = Protocol.operations.LDAP_REQ_BIND LDAPMessage.call(this, options) this.version = options.version || 0x03 diff --git a/lib/messages/bind_response.js b/lib/messages/bind_response.js index de4f078..af51709 100644 --- a/lib/messages/bind_response.js +++ b/lib/messages/bind_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function BindResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_BIND + options.protocolOp = Protocol.operations.LDAP_RES_BIND LDAPResult.call(this, options) } util.inherits(BindResponse, LDAPResult) diff --git a/lib/messages/compare_request.js b/lib/messages/compare_request.js index bd8c24f..b66ac89 100644 --- a/lib/messages/compare_request.js +++ b/lib/messages/compare_request.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const lassert = require('../assert') /// --- API @@ -16,7 +16,7 @@ function CompareRequest (options) { assert.optionalString(options.value) lassert.optionalStringDN(options.entry) - options.protocolOp = Protocol.LDAP_REQ_COMPARE + options.protocolOp = Protocol.operations.LDAP_REQ_COMPARE LDAPMessage.call(this, options) this.entry = options.entry || null diff --git a/lib/messages/compare_response.js b/lib/messages/compare_response.js index 5b75667..7852411 100644 --- a/lib/messages/compare_response.js +++ b/lib/messages/compare_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function CompareResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_COMPARE + options.protocolOp = Protocol.operations.LDAP_RES_COMPARE LDAPResult.call(this, options) } util.inherits(CompareResponse, LDAPResult) diff --git a/lib/messages/del_request.js b/lib/messages/del_request.js index 678f213..b932c93 100644 --- a/lib/messages/del_request.js +++ b/lib/messages/del_request.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const lassert = require('../assert') /// --- API @@ -14,7 +14,7 @@ function DeleteRequest (options) { assert.object(options) lassert.optionalStringDN(options.entry) - options.protocolOp = Protocol.LDAP_REQ_DELETE + options.protocolOp = Protocol.operations.LDAP_REQ_DELETE LDAPMessage.call(this, options) this.entry = options.entry || null diff --git a/lib/messages/del_response.js b/lib/messages/del_response.js index 92d130f..3af01c5 100644 --- a/lib/messages/del_response.js +++ b/lib/messages/del_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function DeleteResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_DELETE + options.protocolOp = Protocol.operations.LDAP_RES_DELETE LDAPResult.call(this, options) } util.inherits(DeleteResponse, LDAPResult) diff --git a/lib/messages/ext_request.js b/lib/messages/ext_request.js index a8d6c63..24459e8 100644 --- a/lib/messages/ext_request.js +++ b/lib/messages/ext_request.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -18,7 +18,7 @@ function ExtendedRequest (options) { throw new TypeError('options.requestValue must be a buffer or a string') } - options.protocolOp = Protocol.LDAP_REQ_EXTENSION + options.protocolOp = Protocol.operations.LDAP_REQ_EXTENSION LDAPMessage.call(this, options) this.requestName = options.requestName || '' diff --git a/lib/messages/ext_response.js b/lib/messages/ext_response.js index 3f8f183..9e5d8df 100644 --- a/lib/messages/ext_response.js +++ b/lib/messages/ext_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -17,7 +17,7 @@ function ExtendedResponse (options) { this.responseName = options.responseName || undefined this.responseValue = options.responseValue || undefined - options.protocolOp = Protocol.LDAP_REP_EXTENSION + options.protocolOp = Protocol.operations.LDAP_RES_EXTENSION LDAPResult.call(this, options) } util.inherits(ExtendedResponse, LDAPResult) diff --git a/lib/messages/message.js b/lib/messages/message.js index cbdf4ff..fecf143 100644 --- a/lib/messages/message.js +++ b/lib/messages/message.js @@ -7,7 +7,6 @@ const asn1 = require('@ldapjs/asn1') const logger = require('../logger') // var Control = require('../controls').Control -// var Protocol = require('../protocol') /// --- Globals diff --git a/lib/messages/moddn_request.js b/lib/messages/moddn_request.js index 0f54823..7358718 100644 --- a/lib/messages/moddn_request.js +++ b/lib/messages/moddn_request.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const dn = require('../dn') const lassert = require('../assert') @@ -18,7 +18,7 @@ function ModifyDNRequest (options) { lassert.optionalDN(options.newRdn) lassert.optionalDN(options.newSuperior) - options.protocolOp = Protocol.LDAP_REQ_MODRDN + options.protocolOp = Protocol.operations.LDAP_REQ_MODRDN LDAPMessage.call(this, options) this.entry = options.entry || null diff --git a/lib/messages/moddn_response.js b/lib/messages/moddn_response.js index 99ecaae..ad93b49 100644 --- a/lib/messages/moddn_response.js +++ b/lib/messages/moddn_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function ModifyDNResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_MODRDN + options.protocolOp = Protocol.operations.LDAP_RES_MODRDN LDAPResult.call(this, options) } util.inherits(ModifyDNResponse, LDAPResult) diff --git a/lib/messages/modify_request.js b/lib/messages/modify_request.js index 03da309..f724305 100644 --- a/lib/messages/modify_request.js +++ b/lib/messages/modify_request.js @@ -5,7 +5,7 @@ const util = require('util') const LDAPMessage = require('./message') const Change = require('../change') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const lassert = require('../assert') /// --- API @@ -16,7 +16,7 @@ function ModifyRequest (options) { lassert.optionalStringDN(options.object) lassert.optionalArrayOfAttribute(options.attributes) - options.protocolOp = Protocol.LDAP_REQ_MODIFY + options.protocolOp = Protocol.operations.LDAP_REQ_MODIFY LDAPMessage.call(this, options) this.object = options.object || null diff --git a/lib/messages/modify_response.js b/lib/messages/modify_response.js index ba6fef0..78aaad4 100644 --- a/lib/messages/modify_response.js +++ b/lib/messages/modify_response.js @@ -4,7 +4,7 @@ const assert = require('assert-plus') const util = require('util') const LDAPResult = require('./result') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -12,7 +12,7 @@ function ModifyResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_MODIFY + options.protocolOp = Protocol.operations.LDAP_RES_MODIFY LDAPResult.call(this, options) } util.inherits(ModifyResponse, LDAPResult) diff --git a/lib/messages/parser.js b/lib/messages/parser.js index 04ac82c..170fc28 100644 --- a/lib/messages/parser.js +++ b/lib/messages/parser.js @@ -33,7 +33,7 @@ const UnbindRequest = require('./unbind_request') const LDAPResult = require('./result') // var Message = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals @@ -118,83 +118,83 @@ Parser.prototype.getMessage = function (ber) { let Message switch (type) { - case Protocol.LDAP_REQ_ABANDON: + case Protocol.operations.LDAP_REQ_ABANDON: Message = AbandonRequest break - case Protocol.LDAP_REQ_ADD: + case Protocol.operations.LDAP_REQ_ADD: Message = AddRequest break - case Protocol.LDAP_REP_ADD: + case Protocol.operations.LDAP_RES_ADD: Message = AddResponse break - case Protocol.LDAP_REQ_BIND: + case Protocol.operations.LDAP_REQ_BIND: Message = BindRequest break - case Protocol.LDAP_REP_BIND: + case Protocol.operations.LDAP_RES_BIND: Message = BindResponse break - case Protocol.LDAP_REQ_COMPARE: + case Protocol.operations.LDAP_REQ_COMPARE: Message = CompareRequest break - case Protocol.LDAP_REP_COMPARE: + case Protocol.operations.LDAP_RES_COMPARE: Message = CompareResponse break - case Protocol.LDAP_REQ_DELETE: + case Protocol.operations.LDAP_REQ_DELETE: Message = DeleteRequest break - case Protocol.LDAP_REP_DELETE: + case Protocol.operations.LDAP_RES_DELETE: Message = DeleteResponse break - case Protocol.LDAP_REQ_EXTENSION: + case Protocol.operations.LDAP_REQ_EXTENSION: Message = ExtendedRequest break - case Protocol.LDAP_REP_EXTENSION: + case Protocol.operations.LDAP_RES_EXTENSION: Message = ExtendedResponse break - case Protocol.LDAP_REQ_MODIFY: + case Protocol.operations.LDAP_REQ_MODIFY: Message = ModifyRequest break - case Protocol.LDAP_REP_MODIFY: + case Protocol.operations.LDAP_RES_MODIFY: Message = ModifyResponse break - case Protocol.LDAP_REQ_MODRDN: + case Protocol.operations.LDAP_REQ_MODRDN: Message = ModifyDNRequest break - case Protocol.LDAP_REP_MODRDN: + case Protocol.operations.LDAP_RES_MODRDN: Message = ModifyDNResponse break - case Protocol.LDAP_REQ_SEARCH: + case Protocol.operations.LDAP_REQ_SEARCH: Message = SearchRequest break - case Protocol.LDAP_REP_SEARCH_ENTRY: + case Protocol.operations.LDAP_RES_SEARCH_ENTRY: Message = SearchEntry break - case Protocol.LDAP_REP_SEARCH_REF: + case Protocol.operations.LDAP_RES_SEARCH_REF: Message = SearchReference break - case Protocol.LDAP_REP_SEARCH: + case Protocol.operations.LDAP_RES_SEARCH: Message = SearchResponse break - case Protocol.LDAP_REQ_UNBIND: + case Protocol.operations.LDAP_REQ_UNBIND: Message = UnbindRequest break @@ -204,7 +204,7 @@ Parser.prototype.getMessage = function (ber) { ' not supported'), new LDAPResult({ messageID: messageID, - protocolOp: type || Protocol.LDAP_REP_EXTENSION + protocolOp: type || Protocol.operations.LDAP_RES_EXTENSION })) return false diff --git a/lib/messages/result.js b/lib/messages/result.js index 3ae8b56..53a00c5 100644 --- a/lib/messages/result.js +++ b/lib/messages/result.js @@ -7,7 +7,7 @@ const util = require('util') const dtrace = require('../dtrace') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals @@ -81,7 +81,7 @@ LDAPResult.prototype._parse = function (ber) { const t = ber.peek() - if (t === Protocol.LDAP_REP_REFERRAL) { + if (t === Protocol.operations.LDAP_RES_REFERRAL) { const end = ber.offset + ber.length while (ber.offset < end) { this.referrals.push(ber.readString()) } } @@ -97,7 +97,7 @@ LDAPResult.prototype._toBer = function (ber) { ber.writeString(this.errorMessage || '') if (this.referrals.length) { - ber.startSequence(Protocol.LDAP_REP_REFERRAL) + ber.startSequence(Protocol.operations.LDAP_RES_REFERRAL) ber.writeStringArray(this.referrals) ber.endSequence() } diff --git a/lib/messages/search_entry.js b/lib/messages/search_entry.js index 7d24dbf..1ba74d2 100644 --- a/lib/messages/search_entry.js +++ b/lib/messages/search_entry.js @@ -7,7 +7,7 @@ const util = require('util') const LDAPMessage = require('./message') const Attribute = require('../attribute') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const lassert = require('../assert') /// --- Globals @@ -21,7 +21,7 @@ function SearchEntry (options) { assert.object(options) lassert.optionalStringDN(options.objectName) - options.protocolOp = Protocol.LDAP_REP_SEARCH_ENTRY + options.protocolOp = Protocol.operations.LDAP_RES_SEARCH_ENTRY LDAPMessage.call(this, options) this.objectName = options.objectName || null diff --git a/lib/messages/search_reference.js b/lib/messages/search_reference.js index 6c9bad2..e10351a 100644 --- a/lib/messages/search_reference.js +++ b/lib/messages/search_reference.js @@ -6,7 +6,7 @@ const util = require('util') // var asn1 = require('@ldapjs/asn1') const LDAPMessage = require('./message') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') const dn = require('../dn') const url = require('../url') @@ -21,7 +21,7 @@ function SearchReference (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_SEARCH_REF + options.protocolOp = Protocol.operations.LDAP_RES_SEARCH_REF LDAPMessage.call(this, options) this.uris = options.uris || [] diff --git a/lib/messages/search_request.js b/lib/messages/search_request.js index fb6c1b9..e8fd345 100644 --- a/lib/messages/search_request.js +++ b/lib/messages/search_request.js @@ -9,7 +9,7 @@ const LDAPMessage = require('./message') // var LDAPResult = require('./result') const dn = require('../dn') const filters = require('../filters') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals @@ -21,7 +21,7 @@ function SearchRequest (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REQ_SEARCH + options.protocolOp = Protocol.operations.LDAP_REQ_SEARCH LDAPMessage.call(this, options) if (options.baseObject !== undefined) { @@ -30,7 +30,7 @@ function SearchRequest (options) { this.baseObject = dn.parse('') } this.scope = options.scope || 'base' - this.derefAliases = options.derefAliases || Protocol.NEVER_DEREF_ALIASES + this.derefAliases = options.derefAliases || Protocol.search.NEVER_DEREF_ALIASES this.sizeLimit = options.sizeLimit || 0 this.timeLimit = options.timeLimit || 0 this.typesOnly = options.typesOnly || false @@ -50,9 +50,9 @@ Object.defineProperties(SearchRequest.prototype, { scope: { get: function getScope () { switch (this._scope) { - case Protocol.SCOPE_BASE_OBJECT: return 'base' - case Protocol.SCOPE_ONE_LEVEL: return 'one' - case Protocol.SCOPE_SUBTREE: return 'sub' + case Protocol.search.SCOPE_BASE_OBJECT: return 'base' + case Protocol.search.SCOPE_ONE_LEVEL: return 'one' + case Protocol.search.SCOPE_SUBTREE: return 'sub' default: throw new Error(this._scope + ' is an invalid search scope') } @@ -61,13 +61,13 @@ Object.defineProperties(SearchRequest.prototype, { if (typeof (val) === 'string') { switch (val) { case 'base': - this._scope = Protocol.SCOPE_BASE_OBJECT + this._scope = Protocol.search.SCOPE_BASE_OBJECT break case 'one': - this._scope = Protocol.SCOPE_ONE_LEVEL + this._scope = Protocol.search.SCOPE_ONE_LEVEL break case 'sub': - this._scope = Protocol.SCOPE_SUBTREE + this._scope = Protocol.search.SCOPE_SUBTREE break default: throw new Error(val + ' is an invalid search scope') diff --git a/lib/messages/search_response.js b/lib/messages/search_response.js index 77edc7b..4b8f99f 100644 --- a/lib/messages/search_response.js +++ b/lib/messages/search_response.js @@ -10,7 +10,7 @@ const SearchReference = require('./search_reference') const dtrace = require('../dtrace') const parseDN = require('../dn').parse const parseURL = require('../url').parse -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- API @@ -18,7 +18,7 @@ function SearchResponse (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REP_SEARCH + options.protocolOp = Protocol.operations.LDAP_RES_SEARCH LDAPResult.call(this, options) this.attributes = options.attributes ? options.attributes.slice() : [] diff --git a/lib/messages/unbind_request.js b/lib/messages/unbind_request.js index 10326e2..37a2092 100644 --- a/lib/messages/unbind_request.js +++ b/lib/messages/unbind_request.js @@ -5,7 +5,7 @@ const util = require('util') const LDAPMessage = require('./message') const dn = require('../dn') -const Protocol = require('../protocol') +const Protocol = require('@ldapjs/protocol') /// --- Globals @@ -18,7 +18,7 @@ function UnbindRequest (options) { options = options || {} assert.object(options) - options.protocolOp = Protocol.LDAP_REQ_UNBIND + options.protocolOp = Protocol.operations.LDAP_REQ_UNBIND LDAPMessage.call(this, options) } util.inherits(UnbindRequest, LDAPMessage) diff --git a/lib/messages/unbind_response.js b/lib/messages/unbind_response.js index 3317984..bf42f93 100644 --- a/lib/messages/unbind_response.js +++ b/lib/messages/unbind_response.js @@ -6,7 +6,6 @@ const util = require('util') const dtrace = require('../dtrace') const LDAPMessage = require('./result') -// var Protocol = require('../protocol') /// --- API // Ok, so there's really no such thing as an unbind 'response', but to make diff --git a/lib/protocol.js b/lib/protocol.js deleted file mode 100644 index 5b7927d..0000000 --- a/lib/protocol.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2011 Mark Cavage, Inc. All rights reserved. - -module.exports = { - - // Misc - LDAP_VERSION_3: 0x03, - LBER_SET: 0x31, - LDAP_CONTROLS: 0xa0, - - // Search - SCOPE_BASE_OBJECT: 0, - SCOPE_ONE_LEVEL: 1, - SCOPE_SUBTREE: 2, - - NEVER_DEREF_ALIASES: 0, - DEREF_IN_SEARCHING: 1, - DEREF_BASE_OBJECT: 2, - DEREF_ALWAYS: 3, - - FILTER_AND: 0xa0, - FILTER_OR: 0xa1, - FILTER_NOT: 0xa2, - FILTER_EQUALITY: 0xa3, - FILTER_SUBSTRINGS: 0xa4, - FILTER_GE: 0xa5, - FILTER_LE: 0xa6, - FILTER_PRESENT: 0x87, - FILTER_APPROX: 0xa8, - FILTER_EXT: 0xa9, - - // Protocol Operations - LDAP_REQ_BIND: 0x60, - LDAP_REQ_UNBIND: 0x42, - LDAP_REQ_SEARCH: 0x63, - LDAP_REQ_MODIFY: 0x66, - LDAP_REQ_ADD: 0x68, - LDAP_REQ_DELETE: 0x4a, - LDAP_REQ_MODRDN: 0x6c, - LDAP_REQ_COMPARE: 0x6e, - LDAP_REQ_ABANDON: 0x50, - LDAP_REQ_EXTENSION: 0x77, - - LDAP_REP_BIND: 0x61, - LDAP_REP_SEARCH_ENTRY: 0x64, - LDAP_REP_SEARCH_REF: 0x73, - LDAP_REP_SEARCH: 0x65, - LDAP_REP_MODIFY: 0x67, - LDAP_REP_ADD: 0x69, - LDAP_REP_DELETE: 0x6b, - LDAP_REP_MODRDN: 0x6d, - LDAP_REP_COMPARE: 0x6f, - LDAP_REP_EXTENSION: 0x78 -} diff --git a/lib/server.js b/lib/server.js index 3601227..4d09e0c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -12,7 +12,7 @@ const VError = require('verror').VError const dn = require('./dn') const dtrace = require('./dtrace') const errors = require('./errors') -const Protocol = require('./protocol') +const Protocol = require('@ldapjs/protocol') const Parser = require('./messages').Parser const AbandonResponse = require('./messages/abandon_response') @@ -71,34 +71,34 @@ function getResponse (req) { let Response switch (req.protocolOp) { - case Protocol.LDAP_REQ_BIND: + case Protocol.operations.LDAP_REQ_BIND: Response = BindResponse break - case Protocol.LDAP_REQ_ABANDON: + case Protocol.operations.LDAP_REQ_ABANDON: Response = AbandonResponse break - case Protocol.LDAP_REQ_ADD: + case Protocol.operations.LDAP_REQ_ADD: Response = AddResponse break - case Protocol.LDAP_REQ_COMPARE: + case Protocol.operations.LDAP_REQ_COMPARE: Response = CompareResponse break - case Protocol.LDAP_REQ_DELETE: + case Protocol.operations.LDAP_REQ_DELETE: Response = DeleteResponse break - case Protocol.LDAP_REQ_EXTENSION: + case Protocol.operations.LDAP_REQ_EXTENSION: Response = ExtendedResponse break - case Protocol.LDAP_REQ_MODIFY: + case Protocol.operations.LDAP_REQ_MODIFY: Response = ModifyResponse break - case Protocol.LDAP_REQ_MODRDN: + case Protocol.operations.LDAP_REQ_MODRDN: Response = ModifyDNResponse break - case Protocol.LDAP_REQ_SEARCH: + case Protocol.operations.LDAP_REQ_SEARCH: Response = SearchResponse break - case Protocol.LDAP_REQ_UNBIND: + case Protocol.operations.LDAP_REQ_UNBIND: Response = UnbindResponse break default: @@ -170,44 +170,44 @@ function fireDTraceProbe (req, res) { let op switch (req.protocolOp) { - case Protocol.LDAP_REQ_ABANDON: + case Protocol.operations.LDAP_REQ_ABANDON: op = 'abandon' break - case Protocol.LDAP_REQ_ADD: + case Protocol.operations.LDAP_REQ_ADD: op = 'add' probeArgs.push(req.attributes.length) break - case Protocol.LDAP_REQ_BIND: + case Protocol.operations.LDAP_REQ_BIND: op = 'bind' break - case Protocol.LDAP_REQ_COMPARE: + case Protocol.operations.LDAP_REQ_COMPARE: op = 'compare' probeArgs.push(req.attribute) probeArgs.push(req.value) break - case Protocol.LDAP_REQ_DELETE: + case Protocol.operations.LDAP_REQ_DELETE: op = 'delete' break - case Protocol.LDAP_REQ_EXTENSION: + case Protocol.operations.LDAP_REQ_EXTENSION: op = 'exop' probeArgs.push(req.name) probeArgs.push(req.value) break - case Protocol.LDAP_REQ_MODIFY: + case Protocol.operations.LDAP_REQ_MODIFY: op = 'modify' probeArgs.push(req.changes.length) break - case Protocol.LDAP_REQ_MODRDN: + case Protocol.operations.LDAP_REQ_MODRDN: op = 'modifydn' probeArgs.push(req.newRdn.toString()) probeArgs.push((req.newSuperior ? req.newSuperior.toString() : '')) break - case Protocol.LDAP_REQ_SEARCH: + case Protocol.operations.LDAP_REQ_SEARCH: op = 'search' probeArgs.push(req.scope) probeArgs.push(req.filter.toString()) break - case Protocol.LDAP_REQ_UNBIND: + case Protocol.operations.LDAP_REQ_UNBIND: op = 'unbind' break default: @@ -343,22 +343,22 @@ function Server (options) { // parse string DNs for routing/etc try { switch (req.protocolOp) { - case Protocol.LDAP_REQ_BIND: + case Protocol.operations.LDAP_REQ_BIND: req.name = dn.parse(req.name) break - case Protocol.LDAP_REQ_ADD: - case Protocol.LDAP_REQ_COMPARE: - case Protocol.LDAP_REQ_DELETE: + case Protocol.operations.LDAP_REQ_ADD: + case Protocol.operations.LDAP_REQ_COMPARE: + case Protocol.operations.LDAP_REQ_DELETE: req.entry = dn.parse(req.entry) break - case Protocol.LDAP_REQ_MODIFY: + case Protocol.operations.LDAP_REQ_MODIFY: req.object = dn.parse(req.object) break - case Protocol.LDAP_REQ_MODRDN: + case Protocol.operations.LDAP_REQ_MODRDN: req.entry = dn.parse(req.entry) // TODO: handle newRdn/Superior break - case Protocol.LDAP_REQ_SEARCH: + case Protocol.operations.LDAP_REQ_SEARCH: req.baseObject = dn.parse(req.baseObject) break default: @@ -406,7 +406,7 @@ function Server (options) { const next = messageIIFE if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) } - if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { + if (req.protocolOp === Protocol.operations.LDAP_REQ_BIND && res.status === 0) { // 0 length == anonymous bind if (req.dn.length === 0 && req.credentials === '') { conn.ldap.bindDN = new DN([new dn.RDN({ cn: 'anonymous' })]) @@ -417,7 +417,7 @@ function Server (options) { // unbind clear bindDN for safety // conn should terminate on unbind (RFC4511 4.3) - if (req.protocolOp === Protocol.LDAP_REQ_UNBIND && res.status === 0) { + if (req.protocolOp === Protocol.operations.LDAP_REQ_UNBIND && res.status === 0) { conn.ldap.bindDN = new DN([new dn.RDN({ cn: 'anonymous' })]) } @@ -536,7 +536,7 @@ module.exports = Server */ Server.prototype.add = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_ADD, name, args) + return this._mount(Protocol.operations.LDAP_REQ_ADD, name, args) } /** @@ -551,7 +551,7 @@ Server.prototype.add = function (name) { */ Server.prototype.bind = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_BIND, name, args) + return this._mount(Protocol.operations.LDAP_REQ_BIND, name, args) } /** @@ -566,7 +566,7 @@ Server.prototype.bind = function (name) { */ Server.prototype.compare = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_COMPARE, name, args) + return this._mount(Protocol.operations.LDAP_REQ_COMPARE, name, args) } /** @@ -581,7 +581,7 @@ Server.prototype.compare = function (name) { */ Server.prototype.del = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_DELETE, name, args) + return this._mount(Protocol.operations.LDAP_REQ_DELETE, name, args) } /** @@ -596,7 +596,7 @@ Server.prototype.del = function (name) { */ Server.prototype.exop = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_EXTENSION, name, args, true) + return this._mount(Protocol.operations.LDAP_REQ_EXTENSION, name, args, true) } /** @@ -611,7 +611,7 @@ Server.prototype.exop = function (name) { */ Server.prototype.modify = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_MODIFY, name, args) + return this._mount(Protocol.operations.LDAP_REQ_MODIFY, name, args) } /** @@ -626,7 +626,7 @@ Server.prototype.modify = function (name) { */ Server.prototype.modifyDN = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_MODRDN, name, args) + return this._mount(Protocol.operations.LDAP_REQ_MODRDN, name, args) } /** @@ -641,7 +641,7 @@ Server.prototype.modifyDN = function (name) { */ Server.prototype.search = function (name) { const args = Array.prototype.slice.call(arguments, 1) - return this._mount(Protocol.LDAP_REQ_SEARCH, name, args) + return this._mount(Protocol.operations.LDAP_REQ_SEARCH, name, args) } /** @@ -655,7 +655,7 @@ Server.prototype.search = function (name) { */ Server.prototype.unbind = function () { const args = Array.prototype.slice.call(arguments, 0) - return this._mount(Protocol.LDAP_REQ_UNBIND, 'unbind', args, true) + return this._mount(Protocol.operations.LDAP_REQ_UNBIND, 'unbind', args, true) } Server.prototype.use = function use () { @@ -787,7 +787,7 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) { let route // check anonymous bind - if (req.protocolOp === Protocol.LDAP_REQ_BIND && + if (req.protocolOp === Protocol.operations.LDAP_REQ_BIND && req.dn.toString() === '' && req.credentials === '') { return { @@ -799,7 +799,7 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) { const op = '0x' + req.protocolOp.toString(16) // Special cases are exops, unbinds and abandons. Handle those first. - if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) { + if (req.protocolOp === Protocol.operations.LDAP_REQ_EXTENSION) { route = routes[req.requestName] if (route) { return { @@ -812,7 +812,7 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) { handlers: [noExOpHandler] } } - } else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) { + } else if (req.protocolOp === Protocol.operations.LDAP_REQ_UNBIND) { route = routes.unbind if (route) { return { @@ -825,7 +825,7 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) { handlers: [defaultNoOpHandler] } } - } else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) { + } else if (req.protocolOp === Protocol.operations.LDAP_REQ_ABANDON) { return { backend: self, handlers: [defaultNoOpHandler] diff --git a/package.json b/package.json index 921a1fc..edcdec7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "@ldapjs/asn1": "^1.0.0", "@ldapjs/controls": "^1.0.0", + "@ldapjs/protocol": "^1.0.0", "abstract-logging": "^2.0.0", "assert-plus": "^1.0.0", "backoff": "^2.5.0",