From 62bad36ae1e7defaf51a13806dac34094a8eedf7 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Tue, 15 Mar 2016 16:07:59 +1300 Subject: [PATCH] Don't write :0 into tty line in utmp/btmp. Based on a patch by Harald Judt --- src/session-child.c | 15 +++------------ tests/scripts/utmp-autologin.conf | 8 ++++---- tests/scripts/utmp-login.conf | 8 ++++---- tests/scripts/utmp-wrong-password.conf | 2 +- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/session-child.c b/src/session-child.c index 36569423..e393ce4c 100644 --- a/src/session-child.c +++ b/src/session-child.c @@ -408,11 +408,8 @@ session_child_run (int argc, char **argv) ut.ut_type = USER_PROCESS; ut.ut_pid = getpid (); if (xdisplay) - { - strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line)); strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); - } - else if (tty) + if (tty && g_str_has_prefix (tty, "/dev/")) strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); strncpy (ut.ut_user, username, sizeof (ut.ut_user)); if (xdisplay) @@ -732,11 +729,8 @@ session_child_run (int argc, char **argv) ut.ut_type = USER_PROCESS; ut.ut_pid = child_pid; if (xdisplay) - { - strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line)); strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); - } - else if (tty) + if (tty && g_str_has_prefix (tty, "/dev/")) strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); strncpy (ut.ut_user, username, sizeof (ut.ut_user)); if (xdisplay) @@ -772,11 +766,8 @@ session_child_run (int argc, char **argv) ut.ut_type = DEAD_PROCESS; ut.ut_pid = child_pid; if (xdisplay) - { - strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line)); strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); - } - else if (tty) + if (tty && g_str_has_prefix (tty, "/dev/")) strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); strncpy (ut.ut_user, username, sizeof (ut.ut_user)); if (xdisplay) diff --git a/tests/scripts/utmp-autologin.conf b/tests/scripts/utmp-autologin.conf index 5b243d95..1af3e10c 100644 --- a/tests/scripts/utmp-autologin.conf +++ b/tests/scripts/utmp-autologin.conf @@ -21,8 +21,8 @@ user-session=default #?XSERVER-0 ACCEPT-CONNECT # UTMP/WTMP record written -#?UTMP TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 -#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 +#?UTMP TYPE=USER_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 +#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 # Autologin session starts #?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1 @@ -34,8 +34,8 @@ user-session=default #?*SESSION-X-0 LOGOUT # UTMP/WTMP record written -#?UTMP TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 -#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 +#?UTMP TYPE=DEAD_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 +#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 # X server stops #?XSERVER-0 TERMINATE SIGNAL=15 diff --git a/tests/scripts/utmp-login.conf b/tests/scripts/utmp-login.conf index 213afb15..594f9737 100644 --- a/tests/scripts/utmp-login.conf +++ b/tests/scripts/utmp-login.conf @@ -36,8 +36,8 @@ user-session=default #?GREETER-X-0 TERMINATE SIGNAL=15 # UTMP/WTMP record written -#?UTMP TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 -#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 +#?UTMP TYPE=USER_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 +#?WTMP FILE=.*/wtmp TYPE=USER_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 # Session starts #?SESSION-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_GREETER_DATA_DIR=.*/have-password1 XDG_SESSION_TYPE=x11 XDG_SESSION_DESKTOP=default USER=have-password1 @@ -49,8 +49,8 @@ user-session=default #?*SESSION-X-0 LOGOUT # UTMP/WTMP record written -#?UTMP TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 -#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 +#?UTMP TYPE=DEAD_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 +#?WTMP FILE=.*/wtmp TYPE=DEAD_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 # X server stops #?XSERVER-0 TERMINATE SIGNAL=15 diff --git a/tests/scripts/utmp-wrong-password.conf b/tests/scripts/utmp-wrong-password.conf index b9090752..ef10b414 100644 --- a/tests/scripts/utmp-wrong-password.conf +++ b/tests/scripts/utmp-wrong-password.conf @@ -28,7 +28,7 @@ check-events=true #?*GREETER-X-0 AUTHENTICATE USERNAME=have-password1 #?GREETER-X-0 SHOW-PROMPT TEXT="Password:" #?*GREETER-X-0 RESPOND TEXT="rubbish" -#?WTMP FILE=.*/btmp TYPE=USER_PROCESS LINE=:0 ID=:0 USER=have-password1 HOST=:0 +#?WTMP FILE=.*/btmp TYPE=USER_PROCESS LINE=tty7 ID=:0 USER=have-password1 HOST=:0 #?GREETER-X-0 AUTHENTICATION-COMPLETE USERNAME=have-password1 AUTHENTICATED=FALSE # Cleanup -- 2.39.2