node_modules updated, buefy add to lib folder
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function AbandonRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalNumber(options.abandonID);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_ABANDON;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.abandonID = options.abandonID || 0;
|
||||
}
|
||||
util.inherits(AbandonRequest, LDAPMessage);
|
||||
Object.defineProperties(AbandonRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'AbandonRequest'; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
AbandonRequest.prototype._parse = function (ber, length) {
|
||||
assert.ok(ber);
|
||||
assert.ok(length);
|
||||
|
||||
// What a PITA - have to replicate ASN.1 integer logic to work around the
|
||||
// way abandon is encoded and the way ldapjs framework handles "normal"
|
||||
// messages
|
||||
|
||||
var buf = ber.buffer;
|
||||
var offset = 0;
|
||||
var value = 0;
|
||||
|
||||
var fb = buf[offset++];
|
||||
value = fb & 0x7F;
|
||||
for (var i = 1; i < length; i++) {
|
||||
value <<= 8;
|
||||
value |= (buf[offset++] & 0xff);
|
||||
}
|
||||
if ((fb & 0x80) == 0x80)
|
||||
value = -value;
|
||||
|
||||
ber._offset += length;
|
||||
|
||||
this.abandonID = value;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
AbandonRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
var i = this.abandonID;
|
||||
var sz = 4;
|
||||
|
||||
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) &&
|
||||
(sz > 1)) {
|
||||
sz--;
|
||||
i <<= 8;
|
||||
}
|
||||
assert.ok(sz <= 4);
|
||||
|
||||
while (sz-- > 0) {
|
||||
ber.writeByte((i & 0xff000000) >> 24);
|
||||
i <<= 8;
|
||||
}
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
AbandonRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.abandonID = this.abandonID;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = AbandonRequest;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function AbandonResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = 0;
|
||||
LDAPMessage.call(this, options);
|
||||
}
|
||||
util.inherits(AbandonResponse, LDAPMessage);
|
||||
Object.defineProperties(AbandonResponse.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'AbandonResponse'; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
AbandonResponse.prototype.end = function (status) {};
|
||||
|
||||
AbandonResponse.prototype._json = function (j) {
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = AbandonResponse;
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Attribute = require('../attribute');
|
||||
var Protocol = require('../protocol');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function AddRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
lassert.optionalStringDN(options.entry);
|
||||
lassert.optionalArrayOfAttribute(options.attributes);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_ADD;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.entry = options.entry || null;
|
||||
this.attributes = options.attributes ? options.attributes.slice(0) : [];
|
||||
}
|
||||
util.inherits(AddRequest, LDAPMessage);
|
||||
Object.defineProperties(AddRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'AddRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.entry; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
AddRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.entry = ber.readString();
|
||||
|
||||
ber.readSequence();
|
||||
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end) {
|
||||
var a = new Attribute();
|
||||
a.parse(ber);
|
||||
a.type = a.type.toLowerCase();
|
||||
if (a.type === 'objectclass') {
|
||||
for (var i = 0; i < a.vals.length; i++)
|
||||
a.vals[i] = a.vals[i].toLowerCase();
|
||||
}
|
||||
this.attributes.push(a);
|
||||
}
|
||||
|
||||
this.attributes.sort(Attribute.compare);
|
||||
return true;
|
||||
};
|
||||
|
||||
AddRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.entry.toString());
|
||||
ber.startSequence();
|
||||
this.attributes.forEach(function (a) {
|
||||
a.toBer(ber);
|
||||
});
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
AddRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.entry = this.entry.toString();
|
||||
j.attributes = [];
|
||||
|
||||
this.attributes.forEach(function (a) {
|
||||
j.attributes.push(a.json);
|
||||
});
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
AddRequest.prototype.indexOf = function (attr) {
|
||||
if (!attr || typeof (attr) !== 'string')
|
||||
throw new TypeError('attr (string) required');
|
||||
|
||||
for (var i = 0; i < this.attributes.length; i++) {
|
||||
if (this.attributes[i].type === attr)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
AddRequest.prototype.attributeNames = function () {
|
||||
var attrs = [];
|
||||
|
||||
for (var i = 0; i < this.attributes.length; i++)
|
||||
attrs.push(this.attributes[i].type.toLowerCase());
|
||||
|
||||
return attrs;
|
||||
};
|
||||
|
||||
AddRequest.prototype.getAttribute = function (name) {
|
||||
if (!name || typeof (name) !== 'string')
|
||||
throw new TypeError('attribute name (string) required');
|
||||
|
||||
name = name.toLowerCase();
|
||||
|
||||
for (var i = 0; i < this.attributes.length; i++) {
|
||||
if (this.attributes[i].type === name)
|
||||
return this.attributes[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
AddRequest.prototype.addAttribute = function (attr) {
|
||||
if (!(attr instanceof Attribute))
|
||||
throw new TypeError('attribute (Attribute) required');
|
||||
|
||||
return this.attributes.push(attr);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a "pure" JS representation of this object.
|
||||
*
|
||||
* An example object would look like:
|
||||
*
|
||||
* {
|
||||
* "dn": "cn=unit, dc=test",
|
||||
* "attributes": {
|
||||
* "cn": ["unit", "foo"],
|
||||
* "objectclass": ["top", "person"]
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @return {Object} that looks like the above.
|
||||
*/
|
||||
AddRequest.prototype.toObject = function () {
|
||||
var self = this;
|
||||
|
||||
var obj = {
|
||||
dn: self.entry ? self.entry.toString() : '',
|
||||
attributes: {}
|
||||
};
|
||||
|
||||
if (!this.attributes || !this.attributes.length)
|
||||
return obj;
|
||||
|
||||
this.attributes.forEach(function (a) {
|
||||
if (!obj.attributes[a.type])
|
||||
obj.attributes[a.type] = [];
|
||||
|
||||
a.vals.forEach(function (v) {
|
||||
if (obj.attributes[a.type].indexOf(v) === -1)
|
||||
obj.attributes[a.type].push(v);
|
||||
});
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = AddRequest;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function AddResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_ADD;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(AddResponse, LDAPResult);
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = AddResponse;
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
var LDAP_BIND_SIMPLE = 'simple';
|
||||
var LDAP_BIND_SASL = 'sasl';
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function BindRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
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);
|
||||
Object.defineProperties(BindRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'BindRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.name; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
BindRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.version = ber.readInt();
|
||||
this.name = ber.readString();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
BindRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeInt(this.version);
|
||||
ber.writeString((this.name || '').toString());
|
||||
// TODO add support for SASL et al
|
||||
ber.writeString((this.credentials || ''), Ber.Context);
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
BindRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.version = this.version;
|
||||
j.name = this.name;
|
||||
j.authenticationType = this.authentication;
|
||||
j.credentials = this.credentials;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = BindRequest;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function BindResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_BIND;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(BindResponse, LDAPResult);
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = BindResponse;
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function CompareRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalString(options.attribute);
|
||||
assert.optionalString(options.value);
|
||||
lassert.optionalStringDN(options.entry);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_COMPARE;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.entry = options.entry || null;
|
||||
this.attribute = options.attribute || '';
|
||||
this.value = options.value || '';
|
||||
}
|
||||
util.inherits(CompareRequest, LDAPMessage);
|
||||
Object.defineProperties(CompareRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'CompareRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.entry; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
CompareRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.entry = ber.readString();
|
||||
|
||||
ber.readSequence();
|
||||
this.attribute = ber.readString().toLowerCase();
|
||||
this.value = ber.readString();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
CompareRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.entry.toString());
|
||||
ber.startSequence();
|
||||
ber.writeString(this.attribute);
|
||||
ber.writeString(this.value);
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
CompareRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.entry = this.entry.toString();
|
||||
j.attribute = this.attribute;
|
||||
j.value = this.value;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = CompareRequest;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function CompareResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_COMPARE;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(CompareResponse, LDAPResult);
|
||||
|
||||
CompareResponse.prototype.end = function (matches) {
|
||||
var status = 0x06;
|
||||
if (typeof (matches) === 'boolean') {
|
||||
if (!matches)
|
||||
status = 0x05; // Compare false
|
||||
} else {
|
||||
status = matches;
|
||||
}
|
||||
|
||||
return LDAPResult.prototype.end.call(this, status);
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = CompareResponse;
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function DeleteRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
lassert.optionalStringDN(options.entry);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_DELETE;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.entry = options.entry || null;
|
||||
}
|
||||
util.inherits(DeleteRequest, LDAPMessage);
|
||||
Object.defineProperties(DeleteRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'DeleteRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.entry; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
DeleteRequest.prototype._parse = function (ber, length) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.entry = ber.buffer.slice(0, length).toString('utf8');
|
||||
ber._offset += ber.length;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
DeleteRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
var buf = new Buffer(this.entry.toString());
|
||||
for (var i = 0; i < buf.length; i++)
|
||||
ber.writeByte(buf[i]);
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
DeleteRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.entry = this.entry;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = DeleteRequest;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function DeleteResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_DELETE;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(DeleteResponse, LDAPResult);
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = DeleteResponse;
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ExtendedRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalString(options.requestName);
|
||||
if (options.requestValue &&
|
||||
!(Buffer.isBuffer(options.requestValue) ||
|
||||
typeof (options.requestValue) === 'string')) {
|
||||
throw new TypeError('options.requestValue must be a buffer or a string');
|
||||
}
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_EXTENSION;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.requestName = options.requestName || '';
|
||||
this.requestValue = options.requestValue;
|
||||
}
|
||||
util.inherits(ExtendedRequest, LDAPMessage);
|
||||
Object.defineProperties(ExtendedRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'ExtendedRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.requestName; },
|
||||
configurable: false
|
||||
},
|
||||
name: {
|
||||
get: function getName() { return this.requestName; },
|
||||
set: function setName(val) {
|
||||
assert.string(val);
|
||||
this.requestName = val;
|
||||
},
|
||||
configurable: false
|
||||
},
|
||||
value: {
|
||||
get: function getValue() { return this.requestValue; },
|
||||
set: function setValue(val) {
|
||||
if (!(Buffer.isBuffer(val) || typeof (val) === 'string'))
|
||||
throw new TypeError('value must be a buffer or a string');
|
||||
|
||||
this.requestValue = val;
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ExtendedRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.requestName = ber.readString(0x80);
|
||||
if (ber.peek() === 0x81)
|
||||
try {
|
||||
this.requestValue = ber.readString(0x81);
|
||||
} catch (e) {
|
||||
this.requestValue = ber.readBuffer(0x81);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ExtendedRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.requestName, 0x80);
|
||||
if (Buffer.isBuffer(this.requestValue)) {
|
||||
ber.writeBuffer(this.requestValue, 0x81);
|
||||
} else if (typeof (this.requestValue) === 'string') {
|
||||
ber.writeString(this.requestValue, 0x81);
|
||||
}
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
ExtendedRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.requestName = this.requestName;
|
||||
j.requestValue = (Buffer.isBuffer(this.requestValue)) ?
|
||||
this.requestValue.toString('hex') : this.requestValue;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ExtendedRequest;
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ExtendedResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalString(options.responseName);
|
||||
assert.optionalString(options.responsevalue);
|
||||
|
||||
this.responseName = options.responseName || undefined;
|
||||
this.responseValue = options.responseValue || undefined;
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_EXTENSION;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(ExtendedResponse, LDAPResult);
|
||||
Object.defineProperties(ExtendedResponse.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'ExtendedResponse'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.responseName; },
|
||||
configurable: false
|
||||
},
|
||||
name: {
|
||||
get: function getName() { return this.responseName; },
|
||||
set: function setName(val) {
|
||||
assert.string(val);
|
||||
this.responseName = val;
|
||||
},
|
||||
configurable: false
|
||||
},
|
||||
value: {
|
||||
get: function getValue() { return this.responseValue; },
|
||||
set: function (val) {
|
||||
assert.string(val);
|
||||
this.responseValue = val;
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ExtendedResponse.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!LDAPResult.prototype._parse.call(this, ber))
|
||||
return false;
|
||||
|
||||
if (ber.peek() === 0x8a)
|
||||
this.responseName = ber.readString(0x8a);
|
||||
if (ber.peek() === 0x8b)
|
||||
this.responseValue = ber.readString(0x8b);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ExtendedResponse.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!LDAPResult.prototype._toBer.call(this, ber))
|
||||
return false;
|
||||
|
||||
if (this.responseName)
|
||||
ber.writeString(this.responseName, 0x8a);
|
||||
if (this.responseValue)
|
||||
ber.writeString(this.responseValue, 0x8b);
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
ExtendedResponse.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j = LDAPResult.prototype._json.call(this, j);
|
||||
|
||||
j.responseName = this.responseName;
|
||||
j.responseValue = this.responseValue;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ExtendedResponse;
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var LDAPResult = require('./result');
|
||||
var Parser = require('./parser');
|
||||
|
||||
var AbandonRequest = require('./abandon_request');
|
||||
var AbandonResponse = require('./abandon_response');
|
||||
var AddRequest = require('./add_request');
|
||||
var AddResponse = require('./add_response');
|
||||
var BindRequest = require('./bind_request');
|
||||
var BindResponse = require('./bind_response');
|
||||
var CompareRequest = require('./compare_request');
|
||||
var CompareResponse = require('./compare_response');
|
||||
var DeleteRequest = require('./del_request');
|
||||
var DeleteResponse = require('./del_response');
|
||||
var ExtendedRequest = require('./ext_request');
|
||||
var ExtendedResponse = require('./ext_response');
|
||||
var ModifyRequest = require('./modify_request');
|
||||
var ModifyResponse = require('./modify_response');
|
||||
var ModifyDNRequest = require('./moddn_request');
|
||||
var ModifyDNResponse = require('./moddn_response');
|
||||
var SearchRequest = require('./search_request');
|
||||
var SearchEntry = require('./search_entry');
|
||||
var SearchReference = require('./search_reference');
|
||||
var SearchResponse = require('./search_response');
|
||||
var UnbindRequest = require('./unbind_request');
|
||||
var UnbindResponse = require('./unbind_response');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
module.exports = {
|
||||
|
||||
LDAPMessage: LDAPMessage,
|
||||
LDAPResult: LDAPResult,
|
||||
Parser: Parser,
|
||||
|
||||
AbandonRequest: AbandonRequest,
|
||||
AbandonResponse: AbandonResponse,
|
||||
AddRequest: AddRequest,
|
||||
AddResponse: AddResponse,
|
||||
BindRequest: BindRequest,
|
||||
BindResponse: BindResponse,
|
||||
CompareRequest: CompareRequest,
|
||||
CompareResponse: CompareResponse,
|
||||
DeleteRequest: DeleteRequest,
|
||||
DeleteResponse: DeleteResponse,
|
||||
ExtendedRequest: ExtendedRequest,
|
||||
ExtendedResponse: ExtendedResponse,
|
||||
ModifyRequest: ModifyRequest,
|
||||
ModifyResponse: ModifyResponse,
|
||||
ModifyDNRequest: ModifyDNRequest,
|
||||
ModifyDNResponse: ModifyDNResponse,
|
||||
SearchRequest: SearchRequest,
|
||||
SearchEntry: SearchEntry,
|
||||
SearchReference: SearchReference,
|
||||
SearchResponse: SearchResponse,
|
||||
UnbindRequest: UnbindRequest,
|
||||
UnbindResponse: UnbindResponse
|
||||
|
||||
};
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('../controls').Control;
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
var getControl = require('../controls').getControl;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
|
||||
/**
|
||||
* LDAPMessage structure.
|
||||
*
|
||||
* @param {Object} options stuff.
|
||||
*/
|
||||
function LDAPMessage(options) {
|
||||
assert.object(options);
|
||||
|
||||
this.messageID = options.messageID || 0;
|
||||
this.protocolOp = options.protocolOp || undefined;
|
||||
this.controls = options.controls ? options.controls.slice(0) : [];
|
||||
|
||||
this.log = options.log;
|
||||
}
|
||||
Object.defineProperties(LDAPMessage.prototype, {
|
||||
id: {
|
||||
get: function getId() { return this.messageID; },
|
||||
configurable: false
|
||||
},
|
||||
dn: {
|
||||
get: function getDN() { return this._dn || ''; },
|
||||
configurable: false
|
||||
},
|
||||
type: {
|
||||
get: function getType() { return 'LDAPMessage'; },
|
||||
configurable: false
|
||||
},
|
||||
json: {
|
||||
get: function () {
|
||||
var out = this._json({
|
||||
messageID: this.messageID,
|
||||
protocolOp: this.type
|
||||
});
|
||||
out.controls = this.controls;
|
||||
return out;
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
LDAPMessage.prototype.toString = function () {
|
||||
return JSON.stringify(this.json);
|
||||
};
|
||||
|
||||
LDAPMessage.prototype.parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (this.log.trace())
|
||||
this.log.trace('parse: data=%s', util.inspect(ber.buffer));
|
||||
|
||||
// Delegate off to the specific type to parse
|
||||
this._parse(ber, ber.length);
|
||||
|
||||
// Look for controls
|
||||
if (ber.peek() === 0xa0) {
|
||||
ber.readSequence();
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end) {
|
||||
var c = getControl(ber);
|
||||
if (c)
|
||||
this.controls.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.log.trace())
|
||||
this.log.trace('Parsing done: %j', this.json);
|
||||
return true;
|
||||
};
|
||||
|
||||
LDAPMessage.prototype.toBer = function () {
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence();
|
||||
writer.writeInt(this.messageID);
|
||||
|
||||
writer.startSequence(this.protocolOp);
|
||||
if (this._toBer)
|
||||
writer = this._toBer(writer);
|
||||
writer.endSequence();
|
||||
|
||||
if (this.controls && this.controls.length) {
|
||||
writer.startSequence(0xa0);
|
||||
this.controls.forEach(function (c) {
|
||||
c.toBer(writer);
|
||||
});
|
||||
writer.endSequence();
|
||||
}
|
||||
|
||||
writer.endSequence();
|
||||
return writer.buffer;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = LDAPMessage;
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
var dn = require('../dn');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ModifyDNRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalBool(options.deleteOldRdn);
|
||||
lassert.optionalStringDN(options.entry);
|
||||
lassert.optionalDN(options.newRdn);
|
||||
lassert.optionalDN(options.newSuperior);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_MODRDN;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.entry = options.entry || null;
|
||||
this.newRdn = options.newRdn || null;
|
||||
this.deleteOldRdn = options.deleteOldRdn || true;
|
||||
this.newSuperior = options.newSuperior || null;
|
||||
}
|
||||
util.inherits(ModifyDNRequest, LDAPMessage);
|
||||
Object.defineProperties(ModifyDNRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'ModifyDNRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.entry; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ModifyDNRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.entry = ber.readString();
|
||||
this.newRdn = dn.parse(ber.readString());
|
||||
this.deleteOldRdn = ber.readBoolean();
|
||||
if (ber.peek() === 0x80)
|
||||
this.newSuperior = dn.parse(ber.readString(0x80));
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
ModifyDNRequest.prototype._toBer = function (ber) {
|
||||
//assert.ok(ber);
|
||||
|
||||
ber.writeString(this.entry.toString());
|
||||
ber.writeString(this.newRdn.toString());
|
||||
ber.writeBoolean(this.deleteOldRdn);
|
||||
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;
|
||||
}
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
ModifyDNRequest.prototype._json = function (j) {
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ModifyDNRequest;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ModifyDNResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_MODRDN;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(ModifyDNResponse, LDAPResult);
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ModifyDNResponse;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Change = require('../change');
|
||||
var Protocol = require('../protocol');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ModifyRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
lassert.optionalStringDN(options.object);
|
||||
lassert.optionalArrayOfAttribute(options.attributes);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_MODIFY;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.object = options.object || null;
|
||||
this.changes = options.changes ? options.changes.slice(0) : [];
|
||||
}
|
||||
util.inherits(ModifyRequest, LDAPMessage);
|
||||
Object.defineProperties(ModifyRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'ModifyRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.object; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ModifyRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.object = ber.readString();
|
||||
|
||||
ber.readSequence();
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end) {
|
||||
var c = new Change();
|
||||
c.parse(ber);
|
||||
c.modification.type = c.modification.type.toLowerCase();
|
||||
this.changes.push(c);
|
||||
}
|
||||
|
||||
this.changes.sort(Change.compare);
|
||||
return true;
|
||||
};
|
||||
|
||||
ModifyRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.object.toString());
|
||||
ber.startSequence();
|
||||
this.changes.forEach(function (c) {
|
||||
c.toBer(ber);
|
||||
});
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
ModifyRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.object = this.object;
|
||||
j.changes = [];
|
||||
|
||||
this.changes.forEach(function (c) {
|
||||
j.changes.push(c.json);
|
||||
});
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ModifyRequest;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ModifyResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_MODIFY;
|
||||
LDAPResult.call(this, options);
|
||||
}
|
||||
util.inherits(ModifyResponse, LDAPResult);
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = ModifyResponse;
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var asn1 = require('asn1');
|
||||
var VError = require('verror').VError;
|
||||
|
||||
var AbandonRequest = require('./abandon_request');
|
||||
var AddRequest = require('./add_request');
|
||||
var AddResponse = require('./add_response');
|
||||
var BindRequest = require('./bind_request');
|
||||
var BindResponse = require('./bind_response');
|
||||
var CompareRequest = require('./compare_request');
|
||||
var CompareResponse = require('./compare_response');
|
||||
var DeleteRequest = require('./del_request');
|
||||
var DeleteResponse = require('./del_response');
|
||||
var ExtendedRequest = require('./ext_request');
|
||||
var ExtendedResponse = require('./ext_response');
|
||||
var ModifyRequest = require('./modify_request');
|
||||
var ModifyResponse = require('./modify_response');
|
||||
var ModifyDNRequest = require('./moddn_request');
|
||||
var ModifyDNResponse = require('./moddn_response');
|
||||
var SearchRequest = require('./search_request');
|
||||
var SearchEntry = require('./search_entry');
|
||||
var SearchReference = require('./search_reference');
|
||||
var SearchResponse = require('./search_response');
|
||||
var UnbindRequest = require('./unbind_request');
|
||||
var UnbindResponse = require('./unbind_response');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var Message = require('./message');
|
||||
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
var BerReader = asn1.BerReader;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function Parser(options) {
|
||||
assert.object(options);
|
||||
assert.object(options.log);
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.buffer = null;
|
||||
this.log = options.log;
|
||||
}
|
||||
util.inherits(Parser, EventEmitter);
|
||||
|
||||
Parser.prototype.write = function (data) {
|
||||
if (!data || !Buffer.isBuffer(data))
|
||||
throw new TypeError('data (buffer) required');
|
||||
|
||||
var nextMessage = null;
|
||||
var self = this;
|
||||
|
||||
function end() {
|
||||
if (nextMessage)
|
||||
return self.write(nextMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
self.buffer = (self.buffer ? Buffer.concat([self.buffer, data]) : data);
|
||||
|
||||
var ber = new BerReader(self.buffer);
|
||||
|
||||
var foundSeq = false;
|
||||
try {
|
||||
foundSeq = ber.readSequence();
|
||||
} catch (e) {
|
||||
this.emit('error', e);
|
||||
}
|
||||
|
||||
if (!foundSeq || ber.remain < ber.length) {
|
||||
// ENOTENOUGH
|
||||
return false;
|
||||
} else if (ber.remain > ber.length) {
|
||||
// ETOOMUCH
|
||||
// This is sort of ugly, but allows us to make miminal copies
|
||||
nextMessage = self.buffer.slice(ber.offset + ber.length);
|
||||
ber._size = ber.offset + ber.length;
|
||||
assert.equal(ber.remain, ber.length);
|
||||
}
|
||||
|
||||
// If we're here, ber holds the message, and nextMessage is temporarily
|
||||
// pointing at the next sequence of data (if it exists)
|
||||
self.buffer = null;
|
||||
|
||||
var message;
|
||||
try {
|
||||
// Bail here if peer isn't speaking protocol at all
|
||||
message = this.getMessage(ber);
|
||||
|
||||
if (!message) {
|
||||
return end();
|
||||
}
|
||||
message.parse(ber);
|
||||
} catch (e) {
|
||||
this.emit('error', e, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.emit('message', message);
|
||||
return end();
|
||||
};
|
||||
|
||||
Parser.prototype.getMessage = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
var self = this;
|
||||
|
||||
var messageID = ber.readInt();
|
||||
var type = ber.readSequence();
|
||||
|
||||
var Message;
|
||||
switch (type) {
|
||||
|
||||
case Protocol.LDAP_REQ_ABANDON:
|
||||
Message = AbandonRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_ADD:
|
||||
Message = AddRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_ADD:
|
||||
Message = AddResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_BIND:
|
||||
Message = BindRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_BIND:
|
||||
Message = BindResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_COMPARE:
|
||||
Message = CompareRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_COMPARE:
|
||||
Message = CompareResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_DELETE:
|
||||
Message = DeleteRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_DELETE:
|
||||
Message = DeleteResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_EXTENSION:
|
||||
Message = ExtendedRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_EXTENSION:
|
||||
Message = ExtendedResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_MODIFY:
|
||||
Message = ModifyRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_MODIFY:
|
||||
Message = ModifyResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_MODRDN:
|
||||
Message = ModifyDNRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_MODRDN:
|
||||
Message = ModifyDNResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_SEARCH:
|
||||
Message = SearchRequest;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_SEARCH_ENTRY:
|
||||
Message = SearchEntry;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_SEARCH_REF:
|
||||
Message = SearchReference;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REP_SEARCH:
|
||||
Message = SearchResponse;
|
||||
break;
|
||||
|
||||
case Protocol.LDAP_REQ_UNBIND:
|
||||
Message = UnbindRequest;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.emit('error',
|
||||
new Error('Op 0x' + (type ? type.toString(16) : '??') +
|
||||
' not supported'),
|
||||
new LDAPResult({
|
||||
messageID: messageID,
|
||||
protocolOp: type || Protocol.LDAP_REP_EXTENSION
|
||||
}));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return new Message({
|
||||
messageID: messageID,
|
||||
log: self.log
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = Parser;
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var dtrace = require('../dtrace');
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function LDAPResult(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
assert.optionalNumber(options.status);
|
||||
assert.optionalString(options.matchedDN);
|
||||
assert.optionalString(options.errorMessage);
|
||||
assert.optionalArrayOfString(options.referrals);
|
||||
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.status = options.status || 0; // LDAP SUCCESS
|
||||
this.matchedDN = options.matchedDN || '';
|
||||
this.errorMessage = options.errorMessage || '';
|
||||
this.referrals = options.referrals || [];
|
||||
|
||||
this.connection = options.connection || null;
|
||||
}
|
||||
util.inherits(LDAPResult, LDAPMessage);
|
||||
Object.defineProperties(LDAPResult.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'LDAPResult'; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
LDAPResult.prototype.end = function (status) {
|
||||
assert.ok(this.connection);
|
||||
|
||||
if (typeof (status) === 'number')
|
||||
this.status = status;
|
||||
|
||||
var ber = this.toBer();
|
||||
if (this.log.debug())
|
||||
this.log.debug('%s: sending: %j', this.connection.ldap.id, this.json);
|
||||
|
||||
try {
|
||||
var self = this;
|
||||
this.connection.write(ber);
|
||||
|
||||
if (self._dtraceOp && self._dtraceId) {
|
||||
dtrace.fire('server-' + self._dtraceOp + '-done', function () {
|
||||
var c = self.connection || {ldap: {}};
|
||||
return [
|
||||
self._dtraceId || 0,
|
||||
(c.remoteAddress || ''),
|
||||
c.ldap.bindDN ? c.ldap.bindDN.toString() : '',
|
||||
(self.requestDN ? self.requestDN.toString() : ''),
|
||||
status || self.status,
|
||||
self.errorMessage
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
this.log.warn(e, '%s failure to write message %j',
|
||||
this.connection.ldap.id, this.json);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LDAPResult.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.status = ber.readEnumeration();
|
||||
this.matchedDN = ber.readString();
|
||||
this.errorMessage = ber.readString();
|
||||
|
||||
var t = ber.peek();
|
||||
|
||||
if (t === Protocol.LDAP_REP_REFERRAL) {
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end)
|
||||
this.referrals.push(ber.readString());
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
LDAPResult.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeEnumeration(this.status);
|
||||
ber.writeString(this.matchedDN || '');
|
||||
ber.writeString(this.errorMessage || '');
|
||||
|
||||
if (this.referrals.length) {
|
||||
ber.startSequence(Protocol.LDAP_REP_REFERRAL);
|
||||
ber.writeStringArray(this.referrals);
|
||||
ber.endSequence();
|
||||
}
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
LDAPResult.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.status = this.status;
|
||||
j.matchedDN = this.matchedDN;
|
||||
j.errorMessage = this.errorMessage;
|
||||
j.referrals = this.referrals;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = LDAPResult;
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Attribute = require('../attribute');
|
||||
var Protocol = require('../protocol');
|
||||
var lassert = require('../assert');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function SearchEntry(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
lassert.optionalStringDN(options.objectName);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_SEARCH_ENTRY;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.objectName = options.objectName || null;
|
||||
this.setAttributes(options.attributes || []);
|
||||
}
|
||||
util.inherits(SearchEntry, LDAPMessage);
|
||||
Object.defineProperties(SearchEntry.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'SearchEntry'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.objectName; },
|
||||
configurable: false
|
||||
},
|
||||
object: {
|
||||
get: function getObject() {
|
||||
var obj = {
|
||||
dn: this.dn.toString(),
|
||||
controls: []
|
||||
};
|
||||
this.attributes.forEach(function (a) {
|
||||
if (a.vals && a.vals.length) {
|
||||
if (a.vals.length > 1) {
|
||||
obj[a.type] = a.vals.slice();
|
||||
} else {
|
||||
obj[a.type] = a.vals[0];
|
||||
}
|
||||
} else {
|
||||
obj[a.type] = [];
|
||||
}
|
||||
});
|
||||
this.controls.forEach(function (element, index, array) {
|
||||
obj.controls.push(element.json);
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
configurable: false
|
||||
},
|
||||
raw: {
|
||||
get: function getRaw() {
|
||||
var obj = {
|
||||
dn: this.dn.toString(),
|
||||
controls: []
|
||||
};
|
||||
|
||||
this.attributes.forEach(function (a) {
|
||||
if (a.buffers && a.buffers.length) {
|
||||
if (a.buffers.length > 1) {
|
||||
obj[a.type] = a.buffers.slice();
|
||||
} else {
|
||||
obj[a.type] = a.buffers[0];
|
||||
}
|
||||
} else {
|
||||
obj[a.type] = [];
|
||||
}
|
||||
});
|
||||
this.controls.forEach(function (element, index, array) {
|
||||
obj.controls.push(element.json);
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
SearchEntry.prototype.addAttribute = function (attr) {
|
||||
if (!attr || typeof (attr) !== 'object')
|
||||
throw new TypeError('attr (attribute) required');
|
||||
|
||||
this.attributes.push(attr);
|
||||
};
|
||||
|
||||
SearchEntry.prototype.toObject = function () {
|
||||
return this.object;
|
||||
};
|
||||
|
||||
SearchEntry.prototype.fromObject = function (obj) {
|
||||
if (typeof (obj) !== 'object')
|
||||
throw new TypeError('object required');
|
||||
|
||||
var self = this;
|
||||
if (obj.controls)
|
||||
this.controls = obj.controls;
|
||||
|
||||
if (obj.attributes)
|
||||
obj = obj.attributes;
|
||||
this.attributes = [];
|
||||
|
||||
Object.keys(obj).forEach(function (k) {
|
||||
self.attributes.push(new Attribute({type: k, vals: obj[k]}));
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
SearchEntry.prototype.setAttributes = function (obj) {
|
||||
if (typeof (obj) !== 'object')
|
||||
throw new TypeError('object required');
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach(function (a) {
|
||||
if (!Attribute.isAttribute(a))
|
||||
throw new TypeError('entry must be an Array of Attributes');
|
||||
});
|
||||
this.attributes = obj;
|
||||
} else {
|
||||
var self = this;
|
||||
|
||||
self.attributes = [];
|
||||
Object.keys(obj).forEach(function (k) {
|
||||
var attr = new Attribute({type: k});
|
||||
if (Array.isArray(obj[k])) {
|
||||
obj[k].forEach(function (v) {
|
||||
attr.addValue(v.toString());
|
||||
});
|
||||
} else {
|
||||
attr.addValue(obj[k].toString());
|
||||
}
|
||||
self.attributes.push(attr);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
SearchEntry.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.objectName = this.objectName.toString();
|
||||
j.attributes = [];
|
||||
this.attributes.forEach(function (a) {
|
||||
j.attributes.push(a.json || a);
|
||||
});
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
SearchEntry.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.objectName = ber.readString();
|
||||
assert.ok(ber.readSequence());
|
||||
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end) {
|
||||
var a = new Attribute();
|
||||
a.parse(ber);
|
||||
this.attributes.push(a);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
SearchEntry.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.objectName.toString());
|
||||
ber.startSequence();
|
||||
this.attributes.forEach(function (a) {
|
||||
// This may or may not be an attribute
|
||||
ber = Attribute.toBer(a, ber);
|
||||
});
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = SearchEntry;
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var Protocol = require('../protocol');
|
||||
var dn = require('../dn');
|
||||
var url = require('../url');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerWriter = asn1.BerWriter;
|
||||
var parseURL = url.parse;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function SearchReference(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_SEARCH_REF;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
this.uris = options.uris || [];
|
||||
}
|
||||
util.inherits(SearchReference, LDAPMessage);
|
||||
Object.defineProperties(SearchReference.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'SearchReference'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return new dn.DN(''); },
|
||||
configurable: false
|
||||
},
|
||||
object: {
|
||||
get: function getObject() {
|
||||
return {
|
||||
dn: this.dn.toString(),
|
||||
uris: this.uris.slice()
|
||||
};
|
||||
},
|
||||
configurable: false
|
||||
},
|
||||
urls: {
|
||||
get: function getUrls() { return this.uris; },
|
||||
set: function setUrls(val) {
|
||||
assert.ok(val);
|
||||
assert.ok(Array.isArray(val));
|
||||
this.uris = val.slice();
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
SearchReference.prototype.toObject = function () {
|
||||
return this.object;
|
||||
};
|
||||
|
||||
SearchReference.prototype.fromObject = function (obj) {
|
||||
if (typeof (obj) !== 'object')
|
||||
throw new TypeError('object required');
|
||||
|
||||
this.uris = obj.uris ? obj.uris.slice() : [];
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
SearchReference.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
j.uris = this.uris.slice();
|
||||
return j;
|
||||
};
|
||||
|
||||
SearchReference.prototype._parse = function (ber, length) {
|
||||
assert.ok(ber);
|
||||
|
||||
while (ber.offset < length) {
|
||||
var _url = ber.readString();
|
||||
parseURL(_url);
|
||||
this.uris.push(_url);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
SearchReference.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.uris.forEach(function (u) {
|
||||
ber.writeString(u.href || u);
|
||||
});
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = SearchReference;
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var LDAPResult = require('./result');
|
||||
var dn = require('../dn');
|
||||
var filters = require('../filters');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function SearchRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_SEARCH;
|
||||
LDAPMessage.call(this, options);
|
||||
|
||||
if (options.baseObject !== undefined) {
|
||||
this.baseObject = options.baseObject;
|
||||
} else {
|
||||
this.baseObject = dn.parse('');
|
||||
}
|
||||
this.scope = options.scope || 'base';
|
||||
this.derefAliases = options.derefAliases || Protocol.NEVER_DEREF_ALIASES;
|
||||
this.sizeLimit = options.sizeLimit || 0;
|
||||
this.timeLimit = options.timeLimit || 0;
|
||||
this.typesOnly = options.typesOnly || false;
|
||||
this.filter = options.filter || null;
|
||||
this.attributes = options.attributes ? options.attributes.slice(0) : [];
|
||||
}
|
||||
util.inherits(SearchRequest, LDAPMessage);
|
||||
Object.defineProperties(SearchRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'SearchRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() { return this.baseObject; },
|
||||
configurable: false
|
||||
},
|
||||
scope: {
|
||||
get: function getScope() {
|
||||
switch (this._scope) {
|
||||
case Protocol.SCOPE_BASE_OBJECT: return 'base';
|
||||
case Protocol.SCOPE_ONE_LEVEL: return 'one';
|
||||
case Protocol.SCOPE_SUBTREE: return 'sub';
|
||||
default:
|
||||
throw new Error(this._scope + ' is an invalid search scope');
|
||||
}
|
||||
},
|
||||
set: function setScope(val) {
|
||||
if (typeof (val) === 'string') {
|
||||
switch (val) {
|
||||
case 'base':
|
||||
this._scope = Protocol.SCOPE_BASE_OBJECT;
|
||||
break;
|
||||
case 'one':
|
||||
this._scope = Protocol.SCOPE_ONE_LEVEL;
|
||||
break;
|
||||
case 'sub':
|
||||
this._scope = Protocol.SCOPE_SUBTREE;
|
||||
break;
|
||||
default:
|
||||
throw new Error(val + ' is an invalid search scope');
|
||||
}
|
||||
} else {
|
||||
this._scope = val;
|
||||
}
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
SearchRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
this.baseObject = ber.readString();
|
||||
this.scope = ber.readEnumeration();
|
||||
this.derefAliases = ber.readEnumeration();
|
||||
this.sizeLimit = ber.readInt();
|
||||
this.timeLimit = ber.readInt();
|
||||
this.typesOnly = ber.readBoolean();
|
||||
|
||||
this.filter = filters.parse(ber);
|
||||
|
||||
// look for attributes
|
||||
if (ber.peek() === 0x30) {
|
||||
ber.readSequence();
|
||||
var end = ber.offset + ber.length;
|
||||
while (ber.offset < end)
|
||||
this.attributes.push(ber.readString().toLowerCase());
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
SearchRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.writeString(this.baseObject.toString());
|
||||
ber.writeEnumeration(this._scope);
|
||||
ber.writeEnumeration(this.derefAliases);
|
||||
ber.writeInt(this.sizeLimit);
|
||||
ber.writeInt(this.timeLimit);
|
||||
ber.writeBoolean(this.typesOnly);
|
||||
|
||||
var f = this.filter || new filters.PresenceFilter({attribute: 'objectclass'});
|
||||
ber = f.toBer(ber);
|
||||
|
||||
ber.startSequence(Ber.Sequence | Ber.Constructor);
|
||||
if (this.attributes && this.attributes.length) {
|
||||
this.attributes.forEach(function (a) {
|
||||
ber.writeString(a);
|
||||
});
|
||||
}
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
SearchRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
j.baseObject = this.baseObject;
|
||||
j.scope = this.scope;
|
||||
j.derefAliases = this.derefAliases;
|
||||
j.sizeLimit = this.sizeLimit;
|
||||
j.timeLimit = this.timeLimit;
|
||||
j.typesOnly = this.typesOnly;
|
||||
j.filter = this.filter.toString();
|
||||
j.attributes = this.attributes;
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = SearchRequest;
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPResult = require('./result');
|
||||
var SearchEntry = require('./search_entry');
|
||||
var SearchReference = require('./search_reference');
|
||||
|
||||
var dtrace = require('../dtrace');
|
||||
var parseDN = require('../dn').parse;
|
||||
var parseURL = require('../url').parse;
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function SearchResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REP_SEARCH;
|
||||
LDAPResult.call(this, options);
|
||||
|
||||
this.attributes = options.attributes ? options.attributes.slice() : [];
|
||||
this.notAttributes = [];
|
||||
this.sentEntries = 0;
|
||||
}
|
||||
util.inherits(SearchResponse, LDAPResult);
|
||||
|
||||
/**
|
||||
* Allows you to send a SearchEntry back to the client.
|
||||
*
|
||||
* @param {Object} entry an instance of SearchEntry.
|
||||
* @param {Boolean} nofiltering skip filtering notAttributes and '_' attributes.
|
||||
* Defaults to 'false'.
|
||||
*/
|
||||
SearchResponse.prototype.send = function (entry, nofiltering) {
|
||||
if (!entry || typeof (entry) !== 'object')
|
||||
throw new TypeError('entry (SearchEntry) required');
|
||||
if (nofiltering === undefined)
|
||||
nofiltering = false;
|
||||
if (typeof (nofiltering) !== 'boolean')
|
||||
throw new TypeError('noFiltering must be a boolean');
|
||||
|
||||
var self = this;
|
||||
|
||||
if (entry instanceof SearchEntry || entry instanceof SearchReference) {
|
||||
if (!entry.messageID)
|
||||
entry.messageID = this.messageID;
|
||||
if (entry.messageID !== this.messageID)
|
||||
throw new Error('SearchEntry messageID mismatch');
|
||||
} else {
|
||||
if (!entry.attributes)
|
||||
throw new Error('entry.attributes required');
|
||||
|
||||
var savedAttrs = {};
|
||||
var all = (self.attributes.indexOf('*') !== -1);
|
||||
Object.keys(entry.attributes).forEach(function (a) {
|
||||
var _a = a.toLowerCase();
|
||||
if (!nofiltering && _a.length && _a[0] === '_') {
|
||||
savedAttrs[a] = entry.attributes[a];
|
||||
delete entry.attributes[a];
|
||||
} else if (!nofiltering && self.notAttributes.indexOf(_a) !== -1) {
|
||||
savedAttrs[a] = entry.attributes[a];
|
||||
delete entry.attributes[a];
|
||||
} else if (all) {
|
||||
return;
|
||||
} else if (self.attributes.length && self.attributes.indexOf(_a) === -1) {
|
||||
savedAttrs[a] = entry.attributes[a];
|
||||
delete entry.attributes[a];
|
||||
}
|
||||
});
|
||||
|
||||
var save = entry;
|
||||
entry = new SearchEntry({
|
||||
objectName: typeof (save.dn) === 'string' ? parseDN(save.dn) : save.dn,
|
||||
messageID: self.messageID,
|
||||
log: self.log
|
||||
});
|
||||
entry.fromObject(save);
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.log.debug())
|
||||
this.log.debug('%s: sending: %j', this.connection.ldap.id, entry.json);
|
||||
|
||||
this.connection.write(entry.toBer());
|
||||
this.sentEntries++;
|
||||
|
||||
if (self._dtraceOp && self._dtraceId) {
|
||||
dtrace.fire('server-search-entry', function () {
|
||||
var c = self.connection || {ldap: {}};
|
||||
return [
|
||||
self._dtraceId || 0,
|
||||
(c.remoteAddress || ''),
|
||||
c.ldap.bindDN ? c.ldap.bindDN.toString() : '',
|
||||
(self.requestDN ? self.requestDN.toString() : ''),
|
||||
entry.objectName.toString(),
|
||||
entry.attributes.length
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
// Restore attributes
|
||||
Object.keys(savedAttrs || {}).forEach(function (k) {
|
||||
save.attributes[k] = savedAttrs[k];
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
this.log.warn(e, '%s failure to write message %j',
|
||||
this.connection.ldap.id, this.json);
|
||||
}
|
||||
};
|
||||
|
||||
SearchResponse.prototype.createSearchEntry = function (object) {
|
||||
assert.object(object);
|
||||
|
||||
var entry = new SearchEntry({
|
||||
messageID: this.messageID,
|
||||
log: this.log,
|
||||
objectName: object.objectName || object.dn
|
||||
});
|
||||
entry.fromObject((object.attributes || object));
|
||||
return entry;
|
||||
};
|
||||
|
||||
SearchResponse.prototype.createSearchReference = function (uris) {
|
||||
if (!uris)
|
||||
throw new TypeError('uris ([string]) required');
|
||||
|
||||
if (!Array.isArray(uris))
|
||||
uris = [uris];
|
||||
|
||||
for (var i = 0; i < uris.length; i++) {
|
||||
if (typeof (uris[i]) == 'string')
|
||||
uris[i] = parseURL(uris[i]);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
return new SearchReference({
|
||||
messageID: self.messageID,
|
||||
log: self.log,
|
||||
uris: uris
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = SearchResponse;
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var LDAPMessage = require('./message');
|
||||
var dn = require('../dn');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var DN = dn.DN;
|
||||
var RDN = dn.RDN;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function UnbindRequest(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = Protocol.LDAP_REQ_UNBIND;
|
||||
LDAPMessage.call(this, options);
|
||||
}
|
||||
util.inherits(UnbindRequest, LDAPMessage);
|
||||
Object.defineProperties(UnbindRequest.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'UnbindRequest'; },
|
||||
configurable: false
|
||||
},
|
||||
_dn: {
|
||||
get: function getDN() {
|
||||
if (this.connection) {
|
||||
return this.connection.ldap.bindDN;
|
||||
} else {
|
||||
return new DN([new RDN({cn: 'anonymous'})]);
|
||||
}
|
||||
},
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
UnbindRequest.prototype._parse = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
UnbindRequest.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
return ber;
|
||||
};
|
||||
|
||||
UnbindRequest.prototype._json = function (j) {
|
||||
assert.ok(j);
|
||||
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = UnbindRequest;
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var dtrace = require('../dtrace');
|
||||
|
||||
var LDAPMessage = require('./result');
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- API
|
||||
// Ok, so there's really no such thing as an unbind 'response', but to make
|
||||
// the framework not suck, I just made this up, and have it stubbed so it's
|
||||
// not such a one-off.
|
||||
|
||||
function UnbindResponse(options) {
|
||||
options = options || {};
|
||||
assert.object(options);
|
||||
|
||||
options.protocolOp = 0;
|
||||
LDAPMessage.call(this, options);
|
||||
}
|
||||
util.inherits(UnbindResponse, LDAPMessage);
|
||||
Object.defineProperties(UnbindResponse.prototype, {
|
||||
type: {
|
||||
get: function getType() { return 'UnbindResponse'; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Special override that just ends the connection, if present.
|
||||
*
|
||||
* @param {Number} status completely ignored.
|
||||
*/
|
||||
UnbindResponse.prototype.end = function (status) {
|
||||
assert.ok(this.connection);
|
||||
|
||||
this.log.trace('%s: unbinding!', this.connection.ldap.id);
|
||||
|
||||
this.connection.end();
|
||||
|
||||
var self = this;
|
||||
if (self._dtraceOp && self._dtraceId) {
|
||||
dtrace.fire('server-' + self._dtraceOp + '-done', function () {
|
||||
var c = self.connection || {ldap: {}};
|
||||
return [
|
||||
self._dtraceId || 0,
|
||||
(c.remoteAddress || ''),
|
||||
c.ldap.bindDN ? c.ldap.bindDN.toString() : '',
|
||||
(self.requestDN ? self.requestDN.toString() : ''),
|
||||
0,
|
||||
''
|
||||
];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
UnbindResponse.prototype._json = function (j) {
|
||||
return j;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
|
||||
module.exports = UnbindResponse;
|
||||
Reference in New Issue
Block a user