]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
debian/control: Set Standards-Version to 3.9.7
[apt.git] / apt-pkg / deb / dpkgpm.cc
index e94a8cfdc3be40e3dcd5aab63887dc3f32715af5..1afcb65273419a6ecc3f3cba57ceda14491fed07 100644 (file)
@@ -49,6 +49,7 @@
 #include <utility>
 #include <vector>
 #include <sstream>
+#include <numeric>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 using namespace std;
 
 APT_PURE static string
-AptHistoryUser()
+AptHistoryRequestingUser()
 {
-   stringstream out;
-   const char* env[]{"SUDO_USER", "PKEXEC_UID", nullptr};
-   for (int i=0; env[i] != nullptr; i++)
+   const char* EnvKeys[]{"SUDO_UID", "PKEXEC_UID", "PACKAGEKIT_CALLER_UID"};
+
+   for (const auto &Key: EnvKeys)
    {
-      if (getenv(env[i]) != nullptr)
+      if (getenv(Key) != nullptr)
       {
-         out << env[i] << "=" << getenv(env[i]) << " ";
+         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 out.str();
+   return "";
 }
 
 APT_PURE static unsigned int
@@ -892,8 +903,9 @@ bool pkgDPkgPM::OpenLog()
       }
       if (_config->Exists("Commandline::AsString") == true)
         WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
-      if (AptHistoryUser() != "")
-         WriteHistoryTag("Requested-By", AptHistoryUser());
+      std::string RequestingUser = AptHistoryRequestingUser();
+      if (RequestingUser != "")
+         WriteHistoryTag("Requested-By", RequestingUser);
       WriteHistoryTag("Install", install);
       WriteHistoryTag("Reinstall", reinstall);
       WriteHistoryTag("Upgrade", upgrade);