From e46560f47770e5989c4483f10251e5d2cbc7f66c Mon Sep 17 00:00:00 2001 From: Brett Gordon Date: Fri, 1 Jun 2018 01:42:41 -0400 Subject: [PATCH] init(getty): set/reset owner of tty on login --- Applications/util/init.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Applications/util/init.c b/Applications/util/init.c index b27a6073..b53c270e 100644 --- a/Applications/util/init.c +++ b/Applications/util/init.c @@ -773,6 +773,9 @@ static pid_t getty(const char **argv, const char *id) if (fdtty < 0) return -1; + if (fchown(fdtty, 0, 0)) + putstr("getty: can not reset owner of tty\n"); + /* here we are inside child's context of execution */ envset("PATH", "/bin:/usr/bin"); envset("CTTY", argv[0]); @@ -873,6 +876,10 @@ static void spawn_login(struct passwd *pwd, const char *tty, const char *id, con /* We don't care if initgroups fails - it only grants extra rights */ initgroups(pwd->pw_name, pwd->pw_gid); + /* change owner of tty device */ + if (fchown(0, pwd->pw_uid, pwd->pw_gid)) + putstr("login: unable to change owner of controlling tty\n"); + /* But we do care if these fail! */ if (setgid(pwd->pw_gid) == -1 || setuid(pwd->pw_uid) == -1) -- 2.34.1