Skip to content

Commit

Permalink
Merge pull request thelounge#697 from cloudron-io/ldap_crashfix
Browse files Browse the repository at this point in the history
Fix crash when LDAP server is unreachable
  • Loading branch information
astorije authored Oct 23, 2016
2 parents c85e407 + 09f2d06 commit 8ec6d96
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var Helper = require("./helper");
var ldap = require("ldapjs");

var manager = null;
var ldapclient = null;
var authFunction = localAuth;

module.exports = function() {
Expand Down Expand Up @@ -60,9 +59,6 @@ module.exports = function() {
}

if (!config.public && (config.ldap || {}).enable) {
ldapclient = ldap.createClient({
url: config.ldap.url
});
authFunction = ldapAuth;
}

Expand Down Expand Up @@ -287,12 +283,22 @@ function ldapAuth(client, user, password, callback) {
var userDN = user.replace(/([,\\\/#+<>;"= ])/g, "\\$1");
var bindDN = Helper.config.ldap.primaryKey + "=" + userDN + "," + Helper.config.ldap.baseDN;

var ldapclient = ldap.createClient({
url: Helper.config.ldap.url
});

ldapclient.on("error", function(err) {
log.error("Unable to connect to LDAP server", err);
callback(!err);
});

ldapclient.bind(bindDN, password, function(err) {
if (!err && !client) {
if (!manager.addUser(user, null)) {
log.error("Unable to create new user", user);
}
}
ldapclient.unbind();
callback(!err);
});
}
Expand Down

0 comments on commit 8ec6d96

Please sign in to comment.