1 var Config = require("./config");
2 var fs = require("fs");
3 var path = require("path");
4 var execSync = require("child_process").execSync;
6 const LOGGER = require('@calzoneman/jsli')('setuid');
8 var needPermissionsFixed = [
9 path.join(__dirname, "..", "chanlogs"),
10 path.join(__dirname, "..", "google-drive-subtitles")
13 function fixPermissions(user, group) {
14 var uid = resolveUid(user);
15 var gid = resolveGid(group);
16 needPermissionsFixed.forEach(function (dir) {
17 if (fs.existsSync(dir)) {
18 fs.chownSync(dir, uid, gid);
23 function resolveUid(user) {
24 return parseInt(execSync('id -u ' + user), 10);
27 function resolveGid(group) {
28 return parseInt(execSync('id -g ' + group), 10);
31 if (Config.get("setuid.enabled")) {
32 setTimeout(function() {
34 fixPermissions(Config.get("setuid.user"), Config.get("setuid.group"));
36 'Old User ID: %s, Old Group ID: %s',
40 process.setgid(Config.get("setuid.group"));
41 process.setuid(Config.get("setuid.user"));
43 'New User ID: %s, New Group ID: %s',
48 LOGGER.error('Error setting uid: %s', err.stack);
51 }, (Config.get("setuid.timeout")));