Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function pam(inner_callback) {
// return true if error, false if auth failed, string for user if successful
try {
var pam = require('authenticate-pam');
} catch (e) {
inner_callback(true);
return;
}
pam.authenticate(user, plaintext, function(err) {
if (err)
inner_callback(false);
else
inner_callback(user);
})
}
function jail(username, password){
pam.authenticate(username, password, function(err) {
if (!err) {
console.log('User %s logged !', username);
passwd.get(username, function(user){
process.title = 'node-xplorer-jailed-'+username;
try {
process.chdir(user.homedir);
posix.chroot(user.homedir);
process.setgid(parseInt(user.groupId, 10));
process.setuid(parseInt(user.userId, 10));
console.log('Subprocess successfully jailed by ' + username + ' ('+process.getuid()+':'+process.getgid()+')');
user.homedir = '/';
process.send({success: true, args:{user: user}});
} catch (err) {
console.log(err);
process.send({success: false, eror: err});
}
return new Promise((resolve, reject) => {
_pam.authenticate(data.username, data.password, (err) => {
if ( err ) {
reject(err);
} else {
resolve({
id: _userid.uid(data.username),
username: data.username,
name: data.username
});
}
});
});
};
var promise = new Promise(function(resolve, reject) {
pam.authenticate(username, password, function(err) {
if(!err) {
resolve(setToken(username));
}
else {
reject(err);
}
});
});
auth.register('pam', function (username, password, done) {
pam.authenticate(username, password, function (err) {
if (err) {
done(err, null);
} else {
var user = unix.getUser({ username: username })[0];
user.chroot = config.auth.default_chroot === '~' ? user.home : config.auth.default_chroot;
done(err, user);
}
});
});