Permalink
Browse files

Respect the --unsafe-perm config

  • Loading branch information...
isaacs committed Feb 7, 2011
1 parent ec2aa21 commit 52e3e88feb75c1e4c5e05771e2f4e67be27015ab
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/utils/uid-number.js
@@ -3,6 +3,8 @@ module.exports = uidNumber
var exec = require("./exec")
, path = require("path")
, log = require("./log")
, constants = require("constants")
, npm = require("../../npm")
function uidNumber (uid, gid, cb) {
if (typeof cb !== "function") cb = gid, gid = null
@@ -21,6 +23,15 @@ function uidNumber (uid, gid, cb) {
if (er) return log.er(cb, "Could not get uid/gid "+err)(er)
log.silly(out, "output from getuid/gid")
out = JSON.parse(out+"")
if (out.error && out.errno === constants.EPERM) {
if (!npm.config.get("unsafe-perm")) {
var er = new Error(out.error)
er.errno = out.errno
return cb(er)
} else {
return cb(null, +process.getuid(), +process.getgid())
}
}
if (isNaN(out.uid) || isNaN(out.gid)) return cb(new Error(
"Could not get uid/gid: "+JSON.stringify(out)))
cb(null, out.uid, out.gid)

0 comments on commit 52e3e88

Please sign in to comment.