[PATCH 1/2] login: use fd instead of pathname for update tty's owner and permissions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To avoid some nasty races, use the only true tty:
the one already opened, don't use the path.

Signed-off-by: Yann Droneaud <yann@xxxxxxxxxxx>
---
 login-utils/login.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/login-utils/login.c b/login-utils/login.c
index 486b30b..fdc8078 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 <michael@xxxxxxxxxxxxxxxxxxxx>
     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
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux