]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
write: tell when effective gid and tty path group mismatch
authorSami Kerola <kerolasa@iki.fi>
Sat, 7 May 2016 22:44:17 +0000 (23:44 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 3 Jul 2016 22:35:09 +0000 (23:35 +0100)
Most commonly this error happens when write(1) executable does not have
correct group ownership and setgid bit.  The earlier message was unclear
what exactly was wrong.

$ mesg
is y
$ write testuser
write: you have write permission turned off

Alternatively the 'getegid() == s.st_gid' could be considered unnecessary.
Afterall if to write to destination tty is denied that does not go unnoticed
at thet time when tty is opened.

Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
term-utils/write.c

index 8855c1e931c1f641f8e2f7fb61caf558d0615802..1b476473f1589a0cf340a3c4edb2757338117b41 100644 (file)
@@ -113,8 +113,13 @@ static int check_tty(char *tty, int *tty_writeable, time_t *tty_atime, int showe
        }
        if (getuid() == 0)      /* root can always write */
                *tty_writeable = 1;
-       else
-               *tty_writeable = (s.st_mode & S_IWGRP) && (getegid() == s.st_gid);
+       else {
+               if (getegid() != s.st_gid) {
+                       warnx(_("effective gid does not match group of %s"), path);
+                       return 1;
+               }
+               *tty_writeable = s.st_mode & S_IWGRP;
+       }
        if (tty_atime)
                *tty_atime = s.st_atime;
        return 0;