2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
2014-09-30 23:39:19 +00:00
|
|
|
var dn = require('../dn');
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
var isDN = dn.DN.isDN;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function ModifyDNRequest(options) {
|
|
|
|
if (options) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (options) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options must be an object');
|
2014-09-30 23:39:19 +00:00
|
|
|
if (options.entry &&
|
|
|
|
!(isDN(options.entry) || typeof (options.entry) === 'string')) {
|
|
|
|
throw new TypeError('options.entry must be a DN or string');
|
|
|
|
}
|
|
|
|
if (options.newRdn && !isDN(options.newRdn))
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.newRdn must be a DN');
|
|
|
|
if (options.deleteOldRdn !== undefined &&
|
2012-02-18 08:15:52 +00:00
|
|
|
typeof (options.deleteOldRdn) !== 'boolean')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.deleteOldRdn must be a boolean');
|
2014-09-30 23:39:19 +00:00
|
|
|
if (options.newSuperior && !isDN(options.newSuperior))
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.newSuperior must be a DN');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_MODRDN;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.entry = options.entry || null;
|
|
|
|
this.newRdn = options.newRdn || null;
|
2011-08-23 23:25:07 +00:00
|
|
|
this.deleteOldRdn = options.deleteOldRdn || true;
|
2011-08-04 20:32:01 +00:00
|
|
|
this.newSuperior = options.newSuperior || null;
|
|
|
|
|
|
|
|
var self = this;
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('type', function () { return 'ModifyDNRequest'; });
|
|
|
|
this.__defineGetter__('_dn', function () { return self.entry; });
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
util.inherits(ModifyDNRequest, LDAPMessage);
|
|
|
|
module.exports = ModifyDNRequest;
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._parse = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
this.entry = ber.readString();
|
2011-08-04 20:32:01 +00:00
|
|
|
this.newRdn = dn.parse(ber.readString());
|
|
|
|
this.deleteOldRdn = ber.readBoolean();
|
2011-08-15 20:50:15 +00:00
|
|
|
if (ber.peek() === 0x80)
|
|
|
|
this.newSuperior = dn.parse(ber.readString(0x80));
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._toBer = function (ber) {
|
2013-01-14 09:14:35 +00:00
|
|
|
//assert.ok(ber);
|
2011-08-04 20:32:01 +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) {
|
|
|
|
var s = this.newSuperior.toString();
|
|
|
|
var len = Buffer.byteLength(s);
|
|
|
|
|
|
|
|
ber.writeByte(0x80); // MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG
|
|
|
|
ber.writeByte(len);
|
|
|
|
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
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ModifyDNRequest.prototype._json = function (j) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.entry = this.entry.toString();
|
|
|
|
j.newRdn = this.newRdn.toString();
|
|
|
|
j.deleteOldRdn = this.deleteOldRdn;
|
|
|
|
j.newSuperior = this.newSuperior ? this.newSuperior.toString() : '';
|
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|