2015-02-21 08:13:55 +00:00
|
|
|
var Config = require("./config");
|
2015-09-03 05:45:33 +00:00
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2015-09-03 06:00:45 +00:00
|
|
|
var execSync = require("child_process").execSync;
|
2015-09-03 05:45:33 +00:00
|
|
|
|
|
|
|
var needPermissionsFixed = [
|
|
|
|
path.join(__dirname, "..", "chanlogs"),
|
|
|
|
path.join(__dirname, "..", "chandump"),
|
|
|
|
path.join(__dirname, "..", "google-drive-subtitles")
|
|
|
|
];
|
|
|
|
|
2015-12-11 05:20:40 +00:00
|
|
|
function fixPermissions(user, group) {
|
|
|
|
var uid = resolveUid(user);
|
|
|
|
var gid = resolveGid(group);
|
2015-09-03 05:45:33 +00:00
|
|
|
needPermissionsFixed.forEach(function (dir) {
|
|
|
|
if (fs.existsSync(dir)) {
|
|
|
|
fs.chownSync(dir, uid, gid);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-02-21 08:13:55 +00:00
|
|
|
|
2015-12-11 05:20:40 +00:00
|
|
|
function resolveUid(user) {
|
|
|
|
return parseInt(execSync('id -u ' + user), 10);
|
2015-09-03 06:00:45 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 05:20:40 +00:00
|
|
|
function resolveGid(group) {
|
|
|
|
return parseInt(execSync('id -g ' + group), 10);
|
2015-09-03 06:00:45 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 08:13:55 +00:00
|
|
|
if (Config.get("setuid.enabled")) {
|
|
|
|
setTimeout(function() {
|
|
|
|
try {
|
2015-09-03 06:00:45 +00:00
|
|
|
fixPermissions(Config.get("setuid.user"), Config.get("setuid.group"));
|
2015-09-03 05:45:33 +00:00
|
|
|
console.log("Old User ID: " + process.getuid() + ", Old Group ID: " +
|
|
|
|
process.getgid());
|
2015-02-21 08:13:55 +00:00
|
|
|
process.setgid(Config.get("setuid.group"));
|
|
|
|
process.setuid(Config.get("setuid.user"));
|
2015-09-03 05:45:33 +00:00
|
|
|
console.log("New User ID: " + process.getuid() + ", New Group ID: "
|
|
|
|
+ process.getgid());
|
2015-02-21 08:13:55 +00:00
|
|
|
} catch (err) {
|
2015-09-03 06:00:45 +00:00
|
|
|
console.log("Error setting uid: " + err.stack);
|
2015-02-21 08:13:55 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2015-02-23 22:08:43 +00:00
|
|
|
}, (Config.get("setuid.timeout")));
|
2015-02-21 08:13:55 +00:00
|
|
|
};
|