|
|
304038 |
From 70ed51ccc2e8e6c4976d422af960e4232210fb99 Mon Sep 17 00:00:00 2001
|
|
|
304038 |
From: Karel Zak <kzak@redhat.com>
|
|
|
304038 |
Date: Mon, 16 Oct 2017 13:31:47 +0200
|
|
|
304038 |
Subject: [PATCH 134/135] logger: do not rely only getlogin(3) telling who ran
|
|
|
304038 |
the command
|
|
|
304038 |
|
|
|
304038 |
The getlogin(3) is known not to always work, and when that happens it
|
|
|
304038 |
is reasonable to try determine user of name by looking process owner
|
|
|
304038 |
and passwd information.
|
|
|
304038 |
|
|
|
304038 |
Upstream: http://github.com/karelzak/util-linux/commit/019b97024fde3f07eaf541eef990762483369a11
|
|
|
304038 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1336432
|
|
|
304038 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
304038 |
---
|
|
|
304038 |
misc-utils/logger.c | 25 ++++++++++++++++---------
|
|
|
304038 |
1 file changed, 16 insertions(+), 9 deletions(-)
|
|
|
304038 |
|
|
|
304038 |
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
|
|
|
304038 |
index dfda01866..c1cec45e8 100644
|
|
|
304038 |
--- a/misc-utils/logger.c
|
|
|
304038 |
+++ b/misc-utils/logger.c
|
|
|
304038 |
@@ -49,6 +49,8 @@
|
|
|
304038 |
#include <arpa/inet.h>
|
|
|
304038 |
#include <netdb.h>
|
|
|
304038 |
#include <getopt.h>
|
|
|
304038 |
+#include <sys/types.h>
|
|
|
304038 |
+#include <pwd.h>
|
|
|
304038 |
|
|
|
304038 |
#include "c.h"
|
|
|
304038 |
#include "closestream.h"
|
|
|
304038 |
@@ -183,9 +185,20 @@ inet_socket(const char *servername, const char *port, const int socket_type)
|
|
|
304038 |
return fd;
|
|
|
304038 |
}
|
|
|
304038 |
|
|
|
304038 |
+static char const *xgetlogin(void)
|
|
|
304038 |
+{
|
|
|
304038 |
+ char const *cp;
|
|
|
304038 |
+ struct passwd *pw;
|
|
|
304038 |
+
|
|
|
304038 |
+ if (!(cp = getlogin()) || !*cp)
|
|
|
304038 |
+ cp = (pw = getpwuid(geteuid()))? pw->pw_name : "<someone>";
|
|
|
304038 |
+ return cp;
|
|
|
304038 |
+}
|
|
|
304038 |
+
|
|
|
304038 |
static void
|
|
|
304038 |
mysyslog(int fd, int logflags, int pri, char *tag, char *msg) {
|
|
|
304038 |
- char *buf, pid[30], *cp, *tp;
|
|
|
304038 |
+ char *buf, pid[30], *tp;
|
|
|
304038 |
+ const char *cp;
|
|
|
304038 |
time_t now;
|
|
|
304038 |
|
|
|
304038 |
if (fd > -1) {
|
|
|
304038 |
@@ -193,13 +206,7 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) {
|
|
|
304038 |
snprintf (pid, sizeof(pid), "[%d]", getpid());
|
|
|
304038 |
else
|
|
|
304038 |
pid[0] = 0;
|
|
|
304038 |
- if (tag)
|
|
|
304038 |
- cp = tag;
|
|
|
304038 |
- else {
|
|
|
304038 |
- cp = getlogin();
|
|
|
304038 |
- if (!cp)
|
|
|
304038 |
- cp = "<someone>";
|
|
|
304038 |
- }
|
|
|
304038 |
+ cp = tag ? tag : xgetlogin();
|
|
|
304038 |
(void)time(&now;;
|
|
|
304038 |
tp = ctime(&now)+4;
|
|
|
304038 |
|
|
|
304038 |
@@ -334,7 +341,7 @@ main(int argc, char **argv) {
|
|
|
304038 |
else if (usock)
|
|
|
304038 |
LogSock = unix_socket(usock, socket_type);
|
|
|
304038 |
else
|
|
|
304038 |
- openlog(tag ? tag : getlogin(), logflags, 0);
|
|
|
304038 |
+ openlog(tag ? tag : xgetlogin(), logflags, 0);
|
|
|
304038 |
|
|
|
304038 |
buf = xcalloc(1, max_message_size);
|
|
|
304038 |
|
|
|
304038 |
--
|
|
|
304038 |
2.13.6
|
|
|
304038 |
|