-.\" $OpenBSD: wall.1,v 1.2 1996/06/26 05:42:47 deraadt Exp $
+.\" $OpenBSD: wall.1,v 1.3 1996/09/02 09:07:35 deraadt Exp $
.\" $NetBSD: wall.1,v 1.3 1994/11/17 07:17:57 jtc Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.Nd write a message to users
.Sh SYNOPSIS
.Nm wall
+.Op Fl g Ar group
.Op Ar file
.Sh DESCRIPTION
.Nm Wall
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 ,
-/* $OpenBSD: wall.c,v 1.5 1996/08/26 10:28:22 deraadt Exp $ */
+/* $OpenBSD: wall.c,v 1.6 1996/09/02 09:07:35 deraadt Exp $ */
/* $NetBSD: wall.c,v 1.6 1994/11/17 07:17:58 jtc Exp $ */
/*
#if 0
static char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93";
#endif
-static char rcsid[] = "$OpenBSD: wall.c,v 1.5 1996/08/26 10:28:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: wall.c,v 1.6 1996/09/02 09:07:35 deraadt Exp $";
#endif /* not lint */
/*
#include <paths.h>
#include <pwd.h>
+#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utmp.h>
#include <vis.h>
+struct wallgroup {
+ struct wallgroup *next;
+ char *name;
+ gid_t gid;
+} *grouplist;
+
void makemsg __P((char *));
#define IGNOREUSER "sleeper"
char *p, *ttymsg();
struct passwd *pep = getpwnam("nobody");
char line[sizeof(utmp.ut_line) + 1];
+ struct wallgroup *g;
- while ((ch = getopt(argc, argv, "n")) != EOF)
+ while ((ch = getopt(argc, argv, "ng:")) != EOF)
switch (ch) {
case 'n':
/* undoc option for shutdown: suppress banner */
if (geteuid() == 0 || (pep && getuid() == pep->pw_uid))
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:
- (void)fprintf(stderr, "usage: wall [file]\n");
+ (void)fprintf(stderr, "usage: wall [-g group] [file]\n");
exit(1);
}
argc -= optind;
if (argc > 1)
goto 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"))) {
if (!utmp.ut_name[0] ||
!strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name)))
continue;
+ if (grouplist) {
+ int ingroup = 0, ngrps, i;
+ char username[16];
+ struct passwd *pw;
+ gid_t grps[NGROUPS_MAX];
+
+ bzero(username, sizeof username);
+ strncpy(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)