Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-01-10 09:59:11 +0300
committerisaacs <i@izs.me>2011-02-08 04:09:04 +0300
commit6db90ffa08aaf1dbd88bf1102c349de965bf24a8 (patch)
tree9403e399c3c032cfc77c18f997ddca999b6cbfdd /bin
parent3d4903fdbd466aa49198e5f82a695bb0d97011f5 (diff)
Broken first pass at setuid script runner
Diffstat (limited to 'bin')
-rw-r--r--bin/npm-script-runner.js31
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) })