Blob Blame History Raw
diff -urNp coreutils-7.6-orig/m4/jm-macros.m4 coreutils-7.6/m4/jm-macros.m4
--- coreutils-7.6-orig/m4/jm-macros.m4	2010-04-28 17:44:36.000000000 +0200
+++ coreutils-7.6/m4/jm-macros.m4	2010-04-28 17:45:01.000000000 +0200
@@ -146,6 +146,25 @@ AC_DEFUN([coreutils_MACROS],
     ])
 
   AC_REQUIRE([AM_LANGINFO_CODESET])
+
+  # Accept configure options: --with-tty-group[=GROUP], --without-tty-group
+  # You can determine the group of a TTY via 'stat --format %G /dev/tty'
+  # Omitting this option is equivalent to using --without-tty-group.
+  AC_ARG_WITH([tty-group],
+    AS_HELP_STRING([--with-tty-group[[[=NAME]]]],
+      [group used by system for TTYs, "tty" when not specified]
+      [ (default: do not rely on any group used for TTYs)]),
+    [tty_group_name=$withval],
+    [tty_group_name=no])
+
+  if test "x$tty_group_name" != xno; then
+    if test "x$tty_group_name" = xyes; then
+      tty_group_name=tty
+    fi
+    AC_MSG_NOTICE([TTY group used by system set to "$tty_group_name"])
+    AC_DEFINE_UNQUOTED([TTY_GROUP_NAME], ["$tty_group_name"],
+      [group used by system for TTYs])
+  fi
 ])
 
 AC_DEFUN([gl_CHECK_ALL_HEADERS],
diff -urNp coreutils-7.6-orig/src/who.c coreutils-7.6/src/who.c
--- coreutils-7.6-orig/src/who.c	2010-04-28 17:44:36.000000000 +0200
+++ coreutils-7.6/src/who.c	2010-04-28 17:45:01.000000000 +0200
@@ -36,6 +36,10 @@
 #include "error.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"
 
@@ -307,6 +311,22 @@ print_line (int userlen, const char *use
   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
@@ -345,7 +365,7 @@ print_user (const STRUCT_UTMP *utmp_ent,
 
   if (stat (line, &stats) == 0)
     {
-      mesg = (stats.st_mode & S_IWGRP) ? '+' : '-';
+      mesg = is_tty_writable (&stats) ? '+' : '-';
       last_change = stats.st_atime;
     }
   else