diff options
author | Joachim Nilsson <troglobit@gmail.com> | 2020-05-09 13:03:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-16 12:09:53 +0100 |
commit | a4747230abfca9c5b5345d9e34574b4f3192be6a (patch) | |
tree | e0c4e6b0369027760ac609fe95f60b5f61f2c864 | |
parent | 5323af7f51808d5ff35c624ba70bdae4807f3717 (diff) | |
download | busybox-w32-a4747230abfca9c5b5345d9e34574b4f3192be6a.tar.gz busybox-w32-a4747230abfca9c5b5345d9e34574b4f3192be6a.tar.bz2 busybox-w32-a4747230abfca9c5b5345d9e34574b4f3192be6a.zip |
login: update UTMP before forking
/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@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | loginutils/login.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/loginutils/login.c b/loginutils/login.c index 4e65b3a19..3531d1424 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -341,6 +341,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
341 | #if ENABLE_LOGIN_SESSION_AS_CHILD | 341 | #if ENABLE_LOGIN_SESSION_AS_CHILD |
342 | pid_t child_pid; | 342 | pid_t child_pid; |
343 | #endif | 343 | #endif |
344 | pid_t my_pid; | ||
344 | 345 | ||
345 | INIT_G(); | 346 | INIT_G(); |
346 | 347 | ||
@@ -525,6 +526,9 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
525 | if (pw->pw_uid != 0) | 526 | if (pw->pw_uid != 0) |
526 | die_if_nologin(); | 527 | die_if_nologin(); |
527 | 528 | ||
529 | my_pid = getpid(); | ||
530 | update_utmp(my_pid, USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL); | ||
531 | |||
528 | #if ENABLE_LOGIN_SESSION_AS_CHILD | 532 | #if ENABLE_LOGIN_SESSION_AS_CHILD |
529 | child_pid = vfork(); | 533 | child_pid = vfork(); |
530 | if (child_pid != 0) { | 534 | if (child_pid != 0) { |
@@ -532,8 +536,8 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
532 | bb_simple_perror_msg("vfork"); | 536 | bb_simple_perror_msg("vfork"); |
533 | else { | 537 | else { |
534 | wait_for_exitstatus(child_pid); | 538 | wait_for_exitstatus(child_pid); |
535 | update_utmp_DEAD_PROCESS(child_pid); | ||
536 | } | 539 | } |
540 | update_utmp_DEAD_PROCESS(my_pid); | ||
537 | login_pam_end(pamh); | 541 | login_pam_end(pamh); |
538 | return 0; | 542 | return 0; |
539 | } | 543 | } |
@@ -546,8 +550,6 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
546 | fchown(0, pw->pw_uid, pw->pw_gid); | 550 | fchown(0, pw->pw_uid, pw->pw_gid); |
547 | fchmod(0, 0600); | 551 | fchmod(0, 0600); |
548 | 552 | ||
549 | update_utmp(getpid(), USER_PROCESS, short_tty, username, run_by_root ? opt_host : NULL); | ||
550 | |||
551 | /* We trust environment only if we run by root */ | 553 | /* We trust environment only if we run by root */ |
552 | if (ENABLE_LOGIN_SCRIPTS && run_by_root) | 554 | if (ENABLE_LOGIN_SCRIPTS && run_by_root) |
553 | run_login_script(pw, full_tty); | 555 | run_login_script(pw, full_tty); |