JSPM

@mh-cbon/challenger

1.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q21079F
    • License MIT

    Challenge sudo over the streams

    Package Exports

    • @mh-cbon/challenger

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mh-cbon/challenger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    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 and stdin