[PATCH] login: update UTMP before forking

Joachim Nilsson troglobit at gmail.com
Sat May 9 11:03:55 UTC 2020


/bin/login updates the preliminary UTMP record created by /bin/getty for
$LOGNAME.  However, if the PID of login is not the same as getty, then
it will create a new entry.  This causes GLIBC getlogin(3) to return the
string 'LOGIN' (set by getty) instead of $LOGNAME.  This affects tools
like /usr/bin/logname but also various 3rd party PAM applications.

Signed-off-by: Joachim Nilsson <troglobit at gmail.com>
---
 loginutils/login.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/loginutils/login.c b/loginutils/login.c
index 4e65b3a19..03301b3bd 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -525,6 +525,8 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 	if (pw->pw_uid != 0)
 		die_if_nologin();
 
+	update_utmp(getpid(), USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL);
+
 #if ENABLE_LOGIN_SESSION_AS_CHILD
 	child_pid = vfork();
 	if (child_pid != 0) {
@@ -546,8 +548,6 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 	fchown(0, pw->pw_uid, pw->pw_gid);
 	fchmod(0, 0600);
 
-	update_utmp(getpid(), USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL);
-
 	/* We trust environment only if we run by root */
 	if (ENABLE_LOGIN_SCRIPTS && run_by_root)
 		run_login_script(pw, full_tty);
-- 
2.25.1



More information about the busybox mailing list