summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2010-09-22 13:01:11 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2010-09-22 13:01:11 +0000
commitdd7ff3035ba24dde9fad643ba832183988a4f9f7 (patch)
tree1717236171fb155bb55be0086014f8ad772c1e4a
parentd2b3e7f46d7c6bad373a9d8f9d7ed144488b62ce (diff)
Kill msgs. Noone uses it, and it has a longjmp in it.
Lots of agreement.
-rw-r--r--etc/Makefile4
-rw-r--r--etc/daily6
-rw-r--r--etc/mail/aliases5
-rw-r--r--etc/mtree/4.4BSD.dist7
-rw-r--r--etc/mtree/4.4BSD.var9
-rw-r--r--usr.bin/Makefile4
-rw-r--r--usr.bin/msgs/Makefile7
-rw-r--r--usr.bin/msgs/msgs.1268
-rw-r--r--usr.bin/msgs/msgs.c902
-rw-r--r--usr.bin/msgs/pathnames.h38
10 files changed, 7 insertions, 1243 deletions
diff --git a/etc/Makefile b/etc/Makefile
index 972226291a3..5f6552c1747 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.290 2010/06/29 17:17:53 nicm Exp $
+# $OpenBSD: Makefile,v 1.291 2010/09/22 13:01:10 deraadt Exp $
TZDIR= /usr/share/zoneinfo
LOCALTIME= Canada/Mountain
@@ -232,8 +232,6 @@ distribution-etc-root-var: distrib-dirs
${DESTDIR}/var/log/wtmp
${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
${DESTDIR}/var/log/xferlog
- ${INSTALL} -c -o daemon -g staff -m 664 /dev/null \
- ${DESTDIR}/var/msgs/bounds
${INSTALL} -c -o ${BINOWN} -g utmp -m 664 /dev/null \
${DESTDIR}/var/run/utmp
.if ${MACHINE} == "vax"
diff --git a/etc/daily b/etc/daily
index 8504b154555..cf010399c74 100644
--- a/etc/daily
+++ b/etc/daily
@@ -1,5 +1,5 @@
#
-# $OpenBSD: daily,v 1.67 2010/07/25 08:49:03 espie Exp $
+# $OpenBSD: daily,v 1.68 2010/09/22 13:01:10 deraadt Exp $
# From: @(#)daily 8.2 (Berkeley) 1/25/94
#
# For local additions, create the file /etc/daily.local.
@@ -80,10 +80,6 @@ if [ -d /var/rwho -a ! -L /var/rwho ] ; then
find . ! -name . -mtime +7 -execdir rm -f -- {} \; ; }
fi
-if [ -d /var/msgs -a ! -L /var/msgs ]; then
- msgs -c
-fi
-
next_part "Purging accounting records:"
if [ -f /var/account/acct ]; then
mv -f /var/account/acct.2 /var/account/acct.3
diff --git a/etc/mail/aliases b/etc/mail/aliases
index e6f0f8be73f..fe41f48e7bf 100644
--- a/etc/mail/aliases
+++ b/etc/mail/aliases
@@ -1,5 +1,5 @@
#
-# $OpenBSD: aliases,v 1.35 2010/06/03 20:32:36 reyk Exp $
+# $OpenBSD: aliases,v 1.36 2010/09/22 13:01:10 deraadt Exp $
#
# Aliases in this file will NOT be expanded in the header from
# Mail, but WILL be visible over networks or from /usr/libexec/mail.local.
@@ -84,6 +84,3 @@ security: root
# news: usenet
# webmaster: root
# ftp: root
-
-# uncomment this for msgs:
-# msgs: "|/usr/bin/msgs -s"
diff --git a/etc/mtree/4.4BSD.dist b/etc/mtree/4.4BSD.dist
index 88ffb7b5f4f..14a7aa6871a 100644
--- a/etc/mtree/4.4BSD.dist
+++ b/etc/mtree/4.4BSD.dist
@@ -1,4 +1,4 @@
-# $OpenBSD: 4.4BSD.dist,v 1.206 2010/06/07 14:15:27 jsg Exp $
+# $OpenBSD: 4.4BSD.dist,v 1.207 2010/09/22 13:01:10 deraadt Exp $
/set type=dir uname=root gname=wheel mode=0755
# .
@@ -2460,11 +2460,6 @@ mail
# ./var/mail
..
-# ./var/msgs
-msgs uname=daemon
-# ./var/msgs
-..
-
# ./var/named
named
diff --git a/etc/mtree/4.4BSD.var b/etc/mtree/4.4BSD.var
index be83deba04c..9cc3fd24442 100644
--- a/etc/mtree/4.4BSD.var
+++ b/etc/mtree/4.4BSD.var
@@ -1,4 +1,4 @@
-# $OpenBSD: 4.4BSD.var,v 1.12 2003/03/30 14:58:18 jmc Exp $
+# $OpenBSD: 4.4BSD.var,v 1.13 2010/09/22 13:01:10 deraadt Exp $
# $NetBSD: 4.4BSD.var,v 1.3 1996/05/12 23:30:47 thorpej Exp $
#
# user: bostic
@@ -93,13 +93,6 @@ mail type=dir uname=root gname=wheel mode=0755
..
-# ./msgs
-/set type=file gname=staff uname=daemon mode=0644
-msgs type=dir mode=0775
-# ./msgs
-..
-
-
# ./obj
/set type=file gname=wsrc uname=root mode=0775
obj type=dir gname=wheel
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 077be9b7272..af5fa5b7426 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.114 2010/06/26 03:59:34 deraadt Exp $
+# $OpenBSD: Makefile,v 1.115 2010/09/22 13:01:10 deraadt Exp $
.include <bsd.own.mk>
@@ -13,7 +13,7 @@ SUBDIR= apply apropos ar arch asa asn1_compile at aucat audioctl awk banner \
join jot kdump keynote ktrace lam last lastcomm leave less lex lndir \
locate lock logger login logname look lorder \
m4 mail make man mandoc mesg mg \
- midiplay mixerctl mkdep mklocale mkstr mktemp modstat msgs nc netstat \
+ midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
newsyslog \
nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
pkg-config pkill \
diff --git a/usr.bin/msgs/Makefile b/usr.bin/msgs/Makefile
deleted file mode 100644
index ad3f0745a54..00000000000
--- a/usr.bin/msgs/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $OpenBSD: Makefile,v 1.7 2002/05/11 00:20:20 espie Exp $
-
-PROG= msgs
-DPADD= ${LIBCURSES}
-LDADD= -lcurses
-
-.include <bsd.prog.mk>
diff --git a/usr.bin/msgs/msgs.1 b/usr.bin/msgs/msgs.1
deleted file mode 100644
index 5479193b8a8..00000000000
--- a/usr.bin/msgs/msgs.1
+++ /dev/null
@@ -1,268 +0,0 @@
-.\" $OpenBSD: msgs.1,v 1.17 2007/05/31 19:20:13 jmc Exp $
-.\" $NetBSD: msgs.1,v 1.5 1995/09/28 06:57:39 tls Exp $
-.\"
-.\" Copyright (c) 1980, 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
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)msgs.1 8.2 (Berkeley) 4/28/95
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt MSGS 1
-.Os
-.Sh NAME
-.Nm msgs
-.Nd system messages and junk mail program
-.Sh SYNOPSIS
-.Nm msgs
-.Op Fl fhlopqr
-.Op Oo Fl Oc Ar number
-.Nm msgs
-.Op Fl s
-.Nm msgs
-.Op Fl c Op Fl Ns Ar days
-.Sh DESCRIPTION
-.Nm msgs
-is used to read system messages.
-These messages are
-sent by mailing to the login
-.Dq msgs
-and should be short
-pieces of information which are suitable to be read once by most users
-of the system.
-.Pp
-The options are as follows:
-.Bl -tag -width "-number"
-.It Fl c Op Fl Ns Ar days
-The
-.Fl c
-option is used for performing cleanup on
-.Pa /var/msgs .
-An entry with the
-.Fl c
-option should be placed in the system
-.Xr crontab 5
-to run every night.
-This will remove all messages over 21 days old.
-The optional
-.Fl Ns Ar days
-argument may be specified on the command line to override the default.
-.It Fl f
-Do not say
-.Dq \&No new messages.
-This is useful in a
-.Pa .login
-file since this is often the case here.
-.It Fl h
-Print the first part of messages only.
-.It Fl l
-Causes only locally originated messages to be reported.
-.It Fl o
-By default,
-.Nm
-exits when there are no more messages to read.
-If the
-.Fl o
-flag is specified,
-the user will be given the chance to save or read messages again.
-.It Fl p
-Pipe long messages through the program specified by the
-.Ev PAGER
-environment variable.
-If
-.Ev PAGER
-is null or not defined,
-.Xr more 1
-is used.
-.It Fl q
-Queries whether there are messages, printing
-.Dq There are new messages.
-if there are.
-The command
-.Ic msgs -q
-is often used in login scripts.
-.It Fl r
-Disables the ability to save messages or enter the mailer.
-It is assumed that the
-.Ev PAGER
-environment is set to something secure.
-.It Fl s
-The
-.Fl s
-option is used for setting up the posting of messages.
-The line
-.Pp
-.Dl msgs: \&"| /usr/bin/msgs -s\&"
-.Pp
-should be included in
-.Pa /etc/mail/aliases
-(see
-.Xr newaliases 8 )
-to enable posting of messages.
-.It Ar number
-A message number can be given
-on the command line, causing
-.Nm msgs
-to start at the specified message rather than at the next message
-indicated by your
-.Pa .msgsrc
-file.
-Thus
-.Pp
-.Dl msgs -h 1
-.Pp
-prints the first part of all messages.
-.It Fl Ns Ar number
-Start
-.Ar number
-messages back from the one indicated in the
-.Pa .msgsrc
-file; useful for reviews of recent messages.
-.El
-.Pp
-.Nm msgs
-is normally invoked each time you login, by placing it in the file
-.Pa .login
-(or
-.Pa .profile
-if you use
-.Xr sh 1 ) .
-It will then prompt you with the source and subject of each new message.
-If there is no subject line, the first few non-blank lines of the
-message will be displayed.
-If there is more to the message, you will be told how
-long it is and asked whether you wish to see the rest of the message.
-The possible responses are:
-.Bl -tag -width Fl
-.It Ic y
-Type the rest of the message.
-.It Ic RETURN
-Synonym for
-.Ic y .
-.It Ic n
-Skip this message
-and go on to the next message.
-.It Ic -
-Redisplay the last message.
-.It Ic q
-Drop out of
-.Nm msgs ;
-the next time
-.Nm msgs
-will pick up where it last left off.
-.It Ic s
-Append the current message to the file
-.Pa Messages
-in the current directory;
-.Sq s-
-will save the previously displayed message.
-An
-.Sq s
-or
-.Sq s-
-may be followed by a space and a file name to receive the message replacing
-the default
-.Dq Messages .
-.It Ic m
-A copy of the specified message is placed in a temporary
-mailbox and
-.Xr mail 1
-is invoked on that mailbox.
-.It Ic p
-The specified message is piped through the program specified by the
-.Ev PAGER
-environment variable.
-If
-.Ev PAGER
-is not defined,
-.Xr more 1
-is used.
-.El
-.Pp
-The commands
-.Ic m ,
-.Ic p ,
-and
-.Ic s
-all accept a numeric argument in place of the
-.Sq - .
-.Pp
-.Nm msgs
-keeps track of the next message you will see by a number in the file
-.Pa .msgsrc
-in your home directory.
-In the directory
-.Pa /var/msgs
-it keeps a set of files whose names are the (sequential) numbers
-of the messages they represent.
-The file
-.Pa /var/msgs/bounds
-shows the low and high number of the messages in the directory
-so that
-.Nm msgs
-can quickly determine if there are no messages for you.
-.\" If the contents of
-.\" .Pa bounds
-.\" is incorrect it can be fixed by removing it;
-.\" .Nm msgs
-.\" will make a new
-.\" .Pa bounds
-.\" file the next time it is run.
-.Pp
-Within
-.Nm msgs
-you can also go to any specific message by typing its number when
-.Nm msgs
-requests input as to what to do.
-.Sh ENVIRONMENT
-.Nm msgs
-uses the
-.Ev HOME
-and
-.Ev TERM
-environment variables for the default home directory and
-terminal type.
-If defined and non-null, the
-.Ev PAGER
-variable is invoked as the pagination program.
-.Sh FILES
-.Bl -tag -width /var/msgs/* -compact
-.It Pa /var/msgs/*
-database
-.It ~/.msgsrc
-number of next message to be presented
-.El
-.Sh SEE ALSO
-.Xr mail 1 ,
-.Xr more 1 ,
-.Xr aliases 5 ,
-.Xr crontab 5 ,
-.Xr newaliases 8
-.Sh HISTORY
-The
-.Nm msgs
-command appeared in
-.Bx 3.0 .
diff --git a/usr.bin/msgs/msgs.c b/usr.bin/msgs/msgs.c
deleted file mode 100644
index 7bb6498b350..00000000000
--- a/usr.bin/msgs/msgs.c
+++ /dev/null
@@ -1,902 +0,0 @@
-/* $OpenBSD: msgs.c,v 1.36 2010/09/22 11:39:01 pirofti Exp $ */
-/* $NetBSD: msgs.c,v 1.7 1995/09/28 06:57:40 tls Exp $ */
-
-/*-
- * Copyright (c) 1980, 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
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * msgs - a user bulletin board program
- *
- * usage:
- * msgs [fhlopqr] [[-]number] to read messages
- * msgs -s to place messages
- * msgs -c [-days] to clean up the bulletin board
- *
- * prompt commands are:
- * y print message
- * n flush message, go to next message
- * q flush message, quit
- * p print message, turn on 'pipe thru more' mode
- * P print message, turn off 'pipe thru more' mode
- * - reprint last message
- * s[-][<num>] [<filename>] save message
- * m[-][<num>] mail with message in temp mbox
- * x exit without flushing this message
- * <num> print message number <num>
- */
-
-#define OBJECT /* will object to messages without Subjects */
-#define REJECT /* will reject messages without Subjects
- (OBJECT must be defined also) */
-#undef UNBUFFERED /* use unbuffered output */
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <term.h>
-#include <termios.h>
-#include <time.h>
-#include <unistd.h>
-#include "pathnames.h"
-
-#define CMODE 0664 /* bounds file creation mode */
-#define NO 0
-#define YES 1
-#define SUPERUSER 0 /* superuser uid */
-#define DAEMON 1 /* daemon uid */
-#define NLINES 24 /* default number of lines/crt screen */
-#define NDAYS 21 /* default keep time for messages */
-#define DAYS *24*60*60 /* seconds/day */
-#define MSGSRC ".msgsrc" /* user's rc file */
-#define BOUNDS "bounds" /* message bounds file */
-#define NEXT "Next message? [yq]"
-#define MORE "More? [ynq]"
-#define NOMORE "(No more) [q] ?"
-
-typedef char bool;
-
-FILE *msgsrc;
-FILE *newmsg;
-char *sep = "-";
-char inbuf[BUFSIZ];
-char fname[MAXPATHLEN];
-char cmdbuf[MAXPATHLEN + MAXPATHLEN];
-char subj[128];
-char from[128];
-char date[128];
-char *ptr;
-char *in;
-bool local;
-bool ruptible;
-bool totty;
-bool seenfrom;
-bool seensubj;
-bool blankline;
-bool printing = NO;
-bool mailing = NO;
-bool quitit = NO;
-bool sending = NO;
-bool restricted = NO;
-int uid;
-int msg;
-int prevmsg;
-int lct;
-int nlines;
-int Lpp = 0;
-time_t t;
-time_t keep;
-volatile sig_atomic_t intrpflg = 0;
-
-void prmesg(int);
-void onintr(int);
-void onsusp(int);
-int linecnt(FILE *);
-int next(char *, int);
-void ask(char *);
-void gfrsub(FILE *);
-char *nxtfld(char *);
-
-/* option initialization */
-bool hdrs = NO;
-bool qopt = NO;
-bool hush = NO;
-bool send_msg = NO;
-bool locomode = NO;
-bool use_pager = NO;
-bool clean = NO;
-bool lastcmd = NO;
-jmp_buf tstpbuf;
-
-int
-main(int argc, char *argv[])
-{
- bool newrc, already;
- int rcfirst = 0; /* first message to print (from .rc) */
- int rcback = 0; /* amount to back off of rcfirst */
- int firstmsg = 0, nextmsg = 0, lastmsg = 0;
- int blast = 0;
- FILE *bounds;
- char *cp;
-
-#ifdef UNBUFFERED
- setbuf(stdout, NULL);
-#endif
-
- time(&t);
- uid = getuid();
- if (setresuid(uid, uid, uid) == -1) {
- perror("setresuid");
- exit(1);
- }
- ruptible = (signal(SIGINT, SIG_IGN) == SIG_DFL);
- if (ruptible)
- signal(SIGINT, SIG_DFL);
-
- argc--, argv++;
- while (argc > 0) {
- if (isdigit(argv[0][0])) { /* starting message # */
- rcfirst = atoi(argv[0]);
- } else if (isdigit(argv[0][1])) { /* backward offset */
- rcback = atoi(&(argv[0][1]));
- } else {
- ptr = *argv;
- while (*ptr) {
- switch (*ptr++) {
- case '-':
- break;
- case 'c':
- if (uid != SUPERUSER && uid != DAEMON) {
- fprintf(stderr, "Sorry\n");
- exit(1);
- }
- clean = YES;
- break;
- case 'f': /* silently */
- hush = YES;
- break;
- case 'h': /* headers only */
- hdrs = YES;
- break;
- case 'l': /* local msgs only */
- locomode = YES;
- break;
- case 'o': /* option to save last message */
- lastcmd = YES;
- break;
- case 'p': /* pipe thru 'more' during long msgs */
- use_pager = YES;
- break;
- case 'q': /* query only */
- qopt = YES;
- break;
- case 'r': /* restricted */
- restricted = YES;
- break;
- case 's': /* sending TO msgs */
- send_msg = YES;
- break;
- default:
- fprintf(stderr,
- "usage: msgs [fhlopqr] [[-]number]\n"
- " msgs [-s]\n"
- " msgs [-c [-days]]\n");
- exit(1);
- }
- }
- }
- argc--, argv++;
- }
-
- /*
- * determine current message bounds
- */
- snprintf(fname, sizeof(fname), "%s/%s", _PATH_MSGS, BOUNDS);
- bounds = fopen(fname, "r");
-
- if (bounds == NULL) {
- if (errno == ENOENT) {
- if ((bounds = fopen(fname, "w+")) == NULL) {
- perror(fname);
- exit(1);
- }
- fprintf(bounds, "1 0\n");
- rewind(bounds);
- } else {
- perror(fname);
- exit(1);
- }
- }
-
- fscanf(bounds, "%d %d\n", &firstmsg, &lastmsg);
- fclose(bounds);
- blast = lastmsg; /* save upper bound */
-
- if (clean)
- keep = t - (rcback? rcback : NDAYS) DAYS;
-
- if (clean || bounds == NULL) { /* relocate message bounds */
- struct dirent *dp;
- struct stat stbuf;
- bool seenany = NO;
- DIR *dirp;
-
- dirp = opendir(_PATH_MSGS);
- if (dirp == NULL) {
- perror(_PATH_MSGS);
- exit(errno);
- }
- chmod(fname, CMODE);
-
- firstmsg = 32767;
- lastmsg = 0;
-
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)){
- int i = 0;
-
- cp = dp->d_name;
- if (dp->d_ino == 0)
- continue;
- if (dp->d_namlen == 0)
- continue;
-
- if (clean)
- snprintf(inbuf, sizeof(inbuf), "%s/%s",
- _PATH_MSGS, cp);
-
- while (isdigit(*cp))
- i = i * 10 + *cp++ - '0';
- if (*cp)
- continue; /* not a message! */
-
- if (clean) {
- if (stat(inbuf, &stbuf) != 0)
- continue;
- if (stbuf.st_mtime < keep &&
- stbuf.st_mode&S_IWRITE) {
- unlink(inbuf);
- continue;
- }
- }
-
- if (i > lastmsg)
- lastmsg = i;
- if (i < firstmsg)
- firstmsg = i;
- seenany = YES;
- }
- closedir(dirp);
-
- if (!seenany) {
- if (blast != 0) /* never lower the upper bound! */
- lastmsg = blast;
- firstmsg = lastmsg + 1;
- } else if (blast > lastmsg)
- lastmsg = blast;
-
- if (!send_msg) {
- bounds = fopen(fname, "w");
- if (bounds == NULL) {
- perror(fname);
- exit(errno);
- }
- chmod(fname, CMODE);
- fprintf(bounds, "%d %d\n", firstmsg, lastmsg);
- fclose(bounds);
- }
- }
-
- if (send_msg) {
- /*
- * Send mode - place msgs in _PATH_MSGS
- */
- bounds = fopen(fname, "w");
- if (bounds == NULL) {
- perror(fname);
- exit(errno);
- }
-
- nextmsg = lastmsg + 1;
- snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, nextmsg);
- newmsg = fopen(fname, "w");
- if (newmsg == NULL) {
- perror(fname);
- exit(errno);
- }
- chmod(fname, 0644);
-
- fprintf(bounds, "%d %d\n", firstmsg, nextmsg);
- fclose(bounds);
-
- sending = YES;
- if (ruptible)
- signal(SIGINT, onintr);
-
- if (isatty(fileno(stdin))) {
- struct passwd *pw;
-
- if ((pw = getpwuid(uid)) == NULL) {
- perror("getpwuid");
- exit(1);
- }
- printf("Message %d:\nFrom %s %sSubject: ",
- nextmsg, pw->pw_name, ctime(&t));
- fflush(stdout);
- if (fgets(inbuf, sizeof inbuf, stdin) == NULL)
- errx(1, "could not read input");
- putchar('\n');
- fflush(stdout);
- fprintf(newmsg, "From %s %sSubject: %s\n",
- pw->pw_name, ctime(&t), inbuf);
- blankline = seensubj = YES;
- } else
- blankline = seensubj = NO;
- for (;;) {
- if (fgets(inbuf, sizeof inbuf, stdin) == NULL)
- break;
- blankline = (blankline || (inbuf[0] == '\n'));
- seensubj = (seensubj ||
- (!blankline && (strncmp(inbuf, "Subj", 4) == 0)));
- fputs(inbuf, newmsg);
- }
-#ifdef OBJECT
- if (!seensubj) {
- printf("NOTICE: Messages should have a Subject field!\n");
-#ifdef REJECT
- unlink(fname);
-#endif
- exit(1);
- }
-#endif
- exit(ferror(stdin));
- }
- if (clean)
- exit(0);
-
- /*
- * prepare to display messages
- */
- totty = (isatty(fileno(stdout)) != 0);
- use_pager = use_pager && totty;
-
- if ((cp = getenv("HOME")) == NULL || *cp == '\0') {
- fprintf(stderr, "Error, no home directory!\n");
- exit(1);
- }
- snprintf(fname, sizeof(fname), "%s/%s", cp, MSGSRC);
- msgsrc = fopen(fname, "r");
- if (msgsrc) {
- newrc = NO;
- fscanf(msgsrc, "%d\n", &nextmsg);
- fclose(msgsrc);
- if (nextmsg > lastmsg+1) {
- printf("Warning: bounds have been reset (%d, %d)\n",
- firstmsg, lastmsg);
- truncate(fname, (off_t)0);
- newrc = YES;
- } else if (!rcfirst)
- rcfirst = nextmsg - rcback;
- } else
- newrc = YES;
- msgsrc = fopen(fname, "r+");
- if (msgsrc == NULL)
- msgsrc = fopen(fname, "w");
- if (msgsrc == NULL) {
- perror(fname);
- exit(errno);
- }
- if (rcfirst) {
- if (rcfirst > lastmsg+1) {
- printf("Warning: the last message is number %d.\n",
- lastmsg);
- rcfirst = nextmsg;
- }
- if (rcfirst > firstmsg)
- firstmsg = rcfirst; /* don't set below first msg */
- }
- if (newrc) {
- nextmsg = firstmsg;
- fseeko(msgsrc, (off_t)0, SEEK_SET);
- fprintf(msgsrc, "%d\n", nextmsg);
- fflush(msgsrc);
- }
-
- if (totty) {
- struct winsize win;
- if (ioctl(fileno(stdout), TIOCGWINSZ, &win) != -1)
- Lpp = win.ws_row;
- if (Lpp <= 0) {
- char *ttype = getenv("TERM");
-
- if (ttype != (char *)NULL) {
- if (tgetent(NULL, ttype) <= 0
- || (Lpp = tgetnum("li")) <= 0) {
- Lpp = NLINES;
- }
- } else
- Lpp = NLINES;
- }
- }
- Lpp -= 6; /* for headers, etc. */
-
- already = NO;
- prevmsg = firstmsg;
- printing = YES;
- if (ruptible)
- signal(SIGINT, onintr);
-
- /*
- * Main program loop
- */
- for (msg = firstmsg; msg <= lastmsg; msg++) {
-
- snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, msg);
- newmsg = fopen(fname, "r");
- if (newmsg == NULL)
- continue;
-
- gfrsub(newmsg); /* get From and Subject fields */
- if (locomode && !local) {
- fclose(newmsg);
- continue;
- }
-
- if (qopt) { /* This has to be located here */
- printf("There are new messages.\n");
- exit(0);
- }
-
- if (already && !hdrs)
- putchar('\n');
-
- /*
- * Print header
- */
- if (totty)
- signal(SIGTSTP, onsusp);
- (void) setjmp(tstpbuf);
- already = YES;
- nlines = 2;
- if (seenfrom) {
- printf("Message %d:\nFrom %s %s", msg, from, date);
- nlines++;
- }
- if (seensubj) {
- printf("Subject: %s", subj);
- nlines++;
- } else {
- if (seenfrom) {
- putchar('\n');
- nlines++;
- }
- while (nlines < 6 &&
- fgets(inbuf, sizeof inbuf, newmsg) &&
- inbuf[0] != '\n') {
- fputs(inbuf, stdout);
- nlines++;
- }
- }
-
- lct = linecnt(newmsg);
- if (lct)
- printf("(%d%slines) ", lct, seensubj? " " : " more ");
-
- if (hdrs) {
- printf("\n-----\n");
- fclose(newmsg);
- continue;
- }
-
- /*
- * Ask user for command
- */
- if (totty)
- ask(lct? MORE : (msg==lastmsg? NOMORE : NEXT));
- else
- inbuf[0] = 'y';
- if (totty)
- signal(SIGTSTP, SIG_DFL);
-cmnd:
- in = inbuf;
- switch (*in) {
- case 'x':
- case 'X':
- exit(0);
-
- case 'q':
- case 'Q':
- quitit = YES;
- printf("--Postponed--\n");
- exit(0);
- /* intentional fall-thru */
- case 'n':
- case 'N':
- if (msg >= nextmsg)
- sep = "Flushed";
- prevmsg = msg;
- break;
-
- case 'p':
- case 'P':
- use_pager = (*in++ == 'p');
- /* intentional fallthru */
- case '\n':
- case 'y':
- default:
- if (*in == '-') {
- msg = prevmsg-1;
- sep = "replay";
- break;
- }
- if (isdigit(*in)) {
- msg = next(in, sizeof inbuf);
- sep = in;
- break;
- }
-
- prmesg(nlines + lct + (seensubj? 1 : 0));
- prevmsg = msg;
- }
-
- printf("--%s--\n", (intrpflg ? "Interrupt" : sep));
- sep = "-";
- if (msg >= nextmsg) {
- nextmsg = msg + 1;
- fseeko(msgsrc, (off_t)0, SEEK_SET);
- fprintf(msgsrc, "%d\n", nextmsg);
- fflush(msgsrc);
- }
- if (newmsg)
- fclose(newmsg);
- if (quitit)
- break;
- }
-
- /*
- * Make sure .rc file gets updated
- */
- if (--msg >= nextmsg) {
- nextmsg = msg + 1;
- fseeko(msgsrc, (off_t)0, SEEK_SET);
- fprintf(msgsrc, "%d\n", nextmsg);
- fflush(msgsrc);
- }
- if (already && !quitit && lastcmd && totty) {
- /*
- * save or reply to last message?
- */
- msg = prevmsg;
- ask(NOMORE);
- if (inbuf[0] == '-' || isdigit(inbuf[0]))
- goto cmnd;
- }
- if (!(already || hush || qopt))
- printf("No new messages.\n");
- exit(0);
-}
-
-void
-prmesg(int length)
-{
- FILE *outf;
- char *env_pager;
-
- if (use_pager && length > Lpp) {
- signal(SIGPIPE, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- if ((env_pager = getenv("PAGER")) == NULL || *env_pager == '\0') {
- snprintf(cmdbuf, sizeof(cmdbuf), _PATH_PAGER, Lpp);
- } else {
- snprintf(cmdbuf, sizeof(cmdbuf), "%s", env_pager);
- }
- outf = popen(cmdbuf, "w");
- if (!outf)
- outf = stdout;
- else
- setbuf(outf, (char *)NULL);
- }
- else
- outf = stdout;
-
- if (seensubj)
- putc('\n', outf);
-
- while (fgets(inbuf, sizeof inbuf, newmsg)) {
- fputs(inbuf, outf);
- if (ferror(outf)) {
- clearerr(outf);
- break;
- }
- }
-
- if (outf != stdout) {
- pclose(outf);
- signal(SIGPIPE, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
- } else {
- fflush(stdout);
- }
-
- /* trick to force wait on output */
- tcdrain(fileno(stdout));
-}
-
-/* ARGSUSED */
-void
-onintr(int signo)
-{
- int save_errno = errno;
-
- signal(SIGINT, onintr);
- if (mailing)
- unlink(fname);
- if (sending) {
- unlink(fname);
- write(STDOUT_FILENO, "--Killed--\n", strlen("--Killed--\n"));
- _exit(1);
- }
- if (printing) {
- write(STDOUT_FILENO, "\n", 1);
- if (hdrs)
- _exit(0);
- if (newmsg)
- fseeko(newmsg, (off_t)0, SEEK_END);
- intrpflg = 1;
- }
- errno = save_errno;
-}
-
-/*
- * We have just gotten a susp. Suspend and prepare to resume.
- */
-/* ARGSUSED */
-void
-onsusp(int signo)
-{
- int save_errno = errno;
- sigset_t emptyset;
-
- signal(SIGTSTP, SIG_DFL);
- sigemptyset(&emptyset);
- sigprocmask(SIG_SETMASK, &emptyset, NULL);
- kill(0, SIGTSTP);
- signal(SIGTSTP, onsusp);
- errno = save_errno;
-
- if (!mailing)
- longjmp(tstpbuf, 1);
-}
-
-int
-linecnt(FILE *f)
-{
- off_t oldpos = ftello(f);
-
- int l = 0;
- char lbuf[BUFSIZ];
-
- while (fgets(lbuf, sizeof lbuf, f))
- l++;
- clearerr(f);
- fseeko(f, oldpos, SEEK_SET);
- return (l);
-}
-
-int
-next(char *buf, int len)
-{
- int i;
- sscanf(buf, "%d", &i);
- snprintf(buf, len, "Goto %d", i);
- return(--i);
-}
-
-void
-ask(char *prompt)
-{
- char inch;
- int n, cmsg, fd;
- off_t oldpos;
- FILE *cpfrom, *cpto;
-
- printf("%s ", prompt);
- fflush(stdout);
- intrpflg = 0;
- if (fgets(inbuf, sizeof inbuf, stdin) == NULL)
- errx(1, "could not read input");
- inbuf[strcspn(inbuf, "\n")] = '\0';
- if (intrpflg)
- inbuf[0] = 'x';
-
- /*
- * Handle 'mail' and 'save' here.
- */
- if (((inch = inbuf[0]) == 's' || inch == 'm') && !restricted) {
- if (inbuf[1] == '-')
- cmsg = prevmsg;
- else if (isdigit(inbuf[1]))
- cmsg = atoi(&inbuf[1]);
- else
- cmsg = msg;
- snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, cmsg);
-
- oldpos = ftello(newmsg);
-
- cpfrom = fopen(fname, "r");
- if (!cpfrom) {
- printf("Message %d not found\n", cmsg);
- ask (prompt);
- return;
- }
-
- if (inch == 's') {
- in = nxtfld(inbuf);
- if (*in) {
- for (n=0;
- in[n] > ' ' && n < sizeof fname - 1;
- n++) {
- fname[n] = in[n];
- }
- fname[n] = NULL;
- }
- else
- strlcpy(fname, "Messages", sizeof fname);
- fd = open(fname, O_RDWR|O_EXCL|O_CREAT|O_APPEND, 0666);
- } else {
- strlcpy(fname, _PATH_TMPFILE, sizeof fname);
- fd = mkstemp(fname);
- if (fd != -1) {
- snprintf(cmdbuf, sizeof(cmdbuf), _PATH_MAIL, fname);
- mailing = YES;
- }
- }
- if (fd == -1 || (cpto = fdopen(fd, "a")) == NULL) {
- if (fd != -1)
- close(fd);
- perror(fname);
- mailing = NO;
- fseeko(newmsg, oldpos, SEEK_SET);
- ask(prompt);
- return;
- }
-
- while ((n = fread(inbuf, 1, sizeof inbuf, cpfrom)))
- fwrite(inbuf, 1, n, cpto);
-
- fclose(cpfrom);
- fclose(cpto);
- fseeko(newmsg, oldpos, SEEK_SET); /* reposition current message */
- if (inch == 's')
- printf("Message %d saved in \"%s\"\n", cmsg, fname);
- else {
- system(cmdbuf);
- unlink(fname);
- mailing = NO;
- }
- ask(prompt);
- }
-}
-
-void
-gfrsub(FILE *infile)
-{
- off_t frompos;
-
- seensubj = seenfrom = NO;
- local = YES;
- subj[0] = from[0] = date[0] = NULL;
-
- /*
- * Is this a normal message?
- */
- if (fgets(inbuf, sizeof inbuf, infile)) {
- if (strncmp(inbuf, "From", 4)==0) {
- /*
- * expected form starts with From
- */
- seenfrom = YES;
- frompos = ftello(infile);
- ptr = from;
- in = nxtfld(inbuf);
- if (*in) {
- while (*in && *in > ' ' &&
- ptr - from < sizeof from -1) {
- if (*in == ':' || *in == '@' || *in == '!')
- local = NO;
- *ptr++ = *in++;
- }
- }
- *ptr = NULL;
- if (*(in = nxtfld(in)))
- strncpy(date, in, sizeof date);
- else {
- date[0] = '\n';
- date[1] = NULL;
- }
- } else {
- /*
- * not the expected form
- */
- fseeko(infile, (off_t)0, SEEK_SET);
- return;
- }
- } else
- /*
- * empty file ?
- */
- return;
-
- /*
- * look for Subject line until EOF or a blank line
- */
- while (fgets(inbuf, sizeof inbuf, infile) &&
- !(blankline = (inbuf[0] == '\n'))) {
- /*
- * extract Subject line
- */
- if (!seensubj && strncmp(inbuf, "Subj", 4)==0) {
- seensubj = YES;
- frompos = ftello(infile);
- strncpy(subj, nxtfld(inbuf), sizeof subj);
- }
- }
- if (!blankline)
- /*
- * ran into EOF
- */
- fseeko(infile, frompos, SEEK_SET);
-
- if (!seensubj)
- /*
- * for possible use with Mail
- */
- strncpy(subj, "(No Subject)\n", sizeof subj);
-}
-
-char *
-nxtfld(char *s)
-{
- if (*s)
- while (*s && *s > ' ')
- s++; /* skip over this field */
- if (*s)
- while (*s && *s <= ' ')
- s++; /* find start of next field */
- return (s);
-}
diff --git a/usr.bin/msgs/pathnames.h b/usr.bin/msgs/pathnames.h
deleted file mode 100644
index 447ef51c96e..00000000000
--- a/usr.bin/msgs/pathnames.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* $OpenBSD: pathnames.h,v 1.5 2003/07/02 00:21:16 avsm Exp $ */
-/* $NetBSD: pathnames.h,v 1.3 1995/09/28 06:57:41 tls Exp $ */
-
-/*
- * 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
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 6/6/93
- */
-
-#define _PATH_MSGS "/var/msgs"
-#define _PATH_MAIL "/usr/bin/Mail -f %s"
-#define _PATH_PAGER "/usr/bin/more -%d"
-#define _PATH_TMPFILE "/tmp/msgXXXXXXXXXX"