Creating the Client Control Object for ldapjs server side sorting

603 views Asked by At

Has anyone has success using the server side sorting control with ldapjs? The docs don't provide any specific examples of creating/using such a control object.

I have enabled the overlay on the openldap server side, but can't seem to come up with the proper format for the client control. I am not sure of the correct format for the Buffer value to create the SortKeyList as mentioned in RFC 2891

 const stringBuf = Buffer.from( 'uid' );

            // The LDAP the Server-Side Sorting Control
            const controls = new ldap.ldapjs.Control( {
                "type": "1.2.840.113556.1.4.473",
                "criticality": true,
                "value": stringBuf
            } );

I receive the following error:

searchErr: TypeError: argument must be a string (was: object)
at Writer.writeString (/srv/node_modules/asn1/lib/ber/writer.js:134:11)
at Control.toBer (/srv/node_modules/ldapjs/lib/controls/control.js:50:27)
at /srv/node_modules/ldapjs/lib/messages/message.js:99:9
at Array.forEach (<anonymous>)
at SearchRequest.LDAPMessage.toBer (/srv/node_modules/ldapjs/lib/messages/message.js:98:19)
at Client._sendSocket (/srv/node_modules/ldapjs/lib/client/client.js:1255:31)
at Client._send (/srv/node_modules/ldapjs/lib/client/client.js:1148:17)
at sendRequest (/srv/node_modules/ldapjs/lib/client/client.js:607:17)
at Client.search (/srv/node_modules/ldapjs/lib/client/client.js:636:5)
at client.starttls (/srv/nodeserver.dev/ldap.js:105:24)

I've consulted function ldapjs.ServerSideSortingRequestControl (options) and also function ldapjs.Control (options) to no avail.

1

There are 1 answers

0
John K Boyd On

I finally got this working by switching from the generic ldapjs.Control to the specific ldapjs.ServerSideSortingRequestControl

You can provide just the value for the SortKeyList. Type OID will be appended by the function. Criticality can be omitted.

const control = { "value": { "attributeType": "uid", "orderingRule": "CaseIgnoreOrderingMatch" } };

const controls = new ldap.ldapjs.ServerSideSortingRequestControl( control );

But be aware that this is not a very performant solution