From bbb4c4e8ee27716448c84fb24856d80bbdbefa96 Mon Sep 17 00:00:00 2001 From: millert Date: Sat, 14 Sep 1996 03:26:01 +0000 Subject: [PATCH] Now uses "wall -g" so no need to be setgid tty. This makes $RSH work. Also fix buf oflow. --- sbin/dump/main.c | 3 +- sbin/dump/optr.c | 133 +++++++----------------------------------- sbin/dump/pathnames.h | 3 +- 3 files changed, 23 insertions(+), 116 deletions(-) diff --git a/sbin/dump/main.c b/sbin/dump/main.c index b319c635e48..0272ac9c240 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.8 1996/09/01 15:31:02 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.9 1996/09/14 03:26:02 millert Exp $ */ /* $NetBSD: main.c,v 1.8 1996/03/15 22:39:32 scottr Exp $ */ /*- @@ -266,7 +266,6 @@ main(argc, argv) if (signal(SIGINT, interrupt) == SIG_IGN) signal(SIGINT, SIG_IGN); - set_operators(); /* /etc/group snarfed */ getfstab(); /* /etc/fstab snarfed */ /* * disk can be either the full special file name, diff --git a/sbin/dump/optr.c b/sbin/dump/optr.c index 836446289a8..03f41e3f303 100644 --- a/sbin/dump/optr.c +++ b/sbin/dump/optr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: optr.c,v 1.9 1996/09/01 15:31:03 deraadt Exp $ */ +/* $OpenBSD: optr.c,v 1.10 1996/09/14 03:26:02 millert Exp $ */ /* $NetBSD: optr.c,v 1.4 1996/05/18 16:16:17 jtk Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)optr.c 8.2 (Berkeley) 1/6/94"; #else -static char rcsid[] = "$OpenBSD: optr.c,v 1.9 1996/09/01 15:31:03 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: optr.c,v 1.10 1996/09/14 03:26:02 millert Exp $"; #endif #endif /* not lint */ @@ -140,7 +140,7 @@ query(question) return(back); } -char lastmsg[100]; +char lastmsg[BUFSIZ]; /* * Alert the console operator, and enable the alarm clock to @@ -181,128 +181,35 @@ interrupt(signo) dumpabort(0); } -/* - * The following variables and routines manage alerting - * operators to the status of dump. - * This works much like wall(1) does. - */ -struct group *gp; - -/* - * Get the names from the group entry "operator" to notify. - */ -void -set_operators() -{ - if (!notify) /*not going to notify*/ - return; - gp = getgrnam(OPGRENT); - (void) endgrent(); - if (gp == NULL) { - msg("No group entry for %s.\n", OPGRENT); - notify = 0; - return; - } -} - -struct tm *localclock; - -/* - * We fork a child to do the actual broadcasting, so - * that the process control groups are not messed up - */ +/* + * We now use wall(1) to do the actual broadcasting. + */ void broadcast(message) char *message; { - time_t clock; - FILE *f_utmp; - struct utmp utmp; - char **np; - int pid, s; + FILE *fp; + char buf[sizeof(_PATH_WALL) + 12]; - if (!notify || gp == NULL) + if (!notify) return; - switch (pid = fork()) { - case -1: + (void) strcpy(buf, _PATH_WALL); + (void) strcpy(buf + sizeof(_PATH_WALL) - 1, " -g operator"); + if ((fp = popen(buf, "w")) == NULL) return; - case 0: - break; - default: - while (wait(&s) != pid) - continue; - return; - } - clock = time((time_t *)0); - localclock = localtime(&clock); - - if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) { - msg("Cannot open %s: %s\n", _PATH_UTMP, strerror(errno)); - return; - } - - while (!feof(f_utmp)) { - if (fread((char *) &utmp, sizeof (struct utmp), 1, f_utmp) != 1) - break; - if (utmp.ut_name[0] == 0) - continue; - for (np = gp->gr_mem; *np; np++) { - if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0) - continue; -#ifdef DEBUG - msg("Message to %s at %s\n", *np, utmp.ut_line); -#endif - sendmes(utmp.ut_line, message); - } - } - (void) fclose(f_utmp); - Exit(0); /* the wait in this same routine will catch this */ - /* NOTREACHED */ -} + (void) fputs("\7\7\7Message from the dump program to all operators\n\nDUMP: NEEDS ATTENTION: ", fp); + if (lastmsg[0]) + (void) fputs(lastmsg, fp); + if (message[0]) + (void) fputs(message, fp); -static void -sendmes(tty, message) - char *tty, *message; -{ - char t[MAXPATHLEN], buf[BUFSIZ]; - register char *cp; - int lmsg = 1; - FILE *f_tty; - - (void) strcpy(t, _PATH_DEV); - (void) strncat(t, tty, sizeof t - strlen(_PATH_DEV)); - - setegid(egid); - if ((f_tty = fopen(t, "w")) != NULL) { - setbuf(f_tty, buf); - (void) fprintf(f_tty, - "\n\ -\7\7\7Message from the dump program to all operators at %d:%02d ...\r\n\n\ -DUMP: NEEDS ATTENTION: ", - localclock->tm_hour, localclock->tm_min); - for (cp = lastmsg; ; cp++) { - if (*cp == '\0') { - if (lmsg) { - cp = message; - if (*cp == '\0') - break; - lmsg = 0; - } else - break; - } - if (*cp == '\n') - (void) putc('\r', f_tty); - (void) putc(*cp, f_tty); - } - (void) fclose(f_tty); - } - setegid(gid); + (void) pclose(fp); } /* - * print out an estimate of the amount of time left to do the dump + * Print out an estimate of the amount of time left to do the dump */ time_t tschedule = 0; @@ -349,7 +256,7 @@ msg(fmt, va_alist) (void) vfprintf(stderr, fmt, ap); (void) fflush(stdout); (void) fflush(stderr); - (void) vsprintf(lastmsg, fmt, ap); + (void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap); va_end(ap); } diff --git a/sbin/dump/pathnames.h b/sbin/dump/pathnames.h index 59ca9fad5a9..6b9c1bd07d4 100644 --- a/sbin/dump/pathnames.h +++ b/sbin/dump/pathnames.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pathnames.h,v 1.2 1996/06/23 14:30:12 deraadt Exp $ */ +/* $OpenBSD: pathnames.h,v 1.3 1996/09/14 03:26:01 millert Exp $ */ /* $NetBSD: pathnames.h,v 1.8 1995/03/18 14:55:06 cgd Exp $ */ /* @@ -43,3 +43,4 @@ #define _PATH_DUMPDATES "/etc/dumpdates" #define _PATH_LOCK "/tmp/dumplockXXXXXX" #define _PATH_RMT "/etc/rmt" +#define _PATH_WALL "/usr/bin/wall" -- 2.20.1