Skip to content

Instantly share code, notes, and snippets.

@thekid
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save thekid/f34447fa2d4127db994e to your computer and use it in GitHub Desktop.

Select an option

Save thekid/f34447fa2d4127db994e to your computer and use it in GitHub Desktop.
LDAP work in progress: Debugging / utilities
var Hexdump = {
chars: function(bytes, start, offset) {
var s = '';
var l = Math.min(offset, bytes.length);
for (j = start; j < l; j++) {
var c = bytes[j];
s += c < 0x20 || c > 0x7F ? '.' : String.fromCharCode(c);
}
return s;
},
lpad: function(string, padding, chr) {
while (string.length < padding) {
string = chr + string;
}
return string;
},
rpad: function(string, padding, chr) {
while (string.length < padding) {
string = string + chr;
}
return string;
},
dump: function(arg, message) {
if (Buffer.isBuffer(arg)) {
var bytes = arg;
} else {
var bytes = new Buffer(arg);
}
var n = bytes.length;
var next = ' ';
if (typeof(message) === 'undefined') {
var s = '';
var p = 74;
} else {
var s = message + ' ';
var p = 74 - message.length - 1;
}
s += Hexdump.lpad('== (' + n + " bytes) ==\n", p, '=');
for (var i = 0; i < n; i++) {
if (0 === i) {
s += '0000: ';
} else if (n - 1 === i) {
p = n % 16;
if (p) {
next = Hexdump.lpad('', (16 - p) * 3 + (p > 8 ? 1 : 2), ' ');
} else {
p = 16;
}
next += '|' + Hexdump.rpad(Hexdump.chars(bytes, n - p, n), 16, ' ') + '|';
} else if (0 === (i % 16)) {
s += '|' + Hexdump.chars(bytes, i - 16, i) + "|\n" + Hexdump.lpad(i.toString(16), 4, '0') + ': ';
} else if (0 === (i % 8)) {
s += ' ';
}
s += Hexdump.lpad(bytes[i].toString(16), 2, '0') + next;
}
return s;
}
};
module.exports = {
dump : Hexdump.dump
};
{
"author": "Timm Friebe <[email protected]>",
"name": "hexdump",
"homepage": "https://github.com/thekid/hexdump",
"description": "Hexdump",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "git://github.com/thekid/hexdump.git"
},
"main": "lib/index.js",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">=0.8"
},
"dependencies": {},
"scripts": {},
"bin": {},
"bugs": {
"url": "https://github.com/thekid/hexdump/issues"
},
"keywords": [
"debug"
],
"license": "BSD"
}
var ldap = require('ldapjs');
var fs = require('fs');
var server = ldap.createServer();
/*
var _70k;
fs.readFile('test', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
_70k = data;
});
*/
server.search('o=example', function(req, res, next) {
var objs = [{
dn: req.dn.toString(),
attributes: {
objectclass: ['organization', 'top'],
o: 'example',
ou : 'Organizational Unit Example',
title : 'OU, Inc.',
c : 'USA',
st : 'Example',
streetAddress : "4711 Example St\n90211 Example",
businessCategory : 'Examples'
}
},
{
dn: req.dn.toString(),
attributes: {
objectclass: ['organization', 'top'],
o: 'xp-framework',
ou : 'XP Framework',
title : 'XP Framework Group'
}
}];
objs.forEach(function(obj) {
if (req.filter.matches(obj.attributes))
res.send(obj);
});
res.end();
});
server.listen(1389, function() {
console.log('LDAP server listening at %s', server.url);
});
USE_XP=../core xp -e '$p= new \peer\ldap\util\LdapProtocol(new \peer\Socket("127.0.0.1", 1389));
$t= new \util\profiling\Timer();
$t->start();
try {
\util\cmd\Console::writeLine($p->search("o=example"));
} catch (\XPException $e) {
$e->printStackTrace(STDOUT);
}
$t->stop();
\util\cmd\Console::writeLinef("%.3f seconds", $t->elapsedTime());'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment