Merge pull request #3416 from thelounge/xpaw/add-user-chown

Set correct file owner for created user files and warn about it
This commit is contained in:
Pavel Djundik 2019-10-10 10:05:45 +03:00 committed by GitHub
commit b3a13f1aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 10 deletions

View File

@ -137,6 +137,35 @@ ClientManager.prototype.addUser = function(name, password, enableLog) {
throw e; throw e;
} }
try {
const userFolderStat = fs.statSync(Helper.getUsersPath());
const userFileStat = fs.statSync(userPath);
if (
userFolderStat &&
userFileStat &&
(userFolderStat.uid !== userFileStat.uid || userFolderStat.gid !== userFileStat.gid)
) {
log.warn(
`User ${colors.green(
name
)} has been created, but with a different uid (or gid) than expected.`
);
log.warn(
"The file owner has been changed to the expected user. " +
"To prevent any issues, please run thelounge commands " +
"as the correct user that owns the config folder."
);
log.warn(
"See https://thelounge.chat/docs/usage#using-the-correct-system-user for more information."
);
fs.chownSync(userPath, userFolderStat.uid, userFolderStat.gid);
}
} catch (e) {
// We're simply verifying file owner as a safe guard for users
// that run `thelounge add` as root, so we don't care if it fails
}
return true; return true;
}; };

View File

@ -40,16 +40,20 @@ if (process.getuid) {
); );
} }
fs.stat(path.join(Helper.getHomePath(), "config.js"), (err, stat) => { const configStat = fs.statSync(path.join(Helper.getHomePath(), "config.js"));
if (!err && stat.uid !== uid) {
if (configStat && configStat.uid !== uid) {
log.warn( log.warn(
"Config file owner does not match the user you are currently running The Lounge as." "Config file owner does not match the user you are currently running The Lounge as."
); );
log.warn( log.warn(
"To avoid issues, you should execute The Lounge commands under the same user." "To prevent any issues, please run thelounge commands " +
"as the correct user that owns the config folder."
);
log.warn(
"See https://thelounge.chat/docs/usage#using-the-correct-system-user for more information."
); );
} }
});
} }
Utils.checkOldHome(); Utils.checkOldHome();