summaryrefslogtreecommitdiff
path: root/src/who.c
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2010-01-22 15:17:19 +0100
committerJim Meyering <meyering@redhat.com>2010-01-25 11:43:49 +0100
commitaad0bde0b5aa6ccf2714f43676d4941f820c6283 (patch)
treea086cfa067f6896226dfaea57b2bf44b6fa36a5a /src/who.c
parent0caead1ea0b2ef63173cde6b583249bea3194817 (diff)
downloadcoreutils-aad0bde0b5aa6ccf2714f43676d4941f820c6283.tar.xz
who --mesg (-T) can use a more accurate test for TTY writability
Enabled when coreutils is configured with --with-tty-group. Based on a patch written by Piotr Gackiewicz. Details at http://bugzilla.redhat.com/454261 * src/who.c (is_tty_writable): A new function returning true if a TTY device is writable by the group. Additionally it checks the group to be the same as TTY_GROUP_NAME when compiled with --with-tty-group. * m4/jm-macros.m4: Introduce a new configure option --with-tty-group. * NEWS: Mention the change.
Diffstat (limited to 'src/who.c')
-rw-r--r--src/who.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/who.c b/src/who.c
index f71db3bb5..48596942d 100644
--- a/src/who.c
+++ b/src/who.c
@@ -37,6 +37,10 @@
#include "hard-locale.h"
#include "quote.h"
+#ifdef TTY_GROUP_NAME
+# include <grp.h>
+#endif
+
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "who"
@@ -308,6 +312,22 @@ print_line (int userlen, const char *user, const char state,
free (x_exitstr);
}
+/* Return true if a terminal device given as PSTAT allows other users
+ to send messages to; false otherwise */
+static bool
+is_tty_writable (struct stat const *pstat)
+{
+#ifdef TTY_GROUP_NAME
+ /* Ensure the group of the TTY device matches TTY_GROUP_NAME, more info at
+ https://bugzilla.redhat.com/454261 */
+ struct group *ttygr = getgrnam (TTY_GROUP_NAME);
+ if (!ttygr || (pstat->st_gid != ttygr->gr_gid))
+ return false;
+#endif
+
+ return pstat->st_mode & S_IWGRP;
+}
+
/* Send properly parsed USER_PROCESS info to print_line. The most
recent boot time is BOOTTIME. */
static void
@@ -346,7 +366,7 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
if (stat (line, &stats) == 0)
{
- mesg = (stats.st_mode & S_IWGRP) ? '+' : '-';
+ mesg = is_tty_writable (&stats) ? '+' : '-';
last_change = stats.st_atime;
}
else