diff options
author | isaacs <i@izs.me> | 2012-04-30 23:46:31 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-04-30 23:47:22 +0400 |
commit | 76c7d93e9d549d5cc0e4d33ee19fdac044a6cda8 (patch) | |
tree | f29387eefecfe529889e2bfd32a54b5377b29a8e | |
parent | 85873cf40ab8c43a27e8f367b5ebe2928677101d (diff) |
Only use numeric UIDs and GIDs in spawn
-rw-r--r-- | lib/utils/exec.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/utils/exec.js b/lib/utils/exec.js index 0fa0371b2..8b75adb24 100644 --- a/lib/utils/exec.js +++ b/lib/utils/exec.js @@ -11,6 +11,7 @@ var log = require("./log.js") , myGID = process.getgid ? process.getgid() : null , isRoot = process.getuid && myUID === 0 , constants = require("constants") + , uidNumber = require("uid-number") function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { if (typeof cb !== "function") cb = gid, gid = null @@ -34,6 +35,15 @@ function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) { log.verbose(uid, "Setting uid from "+myUID) log.verbose(new Error().stack, "stack at uid setting") } + + if (isNaN(uid) || isNaN(gid)) { + // get the numeric values + return uidNumber(uid, gid, function (er, uid, gid) { + if (er) return cb(er) + exec(cmd, args, env, takeOver, cwd, uid, gid, cb) + }) + } + log.silly(cmd+" "+args.map(JSON.stringify).join(" "), "exec") var stdout = "" , stderr = "" @@ -77,6 +87,7 @@ function pipe (cp1, cp2, cb) { cb(errState = new Error( "Failed "+(cp1.name || "<unknown>")+"\nexited with "+code)) }) + cp2.on("exit", function (code) { cp2._exited = true if (errState) return @@ -94,10 +105,14 @@ function spawn (c, a, env, takeOver, cwd, uid, gid) { , env : env || process.env , cwd : cwd || null } , cp - if (uid != null) opts.uid = uid - if (gid != null) opts.gid = gid + + if (!isNaN(uid)) opts.uid = uid + if (!isNaN(gid)) opts.gid = gid + if (!isNaN(opts.uid)) opts.uid = +opts.uid + if (!isNaN(opts.gid)) opts.gid = +opts.gid + var name = c +" "+ a.map(JSON.stringify).join(" ") log.silly([c, a, opts.cwd], "spawning") cp = child_process.spawn(c, a, opts) |