diff options
author | Sami Kerola | 2013-08-18 11:44:13 +0200 |
---|---|---|
committer | Sami Kerola | 2013-08-29 19:14:07 +0200 |
commit | 0233a8ea18bec17dd59cfe1fec8281d2b9c26d22 (patch) | |
tree | 52020d578fc07ebfd17ec3ae7073aaa80fbdf3ff /term-utils/write.c | |
parent | docs: add note to wall(1) about sessions which will not get message (diff) | |
download | kernel-qcow2-util-linux-0233a8ea18bec17dd59cfe1fec8281d2b9c26d22.tar.gz kernel-qcow2-util-linux-0233a8ea18bec17dd59cfe1fec8281d2b9c26d22.tar.xz kernel-qcow2-util-linux-0233a8ea18bec17dd59cfe1fec8281d2b9c26d22.zip |
write: change determination can user write to a terminal
Earlier test failed when user had write permission, but was not in
special group that owns terminal devices, usually tty.
This made write(1) to fail for root, if the root did not happen to be in
tty group. In this commit root is granted ot write to anyone, even if
they have mesg(1) turned off. For an user who is trying to write to own
other session the group write bit is significant only for whether mesg(1)
are enabled.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/write.c')
-rw-r--r-- | term-utils/write.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/term-utils/write.c b/term-utils/write.c index cb3b0444d..173869465 100644 --- a/term-utils/write.c +++ b/term-utils/write.c @@ -73,7 +73,7 @@ static void __attribute__ ((__noreturn__)) done(int); int term_chk(char *, int *, time_t *, int); int utmp_chk(char *, char *); -static gid_t myegid; +static gid_t root_access; static void __attribute__ ((__noreturn__)) usage(FILE * out) { @@ -120,7 +120,7 @@ int main(int argc, char **argv) usage(stderr); } - myegid = getegid(); + root_access = !getegid(); /* check that sender has write enabled */ if (isatty(fileno(stdin))) @@ -299,8 +299,9 @@ int term_chk(char *tty, int *msgsokP, time_t * atimeP, int showerror) return 1; } - /* group write bit and group ownership */ - *msgsokP = (s.st_mode & (S_IWRITE >> 3)) && myegid == s.st_gid; + *msgsokP = !access(path, W_OK); + if (!root_access && *msgsokP) + *msgsokP = s.st_mode & S_IWGRP; *atimeP = s.st_atime; return 0; } |