From 4be18d32991e73c460ca59c43384f75419602a35 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Fri, 3 Aug 2018 09:44:16 +0800 Subject: [PATCH] Log UID in nologin Sometimes getlogin() may fail, e.g., in a chroot() environment or due to NSS misconfiguration. Loggin UID allows for investigation and troubleshooting in such situation. --- src/nologin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nologin.c b/src/nologin.c index 7fe8a6a2..98989d26 100644 --- a/src/nologin.c +++ b/src/nologin.c @@ -24,7 +24,6 @@ * SUCH DAMAGE. */ -#include #ident "$Id$" @@ -36,6 +35,7 @@ int main (void) { const char *user, *tty; + uid_t uid; tty = ttyname (0); if (NULL == tty) { @@ -45,8 +45,9 @@ int main (void) if (NULL == user) { user = "UNKNOWN"; } + uid = getuid (); /* getuid() is always successful */ openlog ("nologin", LOG_CONS, LOG_AUTH); - syslog (LOG_CRIT, "Attempted login by %s on %s", user, tty); + syslog (LOG_CRIT, "Attempted login by %s (UID: %d) on %s", user, uid, tty); closelog (); printf ("%s", "This account is currently not available.\n"); -- 2.40.0