Skip to content

Instantly share code, notes, and snippets.

@tttp
Created November 12, 2011 11:03
Show Gist options
  • Save tttp/1360388 to your computer and use it in GitHub Desktop.
Save tttp/1360388 to your computer and use it in GitHub Desktop.
var ldap = require('ldapjs');
//var argv = require('optimist').argv;
//console.log('(%d,%d)', argv.x, argv.y);
var settings = require('./settings');
//console.log(settings);
var request = require('request');
var server = ldap.createServer();
function contact_search (res,name, callBack) {
var obj = { dn: name, attributes: { objectclass: ['organization', 'top'], o: 'example'}};
request("http://google.com", function (error, response, body) { // page queried irrelevant
callBack (obj,res);//FATAL: how not to loose the res?
});
}
server.bind(settings.ldap.basedn, function (req, res, next) {
var username = req.dn.toString(),
password = req.credentials;
console.log ("bind "+username+":"+password);
res.end();
return next();
});
server.search(settings.ldap.basedn, function(req, res, next) {
//'simplified' parsing of the request
query=req.dn.toString();
contact_search (res,query, function (obj,res) {
console.log (obj);
res.send(obj);
});
res.end();
});
server.listen(1389, function() {
console.log('LDAP server listening at %s', server.url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment