Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moddn_request.js 2.1KB

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