]> git.saurik.com Git - apt.git/commitdiff
Log calling SUDO_USER or PKEXEC_UID in history.log
authorMichael Vogt <mvo@debian.org>
Mon, 25 Jan 2016 13:44:42 +0000 (14:44 +0100)
committerMichael Vogt <mvo@debian.org>
Mon, 25 Jan 2016 13:44:42 +0000 (14:44 +0100)
Thanks: Thomas Reusch

apt-pkg/deb/dpkgpm.cc

index ce92247914ef26e123cefda19f37bceb9814c36a..e94a8cfdc3be40e3dcd5aab63887dc3f32715af5 100644 (file)
 #include <string>
 #include <utility>
 #include <vector>
+#include <sstream>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 using namespace std;
 
+APT_PURE static string
+AptHistoryUser()
+{
+   stringstream out;
+   const char* env[]{"SUDO_USER", "PKEXEC_UID", nullptr};
+   for (int i=0; env[i] != nullptr; i++)
+   {
+      if (getenv(env[i]) != nullptr)
+      {
+         out << env[i] << "=" << getenv(env[i]) << " ";
+      }
+   }
+   return out.str();
+}
+
 APT_PURE static unsigned int
 EnvironmentSize()
 {
@@ -876,6 +892,8 @@ bool pkgDPkgPM::OpenLog()
       }
       if (_config->Exists("Commandline::AsString") == true)
         WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
+      if (AptHistoryUser() != "")
+         WriteHistoryTag("Requested-By", AptHistoryUser());
       WriteHistoryTag("Install", install);
       WriteHistoryTag("Reinstall", reinstall);
       WriteHistoryTag("Upgrade", upgrade);