Permalink
Browse files

Don't try to change uid or gid if in unsafe-perm mode.

  • Loading branch information...
isaacs committed Feb 25, 2011
1 parent 869de96 commit e3c8120ecc137f4e1b6288e64fe171520c26400a
Showing with 14 additions and 6 deletions.
  1. +3 −2 lib/install.js
  2. +4 −0 lib/utils/exec.js
  3. +7 −4 lib/utils/lifecycle.js
View
@@ -274,13 +274,14 @@ function buildAll (installed, bundles, cb) {
cb = rollbackFailure(list, cb)
if (!list.length) return log.info("Nothing to do", "install", cb)
var buildList = []
+ , up = npm.config.get("unsafe-perm")
asyncMap(list, function (i, cb) {
var target = path.join(npm.dir, i[0], i[1])
cache.unpack( i[0], i[1], target
, null, null // don't chmod anything here. just as-is.
- , npm.config.get("user")
- , npm.config.get("group"), function (er) {
+ , up ? null : npm.config.get("user")
+ , up ? null : npm.config.get("group"), function (er) {
if (!er) buildList.push(target)
cb(er)
})
View
@@ -30,6 +30,10 @@ function exec (cmd, args, env, takeOver, cwd, uid, gid, cb) {
return cb(e)
}
}
+ if (uid !== myUID) {
+ log.verbose(uid, "Setting uid from "+myUID)
+ log.verbose(new Error().stack, "stack at uid setting")
+ }
log.silly(cmd+" "+args.map(JSON.stringify).join(" "), "exec")
var stdout = ""
, stderr = ""
View
@@ -141,10 +141,12 @@ function validWd (d) {
function runPackageLifecycle (pkg, env, wd, cb) {
// run package lifecycle scripts in the package root, or the nearest parent.
var stage = env.npm_lifecycle_event
- , user = pkg._link ? null : npm.config.get("user")
- , group = pkg._link ? null : npm.config.get("group")
+ , up = npm.config.get("unsafe-perm")
+ , user = pkg._link || up ? null : npm.config.get("user")
+ , group = pkg._link || up ? null : npm.config.get("group")
, cmd = env.npm_lifecycle_script
+ log.verbose(up, "unsafe-perm in lifecycle")
exec( "sh", ["-c", cmd], env, true, wd
, user, group
, function (er, code, stdout, stderr) {
@@ -173,9 +175,10 @@ function runPackageLifecycle (pkg, env, wd, cb) {
function runHookLifecycle (pkg, env, wd, cb) {
// check for a hook script, run if present.
var stage = env.npm_lifecycle_event
+ , up = npm.config.get("unsafe-perm")
, hook = path.join(npm.dir, ".hooks", stage)
- , user = pkg._link ? null : npm.config.get("user")
- , group = pkg._link ? null : npm.config.get("group")
+ , user = pkg._link || up ? null : npm.config.get("user")
+ , group = pkg._link || up ? null : npm.config.get("group")
, cmd = hook
fs.stat(hook, function (er) {

0 comments on commit e3c8120

Please sign in to comment.