Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Feb 2001 00:08:52 -0700
From:      Warner Losh <imp@harmony.village.org>
To:        audit@freebsd.org
Subject:   wall -g patches for review
Message-ID:  <200102140708.f1E78rW59181@harmony.village.org>

next in thread | raw e-mail | index | archive | help
I've gone ahead and added the wall -g functionality from OpenBSD to
FreeBSD's wall.  I need this for dump, but it seems to be generally
useful.

While I was at it, I did the register and __P thing.  It seems to work
for me, but I thought I'd post this for wider review since it dos run
at an elevated privs (group tty).

Last time this came up, people suggested that this might belong in
syslog.  I don't disagree that this would be useful functionality
there, but wall provides a different service.  syslog is for a oneline
message, while wall can send arbitrary files.

Anyway, I'll commit these Feb 21, 2001 if there are no objections
outstanding.

Warner

Index: ttymsg.c
===================================================================
RCS file: /home/imp/FreeBSD/CVS/src/usr.bin/wall/ttymsg.c,v
retrieving revision 1.6
diff -u -r1.6 ttymsg.c
--- ttymsg.c	2000/06/09 19:44:49	1.6
+++ ttymsg.c	2001/02/14 06:56:23
@@ -59,15 +59,11 @@
  * ignored (exclusive-use, lack of permission, etc.).
  */
 char *
-ttymsg(iov, iovcnt, line, tmout)
-	struct iovec *iov;
-	int iovcnt;
-	char *line;
-	int tmout;
+ttymsg(struct iovec *iov, int iovcnt, char *line, int tmout)
 {
 	static char device[MAXNAMLEN] = _PATH_DEV;
 	static char errbuf[1024];
-	register int cnt, fd, left, wret;
+	int cnt, fd, left, wret;
 	struct iovec localiov[7];
 	int forked = 0;
 
Index: wall.1
===================================================================
RCS file: /home/imp/FreeBSD/CVS/src/usr.bin/wall/wall.1,v
retrieving revision 1.4
diff -u -r1.4 wall.1
--- wall.1	2000/11/20 19:21:18	1.4
+++ wall.1	2001/02/14 06:59:01
@@ -40,6 +40,7 @@
 .Nd write a message to users
 .Sh SYNOPSIS
 .Nm
+.Op Fl g Ar group
 .Op Ar file
 .Sh DESCRIPTION
 .Nm Wall
@@ -52,6 +53,12 @@
 terminals of users who have chosen
 to deny messages or are using a program which
 automatically denies messages.
+.Bl -tag -width indent
+.It Fl g
+Send messages to users in this group.  This option may be specified
+multiple times, and any user in any of the specified groups will
+receive the message.
+.El
 .Sh SEE ALSO
 .Xr mesg 1 ,
 .Xr talk 1 ,
Index: wall.c
===================================================================
RCS file: /home/imp/FreeBSD/CVS/src/usr.bin/wall/wall.c,v
retrieving revision 1.16
diff -u -r1.16 wall.c
--- wall.c	2000/11/26 22:36:35	1.16
+++ wall.c	2001/02/14 06:56:17
@@ -56,6 +56,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <grp.h>
 #include <locale.h>
 #include <paths.h>
 #include <pwd.h>
@@ -66,9 +67,15 @@
 #include <unistd.h>
 #include <utmp.h>
 
-void	makemsg __P((char *));
-static void usage __P((void));
-char   *ttymsg __P((struct iovec *, int, char *, int));
+struct wallgroup {
+	struct wallgroup *next;
+	char	*name;
+	gid_t	gid;
+} *grouplist;
+
+void	makemsg(char *);
+static void usage(void);
+char   *ttymsg(struct iovec *, int, char *, int);
 
 #define	IGNOREUSER	"sleeper"
 
@@ -78,26 +85,36 @@
 
 /* ARGSUSED */
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char *argv[])
 {
+	int ingroup = 0, ngrps, i;
 	int ch;
-	struct iovec iov;
-	struct utmp utmp;
 	FILE *fp;
 	char *p;
+	struct wallgroup *g;
+	struct passwd *pw;
+	struct iovec iov;
+	struct utmp utmp;
+	gid_t grps[NGROUPS_MAX];
 	char line[sizeof(utmp.ut_line) + 1];
+	char username[sizeof(utmp.ut_name) + 1];
 
 	(void)setlocale(LC_CTYPE, "");
 
-	while ((ch = getopt(argc, argv, "n")) != -1)
+	while ((ch = getopt(argc, argv, "g:n")) != -1)
 		switch (ch) {
 		case 'n':
 			/* undoc option for shutdown: suppress banner */
 			if (geteuid() == 0)
 				nobanner = 1;
 			break;
+		case 'g':
+			g = (struct wallgroup *)malloc(sizeof *g);
+			g->next = grouplist;
+			g->name = optarg;
+			g->gid = -1;
+			grouplist = g;
+			break;
 		case '?':
 		default:
 			usage();
@@ -107,6 +124,14 @@
 	if (argc > 1)
 		usage();
 
+	for (g = grouplist; g; g = g->next) {
+		struct group *grp;
+
+		grp = getgrnam(g->name);
+		if (grp)
+			g->gid = grp->gr_gid;
+	}
+
 	makemsg(*argv);
 
 	if (!(fp = fopen(_PATH_UTMP, "r")))
@@ -118,6 +143,24 @@
 		if (!utmp.ut_name[0] ||
 		    !strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name)))
 			continue;
+		if (grouplist) {
+			strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name));
+			pw = getpwnam(username);
+			if (!pw)
+				continue;
+			ngrps = getgroups(pw->pw_gid, grps);
+			for (g = grouplist; g && ingroup == 0; g = g->next) {
+				if (g->gid == -1)
+					continue;
+				if (g->gid == pw->pw_gid)
+					ingroup = 1;
+				for (i = 0; i < ngrps && ingroup == 0; i++)
+					if (g->gid == grps[i])
+						ingroup = 1;
+			}
+			if (ingroup == 0)
+				continue;
+		}
 		strncpy(line, utmp.ut_line, sizeof(utmp.ut_line));
 		line[sizeof(utmp.ut_line)] = '\0';
 		if ((p = ttymsg(&iov, 1, line, 60*5)) != NULL)
@@ -134,11 +177,10 @@
 }
 
 void
-makemsg(fname)
-	char *fname;
+makemsg(char *fname)
 {
-	register int cnt;
-	register unsigned char ch;
+	int cnt;
+	unsigned char ch;
 	struct tm *lt;
 	struct passwd *pw;
 	struct stat sbuf;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102140708.f1E78rW59181>