add persistent search to cli

This commit is contained in:
Yunong Xiao 2011-12-20 15:04:59 -08:00
parent e6a007e032
commit f4729032dd
2 changed files with 21 additions and 3 deletions

View File

@ -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() {

View File

@ -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() {