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.

result.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert-plus');
  3. var util = require('util');
  4. var asn1 = require('asn1');
  5. var dtrace = require('../dtrace');
  6. var LDAPMessage = require('./message');
  7. var Protocol = require('../protocol');
  8. ///--- Globals
  9. var Ber = asn1.Ber;
  10. var BerWriter = asn1.BerWriter;
  11. ///--- API
  12. function LDAPResult(options) {
  13. options = options || {};
  14. assert.object(options);
  15. assert.optionalNumber(options.status);
  16. assert.optionalString(options.matchedDN);
  17. assert.optionalString(options.errorMessage);
  18. assert.optionalArrayOfString(options.referrals);
  19. LDAPMessage.call(this, options);
  20. this.status = options.status || 0; // LDAP SUCCESS
  21. this.matchedDN = options.matchedDN || '';
  22. this.errorMessage = options.errorMessage || '';
  23. this.referrals = options.referrals || [];
  24. this.connection = options.connection || null;
  25. }
  26. util.inherits(LDAPResult, LDAPMessage);
  27. Object.defineProperties(LDAPResult.prototype, {
  28. type: {
  29. get: function getType() { return 'LDAPResult'; },
  30. configurable: false
  31. }
  32. });
  33. LDAPResult.prototype.end = function (status) {
  34. assert.ok(this.connection);
  35. if (typeof (status) === 'number')
  36. this.status = status;
  37. var ber = this.toBer();
  38. if (this.log.debug())
  39. this.log.debug('%s: sending: %j', this.connection.ldap.id, this.json);
  40. try {
  41. var self = this;
  42. this.connection.write(ber);
  43. if (self._dtraceOp && self._dtraceId) {
  44. dtrace.fire('server-' + self._dtraceOp + '-done', function () {
  45. var c = self.connection || {ldap: {}};
  46. return [
  47. self._dtraceId || 0,
  48. (c.remoteAddress || ''),
  49. c.ldap.bindDN ? c.ldap.bindDN.toString() : '',
  50. (self.requestDN ? self.requestDN.toString() : ''),
  51. status || self.status,
  52. self.errorMessage
  53. ];
  54. });
  55. }
  56. } catch (e) {
  57. this.log.warn(e, '%s failure to write message %j',
  58. this.connection.ldap.id, this.json);
  59. }
  60. };
  61. LDAPResult.prototype._parse = function (ber) {
  62. assert.ok(ber);
  63. this.status = ber.readEnumeration();
  64. this.matchedDN = ber.readString();
  65. this.errorMessage = ber.readString();
  66. var t = ber.peek();
  67. if (t === Protocol.LDAP_REP_REFERRAL) {
  68. var end = ber.offset + ber.length;
  69. while (ber.offset < end)
  70. this.referrals.push(ber.readString());
  71. }
  72. return true;
  73. };
  74. LDAPResult.prototype._toBer = function (ber) {
  75. assert.ok(ber);
  76. ber.writeEnumeration(this.status);
  77. ber.writeString(this.matchedDN || '');
  78. ber.writeString(this.errorMessage || '');
  79. if (this.referrals.length) {
  80. ber.startSequence(Protocol.LDAP_REP_REFERRAL);
  81. ber.writeStringArray(this.referrals);
  82. ber.endSequence();
  83. }
  84. return ber;
  85. };
  86. LDAPResult.prototype._json = function (j) {
  87. assert.ok(j);
  88. j.status = this.status;
  89. j.matchedDN = this.matchedDN;
  90. j.errorMessage = this.errorMessage;
  91. j.referrals = this.referrals;
  92. return j;
  93. };
  94. ///--- Exports
  95. module.exports = LDAPResult;