diff options
author | B. Stack <bgstack15@gmail.com> | 2022-04-18 09:47:11 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-04-18 09:47:40 -0400 |
commit | b4b2e4a096fe8fe1ad530a4c181729be05834595 (patch) | |
tree | 84e67ca0a1fb045a12d015fcffca9cd8087c9332 /zen/sys_info.cpp | |
parent | Merge branch 'b11.18' into 'master' (diff) | |
download | FreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.tar.gz FreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.tar.bz2 FreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.zip |
add upstream 11.20
Diffstat (limited to 'zen/sys_info.cpp')
-rw-r--r-- | zen/sys_info.cpp | 18 |
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"; - } |