2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const assert = require('assert-plus')
|
|
|
|
const util = require('util')
|
2019-08-27 21:11:49 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const LDAPMessage = require('./message')
|
|
|
|
const Protocol = require('../protocol')
|
|
|
|
const dn = require('../dn')
|
|
|
|
const lassert = require('../assert')
|
2019-08-27 21:11:49 +00:00
|
|
|
|
|
|
|
/// --- API
|
|
|
|
|
|
|
|
function ModifyDNRequest (options) {
|
|
|
|
options = options || {}
|
|
|
|
assert.object(options)
|
|
|
|
assert.optionalBool(options.deleteOldRdn)
|
|
|
|
lassert.optionalStringDN(options.entry)
|
|
|
|
lassert.optionalDN(options.newRdn)
|
|
|
|
lassert.optionalDN(options.newSuperior)
|
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_MODRDN
|
|
|
|
LDAPMessage.call(this, options)
|
|
|
|
|
|
|
|
this.entry = options.entry || null
|
|
|
|
this.newRdn = options.newRdn || null
|
|
|
|
this.deleteOldRdn = options.deleteOldRdn || true
|
|
|
|
this.newSuperior = options.newSuperior || null
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
util.inherits(ModifyDNRequest, LDAPMessage)
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(ModifyDNRequest.prototype, {
|
|
|
|
type: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function getType () { return 'ModifyDNRequest' },
|
2015-10-31 17:28:25 +00:00
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
_dn: {
|
2019-08-27 21:11:49 +00:00
|
|
|
get: function getDN () { return this.entry },
|
2015-10-31 17:28:25 +00:00
|
|
|
configurable: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._parse = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(ber)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
this.entry = ber.readString()
|
|
|
|
this.newRdn = dn.parse(ber.readString())
|
|
|
|
this.deleteOldRdn = ber.readBoolean()
|
|
|
|
if (ber.peek() === 0x80) { this.newSuperior = dn.parse(ber.readString(0x80)) }
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return true
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._toBer = function (ber) {
|
2019-08-27 21:11:49 +00:00
|
|
|
// assert.ok(ber);
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
ber.writeString(this.entry.toString())
|
|
|
|
ber.writeString(this.newRdn.toString())
|
|
|
|
ber.writeBoolean(this.deleteOldRdn)
|
2013-01-14 09:14:35 +00:00
|
|
|
if (this.newSuperior) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const s = this.newSuperior.toString()
|
|
|
|
const len = Buffer.byteLength(s)
|
2019-08-27 21:11:49 +00:00
|
|
|
|
|
|
|
ber.writeByte(0x80) // MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG
|
2021-07-29 15:53:40 +00:00
|
|
|
ber.writeLength(len)
|
2019-08-27 21:11:49 +00:00
|
|
|
ber._ensure(len)
|
|
|
|
ber._buf.write(s, ber._offset)
|
|
|
|
ber._offset += len
|
2013-01-29 18:38:39 +00:00
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return ber
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._json = function (j) {
|
2019-08-27 21:11:49 +00:00
|
|
|
assert.ok(j)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
j.entry = this.entry.toString()
|
|
|
|
j.newRdn = this.newRdn.toString()
|
|
|
|
j.deleteOldRdn = this.deleteOldRdn
|
|
|
|
j.newSuperior = this.newSuperior ? this.newSuperior.toString() : ''
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return j
|
|
|
|
}
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Exports
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
module.exports = ModifyDNRequest
|