X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/258b9e512c4001e806c5c0966acecd3d742ec6e9..607bab3fe856d228f22e1cd96dbb7204e2f3375d:/apt-pkg/deb/dpkgpm.cc diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 7355af9d5..1afcb6527 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -48,12 +48,39 @@ #include #include #include +#include +#include #include /*}}}*/ using namespace std; +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 ""; +} + APT_PURE static unsigned int EnvironmentSize() { @@ -876,6 +903,9 @@ bool pkgDPkgPM::OpenLog() } if (_config->Exists("Commandline::AsString") == true) WriteHistoryTag("Commandline", _config->Find("Commandline::AsString")); + std::string RequestingUser = AptHistoryRequestingUser(); + if (RequestingUser != "") + WriteHistoryTag("Requested-By", RequestingUser); WriteHistoryTag("Install", install); WriteHistoryTag("Reinstall", reinstall); WriteHistoryTag("Upgrade", upgrade); @@ -1194,7 +1224,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) std::vector Args(sArgs.size(), NULL); std::transform(sArgs.begin(), sArgs.end(), Args.begin(), [](std::string const &s) { return s.c_str(); }); - unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0, + unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0llu, [](unsigned long long const i, std::string const &s) { return i + s.length(); }); size_t const BaseArgs = Args.size();