From f4729032dd93768d17523ed89b8fe6a1b9cefcfb Mon Sep 17 00:00:00 2001 From: Yunong Xiao Date: Tue, 20 Dec 2011 15:04:59 -0800 Subject: [PATCH] add persistent search to cli --- bin/ldapjs-search | 18 ++++++++++++++++-- lib/messages/search_entry.js | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bin/ldapjs-search b/bin/ldapjs-search index e615100..a5eda63 100755 --- a/bin/ldapjs-search +++ b/bin/ldapjs-search @@ -36,6 +36,7 @@ var opts = { 'binddn': ldap.DN, 'control': Array, 'password': String, + 'persistent': Boolean, 'scope': String, 'url': url }; @@ -46,6 +47,7 @@ var shortOpts = { 'b': ['--base'], 'D': ['--binddn'], 'w': ['--password'], + 'p': ['--persistent'], 's': ['--scope'], 'u': ['--url'] }; @@ -122,6 +124,8 @@ if (!parsed.base) parsed.base = ''; if (!parsed.control) parsed.control = []; +if (!parsed.persistent) + parsed.persistent = false; var client = ldap.createClient({ url: parsed.url, @@ -143,6 +147,17 @@ client.bind(parsed.binddn, parsed.password, function(err, res) { criticality: true })); }); + if (parsed.persistent) { + var pCtrl = new ldap.PersistentSearchControl({ + type: '2.16.840.1.113730.3.4.3', + value: { + changeTypes: 15, + changesOnly: false, + returnECs: true + } + }); + controls.push(pCtrl); + } var req = { scope: parsed.scope || 'sub', filter: parsed.argv.remain[0], @@ -154,13 +169,12 @@ client.bind(parsed.binddn, parsed.password, function(err, res) { var entries = []; res.on('searchEntry', function(entry) { - entries.push(entry.object); + process.stdout.write(JSON.stringify(entry.object, null, 2) + '\n'); }); res.on('error', function(err) { perror(err); }); res.on('end', function(res) { - process.stdout.write(JSON.stringify(entries, null, 2) + '\n'); if (res.status !== 0) process.stderr.write(ldap.getMessage(res.status) + '\n'); client.unbind(function() { diff --git a/lib/messages/search_entry.js b/lib/messages/search_entry.js index c9b8e57..f326be2 100644 --- a/lib/messages/search_entry.js +++ b/lib/messages/search_entry.js @@ -40,7 +40,8 @@ function SearchEntry(options) { this.__defineGetter__('type', function() { return 'SearchEntry'; }); this.__defineGetter__('object', function() { var obj = { - dn: self.dn.toString() + dn: self.dn.toString(), + controls: [] }; self.attributes.forEach(function(a) { if (a.vals && a.vals.length) { @@ -53,6 +54,9 @@ function SearchEntry(options) { obj[a.type] = []; } }); + self.controls.forEach(function(element, index, array) { + obj.controls.push(element.json); + }); return obj; }); this.__defineGetter__('_dn', function() {