Replace protocol with module (#806)

This commit is contained in:
James Sumners 2022-06-05 22:01:40 -04:00
parent 4355893077
commit cb70776445
35 changed files with 145 additions and 202 deletions

View File

@ -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)

View File

@ -3,7 +3,6 @@
const assert = require('assert-plus')
const Attribute = require('./attribute')
// var Protocol = require('./protocol')
/// --- API

View File

@ -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,

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -4,7 +4,6 @@ const assert = require('assert-plus')
const util = require('util')
const LDAPMessage = require('./result')
// var Protocol = require('../protocol')
/// --- API

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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 || ''

View File

@ -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)

View File

@ -7,7 +7,6 @@ const asn1 = require('@ldapjs/asn1')
const logger = require('../logger')
// var Control = require('../controls').Control
// var Protocol = require('../protocol')
/// --- Globals

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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()
}

View File

@ -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

View File

@ -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 || []

View File

@ -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')

View File

@ -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() : []

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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]

View File

@ -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",