Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.bind(SUFFIX, function(req, res, next) {
console.log(req.dn.toString());
var dn = req.dn.toString().replaceSpaces();
if (!db[dn]){
return next(new ldap.NoSuchObjectError(dn));
}
if (!db[dn].userpassword)
return next(new ldap.NoSuchAttributeError('userPassword'));
if (db[dn].userpassword.indexOf(req.credentials) === -1){
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
let matchingUsers = _.filter(users, user => normalizedDn == user.dn);
console.log(matchingUsers);
if (matchingUsers.length > 1) {
return next(new ldap.UnwillingToPerformError());
}
if (matchingUsers.length == 0) {
return next(new ldap.NoSuchObjectError(dn));
}
let user = matchingUsers[0];
if (user.password != password) {
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
server.bind(SUFFIX, function(req, res, next) {
var dn = req.dn
.toString()
.replace(/, /g, ',')
.toLowerCase()
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn))
}
if (!db[dn].userpassword) {
return next(new ldap.NoSuchAttributeError('userPassword'))
}
if (db[dn].userpassword.indexOf(req.credentials) === -1) {
return next(new ldap.InvalidCredentialsError())
}
res.end()
return next()
})
function authenticateAdmin(req, res, next) {
if (req.credentials === Mock.PASSWORD_WRONG) {
return next(new LDAP.InvalidCredentialsError());
} else {
res.end();
return next();
}
}
server.bind(config.admin.username, function(req, res, next) {
if (!req.dn.equals(config.admin.username)) {
winston.info('Got a bind for a child of the admin user: %s', req.dn.toString());
return next(new ldap.NoSuchObjectError(req.dn.toString()));
}
if (req.credentials !== config.admin.password) {
winston.info('Got invalid credentials for admin user.');
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
server.bind('o=example', function(req, res, next) {
if (req.dn.toString() !== dn || req.credentials !== 'secret')
return next(new ldapjs.InvalidCredentialsError());
res.end();
return next();
});
server.bind('ou=layers,o=teleport', function(req, res, next) {
if ( 3 === keys(req.rdns).length && req.rdns.cn )
require('./ldap/bindLayer')(req, res, next);
else
next(new ldap.InvalidCredentialsError("Invalid login"));
});
server.unbind(function(req, res, next) {
function(r) {
next(new ldap.InvalidCredentialsError(dn));
});
});
server.bind(SUFFIX, function (req, res, next) {
var dn = req.dn.toString();
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn));
}
if (!db[dn].attributes.userPassword) {
return next(new ldap.NoSuchAttributeError('userPassword'));
}
if (db[dn].attributes.userPassword !== req.credentials) {
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
function authenticate(layer, credential, callback) {
var password = process.env[format('LDAP_LAYER_%s_PASSWORD', layer.toUpperCase())];
if ( password && credential === password )
callback(null, password)
else
callback(new ldap.InvalidCredentialsError("Invalid login for layer " + layer));
}