Fix
This commit is contained in:
parent
5c35f0f39b
commit
f2000b4459
|
@ -1,6 +1,7 @@
|
|||
var Config = require("./config");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var execSync = require("child_process").execSync;
|
||||
|
||||
var needPermissionsFixed = [
|
||||
path.join(__dirname, "..", "chanlogs"),
|
||||
|
@ -9,6 +10,8 @@ var needPermissionsFixed = [
|
|||
];
|
||||
|
||||
function fixPermissions(uid, gid) {
|
||||
uid = resolveUid(uid);
|
||||
gid = resolveGid(uid);
|
||||
needPermissionsFixed.forEach(function (dir) {
|
||||
if (fs.existsSync(dir)) {
|
||||
fs.chownSync(dir, uid, gid);
|
||||
|
@ -16,10 +19,18 @@ function fixPermissions(uid, gid) {
|
|||
});
|
||||
}
|
||||
|
||||
function resolveUid(uid) {
|
||||
return parseInt(execSync('id -u ' + uid), 10);
|
||||
}
|
||||
|
||||
function resolveGid(uid) {
|
||||
return parseInt(execSync('id -g ' + uid), 10);
|
||||
}
|
||||
|
||||
if (Config.get("setuid.enabled")) {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
fixPermissions();
|
||||
fixPermissions(Config.get("setuid.user"), Config.get("setuid.group"));
|
||||
console.log("Old User ID: " + process.getuid() + ", Old Group ID: " +
|
||||
process.getgid());
|
||||
process.setgid(Config.get("setuid.group"));
|
||||
|
@ -27,7 +38,7 @@ if (Config.get("setuid.enabled")) {
|
|||
console.log("New User ID: " + process.getuid() + ", New Group ID: "
|
||||
+ process.getgid());
|
||||
} catch (err) {
|
||||
console.log("Cowardly refusing to keep the process alive as root.");
|
||||
console.log("Error setting uid: " + err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}, (Config.get("setuid.timeout")));
|
||||
|
|
Loading…
Reference in a new issue