Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.add(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn
.toString()
.replace(/, /g, ',')
.toLowerCase()
if (db[dn]) {
return next(new ldap.EntryAlreadyExistsError(dn))
}
db[dn] = req.toObject().attributes
res.end()
return next()
})
server.add(SUFFIX, authorize, function(req, res, next) {
try{
var dn = req.dn.toString().replaceSpaces();
if(!dn.endsWith(SUFFIX.replaceSpaces())){
dn+=","+SUFFIX.replaceSpaces();
}
if (db[dn])
return next(new ldap.EntryAlreadyExistsError(dn));
var attributes = req.toObject().attributes;
if(dn.startsWith("cn=")){
attributes["cn"]=dn.match(/cn=([^,]*),/)[1];
}
db[dn] = attributes;
res.end();
return next();
}catch(e){
return next(new ldap.LdapError(e.toString()));
}
});