Merge pull request #45 from yunong/master

add persistent search to cli
This commit is contained in:
Mark Cavage 2011-12-20 15:10:41 -08:00
commit 1ac67c2bc6
2 changed files with 21 additions and 4 deletions

View File

@ -36,6 +36,7 @@ var opts = {
'binddn': ldap.DN, 'binddn': ldap.DN,
'control': Array, 'control': Array,
'password': String, 'password': String,
'persistent': Boolean,
'scope': String, 'scope': String,
'url': url 'url': url
}; };
@ -46,6 +47,7 @@ var shortOpts = {
'b': ['--base'], 'b': ['--base'],
'D': ['--binddn'], 'D': ['--binddn'],
'w': ['--password'], 'w': ['--password'],
'p': ['--persistent'],
's': ['--scope'], 's': ['--scope'],
'u': ['--url'] 'u': ['--url']
}; };
@ -122,6 +124,8 @@ if (!parsed.base)
parsed.base = ''; parsed.base = '';
if (!parsed.control) if (!parsed.control)
parsed.control = []; parsed.control = [];
if (!parsed.persistent)
parsed.persistent = false;
var client = ldap.createClient({ var client = ldap.createClient({
url: parsed.url, url: parsed.url,
@ -143,6 +147,17 @@ client.bind(parsed.binddn, parsed.password, function(err, res) {
criticality: true 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 = { var req = {
scope: parsed.scope || 'sub', scope: parsed.scope || 'sub',
filter: parsed.argv.remain[0], filter: parsed.argv.remain[0],
@ -152,15 +167,13 @@ client.bind(parsed.binddn, parsed.password, function(err, res) {
if (err) if (err)
perror(err); perror(err);
var entries = [];
res.on('searchEntry', function(entry) { res.on('searchEntry', function(entry) {
entries.push(entry.object); process.stdout.write(JSON.stringify(entry.object, null, 2) + '\n');
}); });
res.on('error', function(err) { res.on('error', function(err) {
perror(err); perror(err);
}); });
res.on('end', function(res) { res.on('end', function(res) {
process.stdout.write(JSON.stringify(entries, null, 2) + '\n');
if (res.status !== 0) if (res.status !== 0)
process.stderr.write(ldap.getMessage(res.status) + '\n'); process.stderr.write(ldap.getMessage(res.status) + '\n');
client.unbind(function() { client.unbind(function() {

View File

@ -40,7 +40,8 @@ function SearchEntry(options) {
this.__defineGetter__('type', function() { return 'SearchEntry'; }); this.__defineGetter__('type', function() { return 'SearchEntry'; });
this.__defineGetter__('object', function() { this.__defineGetter__('object', function() {
var obj = { var obj = {
dn: self.dn.toString() dn: self.dn.toString(),
controls: []
}; };
self.attributes.forEach(function(a) { self.attributes.forEach(function(a) {
if (a.vals && a.vals.length) { if (a.vals && a.vals.length) {
@ -53,6 +54,9 @@ function SearchEntry(options) {
obj[a.type] = []; obj[a.type] = [];
} }
}); });
self.controls.forEach(function(element, index, array) {
obj.controls.push(element.json);
});
return obj; return obj;
}); });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function() {