summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2016-01-25 16:49:48 +0100
committerMichael Vogt <mvo@debian.org>2016-01-25 16:49:48 +0100
commit46e88ba252230858abe891d5815fce884d3cf35d (patch)
treeb1de8279221eb97f7e8d540421af5f1e5d3d5fd1 /apt-pkg
parenta6fd0c5cc412afd5dac7a9952cab741e48342488 (diff)
Store "Requested-By" user in history.log in a simpler format
Git-Dch: ignore Thanks: David Kalnischkies
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/dpkgpm.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index e94a8cfdc..6751e9779 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -56,18 +56,30 @@
using namespace std;
APT_PURE static string
-AptHistoryUser()
+AptHistoryRequestingUser()
{
- stringstream out;
- const char* env[]{"SUDO_USER", "PKEXEC_UID", nullptr};
+ const char* env[]{
+ "SUDO_UID", "PKEXEC_UID", "PACKAGEKIT_CALLER_UID", nullptr
+ };
+
for (int i=0; env[i] != nullptr; i++)
{
if (getenv(env[i]) != nullptr)
{
- out << env[i] << "=" << getenv(env[i]) << " ";
+ int uid = atoi(getenv(env[i]));
+ 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 +904,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);