+APT_PURE static string
+AptHistoryRequestingUser()
+{
+ const char* EnvKeys[]{"SUDO_UID", "PKEXEC_UID", "PACKAGEKIT_CALLER_UID"};
+
+ for (const auto &Key: EnvKeys)
+ {
+ if (getenv(Key) != nullptr)
+ {
+ int uid = atoi(getenv(Key));
+ if (uid > 0) {
+ struct passwd pwd;
+ struct passwd *result;
+ char buf[255];
+ if (getpwuid_r(uid, &pwd, buf, sizeof(buf), &result) == 0 && result != NULL) {
+ std::string res;
+ strprintf(res, "%s (%d)", pwd.pw_name, uid);
+ return res;
+ }
+ }
+ }
+ }
+ return "";
+}
+