mesg: use only stat() to get the current terminal status
open()+stat() does not work for example after su(1) (from root to non-root). It seems better to use only stat() to get the current terminal status. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1906157 Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
37bd59bd53
commit
c0246ce059
|
@ -139,13 +139,9 @@ int main(int argc, char *argv[])
|
||||||
warnx(_("ttyname() failed, attempting to go around using: %s"), tty);
|
warnx(_("ttyname() failed, attempting to go around using: %s"), tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(tty, O_RDONLY)) < 0)
|
|
||||||
err(MESG_EXIT_FAILURE, _("cannot open %s"), tty);
|
|
||||||
if (fstat(fd, &sb))
|
|
||||||
err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
|
|
||||||
|
|
||||||
if (!*argv) {
|
if (!*argv) {
|
||||||
close(fd);
|
if (stat(tty, &sb))
|
||||||
|
err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
|
||||||
if (sb.st_mode & (S_IWGRP | S_IWOTH)) {
|
if (sb.st_mode & (S_IWGRP | S_IWOTH)) {
|
||||||
puts(_("is y"));
|
puts(_("is y"));
|
||||||
return IS_ALLOWED;
|
return IS_ALLOWED;
|
||||||
|
@ -154,6 +150,11 @@ int main(int argc, char *argv[])
|
||||||
return IS_NOT_ALLOWED;
|
return IS_NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((fd = open(tty, O_RDONLY)) < 0)
|
||||||
|
err(MESG_EXIT_FAILURE, _("cannot open %s"), tty);
|
||||||
|
if (fstat(fd, &sb))
|
||||||
|
err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
|
||||||
|
|
||||||
switch (rpmatch(argv[0])) {
|
switch (rpmatch(argv[0])) {
|
||||||
case RPMATCH_YES:
|
case RPMATCH_YES:
|
||||||
#ifdef USE_TTY_GROUP
|
#ifdef USE_TTY_GROUP
|
||||||
|
|
Loading…
Reference in New Issue