1 |
|
2 |
|
3 | const assert = require('assert-plus')
|
4 | const util = require('util')
|
5 |
|
6 | const LDAPMessage = require('./message')
|
7 | const Protocol = require('../protocol')
|
8 | const dn = require('../dn')
|
9 | const lassert = require('../assert')
|
10 |
|
11 |
|
12 |
|
13 | function ModifyDNRequest (options) {
|
14 | options = options || {}
|
15 | assert.object(options)
|
16 | assert.optionalBool(options.deleteOldRdn)
|
17 | lassert.optionalStringDN(options.entry)
|
18 | lassert.optionalDN(options.newRdn)
|
19 | lassert.optionalDN(options.newSuperior)
|
20 |
|
21 | options.protocolOp = Protocol.LDAP_REQ_MODRDN
|
22 | LDAPMessage.call(this, options)
|
23 |
|
24 | this.entry = options.entry || null
|
25 | this.newRdn = options.newRdn || null
|
26 | this.deleteOldRdn = options.deleteOldRdn || true
|
27 | this.newSuperior = options.newSuperior || null
|
28 | }
|
29 | util.inherits(ModifyDNRequest, LDAPMessage)
|
30 | Object.defineProperties(ModifyDNRequest.prototype, {
|
31 | type: {
|
32 | get: function getType () { return 'ModifyDNRequest' },
|
33 | configurable: false
|
34 | },
|
35 | _dn: {
|
36 | get: function getDN () { return this.entry },
|
37 | configurable: false
|
38 | }
|
39 | })
|
40 |
|
41 | ModifyDNRequest.prototype._parse = function (ber) {
|
42 | assert.ok(ber)
|
43 |
|
44 | this.entry = ber.readString()
|
45 | this.newRdn = dn.parse(ber.readString())
|
46 | this.deleteOldRdn = ber.readBoolean()
|
47 | if (ber.peek() === 0x80) { this.newSuperior = dn.parse(ber.readString(0x80)) }
|
48 |
|
49 | return true
|
50 | }
|
51 |
|
52 | ModifyDNRequest.prototype._toBer = function (ber) {
|
53 |
|
54 |
|
55 | ber.writeString(this.entry.toString())
|
56 | ber.writeString(this.newRdn.toString())
|
57 | ber.writeBoolean(this.deleteOldRdn)
|
58 | if (this.newSuperior) {
|
59 | const s = this.newSuperior.toString()
|
60 | const len = Buffer.byteLength(s)
|
61 |
|
62 | ber.writeByte(0x80)
|
63 | ber.writeByte(len)
|
64 | ber._ensure(len)
|
65 | ber._buf.write(s, ber._offset)
|
66 | ber._offset += len
|
67 | }
|
68 |
|
69 | return ber
|
70 | }
|
71 |
|
72 | ModifyDNRequest.prototype._json = function (j) {
|
73 | assert.ok(j)
|
74 |
|
75 | j.entry = this.entry.toString()
|
76 | j.newRdn = this.newRdn.toString()
|
77 | j.deleteOldRdn = this.deleteOldRdn
|
78 | j.newSuperior = this.newSuperior ? this.newSuperior.toString() : ''
|
79 |
|
80 | return j
|
81 | }
|
82 |
|
83 |
|
84 |
|
85 | module.exports = ModifyDNRequest
|