From 453b36147bcd58962fade1cac76ddebecfa2caf6 Mon Sep 17 00:00:00 2001 From: Yann Droneaud Date: Mon, 25 Jan 2010 23:12:09 +0100 Subject: [PATCH] login: use fd instead of pathname for update tty's owner and permissions To avoid some nasty races, use the only true tty: the one already opened, don't use the path. Signed-off-by: Yann Droneaud --- login-utils/login.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 486b30bf..fdc8078d 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -536,8 +536,8 @@ main(int argc, char **argv) ttt.c_cflag &= ~HUPCL; /* These can fail, e.g. with ttyn on a read-only filesystem */ - chown(ttyn, 0, 0); - chmod(ttyn, TTY_MODE); + fchown(0, 0, 0); + fchmod(0, TTY_MODE); /* Kill processes left on this tty */ tcsetattr(0,TCSAFLUSH,&ttt); @@ -1009,9 +1009,9 @@ Michael Riepe logaudit(tty_name, username, hostname, pwd, 1); dolastlog(quietlog); - chown(ttyn, pwd->pw_uid, + fchown(0, pwd->pw_uid, (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid); - chmod(ttyn, TTY_MODE); + fchmod(0, TTY_MODE); #ifdef LOGIN_CHOWN_VCS /* if tty is one of the VC's then change owner and mode of the -- 2.39.5