mirror of https://github.com/calzoneman/sync.git
setuid: fix folder permissions before dropping
This commit is contained in:
parent
de02cdbeff
commit
5c35f0f39b
|
@ -1,14 +1,33 @@
|
|||
var Config = require("./config");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
var needPermissionsFixed = [
|
||||
path.join(__dirname, "..", "chanlogs"),
|
||||
path.join(__dirname, "..", "chandump"),
|
||||
path.join(__dirname, "..", "google-drive-subtitles")
|
||||
];
|
||||
|
||||
function fixPermissions(uid, gid) {
|
||||
needPermissionsFixed.forEach(function (dir) {
|
||||
if (fs.existsSync(dir)) {
|
||||
fs.chownSync(dir, uid, gid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Config.get("setuid.enabled")) {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
console.log('Old User ID: ' + process.getuid() + ', Old Group ID: ' + process.getgid());
|
||||
fixPermissions();
|
||||
console.log("Old User ID: " + process.getuid() + ", Old Group ID: " +
|
||||
process.getgid());
|
||||
process.setgid(Config.get("setuid.group"));
|
||||
process.setuid(Config.get("setuid.user"));
|
||||
console.log('New User ID: ' + process.getuid() + ', New Group ID: ' + process.getgid());
|
||||
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("Cowardly refusing to keep the process alive as root.");
|
||||
process.exit(1);
|
||||
}
|
||||
}, (Config.get("setuid.timeout")));
|
||||
|
|
Loading…
Reference in New Issue