From 1376e593a67281aeaad30e1bd5eb177fb6a3e691 Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Sun, 14 Jun 2015 20:51:14 -0500 Subject: [PATCH] Remove special attribute formatting for objectGUID - Conclude mcavage/node-ldapjs#218 - Clean up exports in index.js --- README.md | 59 ++---------------------------------------------- lib/attribute.js | 28 ----------------------- lib/index.js | 50 ++++------------------------------------ 3 files changed, 7 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 2f75873..6f16466 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ server.listen(1389, function() { }); ``` -To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/) client -on your system: +To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/) +client on your system: ldapsearch -H ldap://localhost:1389 -x -b dc=example objectclass=* @@ -45,61 +45,6 @@ on your system: npm install ldapjs -## Formatting objectGUID attribute value - -```javascript -var ldap = require('ldapjs'); - -ldap.Attribute.settings.guid_format = ldap.GUID_FORMAT_B; - -var client = ldap.createClient({ - url: 'ldap://127.0.0.1/CN=test,OU=Development,DC=Home' -}); - -var opts = { - filter: '(objectclass=user)', - scope: 'sub', - attributes: ['objectGUID'] -}; - -client.bind('username', 'password', function (err) { - client.search('CN=test,OU=Development,DC=Home', opts, function (err, search) { - search.on('searchEntry', function (entry) { - var user = entry.object; - console.log(user.objectGUID); - }); - }); -}); -``` - -_Note: for the sake of simplicity all checks and error handling was removed from the sample above._ - -The console output may be similar to the following (depending on the amount of users in the directory): - - {a7667bb1-4aee-48ce-9d9d-a1193550deba} - {8d642ac8-14c6-4f27-ac5-94d39833da88} - -Available formatting modes: - - GUID_FORMAT_N - N specifier, 32 digits: - 00000000000000000000000000000000 - GUID_FORMAT_D - D specifier, 32 digits separated by hypens: - 00000000-0000-0000-0000-000000000000 - GUID_FORMAT_B - B specifier, 32 digits separated by hyphens, enclosed in braces: - {00000000-0000-0000-0000-000000000000} - GUID_FORMAT_P - P speficier, 32 digits separated by hyphens, enclosed in parentheses: - (00000000-0000-0000-0000-000000000000) - GUID_FORMAT_X - X speficier, four hexadecimal values enclosed in braces, - where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces: - {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} - -GUID formatting is unobtrusive by default. You should explicitly define formatting mode in order to enable it. - ## License MIT. diff --git a/lib/attribute.js b/lib/attribute.js index aefaa9c..b6d8e6b 100644 --- a/lib/attribute.js +++ b/lib/attribute.js @@ -6,9 +6,6 @@ var asn1 = require('asn1'); var Protocol = require('./protocol'); -var settings = {}; -// specifies Guid display format, not defined (and unobstrusive) by default -settings.guid_format = ''; ///--- API @@ -39,19 +36,6 @@ function Attribute(options) { } }); - // processing of objectGUID attribute value - if (/objectGUID$/.test(self.type)) { - // check whether custom display format was defined - if (settings && settings.guid_format && settings.guid_format.length > 0) { - // ensure objectGUID value is present within buffers - var _buffers = self._vals; - if (_buffers && _buffers.length > 0 && Buffer.isBuffer(_buffers[0])) { - // return formatted value as per settings - return formatGuid(settings.guid_format, _buffers[0]); - } - } - } - return _vals; }); @@ -81,7 +65,6 @@ function Attribute(options) { } module.exports = Attribute; -module.exports.settings = settings; Attribute.prototype.addValue = function (val) { if (Buffer.isBuffer(val)) { @@ -186,14 +169,3 @@ Attribute.isAttribute = function (attr) { Attribute.prototype.toString = function () { return JSON.stringify(this.json); }; - - -function formatGuid(format, data) { - for (var i = 0; i < data.length; i++) { - var re = new RegExp('\\{' + i + '\\}', 'g'); - // Leading 0 is needed if value of data[i] is less than 16 (of 10 as hex). - var dataStr = data[i].toString(16); - format = format.replace(re, data[i] >= 16 ? dataStr : '0' + dataStr); - } - return format; -} diff --git a/lib/index.js b/lib/index.js index 5947a43..e25b452 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,41 +17,10 @@ var filters = require('./filters'); var messages = require('./messages'); var url = require('./url'); -// Guid formatting - -// N specifier, 32 digits: -// 00000000000000000000000000000000 -/* JSSTYLED */ -var GUID_FORMAT_N = '{3}{2}{1}{0}{5}{4}{7}{6}{8}{9}{10}{11}{12}{13}{14}{15}'; - -// D specifier, 32 digits separated by hypens: -// 00000000-0000-0000-0000-000000000000 -/* JSSTYLED */ -var GUID_FORMAT_D = '{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}'; - -// B specifier, 32 digits separated by hyphens, enclosed in braces: -// {00000000-0000-0000-0000-000000000000} -/* JSSTYLED */ -var GUID_FORMAT_B = '{{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}}'; - -// P specifier, 32 digits separated by hyphens, enclosed in parentheses: -// (00000000-0000-0000-0000-000000000000) -/* JSSTYLED */ -var GUID_FORMAT_P = '({3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15})'; - -// X specifier, Four hexadecimal values enclosed in braces, -// where the fourth value is a subset of eight hexadecimal values that is also -// enclosed in braces: -// {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} -/* JSSTYLED */ -var GUID_FORMAT_X = '{0x{3}{2}{1}{0},0x{5}{4},0x{7}{6},{0x{8},0x{9},0x{10},0x{11},0x{12},0x{13},0x{14},0x{15}}}'; - - ///--- API module.exports = { - createClient: client.createClient, Server: Server, @@ -76,31 +45,22 @@ module.exports = { Attribute: Attribute, Change: Change, - DN: dn.DN, - PersistentSearchCache: persistentSearch.PersistentSearchCache, - RDN: dn.RDN, - - parseDN: dn.parse, dn: dn, + DN: dn.DN, + RDN: dn.RDN, + parseDN: dn.parse, persistentSearch: persistentSearch, + PersistentSearchCache: persistentSearch.PersistentSearchCache, filters: filters, parseFilter: filters.parseString, - parseURL: url.parse, - url: url, - - GUID_FORMAT_N: GUID_FORMAT_N, - GUID_FORMAT_D: GUID_FORMAT_D, - GUID_FORMAT_B: GUID_FORMAT_B, - GUID_FORMAT_P: GUID_FORMAT_P, - GUID_FORMAT_X: GUID_FORMAT_X + parseURL: url.parse }; - ///--- Export all the childrenz var k;