diff options
author | isaacs <i@izs.me> | 2011-01-10 09:59:11 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-02-08 04:09:04 +0300 |
commit | 6db90ffa08aaf1dbd88bf1102c349de965bf24a8 (patch) | |
tree | 9403e399c3c032cfc77c18f997ddca999b6cbfdd /bin | |
parent | 3d4903fdbd466aa49198e5f82a695bb0d97011f5 (diff) |
Broken first pass at setuid script runner
Diffstat (limited to 'bin')
-rw-r--r-- | bin/npm-script-runner.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/npm-script-runner.js b/bin/npm-script-runner.js new file mode 100644 index 000000000..6b4fdef9b --- /dev/null +++ b/bin/npm-script-runner.js @@ -0,0 +1,31 @@ +#!/usr/bin/env/ node + +// Run a command as nobody +// env is passed through untouched. +// usage: npm-script-runner $folder $uid "make test" +// This is internal plumbing + +console.error(process.argv) + +var argv = process.argv.slice(2) + , cwd = argv.shift() + , cmd = argv.shift() + , uid = argv.shift() + , stdio = process.binding("stdio") + +try { + process.setuid(uid) +} catch (ex) { + console.error("Could not setuid to "+uid) + throw ex +} + + +require("child_process").spawn( "sh", ["-c", cmd] + , { env : process.env + , cwd : cwd + , customFDs: [ stdio.stdinFD + , stdio.stdoutFD + , stdio.stderrFD ] + }) + .on("exit", function (c) { process.exit(c) }) |