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>
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)
{
usage(stderr);
}
- myegid = getegid();
+ root_access = !getegid();
/* check that sender has write enabled */
if (isatty(fileno(stdin)))
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;
}