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();
});
server.compare(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn.toString().replaceSpaces();
if (!db[dn])
return next(new ldap.NoSuchObjectError(dn));
var key = Object.keys(db[dn]).find(_=>_.toLowerCase() === req.attribute);
if (!key)
return next(new ldap.NoSuchAttributeError(req.attribute));
var matches = false;
var vals = db[dn][key];
for (var i = 0; i < vals.length; i++) {
if (vals[i] === req.value) {
matches = true;
break;
}
}
res.end(matches);
return next();
});
server.compare(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn
.toString()
.replace(/, /g, ',')
.toLowerCase()
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn))
}
if (!db[dn][req.attribute]) {
return next(new ldap.NoSuchAttributeError(req.attribute))
}
var matches = false
var vals = db[dn][req.attribute]
for (var i = 0; i < vals.length; i++) {
if (vals[i] === req.value) {
matches = true
break
}
}
res.end(matches)
return next()
})
server.modify(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn.toString().replaceSpaces();
if (!req.changes.length)
return next(new ldap.ProtocolError('changes required'));
if (!db[dn])
return next(new ldap.NoSuchObjectError(dn));
var entry = db[dn];
for (var i = 0; i < req.changes.length; i++) {
mod = req.changes[i].modification;
switch (req.changes[i].operation) {
case 'replace':
if (!entry[mod.type])
return next(new ldap.NoSuchAttributeError(mod.type));
if (!mod.vals || !mod.vals.length) {
delete entry[mod.type];
} else {
entry[mod.type] = mod.vals;
}
break;
case 'add':
if (!entry[mod.type]) {
entry[mod.type] = mod.vals;
} else {
mod.vals.forEach(function(v) {
if (entry[mod.type].indexOf(v) === -1)
entry[mod.type].push(v);
.toLowerCase()
if (!req.changes.length) {
return next(new ldap.ProtocolError('changes required'))
}
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn))
}
var entry = db[dn]
for (var i = 0; i < req.changes.length; i++) {
var mod = req.changes[i].modification
switch (req.changes[i].operation) {
case 'replace':
if (!entry[mod.type]) {
return next(new ldap.NoSuchAttributeError(mod.type))
}
if (!mod.vals || !mod.vals.length) {
delete entry[mod.type]
} else {
entry[mod.type] = mod.vals
}
break
case 'add':
if (!entry[mod.type]) {
entry[mod.type] = mod.vals
} else {
mod.vals.forEach(function(v) {
if (entry[mod.type].indexOf(v) === -1) {
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()
})
server.compare(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString();
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn));
}
if (!db[dn][req.attribute]) {
return next(new ldap.NoSuchAttributeError(req.attribute));
}
var matches = false;
var vals = db[dn][req.attribute];
for (var i = 0; i < vals.length; i++) {
if (vals[i] === req.value) {
matches = true;
break;
}
}
res.end(matches);
return next();
});
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();
});