If you manage to exec login with a userid other than root, and its
input / output directed to a terminal for which it does not have
read/write access, it will attempt to proceed (and can potentially
hang forever -- but this hang has been fixed in a previous commit).
It's better to check if we have permissions for terminal rather than
do any useless things.
From: Jason Vas Dias <jvdias@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
if (lstat(ttyn, &statbuf)
|| !S_ISCHR(statbuf.st_mode)
- || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))) {
+ || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))
+ || (access(ttyn, R_OK | W_OK) != 0)) {
syslog(LOG_ERR, _("FATAL: bad tty"));
sleep(1);
exit(1);