@mh-cbon/challenger
v1.0.1
Published
Challenge sudo over the streams
Downloads
3
Readme
challenger
Challenge sudo over the streams
Install
npm i @mh-cbon/challenger --save
Usage
var challenger = require('./index.js')(process.env['SUDOPWD']);
var cmd = 'echo "token" 1>&2 && sudo -S -k echo "my token" 1>&2 && sudo -S -k echo "my token22" 1>&2';
var child = challenger.spawn('sh', ['-c', cmd], {stdio:'pipe'});
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
child.on('exit', function () {
console.log('exit')
})
child.on('close', function () {
console.log('close')
})
It resolves the sudo challenge given the password provided in env['SUDOPWD']
.
If the password is incorrect, prompt user for a new password until the challenge is solved, or dies.
When the new password is correct, save it in memory for later use.
Also cleans up stderr of any sudo challenge output.
alternate usage
To get the complete about of the child_process you may proceed so,
var spawn = require('child_process').spawn;
var challenger = require('./index.js')(process.env['SUDOPWD']);
var cmd = 'echo "token" 1>&2 && sudo -S -k echo "my token" 1>&2 && sudo -S -k echo "my token22" 1>&2';
var child = spawn('sh', ['-c', cmd], {stdio:'pipe'});
var cleanStderr = challenger(child);
//cleanStderr.pipe(process.stderr);
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
child.on('exit', function () {
console.log('exit')
})
child.on('close', function () {
console.log('close')
})
Notes
- All sudo commands must use
-S
, otherwise sudo writes directly onto the terminal device, which this module does not listen. - the child process must pipe both
stderr
andstdin