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.

bind_request.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 LDAPMessage = require('./message');
  6. var Protocol = require('../protocol');
  7. ///--- Globals
  8. var Ber = asn1.Ber;
  9. var LDAP_BIND_SIMPLE = 'simple';
  10. var LDAP_BIND_SASL = 'sasl';
  11. ///--- API
  12. function BindRequest(options) {
  13. options = options || {};
  14. assert.object(options);
  15. options.protocolOp = Protocol.LDAP_REQ_BIND;
  16. LDAPMessage.call(this, options);
  17. this.version = options.version || 0x03;
  18. this.name = options.name || null;
  19. this.authentication = options.authentication || LDAP_BIND_SIMPLE;
  20. this.credentials = options.credentials || '';
  21. }
  22. util.inherits(BindRequest, LDAPMessage);
  23. Object.defineProperties(BindRequest.prototype, {
  24. type: {
  25. get: function getType() { return 'BindRequest'; },
  26. configurable: false
  27. },
  28. _dn: {
  29. get: function getDN() { return this.name; },
  30. configurable: false
  31. }
  32. });
  33. BindRequest.prototype._parse = function (ber) {
  34. assert.ok(ber);
  35. this.version = ber.readInt();
  36. this.name = ber.readString();
  37. var t = ber.peek();
  38. // TODO add support for SASL et al
  39. if (t !== Ber.Context)
  40. throw new Error('authentication 0x' + t.toString(16) + ' not supported');
  41. this.authentication = LDAP_BIND_SIMPLE;
  42. this.credentials = ber.readString(Ber.Context);
  43. return true;
  44. };
  45. BindRequest.prototype._toBer = function (ber) {
  46. assert.ok(ber);
  47. ber.writeInt(this.version);
  48. ber.writeString((this.name || '').toString());
  49. // TODO add support for SASL et al
  50. ber.writeString((this.credentials || ''), Ber.Context);
  51. return ber;
  52. };
  53. BindRequest.prototype._json = function (j) {
  54. assert.ok(j);
  55. j.version = this.version;
  56. j.name = this.name;
  57. j.authenticationType = this.authentication;
  58. j.credentials = this.credentials;
  59. return j;
  60. };
  61. ///--- Exports
  62. module.exports = BindRequest;