Skip to content

Commit

Permalink
fix(install): fix to drop privilege
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Sep 17, 2017
1 parent 01f44a5 commit 3f57f04
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/utils/drop-privilege.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ const isRoot = require('./is-root')

module.exports = () => {
if (!isRoot()) return
if (!(process.getuid && process.setuid)) return // uid support
const user = process.platform === 'win32' ? 0
: process.env.SUDO_UID || 'nobody'
const group = process.platform === 'win32' ? 0
: process.env.SUDO_GID || (process.getgid && process.getgid())
try {
process.setuid(user)
process.setgid(group)
} catch (e) {
throw new Error(e)
if (process.getuid && process.setuid) {
var group = process.platform === 'win32' ? 0
: process.env.SUDO_GID || 'nobody'
if (!isNaN(group)) group = +group
try {
process.setgid(group)
} catch (e) {
throw new Error(e)
}
}
if (process.getuid && process.setuid) {
var user = process.platform === 'win32' ? 0
: process.env.SUDO_UID || 'nobody'
if (!isNaN(user)) user = +user
try {
process.setuid(user)
} catch (e) {
throw new Error(e)
}
}
}

0 comments on commit 3f57f04

Please sign in to comment.