From: Yann Droneaud Date: Mon, 25 Jan 2010 22:12:09 +0000 (+0100) Subject: login: use fd instead of pathname for update tty's owner and permissions X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=453b36147bcd58962fade1cac76ddebecfa2caf6;p=util-linux 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 --- 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