summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1994-11-17 07:17:53 +0000
committerjtc <jtc@NetBSD.org>1994-11-17 07:17:53 +0000
commita8bfd3d17acdf360bcfa394c375f8a39cfc31df4 (patch)
treeda03bac165230f686406885f0250ba51ef800d18
parentc0b8fbbaad4dd65cbd830a8205052bbe1269a151 (diff)
Merged with 4.4lite
Changed to conform to NetBSD's new RCS Id conventions.
-rw-r--r--lib/libutil/ttymsg.c45
-rw-r--r--usr.bin/wall/Makefile4
-rw-r--r--usr.bin/wall/ttymsg.c45
-rw-r--r--usr.bin/wall/wall.111
-rw-r--r--usr.bin/wall/wall.c34
5 files changed, 87 insertions, 52 deletions
diff --git a/lib/libutil/ttymsg.c b/lib/libutil/ttymsg.c
index 19911a47c45..982481fe4e7 100644
--- a/lib/libutil/ttymsg.c
+++ b/lib/libutil/ttymsg.c
@@ -1,6 +1,8 @@
+/* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */
+
/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,8 +34,10 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)ttymsg.c 5.8 (Berkeley) 7/1/91";*/
-static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93";
+#endif
+static char rcsid[] = "$NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -49,17 +53,18 @@ static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $";
#include <stdlib.h>
/*
- * Display the contents of a uio structure on a terminal. Used by wall(1)
- * and syslogd(8). Forks and finishes in child if write would block, waiting
- * at most five minutes. Returns pointer to error string on unexpected error;
- * string is not newline-terminated. Various "normal" errors are ignored
- * (exclusive-use, lack of permission, etc.).
+ * Display the contents of a uio structure on a terminal. Used by wall(1),
+ * syslogd(8), and talkd(8). Forks and finishes in child if write would block,
+ * waiting up to tmout seconds. Returns pointer to error string on unexpected
+ * error; string is not newline-terminated. Various "normal" errors are
+ * ignored (exclusive-use, lack of permission, etc.).
*/
char *
-ttymsg(iov, iovcnt, line)
+ttymsg(iov, iovcnt, line, tmout)
struct iovec *iov;
int iovcnt;
char *line;
+ int tmout;
{
static char device[MAXNAMLEN] = _PATH_DEV;
static char errbuf[1024];
@@ -67,13 +72,21 @@ ttymsg(iov, iovcnt, line)
struct iovec localiov[6];
int forked = 0;
- if (iovcnt > 6)
+ if (iovcnt > sizeof(localiov) / sizeof(localiov[0]))
return ("too many iov's (change code in wall/ttymsg.c)");
+
+ (void) strcpy(device + sizeof(_PATH_DEV) - 1, line);
+ if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) {
+ /* A slash is an attempt to break security... */
+ (void) snprintf(errbuf, sizeof(errbuf), "'/' in \"%s\"",
+ device);
+ return (errbuf);
+ }
+
/*
* open will fail on slip lines or exclusive-use lines
* if not running as root; not an error.
*/
- (void) strcpy(device + sizeof(_PATH_DEV) - 1, line);
if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) {
if (errno == EBUSY || errno == EACCES)
return (NULL);
@@ -92,7 +105,7 @@ ttymsg(iov, iovcnt, line)
if (wret >= 0) {
left -= wret;
if (iov != localiov) {
- bcopy(iov, localiov,
+ bcopy(iov, localiov,
iovcnt * sizeof(struct iovec));
iov = localiov;
}
@@ -126,14 +139,14 @@ ttymsg(iov, iovcnt, line)
return (NULL);
}
forked++;
- /* wait at most 5 minutes */
+ /* wait at most tmout seconds */
(void) signal(SIGALRM, SIG_DFL);
(void) signal(SIGTERM, SIG_DFL); /* XXX */
(void) sigsetmask(0);
- (void) alarm((u_int)(60 * 5));
+ (void) alarm((u_int)tmout);
(void) fcntl(fd, O_NONBLOCK, &off);
continue;
- }
+ }
/*
* We get ENODEV on a slip line if we're running as root,
* and EIO if the line just went away.
diff --git a/usr.bin/wall/Makefile b/usr.bin/wall/Makefile
index 2fcf7d7cc93..34d9c20634b 100644
--- a/usr.bin/wall/Makefile
+++ b/usr.bin/wall/Makefile
@@ -1,5 +1,5 @@
-# from: @(#)Makefile 5.4 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.2 1993/07/30 22:29:49 mycroft Exp $
+# $NetBSD: Makefile,v 1.3 1994/11/17 07:17:53 jtc Exp $
+# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= wall
SRCS= ttymsg.c wall.c
diff --git a/usr.bin/wall/ttymsg.c b/usr.bin/wall/ttymsg.c
index 19911a47c45..982481fe4e7 100644
--- a/usr.bin/wall/ttymsg.c
+++ b/usr.bin/wall/ttymsg.c
@@ -1,6 +1,8 @@
+/* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */
+
/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,8 +34,10 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)ttymsg.c 5.8 (Berkeley) 7/1/91";*/
-static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93";
+#endif
+static char rcsid[] = "$NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -49,17 +53,18 @@ static char rcsid[] = "$Id: ttymsg.c,v 1.2 1993/08/01 18:03:09 mycroft Exp $";
#include <stdlib.h>
/*
- * Display the contents of a uio structure on a terminal. Used by wall(1)
- * and syslogd(8). Forks and finishes in child if write would block, waiting
- * at most five minutes. Returns pointer to error string on unexpected error;
- * string is not newline-terminated. Various "normal" errors are ignored
- * (exclusive-use, lack of permission, etc.).
+ * Display the contents of a uio structure on a terminal. Used by wall(1),
+ * syslogd(8), and talkd(8). Forks and finishes in child if write would block,
+ * waiting up to tmout seconds. Returns pointer to error string on unexpected
+ * error; string is not newline-terminated. Various "normal" errors are
+ * ignored (exclusive-use, lack of permission, etc.).
*/
char *
-ttymsg(iov, iovcnt, line)
+ttymsg(iov, iovcnt, line, tmout)
struct iovec *iov;
int iovcnt;
char *line;
+ int tmout;
{
static char device[MAXNAMLEN] = _PATH_DEV;
static char errbuf[1024];
@@ -67,13 +72,21 @@ ttymsg(iov, iovcnt, line)
struct iovec localiov[6];
int forked = 0;
- if (iovcnt > 6)
+ if (iovcnt > sizeof(localiov) / sizeof(localiov[0]))
return ("too many iov's (change code in wall/ttymsg.c)");
+
+ (void) strcpy(device + sizeof(_PATH_DEV) - 1, line);
+ if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) {
+ /* A slash is an attempt to break security... */
+ (void) snprintf(errbuf, sizeof(errbuf), "'/' in \"%s\"",
+ device);
+ return (errbuf);
+ }
+
/*
* open will fail on slip lines or exclusive-use lines
* if not running as root; not an error.
*/
- (void) strcpy(device + sizeof(_PATH_DEV) - 1, line);
if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) {
if (errno == EBUSY || errno == EACCES)
return (NULL);
@@ -92,7 +105,7 @@ ttymsg(iov, iovcnt, line)
if (wret >= 0) {
left -= wret;
if (iov != localiov) {
- bcopy(iov, localiov,
+ bcopy(iov, localiov,
iovcnt * sizeof(struct iovec));
iov = localiov;
}
@@ -126,14 +139,14 @@ ttymsg(iov, iovcnt, line)
return (NULL);
}
forked++;
- /* wait at most 5 minutes */
+ /* wait at most tmout seconds */
(void) signal(SIGALRM, SIG_DFL);
(void) signal(SIGTERM, SIG_DFL); /* XXX */
(void) sigsetmask(0);
- (void) alarm((u_int)(60 * 5));
+ (void) alarm((u_int)tmout);
(void) fcntl(fd, O_NONBLOCK, &off);
continue;
- }
+ }
/*
* We get ENODEV on a slip line if we're running as root,
* and EIO if the line just went away.
diff --git a/usr.bin/wall/wall.1 b/usr.bin/wall/wall.1
index 2283df178a1..d2e15e4f688 100644
--- a/usr.bin/wall/wall.1
+++ b/usr.bin/wall/wall.1
@@ -1,5 +1,7 @@
-.\" Copyright (c) 1989, 1990 The Regents of the University of California.
-.\" All rights reserved.
+.\" $NetBSD: wall.1,v 1.3 1994/11/17 07:17:57 jtc Exp $
+.\"
+.\" Copyright (c) 1989, 1990, 1993
+.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -29,10 +31,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" from: @(#)wall.1 6.5 (Berkeley) 4/23/91
-.\" $Id: wall.1,v 1.2 1993/08/01 07:26:28 mycroft Exp $
+.\" @(#)wall.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd April 23, 1991
+.Dd June 6, 1993
.Dt WALL 1
.Os BSD 4
.Sh NAME
diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c
index 818a761d01a..4082ec9e4b4 100644
--- a/usr.bin/wall/wall.c
+++ b/usr.bin/wall/wall.c
@@ -1,6 +1,8 @@
+/* $NetBSD: wall.c,v 1.6 1994/11/17 07:17:58 jtc Exp $ */
+
/*
- * Copyright (c) 1988, 1990 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,14 +34,16 @@
*/
#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1988 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1988, 1990, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)wall.c 5.14 (Berkeley) 3/2/91";*/
-static char rcsid[] = "$Id: wall.c,v 1.5 1993/08/27 22:31:02 jtc Exp $";
+#if 0
+static char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93";
+#endif
+static char rcsid[] = "$NetBSD: wall.c,v 1.6 1994/11/17 07:17:58 jtc Exp $";
#endif /* not lint */
/*
@@ -51,17 +55,19 @@ static char rcsid[] = "$Id: wall.c,v 1.5 1993/08/27 22:31:02 jtc Exp $";
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
-#include <utmp.h>
+
+#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <paths.h>
#include <unistd.h>
+#include <utmp.h>
+
+void makemsg __P((char *));
#define IGNOREUSER "sleeper"
-void makemsg();
int nobanner;
int mbufsize;
char *mbuf;
@@ -79,6 +85,7 @@ main(argc, argv)
FILE *fp;
char *p, *ttymsg();
struct passwd *pep = getpwnam("nobody");
+ char line[sizeof(utmp.ut_line) + 1];
while ((ch = getopt(argc, argv, "n")) != EOF)
switch (ch) {
@@ -111,7 +118,9 @@ usage:
if (!utmp.ut_name[0] ||
!strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name)))
continue;
- if (p = ttymsg(&iov, 1, utmp.ut_line))
+ strncpy(line, utmp.ut_line, sizeof(utmp.ut_line));
+ line[sizeof(utmp.ut_line)] = '\0';
+ if ((p = ttymsg(&iov, 1, line, 60*5)) != NULL)
(void)fprintf(stderr, "wall: %s\n", p);
}
exit(0);
@@ -129,7 +138,6 @@ makemsg(fname)
FILE *fp;
int fd;
char *p, *whom, hostname[MAXHOSTNAMELEN], lbuf[100], tmpname[15];
- char *getlogin(), *strcpy(), *ttyname();
(void)strcpy(tmpname, _PATH_TMP);
(void)strcat(tmpname, "/wall.XXXXXX");
@@ -168,7 +176,7 @@ makemsg(fname)
exit(1);
}
while (fgets(lbuf, sizeof(lbuf), stdin))
- for (cnt = 0, p = lbuf; ch = *p; ++p, cnt++) {
+ for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
if (cnt == 79 || ch == '\n') {
for (; cnt < 79; ++cnt)
putc(' ', fp);