From a24c03a35cac2b7ec7988ab65f5ce04245f7e787 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 24 Sep 2019 13:56:12 +0300 Subject: [PATCH 1/2] Set correct file owner for created user files --- src/clientManager.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/clientManager.js b/src/clientManager.js index 9d66fcf9..27ea6dd1 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -137,6 +137,35 @@ ClientManager.prototype.addUser = function(name, password, enableLog) { 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; }; From 5d13e4c97d51ee48f351b60caa34fd92f4e5e6f0 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 24 Sep 2019 22:06:04 +0300 Subject: [PATCH 2/2] Check config owner synchronously Fixes async warning printing during prompt when adding a user --- src/command-line/index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/command-line/index.js b/src/command-line/index.js index e1b4f2b5..2d71f5a7 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -40,16 +40,20 @@ if (process.getuid) { ); } - fs.stat(path.join(Helper.getHomePath(), "config.js"), (err, stat) => { - if (!err && stat.uid !== uid) { - log.warn( - "Config file owner does not match the user you are currently running The Lounge as." - ); - log.warn( - "To avoid issues, you should execute The Lounge commands under the same user." - ); - } - }); + const configStat = fs.statSync(path.join(Helper.getHomePath(), "config.js")); + + if (configStat && configStat.uid !== uid) { + log.warn( + "Config file owner does not match the user you are currently running The Lounge as." + ); + log.warn( + "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();