diff options
author | isaacs <i@izs.me> | 2010-12-22 18:08:20 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-01-11 10:02:58 -0800 |
commit | 6f5d95de6df6dad23b908fb15ad1a823b9d9a4d1 (patch) | |
tree | c914f3b6933d084c05a28748fefc7e681b5b5ef1 /test/disabled | |
parent | b7419dfaadc512f46898f4ca8dae30b19fede83f (diff) | |
download | android-node-v8-6f5d95de6df6dad23b908fb15ad1a823b9d9a4d1.tar.gz android-node-v8-6f5d95de6df6dad23b908fb15ad1a823b9d9a4d1.tar.bz2 android-node-v8-6f5d95de6df6dad23b908fb15ad1a823b9d9a4d1.zip |
child_process: Add gid/uid flags to spawn config
This is mostly working, but not completely ideal for two reasons.
1. Rather than emitting an error on the ChildProcess object when the
setgid/setuid fails, it is simply printing the error to stderr and
exiting. The same happens with the cwd, so that's not completely
terrible.
2. I don't have a good test for this. It fails with an EPERM if you try
to change the uid or gid as a non-root user.
Diffstat (limited to 'test/disabled')
-rw-r--r-- | test/disabled/test-child-process-uid-gid.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/disabled/test-child-process-uid-gid.js b/test/disabled/test-child-process-uid-gid.js new file mode 100644 index 0000000000..71513c0e0e --- /dev/null +++ b/test/disabled/test-child-process-uid-gid.js @@ -0,0 +1,41 @@ +// must be run as sudo, otherwise the gid/uid setting will fail. +var child_process = require("child_process"), + constants = require("constants"), + passwd = require("fs").readFileSync("/etc/passwd", "utf8"), + myUid = process.getuid(), + myGid = process.getgid(); + +// get a different user. +// don't care who it is, as long as it's not root +passwd = passwd.trim().split(/\n/); +for (var i = 0, l = passwd.length; i < l; i ++) { + if (passwd[i].charAt(0) === "#") continue; + passwd[i] = passwd[i].split(":"); + var otherName = passwd[i][0]; + var otherUid = +passwd[i][2]; + var otherGid = +passwd[i][3]; + if (otherUid && otherUid !== myUid && + otherGid && otherGid !== myGid && + otherUid > 0) { + break; + } +} +if (!otherUid && !otherGid) throw new Error("failed getting passwd info."); + +console.error("name, id, gid = %j", [otherName, otherUid, otherGid]); + +var whoNumber = child_process.spawn("id",[], {uid:otherUid,gid:otherGid}), + assert = require("assert"); + +whoNumber.stdout.buf = "byNumber:"; +whoNumber.stdout.on("data", onData); +function onData (c) { this.buf += c; } + +whoNumber.on("exit", onExit); +function onExit (code) { + var buf = this.stdout.buf; + console.log(buf); + var expr = new RegExp("^byNumber:uid="+otherUid+"\\("+ + otherName+"\\) gid="+otherGid+"\\("); + assert.ok(buf.match(expr), "uid and gid should match "+otherName); +} |