summaryrefslogtreecommitdiff
path: root/zen/sys_info.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-04-18 13:48:31 +0000
committerB. Stack <bgstack15@gmail.com>2022-04-18 13:48:31 +0000
commit8a551d2eff24bdd23bc25caeb8d17207409aae38 (patch)
tree84e67ca0a1fb045a12d015fcffca9cd8087c9332 /zen/sys_info.cpp
parentMerge branch 'b11.18' into 'master' (diff)
parentadd upstream 11.20 (diff)
downloadFreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.tar.gz
FreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.tar.bz2
FreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.zip
Merge branch 'b11.20' into 'master'11.20
add upstream 11.20 See merge request opensource-tracking/FreeFileSync!43
Diffstat (limited to 'zen/sys_info.cpp')
-rw-r--r--zen/sys_info.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/zen/sys_info.cpp b/zen/sys_info.cpp
index cc852510..d208cc98 100644
--- a/zen/sys_info.cpp
+++ b/zen/sys_info.cpp
@@ -26,6 +26,14 @@ using namespace zen;
Zstring zen::getLoginUser() //throw FileError
{
+ auto tryGetNonRootUser = [](const char* varName) -> const char*
+ {
+ if (const char* buf = ::getenv(varName)) //no extended error reporting
+ if (strLength(buf) > 0 && !equalString(buf, "root"))
+ return buf;
+ return nullptr;
+ };
+
const uid_t userIdNo = ::getuid(); //never fails
if (userIdNo != 0) //nofail; non-root
@@ -54,21 +62,15 @@ Zstring zen::getLoginUser() //throw FileError
return loginUser;
//BUT: getlogin() can fail with ENOENT on Linux Mint: https://freefilesync.org/forum/viewtopic.php?t=8181
- auto tryGetNonRootUser = [](const char* varName) -> const char*
- {
- if (const char* buf = ::getenv(varName)) //no extended error reporting
- if (strLength(buf) > 0 && !equalString(buf, "root"))
- return buf;
- return nullptr;
- };
//getting a little desperate: variables used by installer.sh
if (const char* userName = tryGetNonRootUser("USER")) return userName;
if (const char* userName = tryGetNonRootUser("SUDO_USER")) return userName;
if (const char* userName = tryGetNonRootUser("LOGNAME")) return userName;
+
//apparently the current user really IS root: https://freefilesync.org/forum/viewtopic.php?t=8405
+ assert(getuid() == 0);
return "root";
-
}
bgstack15