2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
var assert = require('assert-plus');
|
2011-08-04 20:32:01 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
|
2011-08-04 20:32:01 +00:00
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var Ber = asn1.Ber;
|
2011-08-12 23:37:47 +00:00
|
|
|
var LDAP_BIND_SIMPLE = 'simple';
|
|
|
|
var LDAP_BIND_SASL = 'sasl';
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function BindRequest(options) {
|
2011-11-09 22:57:22 +00:00
|
|
|
options = options || {};
|
2015-10-31 17:28:25 +00:00
|
|
|
assert.object(options);
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_BIND;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.version = options.version || 0x03;
|
|
|
|
this.name = options.name || null;
|
|
|
|
this.authentication = options.authentication || LDAP_BIND_SIMPLE;
|
|
|
|
this.credentials = options.credentials || '';
|
|
|
|
}
|
|
|
|
util.inherits(BindRequest, LDAPMessage);
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(BindRequest.prototype, {
|
|
|
|
type: {
|
|
|
|
get: function getType() { return 'BindRequest'; },
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
_dn: {
|
|
|
|
get: function getDN() { return this.name; },
|
|
|
|
configurable: false
|
|
|
|
}
|
|
|
|
});
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
BindRequest.prototype._parse = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
this.version = ber.readInt();
|
2014-09-30 23:39:19 +00:00
|
|
|
this.name = ber.readString();
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
var t = ber.peek();
|
|
|
|
|
|
|
|
// TODO add support for SASL et al
|
|
|
|
if (t !== Ber.Context)
|
|
|
|
throw new Error('authentication 0x' + t.toString(16) + ' not supported');
|
|
|
|
|
|
|
|
this.authentication = LDAP_BIND_SIMPLE;
|
|
|
|
this.credentials = ber.readString(Ber.Context);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
BindRequest.prototype._toBer = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
ber.writeInt(this.version);
|
2011-11-11 18:08:48 +00:00
|
|
|
ber.writeString((this.name || '').toString());
|
2011-08-04 20:32:01 +00:00
|
|
|
// TODO add support for SASL et al
|
2011-11-11 18:08:48 +00:00
|
|
|
ber.writeString((this.credentials || ''), Ber.Context);
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
BindRequest.prototype._json = function (j) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.version = this.version;
|
|
|
|
j.name = this.name;
|
|
|
|
j.authenticationType = this.authentication;
|
|
|
|
j.credentials = this.credentials;
|
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|
2015-10-31 17:28:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- Exports
|
|
|
|
|
|
|
|
module.exports = BindRequest;
|