update devdependency standard to v16

This commit is contained in:
Tony Brix 2020-10-31 16:07:32 -05:00
parent b796afea64
commit c6fa25985b
67 changed files with 741 additions and 739 deletions

View File

@ -1,10 +1,10 @@
var ldap = require('../lib/index') const ldap = require('../lib/index')
/// --- Shared handlers /// --- Shared handlers
function authorize (req, res, next) { function authorize (req, res, next) {
/* Any user may search after bind, only cn=root has full power */ /* Any user may search after bind, only cn=root has full power */
var isSearch = (req instanceof ldap.SearchRequest) const isSearch = (req instanceof ldap.SearchRequest)
if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) { return next(new ldap.InsufficientAccessRightsError()) } if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) { return next(new ldap.InsufficientAccessRightsError()) }
return next() return next()
@ -12,9 +12,9 @@ function authorize (req, res, next) {
/// --- Globals /// --- Globals
var SUFFIX = 'o=smartdc' const SUFFIX = 'o=smartdc'
var db = {} const db = {}
var server = ldap.createServer() const server = ldap.createServer()
server.bind('cn=root', function (req, res, next) { server.bind('cn=root', function (req, res, next) {
if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret') { return next(new ldap.InvalidCredentialsError()) } if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret') { return next(new ldap.InvalidCredentialsError()) }
@ -24,7 +24,7 @@ server.bind('cn=root', function (req, res, next) {
}) })
server.add(SUFFIX, authorize, function (req, res, next) { server.add(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (db[dn]) { return next(new ldap.EntryAlreadyExistsError(dn)) } if (db[dn]) { return next(new ldap.EntryAlreadyExistsError(dn)) }
@ -34,7 +34,7 @@ server.add(SUFFIX, authorize, function (req, res, next) {
}) })
server.bind(SUFFIX, function (req, res, next) { server.bind(SUFFIX, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) } if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
if (!db[dn].userpassword) { return next(new ldap.NoSuchAttributeError('userPassword')) } if (!db[dn].userpassword) { return next(new ldap.NoSuchAttributeError('userPassword')) }
@ -46,14 +46,14 @@ server.bind(SUFFIX, function (req, res, next) {
}) })
server.compare(SUFFIX, authorize, function (req, res, next) { server.compare(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) } if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
if (!db[dn][req.attribute]) { return next(new ldap.NoSuchAttributeError(req.attribute)) } if (!db[dn][req.attribute]) { return next(new ldap.NoSuchAttributeError(req.attribute)) }
var matches = false let matches = false
var vals = db[dn][req.attribute] const vals = db[dn][req.attribute]
for (var i = 0; i < vals.length; i++) { for (let i = 0; i < vals.length; i++) {
if (vals[i] === req.value) { if (vals[i] === req.value) {
matches = true matches = true
break break
@ -65,7 +65,7 @@ server.compare(SUFFIX, authorize, function (req, res, next) {
}) })
server.del(SUFFIX, authorize, function (req, res, next) { server.del(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) } if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
delete db[dn] delete db[dn]
@ -75,14 +75,14 @@ server.del(SUFFIX, authorize, function (req, res, next) {
}) })
server.modify(SUFFIX, authorize, function (req, res, next) { server.modify(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (!req.changes.length) { return next(new ldap.ProtocolError('changes required')) } if (!req.changes.length) { return next(new ldap.ProtocolError('changes required')) }
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) } if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
var entry = db[dn] const entry = db[dn]
let mod let mod
for (var i = 0; i < req.changes.length; i++) { for (let i = 0; i < req.changes.length; i++) {
mod = req.changes[i].modification mod = req.changes[i].modification
switch (req.changes[i].operation) { switch (req.changes[i].operation) {
case 'replace': case 'replace':
@ -121,10 +121,10 @@ server.modify(SUFFIX, authorize, function (req, res, next) {
}) })
server.search(SUFFIX, authorize, function (req, res, next) { server.search(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString() const dn = req.dn.toString()
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) } if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
var scopeCheck let scopeCheck
switch (req.scope) { switch (req.scope) {
case 'base': case 'base':
@ -142,7 +142,7 @@ server.search(SUFFIX, authorize, function (req, res, next) {
scopeCheck = function (k) { scopeCheck = function (k) {
if (req.dn.equals(k)) { return true } if (req.dn.equals(k)) { return true }
var parent = ldap.parseDN(k).parent() const parent = ldap.parseDN(k).parent()
return (parent ? parent.equals(req.dn) : false) return (parent ? parent.equals(req.dn) : false)
} }
break break

View File

@ -1,10 +1,10 @@
// Copyright 2015 Joyent, Inc. // Copyright 2015 Joyent, Inc.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var isDN = require('./dn').DN.isDN const isDN = require('./dn').DN.isDN
var isAttribute = require('./attribute').isAttribute const isAttribute = require('./attribute').isAttribute
/// --- Helpers /// --- Helpers

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var asn1 = require('asn1') const asn1 = require('asn1')
var Protocol = require('./protocol') const Protocol = require('./protocol')
/// --- API /// --- API
@ -42,13 +42,13 @@ Object.defineProperties(Attribute.prototype, {
}, },
vals: { vals: {
get: function getVals () { get: function getVals () {
var eType = _bufferEncoding(this.type) const eType = _bufferEncoding(this.type)
return this._vals.map(function (v) { return this._vals.map(function (v) {
return v.toString(eType) return v.toString(eType)
}) })
}, },
set: function setVals (vals) { set: function setVals (vals) {
var self = this const self = this
this._vals = [] this._vals = []
if (Array.isArray(vals)) { if (Array.isArray(vals)) {
vals.forEach(function (v) { vals.forEach(function (v) {
@ -81,7 +81,7 @@ Attribute.compare = function compare (a, b) {
if (a.vals.length < b.vals.length) return -1 if (a.vals.length < b.vals.length) return -1
if (a.vals.length > b.vals.length) return 1 if (a.vals.length > b.vals.length) return 1
for (var i = 0; i < a.vals.length; i++) { for (let i = 0; i < a.vals.length; i++) {
if (a.vals[i] < b.vals[i]) return -1 if (a.vals[i] < b.vals[i]) return -1
if (a.vals[i] > b.vals[i]) return 1 if (a.vals[i] > b.vals[i]) return 1
} }
@ -98,7 +98,7 @@ Attribute.prototype.parse = function parse (ber) {
if (ber.peek() === Protocol.LBER_SET) { if (ber.peek() === Protocol.LBER_SET) {
if (ber.readSequence(Protocol.LBER_SET)) { if (ber.readSequence(Protocol.LBER_SET)) {
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { this._vals.push(ber.readString(asn1.Ber.OctetString, true)) } while (ber.offset < end) { this._vals.push(ber.readString(asn1.Ber.OctetString, true)) }
} }
} }
@ -116,7 +116,7 @@ Attribute.prototype.toBer = function toBer (ber) {
this._vals.forEach(function (b) { this._vals.forEach(function (b) {
ber.writeByte(asn1.Ber.OctetString) ber.writeByte(asn1.Ber.OctetString)
ber.writeLength(b.length) ber.writeLength(b.length)
for (var i = 0; i < b.length; i++) { ber.writeByte(b[i]) } for (let i = 0; i < b.length; i++) { ber.writeByte(b[i]) }
}) })
} else { } else {
ber.writeStringArray([]) ber.writeStringArray([])

View File

@ -1,8 +1,8 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var Attribute = require('./attribute') const Attribute = require('./attribute')
// var Protocol = require('./protocol') // var Protocol = require('./protocol')
/// --- API /// --- API
@ -68,15 +68,15 @@ Object.defineProperties(Change.prototype, {
return return
} }
var keys = Object.keys(val) const keys = Object.keys(val)
if (keys.length > 1) { if (keys.length > 1) {
throw new Error('Only one attribute per Change allowed') throw new Error('Only one attribute per Change allowed')
} else if (keys.length === 0) { } else if (keys.length === 0) {
return return
} }
var k = keys[0] const k = keys[0]
var _attr = new Attribute({ type: k }) const _attr = new Attribute({ type: k })
if (Array.isArray(val[k])) { if (Array.isArray(val[k])) {
val[k].forEach(function (v) { val[k].forEach(function (v) {
_attr.addValue(v.toString()) _attr.addValue(v.toString())
@ -136,9 +136,9 @@ Change.apply = function apply (change, obj, scalar) {
assert.ok(Array.isArray(change.modification.vals)) assert.ok(Array.isArray(change.modification.vals))
assert.object(obj) assert.object(obj)
var type = change.modification.type const type = change.modification.type
var vals = change.modification.vals const vals = change.modification.vals
var data = obj[type] let data = obj[type]
if (data !== undefined) { if (data !== undefined) {
if (!Array.isArray(data)) { if (!Array.isArray(data)) {
data = [data] data = [data]
@ -156,13 +156,14 @@ Change.apply = function apply (change, obj, scalar) {
data = vals data = vals
} }
break break
case 'add': case 'add': {
// add only new unique entries // add only new unique entries
var newValues = vals.filter(function (entry) { const newValues = vals.filter(function (entry) {
return (data.indexOf(entry) === -1) return (data.indexOf(entry) === -1)
}) })
data = data.concat(newValues) data = data.concat(newValues)
break break
}
case 'delete': case 'delete':
data = data.filter(function (entry) { data = data.filter(function (entry) {
return (vals.indexOf(entry) === -1) return (vals.indexOf(entry) === -1)

View File

@ -4,57 +4,57 @@ const requestQueueFactory = require('./request-queue')
const messageTrackerFactory = require('./message-tracker') const messageTrackerFactory = require('./message-tracker')
const { MAX_MSGID } = require('./constants') const { MAX_MSGID } = require('./constants')
var EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
var net = require('net') const net = require('net')
var tls = require('tls') const tls = require('tls')
var util = require('util') const util = require('util')
var once = require('once') const once = require('once')
var backoff = require('backoff') const backoff = require('backoff')
var vasync = require('vasync') const vasync = require('vasync')
var assert = require('assert-plus') const assert = require('assert-plus')
var VError = require('verror').VError const VError = require('verror').VError
var Attribute = require('../attribute') const Attribute = require('../attribute')
var Change = require('../change') const Change = require('../change')
var Control = require('../controls/index').Control const Control = require('../controls/index').Control
var SearchPager = require('./search_pager') const SearchPager = require('./search_pager')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var dn = require('../dn') const dn = require('../dn')
var errors = require('../errors') const errors = require('../errors')
var filters = require('../filters') const filters = require('../filters')
var messages = require('../messages') const messages = require('../messages')
var url = require('../url') const url = require('../url')
var CorkedEmitter = require('../corked_emitter') const CorkedEmitter = require('../corked_emitter')
/// --- Globals /// --- Globals
var AbandonRequest = messages.AbandonRequest const AbandonRequest = messages.AbandonRequest
var AddRequest = messages.AddRequest const AddRequest = messages.AddRequest
var BindRequest = messages.BindRequest const BindRequest = messages.BindRequest
var CompareRequest = messages.CompareRequest const CompareRequest = messages.CompareRequest
var DeleteRequest = messages.DeleteRequest const DeleteRequest = messages.DeleteRequest
var ExtendedRequest = messages.ExtendedRequest const ExtendedRequest = messages.ExtendedRequest
var ModifyRequest = messages.ModifyRequest const ModifyRequest = messages.ModifyRequest
var ModifyDNRequest = messages.ModifyDNRequest const ModifyDNRequest = messages.ModifyDNRequest
var SearchRequest = messages.SearchRequest const SearchRequest = messages.SearchRequest
var UnbindRequest = messages.UnbindRequest const UnbindRequest = messages.UnbindRequest
var UnbindResponse = messages.UnbindResponse const UnbindResponse = messages.UnbindResponse
var LDAPResult = messages.LDAPResult const LDAPResult = messages.LDAPResult
var SearchEntry = messages.SearchEntry const SearchEntry = messages.SearchEntry
var SearchReference = messages.SearchReference const SearchReference = messages.SearchReference
// var SearchResponse = messages.SearchResponse // var SearchResponse = messages.SearchResponse
var Parser = messages.Parser const Parser = messages.Parser
var PresenceFilter = filters.PresenceFilter const PresenceFilter = filters.PresenceFilter
var ConnectionError = errors.ConnectionError const ConnectionError = errors.ConnectionError
var CMP_EXPECT = [errors.LDAP_COMPARE_TRUE, errors.LDAP_COMPARE_FALSE] const CMP_EXPECT = [errors.LDAP_COMPARE_TRUE, errors.LDAP_COMPARE_FALSE]
// node 0.6 got rid of FDs, so make up a client id for logging // node 0.6 got rid of FDs, so make up a client id for logging
var CLIENT_ID = 0 let CLIENT_ID = 0
/// --- Internal Helpers /// --- Internal Helpers
@ -109,7 +109,7 @@ function Client (options) {
EventEmitter.call(this, options) EventEmitter.call(this, options)
var self = this const self = this
this.urls = options.url ? [].concat(options.url).map(url.parse) : [] this.urls = options.url ? [].concat(options.url).map(url.parse) : []
this._nextServer = 0 this._nextServer = 0
// updated in connectSocket() after each connect // updated in connectSocket() after each connect
@ -127,7 +127,7 @@ function Client (options) {
this.idleTimeout = parseInt((options.idleTimeout || 0), 10) this.idleTimeout = parseInt((options.idleTimeout || 0), 10)
if (options.reconnect) { if (options.reconnect) {
// Fall back to defaults if options.reconnect === true // Fall back to defaults if options.reconnect === true
var rOpts = (typeof (options.reconnect) === 'object') const rOpts = (typeof (options.reconnect) === 'object')
? options.reconnect ? options.reconnect
: {} : {}
this.reconnect = { this.reconnect = {
@ -192,7 +192,7 @@ Client.prototype.abandon = function abandon (messageID, controls, callback) {
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new AbandonRequest({ const req = new AbandonRequest({
abandonID: messageID, abandonID: messageID,
controls: controls controls: controls
}) })
@ -229,11 +229,11 @@ Client.prototype.add = function add (name, entry, controls, callback) {
if (!Attribute.isAttribute(a)) { throw new TypeError('entry must be an Array of Attributes') } if (!Attribute.isAttribute(a)) { throw new TypeError('entry must be an Array of Attributes') }
}) })
} else { } else {
var save = entry const save = entry
entry = [] entry = []
Object.keys(save).forEach(function (k) { Object.keys(save).forEach(function (k) {
var attr = new Attribute({ type: k }) const attr = new Attribute({ type: k })
if (Array.isArray(save[k])) { if (Array.isArray(save[k])) {
save[k].forEach(function (v) { save[k].forEach(function (v) {
attr.addValue(v.toString()) attr.addValue(v.toString())
@ -245,7 +245,7 @@ Client.prototype.add = function add (name, entry, controls, callback) {
}) })
} }
var req = new AddRequest({ const req = new AddRequest({
entry: ensureDN(name, this.strictDN), entry: ensureDN(name, this.strictDN),
attributes: entry, attributes: entry,
controls: controls controls: controls
@ -278,7 +278,7 @@ Client.prototype.bind = function bind (name,
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new BindRequest({ const req = new BindRequest({
name: name || '', name: name || '',
authentication: 'Simple', authentication: 'Simple',
credentials: credentials || '', credentials: credentials || '',
@ -286,7 +286,7 @@ Client.prototype.bind = function bind (name,
}) })
// Connection errors will be reported to the bind callback too (useful when the LDAP server is not available) // Connection errors will be reported to the bind callback too (useful when the LDAP server is not available)
var self = this const self = this
function callbackWrapper (err, ret) { function callbackWrapper (err, ret) {
self.removeListener('connectError', callbackWrapper) self.removeListener('connectError', callbackWrapper)
callback(err, ret) callback(err, ret)
@ -322,7 +322,7 @@ Client.prototype.compare = function compare (name,
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new CompareRequest({ const req = new CompareRequest({
entry: ensureDN(name, this.strictDN), entry: ensureDN(name, this.strictDN),
attribute: attr, attribute: attr,
value: value, value: value,
@ -354,7 +354,7 @@ Client.prototype.del = function del (name, controls, callback) {
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new DeleteRequest({ const req = new DeleteRequest({
entry: ensureDN(name, this.strictDN), entry: ensureDN(name, this.strictDN),
controls: controls controls: controls
}) })
@ -390,7 +390,7 @@ Client.prototype.exop = function exop (name, value, controls, callback) {
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new ExtendedRequest({ const req = new ExtendedRequest({
requestName: name, requestName: name,
requestValue: value, requestValue: value,
controls: controls controls: controls
@ -416,7 +416,7 @@ Client.prototype.modify = function modify (name, change, controls, callback) {
assert.ok(name !== undefined, 'name') assert.ok(name !== undefined, 'name')
assert.object(change, 'change') assert.object(change, 'change')
var changes = [] const changes = []
function changeFromObject (change) { function changeFromObject (change) {
if (!change.operation && !change.type) { throw new Error('change.operation required') } if (!change.operation && !change.type) { throw new Error('change.operation required') }
@ -433,7 +433,7 @@ Client.prototype.modify = function modify (name, change, controls, callback) {
} else { } else {
// Normalize the modification object // Normalize the modification object
Object.keys(change.modification).forEach(function (k) { Object.keys(change.modification).forEach(function (k) {
var mod = {} const mod = {}
mod[k] = change.modification[k] mod[k] = change.modification[k]
changes.push(new Change({ changes.push(new Change({
operation: change.operation || change.type, operation: change.operation || change.type,
@ -465,7 +465,7 @@ Client.prototype.modify = function modify (name, change, controls, callback) {
} }
assert.func(callback, 'callback') assert.func(callback, 'callback')
var req = new ModifyRequest({ const req = new ModifyRequest({
object: ensureDN(name, this.strictDN), object: ensureDN(name, this.strictDN),
changes: changes, changes: changes,
controls: controls controls: controls
@ -502,11 +502,11 @@ Client.prototype.modifyDN = function modifyDN (name,
} }
assert.func(callback) assert.func(callback)
var DN = ensureDN(name) const DN = ensureDN(name)
// TODO: is non-strict handling desired here? // TODO: is non-strict handling desired here?
var newDN = dn.parse(newName) const newDN = dn.parse(newName)
var req = new ModifyDNRequest({ const req = new ModifyDNRequest({
entry: DN, entry: DN,
deleteOldRdn: true, deleteOldRdn: true,
controls: controls controls: controls
@ -590,11 +590,11 @@ Client.prototype.search = function search (base,
} }
} }
var self = this const self = this
var baseDN = ensureDN(base, this.strictDN) const baseDN = ensureDN(base, this.strictDN)
function sendRequest (ctrls, emitter, cb) { function sendRequest (ctrls, emitter, cb) {
var req = new SearchRequest({ const req = new SearchRequest({
baseObject: baseDN, baseObject: baseDN,
scope: options.scope || 'base', scope: options.scope || 'base',
filter: options.filter, filter: options.filter,
@ -615,8 +615,8 @@ Client.prototype.search = function search (base,
if (options.paged) { if (options.paged) {
// Perform automated search paging // Perform automated search paging
var pageOpts = typeof (options.paged) === 'object' ? options.paged : {} const pageOpts = typeof (options.paged) === 'object' ? options.paged : {}
var size = 100 // Default page size let size = 100 // Default page size
if (pageOpts.pageSize > 0) { if (pageOpts.pageSize > 0) {
size = pageOpts.pageSize size = pageOpts.pageSize
} else if (options.sizeLimit > 1) { } else if (options.sizeLimit > 1) {
@ -626,7 +626,7 @@ Client.prototype.search = function search (base,
size = options.sizeLimit - 1 size = options.sizeLimit - 1
} }
var pager = new SearchPager({ const pager = new SearchPager({
callback: callback, callback: callback,
controls: controls, controls: controls,
pageSize: size, pageSize: size,
@ -659,7 +659,7 @@ Client.prototype.unbind = function unbind (callback) {
if (!this._socket) { return callback() } if (!this._socket) { return callback() }
var req = new UnbindRequest() const req = new UnbindRequest()
return this._send(req, 'unbind', null, callback) return this._send(req, 'unbind', null, callback)
} }
@ -673,7 +673,7 @@ Client.prototype.starttls = function starttls (options,
assert.optionalObject(options) assert.optionalObject(options)
options = options || {} options = options || {}
callback = once(callback) callback = once(callback)
var self = this const self = this
if (this._starttls) { if (this._starttls) {
return callback(new Error('STARTTLS already in progress or active')) return callback(new Error('STARTTLS already in progress or active'))
@ -698,7 +698,7 @@ Client.prototype.starttls = function starttls (options,
callback(err) callback(err)
}) })
emitter.on('end', function (res) { emitter.on('end', function (res) {
var sock = self._socket const sock = self._socket
/* /*
* Unplumb socket data during SSL negotiation. * Unplumb socket data during SSL negotiation.
* This will prevent the LDAP parser from stumbling over the TLS * This will prevent the LDAP parser from stumbling over the TLS
@ -707,7 +707,7 @@ Client.prototype.starttls = function starttls (options,
sock.removeAllListeners('data') sock.removeAllListeners('data')
options.socket = sock options.socket = sock
var secure = tls.connect(options) const secure = tls.connect(options)
secure.once('secureConnect', function () { secure.once('secureConnect', function () {
/* /*
* Wire up 'data' and 'error' handlers like the normal socket. * Wire up 'data' and 'error' handlers like the normal socket.
@ -739,7 +739,7 @@ Client.prototype.starttls = function starttls (options,
}) })
} }
var req = new ExtendedRequest({ const req = new ExtendedRequest({
requestName: '1.3.6.1.4.1.1466.20037', requestName: '1.3.6.1.4.1.1466.20037',
requestValue: null, requestValue: null,
controls: controls controls: controls
@ -787,14 +787,14 @@ Client.prototype.connect = function connect () {
if (this.connecting || this.connected) { if (this.connecting || this.connected) {
return return
} }
var self = this const self = this
var log = this.log const log = this.log
var socket let socket
var tracker let tracker
// Establish basic socket connection // Establish basic socket connection
function connectSocket (cb) { function connectSocket (cb) {
var server = self.urls[self._nextServer] const server = self.urls[self._nextServer]
self._nextServer = (self._nextServer + 1) % self.urls.length self._nextServer = (self._nextServer + 1) % self.urls.length
cb = once(cb) cb = once(cb)
@ -825,8 +825,8 @@ Client.prototype.connect = function connect () {
setupClient(cb) setupClient(cb)
} }
var port = (server && server.port) || self.socketPath const port = (server && server.port) || self.socketPath
var host = server && server.hostname const host = server && server.hostname
if (server && server.secure) { if (server && server.secure) {
socket = tls.connect(port, host, self.tlsOptions) socket = tls.connect(port, host, self.tlsOptions)
socket.once('secureConnect', onConnect) socket.once('secureConnect', onConnect)
@ -874,7 +874,7 @@ Client.prototype.connect = function connect () {
// The "router" // The "router"
tracker.parser.on('message', function onMessage (message) { tracker.parser.on('message', function onMessage (message) {
message.connection = self._socket message.connection = self._socket
var callback = tracker.fetch(message.messageID) const callback = tracker.fetch(message.messageID)
if (!callback) { if (!callback) {
log.error({ message: message.json }, 'unsolicited message') log.error({ message: message.json }, 'unsolicited message')
@ -921,7 +921,7 @@ Client.prototype.connect = function connect () {
// This setup needs to bypass the request queue since all other activity is // This setup needs to bypass the request queue since all other activity is
// blocked until the connection is considered fully established post-setup. // blocked until the connection is considered fully established post-setup.
// Only allow bind/search/starttls for now. // Only allow bind/search/starttls for now.
var basicClient = { const basicClient = {
bind: function bindBypass (name, credentials, controls, callback) { bind: function bindBypass (name, credentials, controls, callback) {
return self.bind(name, credentials, controls, callback, true) return self.bind(name, credentials, controls, callback, true)
}, },
@ -973,7 +973,7 @@ Client.prototype.connect = function connect () {
socket.end() socket.end()
}) })
var server = self.urls[self._nextServer] const server = self.urls[self._nextServer]
if (server) { if (server) {
self.host = server.hostname self.host = server.hostname
self.port = server.port self.port = server.port
@ -981,8 +981,8 @@ Client.prototype.connect = function connect () {
} }
} }
var retry let retry
var failAfter let failAfter
if (this.reconnect) { if (this.reconnect) {
retry = backoff.exponential({ retry = backoff.exponential({
initialDelay: this.reconnect.initialDelay, initialDelay: this.reconnect.initialDelay,
@ -1056,8 +1056,8 @@ Client.prototype._flushQueue = function _flushQueue () {
* Clean up socket/parser resources after socket close. * Clean up socket/parser resources after socket close.
*/ */
Client.prototype._onClose = function _onClose (closeError) { Client.prototype._onClose = function _onClose (closeError) {
var socket = this._socket const socket = this._socket
var tracker = this._tracker const tracker = this._tracker
socket.removeAllListeners('connect') socket.removeAllListeners('connect')
.removeAllListeners('data') .removeAllListeners('data')
.removeAllListeners('drain') .removeAllListeners('drain')
@ -1079,7 +1079,7 @@ Client.prototype._onClose = function _onClose (closeError) {
return cb(new ConnectionError(tracker.id + ' closed')) return cb(new ConnectionError(tracker.id + ' closed'))
} else { } else {
// Unbinds will be communicated as a success since we're closed // Unbinds will be communicated as a success since we're closed
var unbind = new UnbindResponse({ messageID: msgid }) const unbind = new UnbindResponse({ messageID: msgid })
unbind.status = 'unbind' unbind.status = 'unbind'
return cb(unbind) return cb(unbind)
} }
@ -1111,7 +1111,7 @@ Client.prototype._updateIdle = function _updateIdle (override) {
return return
} }
// Client must be connected but not waiting on any request data // Client must be connected but not waiting on any request data
var self = this const self = this
function isIdle (disable) { function isIdle (disable) {
return ((disable !== true) && return ((disable !== true) &&
(self._socket && self.connected) && (self._socket && self.connected) &&
@ -1170,12 +1170,12 @@ Client.prototype._sendSocket = function _sendSocket (message,
expect, expect,
emitter, emitter,
callback) { callback) {
var conn = this._socket const conn = this._socket
var tracker = this._tracker const tracker = this._tracker
var log = this.log const log = this.log
var self = this const self = this
var timer = false let timer = false
var sentEmitter = false let sentEmitter = false
function sendResult (event, obj) { function sendResult (event, obj) {
if (event === 'error') { if (event === 'error') {
@ -1203,7 +1203,7 @@ Client.prototype._sendSocket = function _sendSocket (message,
if (expect === 'abandon') { return sendResult('end', null) } if (expect === 'abandon') { return sendResult('end', null) }
if (msg instanceof SearchEntry || msg instanceof SearchReference) { if (msg instanceof SearchEntry || msg instanceof SearchReference) {
var event = msg.constructor.name let event = msg.constructor.name
event = event[0].toLowerCase() + event.slice(1) event = event[0].toLowerCase() + event.slice(1)
return sendResult(event, msg) return sendResult(event, msg)
} else { } else {
@ -1226,7 +1226,7 @@ Client.prototype._sendSocket = function _sendSocket (message,
function onRequestTimeout () { function onRequestTimeout () {
self.emit('timeout', message) self.emit('timeout', message)
var cb = tracker.fetch(message.messageID) const cb = tracker.fetch(message.messageID)
if (cb) { if (cb) {
// FIXME: the timed-out request should be abandoned // FIXME: the timed-out request should be abandoned
cb(new errors.TimeoutError('request timeout (client interrupt)')) cb(new errors.TimeoutError('request timeout (client interrupt)'))

View File

@ -1,14 +1,14 @@
'use strict' 'use strict'
var EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
var util = require('util') const util = require('util')
var assert = require('assert-plus') const assert = require('assert-plus')
// var dn = require('../dn') // var dn = require('../dn')
// var messages = require('../messages/index') // var messages = require('../messages/index')
// var Protocol = require('../protocol') // var Protocol = require('../protocol')
var PagedControl = require('../controls/paged_results_control.js') const PagedControl = require('../controls/paged_results_control.js')
/// --- API /// --- API
@ -54,7 +54,7 @@ function SearchPager (opts) {
this.finished = false this.finished = false
this.started = false this.started = false
var emitter = new EventEmitter() const emitter = new EventEmitter()
emitter.on('searchEntry', this.emit.bind(this, 'searchEntry')) emitter.on('searchEntry', this.emit.bind(this, 'searchEntry'))
emitter.on('end', this._onEnd.bind(this)) emitter.on('end', this._onEnd.bind(this))
emitter.on('error', this._onError.bind(this)) emitter.on('error', this._onError.bind(this))
@ -72,21 +72,21 @@ SearchPager.prototype.begin = function begin () {
} }
SearchPager.prototype._onEnd = function _onEnd (res) { SearchPager.prototype._onEnd = function _onEnd (res) {
var self = this const self = this
var cookie = null let cookie = null
res.controls.forEach(function (control) { res.controls.forEach(function (control) {
if (control.type === PagedControl.OID) { if (control.type === PagedControl.OID) {
cookie = control.value.cookie cookie = control.value.cookie
} }
}) })
// Pass a noop callback by default for page events // Pass a noop callback by default for page events
var nullCb = function () { } const nullCb = function () { }
if (cookie === null) { if (cookie === null) {
// paged search not supported // paged search not supported
this.finished = true this.finished = true
this.emit('page', res, nullCb) this.emit('page', res, nullCb)
var err = new Error('missing paged control') const err = new Error('missing paged control')
err.name = 'PagedError' err.name = 'PagedError'
if (this.listeners('pageError').length > 0) { if (this.listeners('pageError').length > 0) {
this.emit('pageError', err) this.emit('pageError', err)
@ -135,7 +135,7 @@ SearchPager.prototype._onError = function _onError (err) {
* Initiate a search for the next page using the returned cookie value. * Initiate a search for the next page using the returned cookie value.
*/ */
SearchPager.prototype._nextPage = function _nextPage (cookie) { SearchPager.prototype._nextPage = function _nextPage (cookie) {
var controls = this.controls.slice(0) const controls = this.controls.slice(0)
controls.push(new PagedControl({ controls.push(new PagedControl({
value: { value: {
size: this.pageSize, size: this.pageSize,

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
// var asn1 = require('asn1') // var asn1 = require('asn1')
@ -28,7 +28,7 @@ function Control (options) {
Object.defineProperties(Control.prototype, { Object.defineProperties(Control.prototype, {
json: { json: {
get: function getJson () { get: function getJson () {
var obj = { const obj = {
controlType: this.type, controlType: this.type,
criticality: this.criticality, criticality: this.criticality,
controlValue: this.value controlValue: this.value

View File

@ -1,14 +1,14 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
/// --- API /// --- API
@ -39,7 +39,7 @@ Object.defineProperties(EntryChangeNotificationControl.prototype, {
EntryChangeNotificationControl.prototype.parse = function parse (buffer) { EntryChangeNotificationControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence()) { if (ber.readSequence()) {
this._value = { this._value = {
changeType: ber.readInt() changeType: ber.readInt()
@ -61,7 +61,7 @@ EntryChangeNotificationControl.prototype._toBer = function (ber) {
if (!this._value) { return } if (!this._value) { return }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence() writer.startSequence()
writer.writeInt(this.value.changeType) writer.writeInt(this.value.changeType)
if (this.value.previousDN) { writer.writeString(this.value.previousDN) } if (this.value.previousDN) { writer.writeString(this.value.previousDN) }

View File

@ -1,20 +1,20 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var Ber = require('asn1').Ber const Ber = require('asn1').Ber
var Control = require('./control') const Control = require('./control')
var EntryChangeNotificationControl = const EntryChangeNotificationControl =
require('./entry_change_notification_control') require('./entry_change_notification_control')
var PersistentSearchControl = require('./persistent_search_control') const PersistentSearchControl = require('./persistent_search_control')
var PagedResultsControl = require('./paged_results_control') const PagedResultsControl = require('./paged_results_control')
var ServerSideSortingRequestControl = const ServerSideSortingRequestControl =
require('./server_side_sorting_request_control.js') require('./server_side_sorting_request_control.js')
var ServerSideSortingResponseControl = const ServerSideSortingResponseControl =
require('./server_side_sorting_response_control.js') require('./server_side_sorting_response_control.js')
var VirtualListViewRequestControl = const VirtualListViewRequestControl =
require('./virtual_list_view_request_control.js') require('./virtual_list_view_request_control.js')
var VirtualListViewResponseControl = const VirtualListViewResponseControl =
require('./virtual_list_view_response_control.js') require('./virtual_list_view_response_control.js')
/// --- API /// --- API
@ -26,14 +26,14 @@ module.exports = {
if (ber.readSequence() === null) { return null } if (ber.readSequence() === null) { return null }
var type let type
var opts = { const opts = {
criticality: false, criticality: false,
value: null value: null
} }
if (ber.length) { if (ber.length) {
var end = ber.offset + ber.length const end = ber.offset + ber.length
type = ber.readString() type = ber.readString()
if (ber.offset < end) { if (ber.offset < end) {
@ -43,7 +43,7 @@ module.exports = {
if (ber.offset < end) { opts.value = ber.readString(Ber.OctetString, true) } if (ber.offset < end) { opts.value = ber.readString(Ber.OctetString, true) }
} }
var control let control
switch (type) { switch (type) {
case PersistentSearchControl.OID: case PersistentSearchControl.OID:
control = new PersistentSearchControl(opts) control = new PersistentSearchControl(opts)

View File

@ -1,14 +1,14 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
/// --- API /// --- API
@ -39,7 +39,7 @@ Object.defineProperties(PagedResultsControl.prototype, {
PagedResultsControl.prototype.parse = function parse (buffer) { PagedResultsControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence()) { if (ber.readSequence()) {
this._value = {} this._value = {}
this._value.size = ber.readInt() this._value.size = ber.readInt()
@ -58,7 +58,7 @@ PagedResultsControl.prototype._toBer = function (ber) {
if (!this._value) { return } if (!this._value) { return }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence() writer.startSequence()
writer.writeInt(this.value.size) writer.writeInt(this.value.size)
if (this.value.cookie && this.value.cookie.length > 0) { if (this.value.cookie && this.value.cookie.length > 0) {

View File

@ -1,16 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
/// --- API /// --- API
@ -42,7 +42,7 @@ Object.defineProperties(PersistentSearchControl.prototype, {
PersistentSearchControl.prototype.parse = function parse (buffer) { PersistentSearchControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence()) { if (ber.readSequence()) {
this._value = { this._value = {
changeTypes: ber.readInt(), changeTypes: ber.readInt(),
@ -61,7 +61,7 @@ PersistentSearchControl.prototype._toBer = function (ber) {
if (!this._value) { return } if (!this._value) { return }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence() writer.startSequence()
writer.writeInt(this.value.changeTypes) writer.writeInt(this.value.changeTypes)
writer.writeBoolean(this.value.changesOnly) writer.writeBoolean(this.value.changesOnly)

View File

@ -1,14 +1,14 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
/// --- API /// --- API
@ -21,7 +21,7 @@ function ServerSideSortingRequestControl (options) {
this.parse(options.value) this.parse(options.value)
} else if (Array.isArray(options.value)) { } else if (Array.isArray(options.value)) {
assert.arrayOfObject(options.value, 'options.value must be Objects') assert.arrayOfObject(options.value, 'options.value must be Objects')
for (var i = 0; i < options.value.length; i++) { for (let i = 0; i < options.value.length; i++) {
if (Object.prototype.hasOwnProperty.call(options.value[i], 'attributeType') === false) { if (Object.prototype.hasOwnProperty.call(options.value[i], 'attributeType') === false) {
throw new Error('Missing required key: attributeType') throw new Error('Missing required key: attributeType')
} }
@ -50,8 +50,8 @@ Object.defineProperties(ServerSideSortingRequestControl.prototype, {
ServerSideSortingRequestControl.prototype.parse = function parse (buffer) { ServerSideSortingRequestControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
var item let item
if (ber.readSequence(0x30)) { if (ber.readSequence(0x30)) {
this._value = [] this._value = []
@ -76,10 +76,10 @@ ServerSideSortingRequestControl.prototype._toBer = function (ber) {
if (!this._value || this.value.length === 0) { return } if (!this._value || this.value.length === 0) { return }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence(0x30) writer.startSequence(0x30)
for (var i = 0; i < this.value.length; i++) { for (let i = 0; i < this.value.length; i++) {
var item = this.value[i] const item = this.value[i]
writer.startSequence(0x30) writer.startSequence(0x30)
if (item.attributeType) { if (item.attributeType) {
writer.writeString(item.attributeType, asn1.Ber.OctetString) writer.writeString(item.attributeType, asn1.Ber.OctetString)

View File

@ -1,17 +1,17 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
var CODES = require('../errors/codes') const CODES = require('../errors/codes')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
var VALID_CODES = [ const VALID_CODES = [
CODES.LDAP_SUCCESS, CODES.LDAP_SUCCESS,
CODES.LDAP_OPERATIONS_ERROR, CODES.LDAP_OPERATIONS_ERROR,
CODES.LDAP_TIME_LIMIT_EXCEEDED, CODES.LDAP_TIME_LIMIT_EXCEEDED,
@ -62,7 +62,7 @@ Object.defineProperties(ServerSideSortingResponseControl.prototype, {
ServerSideSortingResponseControl.prototype.parse = function parse (buffer) { ServerSideSortingResponseControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence(0x30)) { if (ber.readSequence(0x30)) {
this._value = {} this._value = {}
this._value.result = ber.readEnumeration() this._value.result = ber.readEnumeration()
@ -79,7 +79,7 @@ ServerSideSortingResponseControl.prototype._toBer = function (ber) {
if (!this._value || this.value.length === 0) { return } if (!this._value || this.value.length === 0) { return }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence(0x30) writer.startSequence(0x30)
writer.writeEnumeration(this.value.result) writer.writeEnumeration(this.value.result)
if (this.value.result !== CODES.LDAP_SUCCESS && this.value.failedAttribute) { if (this.value.result !== CODES.LDAP_SUCCESS && this.value.failedAttribute) {

View File

@ -1,14 +1,14 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
/// --- API /// --- API
@ -44,7 +44,7 @@ Object.defineProperties(VirtualListViewControl.prototype, {
VirtualListViewControl.prototype.parse = function parse (buffer) { VirtualListViewControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence()) { if (ber.readSequence()) {
this._value = {} this._value = {}
this._value.beforeCount = ber.readInt() this._value.beforeCount = ber.readInt()
@ -68,7 +68,7 @@ VirtualListViewControl.prototype._toBer = function (ber) {
if (!this._value || this.value.length === 0) { if (!this._value || this.value.length === 0) {
return return
} }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence(0x30) writer.startSequence(0x30)
writer.writeInt(this.value.beforeCount) writer.writeInt(this.value.beforeCount)
writer.writeInt(this.value.afterCount) writer.writeInt(this.value.afterCount)

View File

@ -1,17 +1,17 @@
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var Control = require('./control') const Control = require('./control')
var CODES = require('../errors/codes') const CODES = require('../errors/codes')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
var VALID_CODES = [ const VALID_CODES = [
CODES.LDAP_SUCCESS, CODES.LDAP_SUCCESS,
CODES.LDAP_OPERATIONS_ERROR, CODES.LDAP_OPERATIONS_ERROR,
CODES.LDAP_UNWILLING_TO_PERFORM, CODES.LDAP_UNWILLING_TO_PERFORM,
@ -56,7 +56,7 @@ Object.defineProperties(VirtualListViewResponseControl.prototype, {
VirtualListViewResponseControl.prototype.parse = function parse (buffer) { VirtualListViewResponseControl.prototype.parse = function parse (buffer) {
assert.ok(buffer) assert.ok(buffer)
var ber = new BerReader(buffer) const ber = new BerReader(buffer)
if (ber.readSequence()) { if (ber.readSequence()) {
this._value = {} this._value = {}
if (ber.peek(0x02)) { if (ber.peek(0x02)) {
@ -83,7 +83,7 @@ VirtualListViewResponseControl.prototype._toBer = function (ber) {
return return
} }
var writer = new BerWriter() const writer = new BerWriter()
writer.startSequence() writer.startSequence()
if (this.value.targetPosition !== undefined) { if (this.value.targetPosition !== undefined) {
writer.writeInt(this.value.targetPosition) writer.writeInt(this.value.targetPosition)

View File

@ -1,6 +1,6 @@
'use strict' 'use strict'
var EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
/** /**
* A CorkedEmitter is a variant of an EventEmitter where events emitted * A CorkedEmitter is a variant of an EventEmitter where events emitted
@ -16,7 +16,7 @@ var EventEmitter = require('events').EventEmitter
* re-ordering emits - either everything is being buffered, or nothing. * re-ordering emits - either everything is being buffered, or nothing.
*/ */
function CorkedEmitter () { function CorkedEmitter () {
var self = this const self = this
EventEmitter.call(self) EventEmitter.call(self)
/** /**
* An array of arguments objects (array-likes) to emit on open. * An array of arguments objects (array-likes) to emit on open.

100
lib/dn.js
View File

@ -1,37 +1,37 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
/// --- Helpers /// --- Helpers
function invalidDN (name) { function invalidDN (name) {
var e = new Error() const e = new Error()
e.name = 'InvalidDistinguishedNameError' e.name = 'InvalidDistinguishedNameError'
e.message = name e.message = name
return e return e
} }
function isAlphaNumeric (c) { function isAlphaNumeric (c) {
var re = /[A-Za-z0-9]/ const re = /[A-Za-z0-9]/
return re.test(c) return re.test(c)
} }
function isWhitespace (c) { function isWhitespace (c) {
var re = /\s/ const re = /\s/
return re.test(c) return re.test(c)
} }
function repeatChar (c, n) { function repeatChar (c, n) {
var out = '' let out = ''
var max = n || 0 const max = n || 0
for (var i = 0; i < max; i++) { out += c } for (let i = 0; i < max; i++) { out += c }
return out return out
} }
/// --- API /// --- API
function RDN (obj) { function RDN (obj) {
var self = this const self = this
this.attrs = {} this.attrs = {}
if (obj) { if (obj) {
@ -45,8 +45,8 @@ RDN.prototype.set = function rdnSet (name, value, opts) {
assert.string(name, 'name (string) required') assert.string(name, 'name (string) required')
assert.string(value, 'value (string) required') assert.string(value, 'value (string) required')
var self = this const self = this
var lname = name.toLowerCase() const lname = name.toLowerCase()
this.attrs[lname] = { this.attrs[lname] = {
value: value, value: value,
name: name name: name
@ -61,14 +61,14 @@ RDN.prototype.set = function rdnSet (name, value, opts) {
RDN.prototype.equals = function rdnEquals (rdn) { RDN.prototype.equals = function rdnEquals (rdn) {
if (typeof (rdn) !== 'object') { return false } if (typeof (rdn) !== 'object') { return false }
var ourKeys = Object.keys(this.attrs) const ourKeys = Object.keys(this.attrs)
var theirKeys = Object.keys(rdn.attrs) const theirKeys = Object.keys(rdn.attrs)
if (ourKeys.length !== theirKeys.length) { return false } if (ourKeys.length !== theirKeys.length) { return false }
ourKeys.sort() ourKeys.sort()
theirKeys.sort() theirKeys.sort()
for (var i = 0; i < ourKeys.length; i++) { for (let i = 0; i < ourKeys.length; i++) {
if (ourKeys[i] !== theirKeys[i]) { return false } if (ourKeys[i] !== theirKeys[i]) { return false }
if (this.attrs[ourKeys[i]].value !== rdn.attrs[ourKeys[i]].value) { return false } if (this.attrs[ourKeys[i]].value !== rdn.attrs[ourKeys[i]].value) { return false }
} }
@ -83,20 +83,20 @@ RDN.prototype.format = function rdnFormat (options) {
assert.optionalObject(options, 'options must be an object') assert.optionalObject(options, 'options must be an object')
options = options || {} options = options || {}
var self = this const self = this
var str = '' let str = ''
function escapeValue (val, forceQuote) { function escapeValue (val, forceQuote) {
var out = '' let out = ''
var cur = 0 let cur = 0
var len = val.length const len = val.length
var quoted = false let quoted = false
/* BEGIN JSSTYLED */ /* BEGIN JSSTYLED */
// TODO: figure out what this regex is actually trying to test for and // TODO: figure out what this regex is actually trying to test for and
// fix it to appease the linter. // fix it to appease the linter.
/* eslint-disable-next-line no-useless-escape */ /* eslint-disable-next-line no-useless-escape */
var escaped = /[\\\"]/ const escaped = /[\\\"]/
var special = /[,=+<>#;]/ const special = /[,=+<>#;]/
/* END JSSTYLED */ /* END JSSTYLED */
if (len > 0) { if (len > 0) {
@ -117,7 +117,7 @@ RDN.prototype.format = function rdnFormat (options) {
return self.attrs[a].order - self.attrs[b].order return self.attrs[a].order - self.attrs[b].order
} }
function sortStandard (a, b) { function sortStandard (a, b) {
var nameCompare = a.localeCompare(b) const nameCompare = a.localeCompare(b)
if (nameCompare === 0) { if (nameCompare === 0) {
// TODO: Handle binary values // TODO: Handle binary values
return self.attrs[a].value.localeCompare(self.attrs[b].value) return self.attrs[a].value.localeCompare(self.attrs[b].value)
@ -126,7 +126,7 @@ RDN.prototype.format = function rdnFormat (options) {
} }
} }
var keys = Object.keys(this.attrs) const keys = Object.keys(this.attrs)
if (options.keepOrder) { if (options.keepOrder) {
keys.sort(sortParsed) keys.sort(sortParsed)
} else { } else {
@ -134,7 +134,7 @@ RDN.prototype.format = function rdnFormat (options) {
} }
keys.forEach(function (key) { keys.forEach(function (key) {
var attr = self.attrs[key] const attr = self.attrs[key]
if (str.length) { str += '+' } if (str.length) { str += '+' }
if (options.keepCase) { if (options.keepCase) {
@ -157,24 +157,24 @@ RDN.prototype.toString = function rdnToString () {
function parse (name) { function parse (name) {
if (typeof (name) !== 'string') { throw new TypeError('name (string) required') } if (typeof (name) !== 'string') { throw new TypeError('name (string) required') }
var cur = 0 let cur = 0
var len = name.length const len = name.length
function parseRdn () { function parseRdn () {
var rdn = new RDN() const rdn = new RDN()
var order = 0 let order = 0
rdn.spLead = trim() rdn.spLead = trim()
while (cur < len) { while (cur < len) {
var opts = { const opts = {
order: order order: order
} }
var attr = parseAttrType() const attr = parseAttrType()
trim() trim()
if (cur >= len || name[cur++] !== '=') { throw invalidDN(name) } if (cur >= len || name[cur++] !== '=') { throw invalidDN(name) }
trim() trim()
// Parameters about RDN value are set in 'opts' by parseAttrValue // Parameters about RDN value are set in 'opts' by parseAttrValue
var value = parseAttrValue(opts) const value = parseAttrValue(opts)
rdn.set(attr, value, opts) rdn.set(attr, value, opts)
rdn.spTrail = trim() rdn.spTrail = trim()
if (cur >= len || name[cur] !== '+') { break } if (cur >= len || name[cur] !== '+') { break }
@ -185,7 +185,7 @@ function parse (name) {
} }
function trim () { function trim () {
var count = 0 let count = 0
while ((cur < len) && isWhitespace(name[cur])) { while ((cur < len) && isWhitespace(name[cur])) {
++cur ++cur
count++ count++
@ -194,9 +194,9 @@ function parse (name) {
} }
function parseAttrType () { function parseAttrType () {
var beg = cur const beg = cur
while (cur < len) { while (cur < len) {
var c = name[cur] const c = name[cur]
if (isAlphaNumeric(c) || if (isAlphaNumeric(c) ||
c === '.' || c === '.' ||
c === '-' || c === '-' ||
@ -227,14 +227,14 @@ function parse (name) {
} }
function parseBinaryAttrValue () { function parseBinaryAttrValue () {
var beg = cur++ const beg = cur++
while (cur < len && isAlphaNumeric(name[cur])) { ++cur } while (cur < len && isAlphaNumeric(name[cur])) { ++cur }
return name.slice(beg, cur) return name.slice(beg, cur)
} }
function parseQuotedAttrValue () { function parseQuotedAttrValue () {
var str = '' let str = ''
++cur // Consume the first quote ++cur // Consume the first quote
while ((cur < len) && name[cur] !== '"') { while ((cur < len) && name[cur] !== '"') {
@ -250,9 +250,9 @@ function parse (name) {
} }
function parseStringAttrValue () { function parseStringAttrValue () {
var beg = cur const beg = cur
var str = '' let str = ''
var esc = -1 let esc = -1
while ((cur < len) && !atTerminator()) { while ((cur < len) && !atTerminator()) {
if (name[cur] === '\\') { if (name[cur] === '\\') {
@ -282,7 +282,7 @@ function parse (name) {
name[cur] === '+')) name[cur] === '+'))
} }
var rdns = [] const rdns = []
// Short-circuit for empty DNs // Short-circuit for empty DNs
if (len === 0) { return new DN(rdns) } if (len === 0) { return new DN(rdns) }
@ -340,9 +340,9 @@ DN.prototype.format = function dnFormat (options) {
assert.optionalObject(options, 'options must be an object') assert.optionalObject(options, 'options must be an object')
options = options || this._format options = options || this._format
var str = '' let str = ''
this.rdns.forEach(function (rdn) { this.rdns.forEach(function (rdn) {
var rdnString = rdn.format(options) const rdnString = rdn.format(options)
if (str.length !== 0) { if (str.length !== 0) {
str += ',' str += ','
} }
@ -376,10 +376,10 @@ DN.prototype.parentOf = function parentOf (dn) {
if (this.rdns.length >= dn.rdns.length) { return false } if (this.rdns.length >= dn.rdns.length) { return false }
var diff = dn.rdns.length - this.rdns.length const diff = dn.rdns.length - this.rdns.length
for (var i = this.rdns.length - 1; i >= 0; i--) { for (let i = this.rdns.length - 1; i >= 0; i--) {
var myRDN = this.rdns[i] const myRDN = this.rdns[i]
var theirRDN = dn.rdns[i + diff] const theirRDN = dn.rdns[i + diff]
if (!myRDN.equals(theirRDN)) { return false } if (!myRDN.equals(theirRDN)) { return false }
} }
@ -401,7 +401,7 @@ DN.prototype.equals = function dnEquals (dn) {
if (this.rdns.length !== dn.rdns.length) { return false } if (this.rdns.length !== dn.rdns.length) { return false }
for (var i = 0; i < this.rdns.length; i++) { for (let i = 0; i < this.rdns.length; i++) {
if (!this.rdns[i].equals(dn.rdns[i])) { return false } if (!this.rdns[i].equals(dn.rdns[i])) { return false }
} }
@ -410,8 +410,8 @@ DN.prototype.equals = function dnEquals (dn) {
DN.prototype.parent = function dnParent () { DN.prototype.parent = function dnParent () {
if (this.rdns.length !== 0) { if (this.rdns.length !== 0) {
var save = this.rdns.shift() const save = this.rdns.shift()
var dn = new DN(this.rdns) const dn = new DN(this.rdns)
this.rdns.unshift(save) this.rdns.unshift(save)
return dn return dn
} }
@ -420,7 +420,7 @@ DN.prototype.parent = function dnParent () {
} }
DN.prototype.clone = function dnClone () { DN.prototype.clone = function dnClone () {
var dn = new DN(this.rdns) const dn = new DN(this.rdns)
dn._format = this._format dn._format = this._format
return dn return dn
} }

View File

@ -2,9 +2,9 @@
/// --- Globals /// --- Globals
var SERVER_PROVIDER let SERVER_PROVIDER
var DTRACE_ID = 0 let DTRACE_ID = 0
var MAX_INT = 4294967295 const MAX_INT = 4294967295
/* /*
* Args: * Args:
@ -24,7 +24,7 @@ var MAX_INT = 4294967295
* 5 -> errorMessage * 5 -> errorMessage
* *
*/ */
var SERVER_PROBES = { const SERVER_PROBES = {
// 4: attributes.length // 4: attributes.length
'server-add-start': ['int', 'char *', 'char *', 'char *', 'int'], 'server-add-start': ['int', 'char *', 'char *', 'char *', 'int'],
@ -78,11 +78,11 @@ var SERVER_PROBES = {
module.exports = (function () { module.exports = (function () {
if (!SERVER_PROVIDER) { if (!SERVER_PROVIDER) {
try { try {
var dtrace = require('dtrace-provider') const dtrace = require('dtrace-provider')
SERVER_PROVIDER = dtrace.createDTraceProvider('ldapjs') SERVER_PROVIDER = dtrace.createDTraceProvider('ldapjs')
Object.keys(SERVER_PROBES).forEach(function (p) { Object.keys(SERVER_PROBES).forEach(function (p) {
var args = SERVER_PROBES[p].splice(0) const args = SERVER_PROBES[p].splice(0)
args.unshift(p) args.unshift(p)
dtrace.DTraceProvider.prototype.addProbe.apply(SERVER_PROVIDER, args) dtrace.DTraceProvider.prototype.addProbe.apply(SERVER_PROVIDER, args)
@ -94,7 +94,7 @@ module.exports = (function () {
enable: function () { enable: function () {
}, },
addProbe: function () { addProbe: function () {
var p = { const p = {
fire: function () { fire: function () {
} }
} }

View File

@ -1,14 +1,14 @@
'use strict' 'use strict'
var util = require('util') const util = require('util')
var assert = require('assert-plus') const assert = require('assert-plus')
var LDAPResult = require('../messages').LDAPResult const LDAPResult = require('../messages').LDAPResult
/// --- Globals /// --- Globals
var CODES = require('./codes') const CODES = require('./codes')
var ERRORS = [] const ERRORS = []
/// --- Error Base class /// --- Error Base class
@ -52,12 +52,12 @@ Object.keys(CODES).forEach(function (code) {
module.exports[code] = CODES[code] module.exports[code] = CODES[code]
if (code === 'LDAP_SUCCESS') { return } if (code === 'LDAP_SUCCESS') { return }
var err = '' let err = ''
var msg = '' let msg = ''
var pieces = code.split('_').slice(1) const pieces = code.split('_').slice(1)
for (var i = 0; i < pieces.length; i++) { for (let i = 0; i < pieces.length; i++) {
var lc = pieces[i].toLowerCase() const lc = pieces[i].toLowerCase()
var key = lc.charAt(0).toUpperCase() + lc.slice(1) const key = lc.charAt(0).toUpperCase() + lc.slice(1)
err += key err += key
msg += key + ((i + 1) < pieces.length ? ' ' : '') msg += key + ((i + 1) < pieces.length ? ' ' : '')
} }
@ -91,8 +91,8 @@ Object.keys(CODES).forEach(function (code) {
module.exports.getError = function (res) { module.exports.getError = function (res) {
assert.ok(res instanceof LDAPResult, 'res (LDAPResult) required') assert.ok(res instanceof LDAPResult, 'res (LDAPResult) required')
var errObj = ERRORS[res.status] const errObj = ERRORS[res.status]
var E = module.exports[errObj.err] const E = module.exports[errObj.err]
return new E(res.errorMessage || errObj.message, return new E(res.errorMessage || errObj.message,
res.matchedDN || null, res.matchedDN || null,
module.exports.getError) module.exports.getError)
@ -101,7 +101,7 @@ module.exports.getError = function (res) {
module.exports.getMessage = function (code) { module.exports.getMessage = function (code) {
assert.number(code, 'code (number) required') assert.number(code, 'code (number) required')
var errObj = ERRORS[code] const errObj = ERRORS[code]
return (errObj && errObj.message ? errObj.message : '') return (errObj && errObj.message ? errObj.message : '')
} }

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,12 +1,12 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var ASN1 = require('asn1').Ber const ASN1 = require('asn1').Ber
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API
@ -20,8 +20,8 @@ module.exports = EqualityFilter
EqualityFilter.prototype.matches = function (target, strictAttrCase) { EqualityFilter.prototype.matches = function (target, strictAttrCase) {
assert.object(target, 'target') assert.object(target, 'target')
var tv = parents.getAttrValue(target, this.attribute, strictAttrCase) const tv = parents.getAttrValue(target, this.attribute, strictAttrCase)
var value = this.value let value = this.value
if (this.attribute.toLowerCase() === 'objectclass') { if (this.attribute.toLowerCase() === 'objectclass') {
/* /*

View File

@ -14,8 +14,8 @@
*/ */
exports.escape = function (inp) { exports.escape = function (inp) {
if (typeof (inp) === 'string') { if (typeof (inp) === 'string') {
var esc = '' let esc = ''
for (var i = 0; i < inp.length; i++) { for (let i = 0; i < inp.length; i++) {
switch (inp[i]) { switch (inp[i]) {
case '*': case '*':
esc += '\\2a' esc += '\\2a'

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
// THIS IS A STUB! // THIS IS A STUB!
// //
@ -22,9 +22,9 @@ Filter.mixin(ExtensibleFilter)
module.exports = ExtensibleFilter module.exports = ExtensibleFilter
ExtensibleFilter.prototype.parse = function (ber) { ExtensibleFilter.prototype.parse = function (ber) {
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var tag = ber.peek() const tag = ber.peek()
switch (tag) { switch (tag) {
case 0x81: case 0x81:
this.rule = ber.readString(tag) this.rule = ber.readString(tag)

View File

@ -2,11 +2,11 @@
// var assert = require('assert') // var assert = require('assert')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
var TYPES = { const TYPES = {
and: Protocol.FILTER_AND, and: Protocol.FILTER_AND,
or: Protocol.FILTER_OR, or: Protocol.FILTER_OR,
not: Protocol.FILTER_NOT, not: Protocol.FILTER_NOT,

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,28 +1,28 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var asn1 = require('asn1') const asn1 = require('asn1')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var Filter = require('./filter') const Filter = require('./filter')
var AndFilter = require('./and_filter') const AndFilter = require('./and_filter')
var ApproximateFilter = require('./approx_filter') const ApproximateFilter = require('./approx_filter')
var EqualityFilter = require('./equality_filter') const EqualityFilter = require('./equality_filter')
var ExtensibleFilter = require('./ext_filter') const ExtensibleFilter = require('./ext_filter')
var GreaterThanEqualsFilter = require('./ge_filter') const GreaterThanEqualsFilter = require('./ge_filter')
var LessThanEqualsFilter = require('./le_filter') const LessThanEqualsFilter = require('./le_filter')
var NotFilter = require('./not_filter') const NotFilter = require('./not_filter')
var OrFilter = require('./or_filter') const OrFilter = require('./or_filter')
var PresenceFilter = require('./presence_filter') const PresenceFilter = require('./presence_filter')
var SubstringFilter = require('./substr_filter') const SubstringFilter = require('./substr_filter')
/// --- Globals /// --- Globals
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
/// --- Internal Parsers /// --- Internal Parsers
@ -63,13 +63,13 @@ function _parse (ber) {
assert.ok(ber) assert.ok(ber)
function parseSet (f) { function parseSet (f) {
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { f.addFilter(_parse(ber)) } while (ber.offset < end) { f.addFilter(_parse(ber)) }
} }
var f let f
var type = ber.readSequence() const type = ber.readSequence()
switch (type) { switch (type) {
case Protocol.FILTER_AND: case Protocol.FILTER_AND:
f = new AndFilter() f = new AndFilter()
@ -102,9 +102,8 @@ function _parse (ber) {
return f return f
case Protocol.FILTER_NOT: case Protocol.FILTER_NOT:
var _f = _parse(ber)
f = new NotFilter({ f = new NotFilter({
filter: _f filter: _parse(ber)
}) })
break break
@ -132,7 +131,7 @@ function _parse (ber) {
} }
function cloneFilter (input) { function cloneFilter (input) {
var child let child
if (input.type === 'and' || input.type === 'or') { if (input.type === 'and' || input.type === 'or') {
child = input.filters.map(cloneFilter) child = input.filters.map(cloneFilter)
} else if (input.type === 'not') { } else if (input.type === 'not') {

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API
@ -30,7 +30,7 @@ PresenceFilter.prototype.parse = function (ber) {
PresenceFilter.prototype._toBer = function (ber) { PresenceFilter.prototype._toBer = function (ber) {
assert.ok(ber) assert.ok(ber)
for (var i = 0; i < this.attribute.length; i++) { ber.writeByte(this.attribute.charCodeAt(i)) } for (let i = 0; i < this.attribute.length; i++) { ber.writeByte(this.attribute.charCodeAt(i)) }
return ber return ber
} }

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var util = require('util') const util = require('util')
var parents = require('ldap-filter') const parents = require('ldap-filter')
var Filter = require('./filter') const Filter = require('./filter')
/// --- API /// --- API
@ -21,20 +21,21 @@ SubstringFilter.prototype.parse = function (ber) {
this.attribute = ber.readString().toLowerCase() this.attribute = ber.readString().toLowerCase()
ber.readSequence() ber.readSequence()
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var tag = ber.peek() const tag = ber.peek()
switch (tag) { switch (tag) {
case 0x80: // Initial case 0x80: // Initial
this.initial = ber.readString(tag) this.initial = ber.readString(tag)
if (this.attribute === 'objectclass') { this.initial = this.initial.toLowerCase() } if (this.attribute === 'objectclass') { this.initial = this.initial.toLowerCase() }
break break
case 0x81: // Any case 0x81: { // Any
var anyVal = ber.readString(tag) let anyVal = ber.readString(tag)
if (this.attribute === 'objectclass') { anyVal = anyVal.toLowerCase() } if (this.attribute === 'objectclass') { anyVal = anyVal.toLowerCase() }
this.any.push(anyVal) this.any.push(anyVal)
break break
}
case 0x82: // Final case 0x82: // Final
this.final = ber.readString(tag) this.final = ber.readString(tag)
if (this.attribute === 'objectclass') { this.final = this.final.toLowerCase() } if (this.attribute === 'objectclass') { this.final = this.final.toLowerCase() }

View File

@ -1,20 +1,20 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var logger = require('./logger') const logger = require('./logger')
var client = require('./client') const client = require('./client')
var Attribute = require('./attribute') const Attribute = require('./attribute')
var Change = require('./change') const Change = require('./change')
var Protocol = require('./protocol') const Protocol = require('./protocol')
var Server = require('./server') const Server = require('./server')
var controls = require('./controls') const controls = require('./controls')
var persistentSearch = require('./persistent_search') const persistentSearch = require('./persistent_search')
var dn = require('./dn') const dn = require('./dn')
var errors = require('./errors') const errors = require('./errors')
var filters = require('./filters') const filters = require('./filters')
var messages = require('./messages') const messages = require('./messages')
var url = require('./url') const url = require('./url')
const hasOwnProperty = (target, val) => Object.prototype.hasOwnProperty.call(target, val) const hasOwnProperty = (target, val) => Object.prototype.hasOwnProperty.call(target, val)
@ -57,7 +57,7 @@ module.exports = {
/// --- Export all the childrenz /// --- Export all the childrenz
var k let k
for (k in Protocol) { for (k in Protocol) {
if (hasOwnProperty(Protocol, k)) { module.exports[k] = Protocol[k] } if (hasOwnProperty(Protocol, k)) { module.exports[k] = Protocol[k] }

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API
@ -34,13 +34,13 @@ AbandonRequest.prototype._parse = function (ber, length) {
// way abandon is encoded and the way ldapjs framework handles "normal" // way abandon is encoded and the way ldapjs framework handles "normal"
// messages // messages
var buf = ber.buffer const buf = ber.buffer
var offset = 0 let offset = 0
var value = 0 let value = 0
var fb = buf[offset++] const fb = buf[offset++]
value = fb & 0x7F value = fb & 0x7F
for (var i = 1; i < length; i++) { for (let i = 1; i < length; i++) {
value <<= 8 value <<= 8
value |= (buf[offset++] & 0xff) value |= (buf[offset++] & 0xff)
} }
@ -56,8 +56,8 @@ AbandonRequest.prototype._parse = function (ber, length) {
AbandonRequest.prototype._toBer = function (ber) { AbandonRequest.prototype._toBer = function (ber) {
assert.ok(ber) assert.ok(ber)
var i = this.abandonID let i = this.abandonID
var sz = 4 let sz = 4
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) && while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) &&
(sz > 1)) { (sz > 1)) {

View File

@ -1,9 +1,9 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./result') const LDAPMessage = require('./result')
// var Protocol = require('../protocol') // var Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,12 +1,12 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Attribute = require('../attribute') const Attribute = require('../attribute')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var lassert = require('../assert') const lassert = require('../assert')
/// --- API /// --- API
@ -41,13 +41,13 @@ AddRequest.prototype._parse = function (ber) {
ber.readSequence() ber.readSequence()
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var a = new Attribute() const a = new Attribute()
a.parse(ber) a.parse(ber)
a.type = a.type.toLowerCase() a.type = a.type.toLowerCase()
if (a.type === 'objectclass') { if (a.type === 'objectclass') {
for (var i = 0; i < a.vals.length; i++) { a.vals[i] = a.vals[i].toLowerCase() } for (let i = 0; i < a.vals.length; i++) { a.vals[i] = a.vals[i].toLowerCase() }
} }
this.attributes.push(a) this.attributes.push(a)
} }
@ -85,7 +85,7 @@ AddRequest.prototype._json = function (j) {
AddRequest.prototype.indexOf = function (attr) { AddRequest.prototype.indexOf = function (attr) {
if (!attr || typeof (attr) !== 'string') { throw new TypeError('attr (string) required') } if (!attr || typeof (attr) !== 'string') { throw new TypeError('attr (string) required') }
for (var i = 0; i < this.attributes.length; i++) { for (let i = 0; i < this.attributes.length; i++) {
if (this.attributes[i].type === attr) { return i } if (this.attributes[i].type === attr) { return i }
} }
@ -93,9 +93,9 @@ AddRequest.prototype.indexOf = function (attr) {
} }
AddRequest.prototype.attributeNames = function () { AddRequest.prototype.attributeNames = function () {
var attrs = [] const attrs = []
for (var i = 0; i < this.attributes.length; i++) { attrs.push(this.attributes[i].type.toLowerCase()) } for (let i = 0; i < this.attributes.length; i++) { attrs.push(this.attributes[i].type.toLowerCase()) }
return attrs return attrs
} }
@ -105,7 +105,7 @@ AddRequest.prototype.getAttribute = function (name) {
name = name.toLowerCase() name = name.toLowerCase()
for (var i = 0; i < this.attributes.length; i++) { for (let i = 0; i < this.attributes.length; i++) {
if (this.attributes[i].type === name) { return this.attributes[i] } if (this.attributes[i].type === name) { return this.attributes[i] }
} }
@ -134,9 +134,9 @@ AddRequest.prototype.addAttribute = function (attr) {
* @return {Object} that looks like the above. * @return {Object} that looks like the above.
*/ */
AddRequest.prototype.toObject = function () { AddRequest.prototype.toObject = function () {
var self = this const self = this
var obj = { const obj = {
dn: self.entry ? self.entry.toString() : '', dn: self.entry ? self.entry.toString() : '',
attributes: {} attributes: {}
} }

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,17 +1,17 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
var Ber = asn1.Ber const Ber = asn1.Ber
var LDAP_BIND_SIMPLE = 'simple' const LDAP_BIND_SIMPLE = 'simple'
// var LDAP_BIND_SASL = 'sasl' // var LDAP_BIND_SASL = 'sasl'
/// --- API /// --- API
@ -46,7 +46,7 @@ BindRequest.prototype._parse = function (ber) {
this.version = ber.readInt() this.version = ber.readInt()
this.name = ber.readString() this.name = ber.readString()
var t = ber.peek() const t = ber.peek()
// TODO add support for SASL et al // TODO add support for SASL et al
if (t !== Ber.Context) { throw new Error('authentication 0x' + t.toString(16) + ' not supported') } if (t !== Ber.Context) { throw new Error('authentication 0x' + t.toString(16) + ' not supported') }

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var lassert = require('../assert') const lassert = require('../assert')
/// --- API /// --- API

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API
@ -18,7 +18,7 @@ function CompareResponse (options) {
util.inherits(CompareResponse, LDAPResult) util.inherits(CompareResponse, LDAPResult)
CompareResponse.prototype.end = function (matches) { CompareResponse.prototype.end = function (matches) {
var status = 0x06 let status = 0x06
if (typeof (matches) === 'boolean') { if (typeof (matches) === 'boolean') {
if (!matches) { status = 0x05 } // Compare false if (!matches) { status = 0x05 } // Compare false
} else { } else {

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var lassert = require('../assert') const lassert = require('../assert')
/// --- API /// --- API
@ -43,8 +43,8 @@ DeleteRequest.prototype._parse = function (ber, length) {
DeleteRequest.prototype._toBer = function (ber) { DeleteRequest.prototype._toBer = function (ber) {
assert.ok(ber) assert.ok(ber)
var buf = Buffer.from(this.entry.toString()) const buf = Buffer.from(this.entry.toString())
for (var i = 0; i < buf.length; i++) { ber.writeByte(buf[i]) } for (let i = 0; i < buf.length; i++) { ber.writeByte(buf[i]) }
return ber return ber
} }

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,31 +1,31 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Parser = require('./parser') const Parser = require('./parser')
var AbandonRequest = require('./abandon_request') const AbandonRequest = require('./abandon_request')
var AbandonResponse = require('./abandon_response') const AbandonResponse = require('./abandon_response')
var AddRequest = require('./add_request') const AddRequest = require('./add_request')
var AddResponse = require('./add_response') const AddResponse = require('./add_response')
var BindRequest = require('./bind_request') const BindRequest = require('./bind_request')
var BindResponse = require('./bind_response') const BindResponse = require('./bind_response')
var CompareRequest = require('./compare_request') const CompareRequest = require('./compare_request')
var CompareResponse = require('./compare_response') const CompareResponse = require('./compare_response')
var DeleteRequest = require('./del_request') const DeleteRequest = require('./del_request')
var DeleteResponse = require('./del_response') const DeleteResponse = require('./del_response')
var ExtendedRequest = require('./ext_request') const ExtendedRequest = require('./ext_request')
var ExtendedResponse = require('./ext_response') const ExtendedResponse = require('./ext_response')
var ModifyRequest = require('./modify_request') const ModifyRequest = require('./modify_request')
var ModifyResponse = require('./modify_response') const ModifyResponse = require('./modify_response')
var ModifyDNRequest = require('./moddn_request') const ModifyDNRequest = require('./moddn_request')
var ModifyDNResponse = require('./moddn_response') const ModifyDNResponse = require('./moddn_response')
var SearchRequest = require('./search_request') const SearchRequest = require('./search_request')
var SearchEntry = require('./search_entry') const SearchEntry = require('./search_entry')
var SearchReference = require('./search_reference') const SearchReference = require('./search_reference')
var SearchResponse = require('./search_response') const SearchResponse = require('./search_response')
var UnbindRequest = require('./unbind_request') const UnbindRequest = require('./unbind_request')
var UnbindResponse = require('./unbind_response') const UnbindResponse = require('./unbind_response')
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var logger = require('../logger') const logger = require('../logger')
// var Control = require('../controls').Control // var Control = require('../controls').Control
// var Protocol = require('../protocol') // var Protocol = require('../protocol')
@ -13,8 +13,8 @@ var logger = require('../logger')
// var Ber = asn1.Ber // var Ber = asn1.Ber
// var BerReader = asn1.BerReader // var BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
var getControl = require('../controls').getControl const getControl = require('../controls').getControl
/// --- API /// --- API
@ -47,7 +47,7 @@ Object.defineProperties(LDAPMessage.prototype, {
}, },
json: { json: {
get: function () { get: function () {
var out = this._json({ const out = this._json({
messageID: this.messageID, messageID: this.messageID,
protocolOp: this.type protocolOp: this.type
}) })
@ -73,9 +73,9 @@ LDAPMessage.prototype.parse = function (ber) {
// Look for controls // Look for controls
if (ber.peek() === 0xa0) { if (ber.peek() === 0xa0) {
ber.readSequence() ber.readSequence()
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var c = getControl(ber) const c = getControl(ber)
if (c) { this.controls.push(c) } if (c) { this.controls.push(c) }
} }
} }
@ -85,7 +85,7 @@ LDAPMessage.prototype.parse = function (ber) {
} }
LDAPMessage.prototype.toBer = function () { LDAPMessage.prototype.toBer = function () {
var writer = new BerWriter() let writer = new BerWriter()
writer.startSequence() writer.startSequence()
writer.writeInt(this.messageID) writer.writeInt(this.messageID)

View File

@ -1,12 +1,12 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var dn = require('../dn') const dn = require('../dn')
var lassert = require('../assert') const lassert = require('../assert')
/// --- API /// --- API
@ -56,8 +56,8 @@ ModifyDNRequest.prototype._toBer = function (ber) {
ber.writeString(this.newRdn.toString()) ber.writeString(this.newRdn.toString())
ber.writeBoolean(this.deleteOldRdn) ber.writeBoolean(this.deleteOldRdn)
if (this.newSuperior) { if (this.newSuperior) {
var s = this.newSuperior.toString() const s = this.newSuperior.toString()
var len = Buffer.byteLength(s) const len = Buffer.byteLength(s)
ber.writeByte(0x80) // MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG ber.writeByte(0x80) // MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG
ber.writeByte(len) ber.writeByte(len)

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,12 +1,12 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Change = require('../change') const Change = require('../change')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var lassert = require('../assert') const lassert = require('../assert')
/// --- API /// --- API
@ -40,9 +40,9 @@ ModifyRequest.prototype._parse = function (ber) {
this.object = ber.readString() this.object = ber.readString()
ber.readSequence() ber.readSequence()
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var c = new Change() const c = new Change()
c.parse(ber) c.parse(ber)
c.modification.type = c.modification.type.toLowerCase() c.modification.type = c.modification.type.toLowerCase()
this.changes.push(c) this.changes.push(c)

View File

@ -1,10 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API

View File

@ -1,44 +1,44 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
var util = require('util') const util = require('util')
var assert = require('assert-plus') const assert = require('assert-plus')
var asn1 = require('asn1') const asn1 = require('asn1')
// var VError = require('verror').VError // var VError = require('verror').VError
var logger = require('../logger') const logger = require('../logger')
var AbandonRequest = require('./abandon_request') const AbandonRequest = require('./abandon_request')
var AddRequest = require('./add_request') const AddRequest = require('./add_request')
var AddResponse = require('./add_response') const AddResponse = require('./add_response')
var BindRequest = require('./bind_request') const BindRequest = require('./bind_request')
var BindResponse = require('./bind_response') const BindResponse = require('./bind_response')
var CompareRequest = require('./compare_request') const CompareRequest = require('./compare_request')
var CompareResponse = require('./compare_response') const CompareResponse = require('./compare_response')
var DeleteRequest = require('./del_request') const DeleteRequest = require('./del_request')
var DeleteResponse = require('./del_response') const DeleteResponse = require('./del_response')
var ExtendedRequest = require('./ext_request') const ExtendedRequest = require('./ext_request')
var ExtendedResponse = require('./ext_response') const ExtendedResponse = require('./ext_response')
var ModifyRequest = require('./modify_request') const ModifyRequest = require('./modify_request')
var ModifyResponse = require('./modify_response') const ModifyResponse = require('./modify_response')
var ModifyDNRequest = require('./moddn_request') const ModifyDNRequest = require('./moddn_request')
var ModifyDNResponse = require('./moddn_response') const ModifyDNResponse = require('./moddn_response')
var SearchRequest = require('./search_request') const SearchRequest = require('./search_request')
var SearchEntry = require('./search_entry') const SearchEntry = require('./search_entry')
var SearchReference = require('./search_reference') const SearchReference = require('./search_reference')
var SearchResponse = require('./search_response') const SearchResponse = require('./search_response')
var UnbindRequest = require('./unbind_request') const UnbindRequest = require('./unbind_request')
// var UnbindResponse = require('./unbind_response') // var UnbindResponse = require('./unbind_response')
var LDAPResult = require('./result') const LDAPResult = require('./result')
// var Message = require('./message') // var Message = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
// var Ber = asn1.Ber // var Ber = asn1.Ber
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
/// --- API /// --- API
@ -55,8 +55,8 @@ util.inherits(Parser, EventEmitter)
Parser.prototype.write = function (data) { Parser.prototype.write = function (data) {
if (!data || !Buffer.isBuffer(data)) { throw new TypeError('data (buffer) required') } if (!data || !Buffer.isBuffer(data)) { throw new TypeError('data (buffer) required') }
var nextMessage = null let nextMessage = null
var self = this const self = this
function end () { function end () {
if (nextMessage) { return self.write(nextMessage) } if (nextMessage) { return self.write(nextMessage) }
@ -66,9 +66,9 @@ Parser.prototype.write = function (data) {
self.buffer = (self.buffer ? Buffer.concat([self.buffer, data]) : data) self.buffer = (self.buffer ? Buffer.concat([self.buffer, data]) : data)
var ber = new BerReader(self.buffer) const ber = new BerReader(self.buffer)
var foundSeq = false let foundSeq = false
try { try {
foundSeq = ber.readSequence() foundSeq = ber.readSequence()
} catch (e) { } catch (e) {
@ -90,7 +90,7 @@ Parser.prototype.write = function (data) {
// pointing at the next sequence of data (if it exists) // pointing at the next sequence of data (if it exists)
self.buffer = null self.buffer = null
var message let message
try { try {
// Bail here if peer isn't speaking protocol at all // Bail here if peer isn't speaking protocol at all
message = this.getMessage(ber) message = this.getMessage(ber)
@ -111,12 +111,12 @@ Parser.prototype.write = function (data) {
Parser.prototype.getMessage = function (ber) { Parser.prototype.getMessage = function (ber) {
assert.ok(ber) assert.ok(ber)
var self = this const self = this
var messageID = ber.readInt() const messageID = ber.readInt()
var type = ber.readSequence() const type = ber.readSequence()
var Message let Message
switch (type) { switch (type) {
case Protocol.LDAP_REQ_ABANDON: case Protocol.LDAP_REQ_ABANDON:
Message = AbandonRequest Message = AbandonRequest

View File

@ -1,13 +1,13 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
// var asn1 = require('asn1') // var asn1 = require('asn1')
var dtrace = require('../dtrace') const dtrace = require('../dtrace')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
@ -46,16 +46,16 @@ LDAPResult.prototype.end = function (status) {
if (typeof (status) === 'number') { this.status = status } if (typeof (status) === 'number') { this.status = status }
var ber = this.toBer() const ber = this.toBer()
if (this.log.debug()) { this.log.debug('%s: sending: %j', this.connection.ldap.id, this.json) } if (this.log.debug()) { this.log.debug('%s: sending: %j', this.connection.ldap.id, this.json) }
try { try {
var self = this const self = this
this.connection.write(ber) this.connection.write(ber)
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-' + self._dtraceOp + '-done', function () { dtrace.fire('server-' + self._dtraceOp + '-done', function () {
var c = self.connection || { ldap: {} } const c = self.connection || { ldap: {} }
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
(c.remoteAddress || ''), (c.remoteAddress || ''),
@ -79,10 +79,10 @@ LDAPResult.prototype._parse = function (ber) {
this.matchedDN = ber.readString() this.matchedDN = ber.readString()
this.errorMessage = ber.readString() this.errorMessage = ber.readString()
var t = ber.peek() const t = ber.peek()
if (t === Protocol.LDAP_REP_REFERRAL) { if (t === Protocol.LDAP_REP_REFERRAL) {
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { this.referrals.push(ber.readString()) } while (ber.offset < end) { this.referrals.push(ber.readString()) }
} }

View File

@ -1,14 +1,14 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
// var asn1 = require('asn1') // var asn1 = require('asn1')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Attribute = require('../attribute') const Attribute = require('../attribute')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var lassert = require('../assert') const lassert = require('../assert')
/// --- Globals /// --- Globals
@ -39,7 +39,7 @@ Object.defineProperties(SearchEntry.prototype, {
}, },
object: { object: {
get: function getObject () { get: function getObject () {
var obj = { const obj = {
dn: this.dn.toString(), dn: this.dn.toString(),
controls: [] controls: []
} }
@ -63,7 +63,7 @@ Object.defineProperties(SearchEntry.prototype, {
}, },
raw: { raw: {
get: function getRaw () { get: function getRaw () {
var obj = { const obj = {
dn: this.dn.toString(), dn: this.dn.toString(),
controls: [] controls: []
} }
@ -101,7 +101,7 @@ SearchEntry.prototype.toObject = function () {
SearchEntry.prototype.fromObject = function (obj) { SearchEntry.prototype.fromObject = function (obj) {
if (typeof (obj) !== 'object') { throw new TypeError('object required') } if (typeof (obj) !== 'object') { throw new TypeError('object required') }
var self = this const self = this
if (obj.controls) { this.controls = obj.controls } if (obj.controls) { this.controls = obj.controls }
if (obj.attributes) { obj = obj.attributes } if (obj.attributes) { obj = obj.attributes }
@ -123,11 +123,11 @@ SearchEntry.prototype.setAttributes = function (obj) {
}) })
this.attributes = obj this.attributes = obj
} else { } else {
var self = this const self = this
self.attributes = [] self.attributes = []
Object.keys(obj).forEach(function (k) { Object.keys(obj).forEach(function (k) {
var attr = new Attribute({ type: k }) const attr = new Attribute({ type: k })
if (Array.isArray(obj[k])) { if (Array.isArray(obj[k])) {
obj[k].forEach(function (v) { obj[k].forEach(function (v) {
attr.addValue(v.toString()) attr.addValue(v.toString())
@ -158,9 +158,9 @@ SearchEntry.prototype._parse = function (ber) {
this.objectName = ber.readString() this.objectName = ber.readString()
assert.ok(ber.readSequence()) assert.ok(ber.readSequence())
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { while (ber.offset < end) {
var a = new Attribute() const a = new Attribute()
a.parse(ber) a.parse(ber)
this.attributes.push(a) this.attributes.push(a)
} }
@ -171,7 +171,7 @@ SearchEntry.prototype._parse = function (ber) {
SearchEntry.prototype._toBer = function (ber) { SearchEntry.prototype._toBer = function (ber) {
assert.ok(ber) assert.ok(ber)
var formattedObjectName = this.objectName.format({ skipSpace: true }) const formattedObjectName = this.objectName.format({ skipSpace: true })
ber.writeString(formattedObjectName) ber.writeString(formattedObjectName)
ber.startSequence() ber.startSequence()
this.attributes.forEach(function (a) { this.attributes.forEach(function (a) {

View File

@ -1,19 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
// var asn1 = require('asn1') // var asn1 = require('asn1')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var Protocol = require('../protocol') const Protocol = require('../protocol')
var dn = require('../dn') const dn = require('../dn')
var url = require('../url') const url = require('../url')
/// --- Globals /// --- Globals
// var BerWriter = asn1.BerWriter // var BerWriter = asn1.BerWriter
var parseURL = url.parse const parseURL = url.parse
/// --- API /// --- API
@ -78,7 +78,7 @@ SearchReference.prototype._parse = function (ber, length) {
assert.ok(ber) assert.ok(ber)
while (ber.offset < length) { while (ber.offset < length) {
var _url = ber.readString() const _url = ber.readString()
parseURL(_url) parseURL(_url)
this.uris.push(_url) this.uris.push(_url)
} }

View File

@ -1,19 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var asn1 = require('asn1') const asn1 = require('asn1')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
// var LDAPResult = require('./result') // var LDAPResult = require('./result')
var dn = require('../dn') const dn = require('../dn')
var filters = require('../filters') const filters = require('../filters')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
var Ber = asn1.Ber const Ber = asn1.Ber
/// --- API /// --- API
@ -95,7 +95,7 @@ SearchRequest.prototype._parse = function (ber) {
// look for attributes // look for attributes
if (ber.peek() === 0x30) { if (ber.peek() === 0x30) {
ber.readSequence() ber.readSequence()
var end = ber.offset + ber.length const end = ber.offset + ber.length
while (ber.offset < end) { this.attributes.push(ber.readString().toLowerCase()) } while (ber.offset < end) { this.attributes.push(ber.readString().toLowerCase()) }
} }
@ -108,7 +108,7 @@ SearchRequest.prototype._toBer = function (ber) {
// Format only with commas, since that is what RFC 4514 mandates. // Format only with commas, since that is what RFC 4514 mandates.
// There's a gotcha here: even though it's called baseObject, // There's a gotcha here: even though it's called baseObject,
// it can be a string or a DN object. // it can be a string or a DN object.
var formattedDN = dn.DN.isDN(this.baseObject) const formattedDN = dn.DN.isDN(this.baseObject)
? this.baseObject.format({ skipSpace: true }) ? this.baseObject.format({ skipSpace: true })
: this.baseObject.toString() : this.baseObject.toString()
ber.writeString(formattedDN) ber.writeString(formattedDN)
@ -118,7 +118,7 @@ SearchRequest.prototype._toBer = function (ber) {
ber.writeInt(this.timeLimit) ber.writeInt(this.timeLimit)
ber.writeBoolean(this.typesOnly) ber.writeBoolean(this.typesOnly)
var f = this.filter || new filters.PresenceFilter({ attribute: 'objectclass' }) const f = this.filter || new filters.PresenceFilter({ attribute: 'objectclass' })
ber = f.toBer(ber) ber = f.toBer(ber)
ber.startSequence(Ber.Sequence | Ber.Constructor) ber.startSequence(Ber.Sequence | Ber.Constructor)

View File

@ -1,16 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPResult = require('./result') const LDAPResult = require('./result')
var SearchEntry = require('./search_entry') const SearchEntry = require('./search_entry')
var SearchReference = require('./search_reference') const SearchReference = require('./search_reference')
var dtrace = require('../dtrace') const dtrace = require('../dtrace')
var parseDN = require('../dn').parse const parseDN = require('../dn').parse
var parseURL = require('../url').parse const parseURL = require('../url').parse
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- API /// --- API
@ -39,18 +39,19 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
if (nofiltering === undefined) { nofiltering = false } if (nofiltering === undefined) { nofiltering = false }
if (typeof (nofiltering) !== 'boolean') { throw new TypeError('noFiltering must be a boolean') } if (typeof (nofiltering) !== 'boolean') { throw new TypeError('noFiltering must be a boolean') }
var self = this const self = this
const savedAttrs = {}
const save = null
if (entry instanceof SearchEntry || entry instanceof SearchReference) { if (entry instanceof SearchEntry || entry instanceof SearchReference) {
if (!entry.messageID) { entry.messageID = this.messageID } if (!entry.messageID) { entry.messageID = this.messageID }
if (entry.messageID !== this.messageID) { throw new Error('SearchEntry messageID mismatch') } if (entry.messageID !== this.messageID) { throw new Error('SearchEntry messageID mismatch') }
} else { } else {
if (!entry.attributes) { throw new Error('entry.attributes required') } if (!entry.attributes) { throw new Error('entry.attributes required') }
var savedAttrs = {} const all = (self.attributes.indexOf('*') !== -1)
var all = (self.attributes.indexOf('*') !== -1)
Object.keys(entry.attributes).forEach(function (a) { Object.keys(entry.attributes).forEach(function (a) {
var _a = a.toLowerCase() const _a = a.toLowerCase()
if (!nofiltering && _a.length && _a[0] === '_') { if (!nofiltering && _a.length && _a[0] === '_') {
savedAttrs[a] = entry.attributes[a] savedAttrs[a] = entry.attributes[a]
delete entry.attributes[a] delete entry.attributes[a]
@ -58,14 +59,14 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
savedAttrs[a] = entry.attributes[a] savedAttrs[a] = entry.attributes[a]
delete entry.attributes[a] delete entry.attributes[a]
} else if (all) { } else if (all) {
// do nothing
} else if (self.attributes.length && self.attributes.indexOf(_a) === -1) { } else if (self.attributes.length && self.attributes.indexOf(_a) === -1) {
savedAttrs[a] = entry.attributes[a] savedAttrs[a] = entry.attributes[a]
delete entry.attributes[a] delete entry.attributes[a]
} }
}) })
var save = entry const save = entry
entry = new SearchEntry({ entry = new SearchEntry({
objectName: typeof (save.dn) === 'string' ? parseDN(save.dn) : save.dn, objectName: typeof (save.dn) === 'string' ? parseDN(save.dn) : save.dn,
messageID: self.messageID, messageID: self.messageID,
@ -82,7 +83,7 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-search-entry', function () { dtrace.fire('server-search-entry', function () {
var c = self.connection || { ldap: {} } const c = self.connection || { ldap: {} }
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
(c.remoteAddress || ''), (c.remoteAddress || ''),
@ -95,7 +96,7 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
} }
// Restore attributes // Restore attributes
Object.keys(savedAttrs || {}).forEach(function (k) { Object.keys(savedAttrs).forEach(function (k) {
save.attributes[k] = savedAttrs[k] save.attributes[k] = savedAttrs[k]
}) })
} catch (e) { } catch (e) {
@ -107,7 +108,7 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
SearchResponse.prototype.createSearchEntry = function (object) { SearchResponse.prototype.createSearchEntry = function (object) {
assert.object(object) assert.object(object)
var entry = new SearchEntry({ const entry = new SearchEntry({
messageID: this.messageID, messageID: this.messageID,
log: this.log, log: this.log,
objectName: object.objectName || object.dn objectName: object.objectName || object.dn
@ -121,11 +122,11 @@ SearchResponse.prototype.createSearchReference = function (uris) {
if (!Array.isArray(uris)) { uris = [uris] } if (!Array.isArray(uris)) { uris = [uris] }
for (var i = 0; i < uris.length; i++) { for (let i = 0; i < uris.length; i++) {
if (typeof (uris[i]) === 'string') { uris[i] = parseURL(uris[i]) } if (typeof (uris[i]) === 'string') { uris[i] = parseURL(uris[i]) }
} }
var self = this const self = this
return new SearchReference({ return new SearchReference({
messageID: self.messageID, messageID: self.messageID,
log: self.log, log: self.log,

View File

@ -1,16 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var LDAPMessage = require('./message') const LDAPMessage = require('./message')
var dn = require('../dn') const dn = require('../dn')
var Protocol = require('../protocol') const Protocol = require('../protocol')
/// --- Globals /// --- Globals
var DN = dn.DN const DN = dn.DN
var RDN = dn.RDN const RDN = dn.RDN
/// --- API /// --- API

View File

@ -1,11 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus') const assert = require('assert-plus')
var util = require('util') const util = require('util')
var dtrace = require('../dtrace') const dtrace = require('../dtrace')
var LDAPMessage = require('./result') const LDAPMessage = require('./result')
// var Protocol = require('../protocol') // var Protocol = require('../protocol')
/// --- API /// --- API
@ -40,10 +40,10 @@ UnbindResponse.prototype.end = function (status) {
this.connection.end() this.connection.end()
var self = this const self = this
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-' + self._dtraceOp + '-done', function () { dtrace.fire('server-' + self._dtraceOp + '-done', function () {
var c = self.connection || { ldap: {} } const c = self.connection || { ldap: {} }
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
(c.remoteAddress || ''), (c.remoteAddress || ''),

View File

@ -2,7 +2,7 @@
// var parseDN = require('./dn').parse // var parseDN = require('./dn').parse
var EntryChangeNotificationControl = const EntryChangeNotificationControl =
require('./controls').EntryChangeNotificationControl require('./controls').EntryChangeNotificationControl
/// --- API /// --- API
@ -17,9 +17,9 @@ PersistentSearch.prototype.addClient = function (req, res, callback) {
if (typeof (res) !== 'object') { throw new TypeError('res must be an object') } if (typeof (res) !== 'object') { throw new TypeError('res must be an object') }
if (callback && typeof (callback) !== 'function') { throw new TypeError('callback must be a function') } if (callback && typeof (callback) !== 'function') { throw new TypeError('callback must be a function') }
var log = req.log const log = req.log
var client = {} const client = {}
client.req = req client.req = req
client.res = res client.res = res
@ -38,9 +38,9 @@ PersistentSearch.prototype.removeClient = function (req, res, callback) {
if (typeof (res) !== 'object') { throw new TypeError('res must be an object') } if (typeof (res) !== 'object') { throw new TypeError('res must be an object') }
if (callback && typeof (callback) !== 'function') { throw new TypeError('callback must be a function') } if (callback && typeof (callback) !== 'function') { throw new TypeError('callback must be a function') }
var log = req.log const log = req.log
log.debug('%s removing client', req.logId) log.debug('%s removing client', req.logId)
var client = {} const client = {}
client.req = req client.req = req
client.res = res client.res = res
@ -80,8 +80,8 @@ function getOperationType (requestType) {
function getEntryChangeNotificationControl (req, obj, callback) { function getEntryChangeNotificationControl (req, obj, callback) {
// if we want to return a ECNC // if we want to return a ECNC
if (req.persistentSearch.value.returnECs) { if (req.persistentSearch.value.returnECs) {
var attrs = obj.attributes const attrs = obj.attributes
var value = {} const value = {}
value.changeType = getOperationType(attrs.changetype) value.changeType = getOperationType(attrs.changetype)
// if it's a modDN request, fill in the previous DN // if it's a modDN request, fill in the previous DN
if (value.changeType === 8 && attrs.previousDN) { if (value.changeType === 8 && attrs.previousDN) {

View File

@ -1,38 +1,38 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert') const assert = require('assert')
var EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
var net = require('net') const net = require('net')
var tls = require('tls') const tls = require('tls')
var util = require('util') const util = require('util')
// var asn1 = require('asn1') // var asn1 = require('asn1')
var VError = require('verror').VError const VError = require('verror').VError
var dn = require('./dn') const dn = require('./dn')
var dtrace = require('./dtrace') const dtrace = require('./dtrace')
var errors = require('./errors') const errors = require('./errors')
var Protocol = require('./protocol') const Protocol = require('./protocol')
var Parser = require('./messages').Parser const Parser = require('./messages').Parser
var AbandonResponse = require('./messages/abandon_response') const AbandonResponse = require('./messages/abandon_response')
var AddResponse = require('./messages/add_response') const AddResponse = require('./messages/add_response')
var BindResponse = require('./messages/bind_response') const BindResponse = require('./messages/bind_response')
var CompareResponse = require('./messages/compare_response') const CompareResponse = require('./messages/compare_response')
var DeleteResponse = require('./messages/del_response') const DeleteResponse = require('./messages/del_response')
var ExtendedResponse = require('./messages/ext_response') const ExtendedResponse = require('./messages/ext_response')
// var LDAPResult = require('./messages/result') // var LDAPResult = require('./messages/result')
var ModifyResponse = require('./messages/modify_response') const ModifyResponse = require('./messages/modify_response')
var ModifyDNResponse = require('./messages/moddn_response') const ModifyDNResponse = require('./messages/moddn_response')
var SearchRequest = require('./messages/search_request') const SearchRequest = require('./messages/search_request')
var SearchResponse = require('./messages/search_response') const SearchResponse = require('./messages/search_response')
var UnbindResponse = require('./messages/unbind_response') const UnbindResponse = require('./messages/unbind_response')
/// --- Globals /// --- Globals
// var Ber = asn1.Ber // var Ber = asn1.Ber
// var BerReader = asn1.BerReader // var BerReader = asn1.BerReader
var DN = dn.DN const DN = dn.DN
// var sprintf = util.format // var sprintf = util.format
@ -44,12 +44,12 @@ function mergeFunctionArgs (argv, start, end) {
if (!start) { start = 0 } if (!start) { start = 0 }
if (!end) { end = argv.length } if (!end) { end = argv.length }
var handlers = [] const handlers = []
for (var i = start; i < end; i++) { for (let i = start; i < end; i++) {
if (argv[i] instanceof Array) { if (argv[i] instanceof Array) {
var arr = argv[i] const arr = argv[i]
for (var j = 0; j < arr.length; j++) { for (let j = 0; j < arr.length; j++) {
if (!(arr[j] instanceof Function)) { if (!(arr[j] instanceof Function)) {
throw new TypeError('Invalid argument type: ' + typeof (arr[j])) throw new TypeError('Invalid argument type: ' + typeof (arr[j]))
} }
@ -68,7 +68,7 @@ function mergeFunctionArgs (argv, start, end) {
function getResponse (req) { function getResponse (req) {
assert.ok(req) assert.ok(req)
var Response let Response
switch (req.protocolOp) { switch (req.protocolOp) {
case Protocol.LDAP_REQ_BIND: case Protocol.LDAP_REQ_BIND:
@ -106,7 +106,7 @@ function getResponse (req) {
} }
assert.ok(Response) assert.ok(Response)
var res = new Response({ const res = new Response({
messageID: req.messageID, messageID: req.messageID,
log: req.log, log: req.log,
attributes: ((req instanceof SearchRequest) ? req.attributes : undefined) attributes: ((req instanceof SearchRequest) ? req.attributes : undefined)
@ -161,14 +161,14 @@ function fireDTraceProbe (req, res) {
assert.ok(req) assert.ok(req)
req._dtraceId = res._dtraceId = dtrace._nextId() req._dtraceId = res._dtraceId = dtrace._nextId()
var probeArgs = [ const probeArgs = [
req._dtraceId, req._dtraceId,
req.connection.remoteAddress || 'localhost', req.connection.remoteAddress || 'localhost',
req.connection.ldap.bindDN.toString(), req.connection.ldap.bindDN.toString(),
req.dn.toString() req.dn.toString()
] ]
var op let op
switch (req.protocolOp) { switch (req.protocolOp) {
case Protocol.LDAP_REQ_ABANDON: case Protocol.LDAP_REQ_ABANDON:
op = 'abandon' op = 'abandon'
@ -255,7 +255,7 @@ function Server (options) {
} else { } else {
options = {} options = {}
} }
var self = this const self = this
EventEmitter.call(this, options) EventEmitter.call(this, options)
@ -263,7 +263,7 @@ function Server (options) {
this.log = options.log this.log = options.log
this.strictDN = (options.strictDN !== undefined) ? options.strictDN : true this.strictDN = (options.strictDN !== undefined) ? options.strictDN : true
var log = this.log const log = this.log
function setupConnection (c) { function setupConnection (c) {
assert.ok(c) assert.ok(c)
@ -277,7 +277,7 @@ function Server (options) {
c.remotePort = c.socket.remotePort c.remotePort = c.socket.remotePort
} }
var rdn = new dn.RDN({ cn: 'anonymous' }) const rdn = new dn.RDN({ cn: 'anonymous' })
c.ldap = { c.ldap = {
id: c.remoteAddress + ':' + c.remotePort, id: c.remoteAddress + ':' + c.remotePort,
@ -331,7 +331,7 @@ function Server (options) {
if (log.debug()) { log.debug('%s: message received: req=%j', c.ldap.id, req.json) } if (log.debug()) { log.debug('%s: message received: req=%j', c.ldap.id, req.json) }
var res = getResponse(req) const res = getResponse(req)
if (!res) { if (!res) {
log.warn('Unimplemented server method: %s', req.type) log.warn('Unimplemented server method: %s', req.type)
c.destroy() c.destroy()
@ -372,9 +372,9 @@ function Server (options) {
res.logId = req.logId res.logId = req.logId
res.requestDN = req.dn res.requestDN = req.dn
var chain = self._getHandlerChain(req, res) const chain = self._getHandlerChain(req, res)
var i = 0 let i = 0
return (function messageIIFE (err) { return (function messageIIFE (err) {
function sendError (err) { function sendError (err) {
res.status = err.code || errors.LDAP_OPERATIONS_ERROR res.status = err.code || errors.LDAP_OPERATIONS_ERROR
@ -401,7 +401,7 @@ function Server (options) {
} }
try { try {
var next = messageIIFE const next = messageIIFE
if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) } if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) }
if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { c.ldap.bindDN = req.dn } if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { c.ldap.bindDN = req.dn }
@ -420,7 +420,7 @@ function Server (options) {
if (!message) { return c.destroy() } if (!message) { return c.destroy() }
var res = getResponse(message) const res = getResponse(message)
if (!res) { return c.destroy() } if (!res) { return c.destroy() }
res.status = 0x02 // protocol error res.status = 0x02 // protocol error
@ -478,14 +478,14 @@ Object.defineProperties(Server.prototype, {
}, },
url: { url: {
get: function getURL () { get: function getURL () {
var str let str
var addr = this.server.address() const addr = this.server.address()
if (!addr) { if (!addr) {
return null return null
} }
if (!addr.family) { if (!addr.family) {
str = 'ldapi://' str = 'ldapi://'
str += this.host.replace(new RegExp('/', 'g'), '%2f') str += this.host.replace(/\//g, '%2f')
return str return str
} }
if (this.server instanceof tls.Server) { if (this.server instanceof tls.Server) {
@ -512,7 +512,7 @@ module.exports = Server
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.add = function (name) { Server.prototype.add = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_ADD, name, args) return this._mount(Protocol.LDAP_REQ_ADD, name, args)
} }
@ -527,7 +527,7 @@ Server.prototype.add = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.bind = function (name) { Server.prototype.bind = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_BIND, name, args) return this._mount(Protocol.LDAP_REQ_BIND, name, args)
} }
@ -542,7 +542,7 @@ Server.prototype.bind = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.compare = function (name) { Server.prototype.compare = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_COMPARE, name, args) return this._mount(Protocol.LDAP_REQ_COMPARE, name, args)
} }
@ -557,7 +557,7 @@ Server.prototype.compare = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.del = function (name) { Server.prototype.del = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_DELETE, name, args) return this._mount(Protocol.LDAP_REQ_DELETE, name, args)
} }
@ -572,7 +572,7 @@ Server.prototype.del = function (name) {
* @throws {TypeError} on bad input. * @throws {TypeError} on bad input.
*/ */
Server.prototype.exop = function (name) { Server.prototype.exop = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_EXTENSION, name, args, true) return this._mount(Protocol.LDAP_REQ_EXTENSION, name, args, true)
} }
@ -587,7 +587,7 @@ Server.prototype.exop = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.modify = function (name) { Server.prototype.modify = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_MODIFY, name, args) return this._mount(Protocol.LDAP_REQ_MODIFY, name, args)
} }
@ -602,7 +602,7 @@ Server.prototype.modify = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.modifyDN = function (name) { Server.prototype.modifyDN = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_MODRDN, name, args) return this._mount(Protocol.LDAP_REQ_MODRDN, name, args)
} }
@ -617,7 +617,7 @@ Server.prototype.modifyDN = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.search = function (name) { Server.prototype.search = function (name) {
var args = Array.prototype.slice.call(arguments, 1) const args = Array.prototype.slice.call(arguments, 1)
return this._mount(Protocol.LDAP_REQ_SEARCH, name, args) return this._mount(Protocol.LDAP_REQ_SEARCH, name, args)
} }
@ -631,14 +631,14 @@ Server.prototype.search = function (name) {
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.unbind = function () { Server.prototype.unbind = function () {
var args = Array.prototype.slice.call(arguments, 0) const args = Array.prototype.slice.call(arguments, 0)
return this._mount(Protocol.LDAP_REQ_UNBIND, 'unbind', args, true) return this._mount(Protocol.LDAP_REQ_UNBIND, 'unbind', args, true)
} }
Server.prototype.use = function use () { Server.prototype.use = function use () {
var args = Array.prototype.slice.call(arguments) const args = Array.prototype.slice.call(arguments)
var chain = mergeFunctionArgs(args, 0, args.length) const chain = mergeFunctionArgs(args, 0, args.length)
var self = this const self = this
chain.forEach(function (c) { chain.forEach(function (c) {
self._chain.push(c) self._chain.push(c)
}) })
@ -647,7 +647,7 @@ Server.prototype.use = function use () {
Server.prototype.after = function () { Server.prototype.after = function () {
if (!this._postChain) { this._postChain = [] } if (!this._postChain) { this._postChain = [] }
var self = this const self = this
mergeFunctionArgs(arguments).forEach(function (h) { mergeFunctionArgs(arguments).forEach(function (h) {
self._postChain.push(h) self._postChain.push(h)
}) })
@ -665,7 +665,7 @@ Server.prototype.listen = function (port, host, callback) {
// Disambiguate between string ports and file paths // Disambiguate between string ports and file paths
port = parseInt(port, 10) port = parseInt(port, 10)
} }
var self = this const self = this
function cbListen () { function cbListen () {
if (typeof (port) === 'number') { if (typeof (port) === 'number') {
@ -706,7 +706,7 @@ Server.prototype._getRoute = function (_dn, backend) {
if (!backend) { backend = this } if (!backend) { backend = this }
var name let name
if (_dn instanceof dn.DN) { if (_dn instanceof dn.DN) {
name = _dn.toString() name = _dn.toString()
} else { } else {
@ -728,19 +728,19 @@ Server.prototype._sortedRouteKeys = function _sortedRouteKeys () {
// The filtered/sorted route keys are cached to prevent needlessly // The filtered/sorted route keys are cached to prevent needlessly
// regenerating the list for every incoming request. // regenerating the list for every incoming request.
if (!this._routeKeyCache) { if (!this._routeKeyCache) {
var self = this const self = this
var reversedRDNsToKeys = {} const reversedRDNsToKeys = {}
// Generate mapping of reversedRDNs(DN) -> routeKey // Generate mapping of reversedRDNs(DN) -> routeKey
Object.keys(this.routes).forEach(function (key) { Object.keys(this.routes).forEach(function (key) {
var _dn = self.routes[key].dn const _dn = self.routes[key].dn
// Ignore non-DN routes such as exop or unbind // Ignore non-DN routes such as exop or unbind
if (_dn instanceof dn.DN) { if (_dn instanceof dn.DN) {
var reversed = _dn.clone() const reversed = _dn.clone()
reversed.rdns.reverse() reversed.rdns.reverse()
reversedRDNsToKeys[reversed.format()] = key reversedRDNsToKeys[reversed.format()] = key
} }
}) })
var output = [] const output = []
// Reverse-sort on reversedRDS(DN) in order to output routeKey list. // Reverse-sort on reversedRDS(DN) in order to output routeKey list.
// This will place more specific DNs in front of their parents: // This will place more specific DNs in front of their parents:
// 1. dc=test, dc=domain, dc=sub // 1. dc=test, dc=domain, dc=sub
@ -759,9 +759,9 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) {
fireDTraceProbe(req, res) fireDTraceProbe(req, res)
var self = this const self = this
var routes = this.routes const routes = this.routes
var route let route
// check anonymous bind // check anonymous bind
if (req.protocolOp === Protocol.LDAP_REQ_BIND && if (req.protocolOp === Protocol.LDAP_REQ_BIND &&
@ -773,7 +773,7 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) {
} }
} }
var op = '0x' + req.protocolOp.toString(16) const op = '0x' + req.protocolOp.toString(16)
// Special cases are exops, unbinds and abandons. Handle those first. // Special cases are exops, unbinds and abandons. Handle those first.
if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) { if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) {
@ -811,13 +811,13 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req, res) {
// Otherwise, match via DN rules // Otherwise, match via DN rules
assert.ok(req.dn) assert.ok(req.dn)
var keys = this._sortedRouteKeys() const keys = this._sortedRouteKeys()
var fallbackHandler = [noSuffixHandler] let fallbackHandler = [noSuffixHandler]
// invalid DNs in non-strict mode are routed to the default handler // invalid DNs in non-strict mode are routed to the default handler
var testDN = (typeof (req.dn) === 'string') ? '' : req.dn const testDN = (typeof (req.dn) === 'string') ? '' : req.dn
for (var i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
var suffix = keys[i] const suffix = keys[i]
route = routes[suffix] route = routes[suffix]
assert.ok(route.dn) assert.ok(route.dn)
// Match a valid route or the route wildcard ('') // Match a valid route or the route wildcard ('')
@ -854,16 +854,16 @@ Server.prototype._mount = function (op, name, argv, notDN) {
if (typeof (name) !== 'string') { throw new TypeError('name (string) required') } if (typeof (name) !== 'string') { throw new TypeError('name (string) required') }
if (!argv.length) { throw new Error('at least one handler required') } if (!argv.length) { throw new Error('at least one handler required') }
var backend = this let backend = this
var index = 0 let index = 0
if (typeof (argv[0]) === 'object' && !Array.isArray(argv[0])) { if (typeof (argv[0]) === 'object' && !Array.isArray(argv[0])) {
backend = argv[0] backend = argv[0]
index = 1 index = 1
} }
var route = this._getRoute(notDN ? name : dn.parse(name), backend) const route = this._getRoute(notDN ? name : dn.parse(name), backend)
var chain = this._chain.slice() const chain = this._chain.slice()
argv.slice(index).forEach(function (a) { argv.slice(index).forEach(function (a) {
chain.push(a) chain.push(a)
}) })

View File

@ -43,7 +43,7 @@ module.exports = {
if (u.search) { if (u.search) {
u.attributes = [] u.attributes = []
var tmp = u.search.substr(1).split('?') const tmp = u.search.substr(1).split('?')
if (tmp && tmp.length) { if (tmp && tmp.length) {
if (tmp[0]) { if (tmp[0]) {
tmp[0].split(',').forEach(function (a) { tmp[0].split(',').forEach(function (a) {

View File

@ -30,7 +30,7 @@
"get-port": "^5.1.1", "get-port": "^5.1.1",
"husky": "^4.2.5", "husky": "^4.2.5",
"snazzy": "^9.0.0", "snazzy": "^9.0.0",
"standard": "^15.0.0", "standard": "^16.0.0",
"tap": "14.10.8" "tap": "14.10.8"
}, },
"scripts": { "scripts": {

View File

@ -31,9 +31,9 @@ test('new with args', function (t) {
}) })
test('new with args and buffer', function (t) { test('new with args and buffer', function (t) {
var img = fs.readFileSync(path.join(__dirname, '/imgs/test.jpg')) const img = fs.readFileSync(path.join(__dirname, '/imgs/test.jpg'))
var change = new Change({ const change = new Change({
operation: 'add', operation: 'add',
modification: { modification: {
thumbnailPhoto: img thumbnailPhoto: img

View File

@ -96,7 +96,7 @@ tap.beforeEach((done, t) => {
} }
})) }))
} else { } else {
var e = res.createSearchEntry({ const e = res.createSearchEntry({
objectName: req.dn, objectName: req.dn,
attributes: { attributes: {
cn: ['unit', 'test'], cn: ['unit', 'test'],
@ -1100,7 +1100,7 @@ tap.test('search empty attribute', function (t) {
t.ok(res) t.ok(res)
let gotEntry = 0 let gotEntry = 0
res.on('searchEntry', function (entry) { res.on('searchEntry', function (entry) {
var obj = entry.toObject() const obj = entry.toObject()
t.equal('dc=empty', obj.dn) t.equal('dc=empty', obj.dn)
t.ok(obj.member) t.ok(obj.member)
t.equal(obj.member.length, 0) t.equal(obj.member.length, 0)
@ -1142,7 +1142,7 @@ tap.test('GH-21 binary attributes', function (t) {
t.ok(entry.attributes[1].type, 'gb18030') t.ok(entry.attributes[1].type, 'gb18030')
t.equal(entry.attributes[1].buffers.length, 1) t.equal(entry.attributes[1].buffers.length, 1)
t.equal(expect2.length, entry.attributes[1].buffers[0].length) t.equal(expect2.length, entry.attributes[1].buffers[0].length)
for (var i = 0; i < expect2.length; i++) { t.equal(expect2[i], entry.attributes[1].buffers[0][i]) } for (let i = 0; i < expect2.length; i++) { t.equal(expect2[i], entry.attributes[1].buffers[0][i]) }
t.ok(entry.object) t.ok(entry.object)
gotEntry++ gotEntry++
@ -1240,7 +1240,7 @@ tap.test('idle timeout', function (t) {
t.error(err) t.error(err)
}) })
res.on('end', function () { res.on('end', function () {
var late = setTimeout(function () { const late = setTimeout(function () {
t.fail('too late') t.fail('too late')
}, 500) }, 500)
// It's ok to go idle now // It's ok to go idle now
@ -1358,7 +1358,7 @@ tap.test('abort reconnect', function (t) {
socketPath: 'an invalid path', socketPath: 'an invalid path',
reconnect: true reconnect: true
}) })
var retryCount = 0 let retryCount = 0
abortClient.on('connectError', function () { abortClient.on('connectError', function () {
++retryCount ++retryCount
}) })
@ -1531,7 +1531,7 @@ tap.test('connection timeout', function (t) {
timeout: 1 timeout: 1
}) })
var done = false let done = false
setTimeout(function () { setTimeout(function () {
if (!done) { if (!done) {

View File

@ -1,13 +1,13 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test const test = require('tap').test
var asn1 = require('asn1') const asn1 = require('asn1')
var BerReader = asn1.BerReader const BerReader = asn1.BerReader
var BerWriter = asn1.BerWriter const BerWriter = asn1.BerWriter
var getControl let getControl
var PersistentSearchControl let PersistentSearchControl
/// --- Tests /// --- Tests
@ -25,7 +25,7 @@ test('new no args', function (t) {
}) })
test('new with args', function (t) { test('new with args', function (t) {
var c = new PersistentSearchControl({ const c = new PersistentSearchControl({
type: '2.16.840.1.113730.3.4.3', type: '2.16.840.1.113730.3.4.3',
criticality: true, criticality: true,
value: { value: {
@ -42,10 +42,10 @@ test('new with args', function (t) {
t.equal(c.value.changesOnly, false) t.equal(c.value.changesOnly, false)
t.equal(c.value.returnECs, false) t.equal(c.value.returnECs, false)
var writer = new BerWriter() const writer = new BerWriter()
c.toBer(writer) c.toBer(writer)
var reader = new BerReader(writer.buffer) const reader = new BerReader(writer.buffer)
var psc = getControl(reader) const psc = getControl(reader)
t.ok(psc) t.ok(psc)
t.equal(psc.type, '2.16.840.1.113730.3.4.3') t.equal(psc.type, '2.16.840.1.113730.3.4.3')
t.ok(psc.criticality) t.ok(psc.criticality)
@ -57,14 +57,14 @@ test('new with args', function (t) {
}) })
test('getControl with args', function (t) { test('getControl with args', function (t) {
var buf = Buffer.from([ const buf = Buffer.from([
0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30, 0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30,
0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e, 0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e,
0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01, 0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01,
0xff, 0x01, 0x01, 0xff]) 0xff, 0x01, 0x01, 0xff])
var ber = new BerReader(buf) const ber = new BerReader(buf)
var psc = getControl(ber) const psc = getControl(ber)
t.ok(psc) t.ok(psc)
t.equal(psc.type, '2.16.840.1.113730.3.4.3') t.equal(psc.type, '2.16.840.1.113730.3.4.3')
t.equal(psc.criticality, false) t.equal(psc.criticality, false)
@ -75,7 +75,7 @@ test('getControl with args', function (t) {
}) })
test('tober', function (t) { test('tober', function (t) {
var psc = new PersistentSearchControl({ const psc = new PersistentSearchControl({
type: '2.16.840.1.113730.3.4.3', type: '2.16.840.1.113730.3.4.3',
criticality: true, criticality: true,
value: { value: {
@ -85,10 +85,10 @@ test('tober', function (t) {
} }
}) })
var ber = new BerWriter() const ber = new BerWriter()
psc.toBer(ber) psc.toBer(ber)
var c = getControl(new BerReader(ber.buffer)) const c = getControl(new BerReader(ber.buffer))
t.ok(c) t.ok(c)
t.equal(c.type, '2.16.840.1.113730.3.4.3') t.equal(c.type, '2.16.840.1.113730.3.4.3')
t.ok(c.criticality) t.ok(c.criticality)

View File

@ -35,7 +35,7 @@ tap.beforeEach((done, t) => {
}) })
server.search(suffix, function (req, res, next) { server.search(suffix, function (req, res, next) {
var entry = { const entry = {
dn: 'cn=foo, ' + suffix, dn: 'cn=foo, ' + suffix,
attributes: { attributes: {
objectclass: ['person', 'top'], objectclass: ['person', 'top'],