=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/wall/wall.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- src/usr.bin/wall/wall.c 1996/08/26 10:28:22 1.5 +++ src/usr.bin/wall/wall.c 1996/09/02 09:07:35 1.6 @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -44,7 +44,7 @@ #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 */ /* @@ -59,6 +59,7 @@ #include #include +#include #include #include #include @@ -66,6 +67,12 @@ #include #include +struct wallgroup { + struct wallgroup *next; + char *name; + gid_t gid; +} *grouplist; + void makemsg __P((char *)); #define IGNOREUSER "sleeper" @@ -88,18 +95,26 @@ 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; @@ -107,6 +122,14 @@ 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"))) { @@ -120,6 +143,30 @@ 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)