diff options
author | B. Stack <bgstack15@gmail.com> | 2022-01-04 16:21:19 +0000 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-01-04 16:21:19 +0000 |
commit | 2c8ae2c99308b4f0bf2bb08161829efee43e31ca (patch) | |
tree | b8252ff8a09d9143ed2dc299d082f9d86535c1a2 /zen/sys_info.cpp | |
parent | Merge branch 'b11.15' into 'master' (diff) | |
parent | add upstream 11.16 (diff) | |
download | FreeFileSync-2c8ae2c99308b4f0bf2bb08161829efee43e31ca.tar.gz FreeFileSync-2c8ae2c99308b4f0bf2bb08161829efee43e31ca.tar.bz2 FreeFileSync-2c8ae2c99308b4f0bf2bb08161829efee43e31ca.zip |
Merge branch 'b11.16' into 'master'11.16
add upstream 11.16
See merge request opensource-tracking/FreeFileSync!40
Diffstat (limited to 'zen/sys_info.cpp')
-rw-r--r-- | zen/sys_info.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/zen/sys_info.cpp b/zen/sys_info.cpp index edb8dd9d..54a5ecae 100644 --- a/zen/sys_info.cpp +++ b/zen/sys_info.cpp @@ -28,7 +28,7 @@ Zstring zen::getLoginUser() //throw FileError { const uid_t userIdNo = ::getuid(); //never fails - if (userIdNo != 0) //nofail; root(0) => consider as request for elevation, NOT impersonation + if (userIdNo != 0) //nofail; non-root { std::vector<char> buf(std::max<long>(10000, ::sysconf(_SC_GETPW_R_SIZE_MAX))); //::sysconf may return long(-1) passwd buf2 = {}; @@ -45,7 +45,7 @@ Zstring zen::getLoginUser() //throw FileError return pwsEntry->pw_name; } - //else root(0): what now!? + //else: root(0) => consider as request for elevation, NOT impersonation! //getlogin() is smarter than simply evaluating $LOGNAME! even in contexts without //$LOGNAME, e.g. "sudo su" on Ubuntu, it returns the correct non-root user! @@ -72,6 +72,29 @@ Zstring zen::getLoginUser() //throw FileError } +Zstring zen::getUserDescription() //throw FileError +{ + const Zstring userName = getLoginUser(); //throw FileError + const Zstring computerName = []() -> Zstring //throw FileError + { + std::vector<char> buf(10000); + if (::gethostname(&buf[0], buf.size()) != 0) + THROW_LAST_FILE_ERROR(_("Cannot get process information."), "gethostname"); + + Zstring hostName = &buf[0]; + if (endsWithAsciiNoCase(hostName, ".local")) //strip fluff (macOS) => apparently not added on Linux? + hostName = beforeLast(hostName, '.', IfNotFoundReturn::none); + + return hostName; + }(); + + if (contains(getUpperCase(computerName), getUpperCase(userName))) + return userName; //no need for text duplication! e.g. "Zenju (Zenju-PC)" + + return userName + Zstr(" (") + computerName + Zstr(')'); //e.g. "Admin (Zenju-PC)" +} + + namespace { } |