diff --git a/lib/client.js b/lib/client.js index bd3c069..2c27f31 100644 --- a/lib/client.js +++ b/lib/client.js @@ -564,7 +564,7 @@ Client.prototype.search = function(base, options, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -577,7 +577,8 @@ Client.prototype.search = function(base, options, controls, callback) { sizeLimit: options.sizeLimit || 0, timeLimit: options.timeLimit || 10, typesOnly: options.typesOnly || false, - attributes: options.attributes || [] + attributes: options.attributes || [], + controls: controls }); var res = new EventEmitter(); diff --git a/lib/control.js b/lib/control.js index dc6ce89..a7c2688 100644 --- a/lib/control.js +++ b/lib/control.js @@ -72,3 +72,15 @@ Control.prototype.parse = function(ber) { return true; }; + + +Control.prototype.toBer = function(ber) { + assert.ok(ber); + + ber.startSequence(); + ber.writeString(this.type || ''); + ber.writeBoolean(this.criticality); + if (this.value) + ber.writeString(this.value); + ber.endSequence(); +}; diff --git a/lib/messages/message.js b/lib/messages/message.js index a95e958..c01f1ef 100644 --- a/lib/messages/message.js +++ b/lib/messages/message.js @@ -95,12 +95,20 @@ LDAPMessage.prototype.toBer = function() { var writer = new BerWriter(); writer.startSequence(); writer.writeInt(this.messageID); - writer.startSequence(this.protocolOp); + 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; };