Add the source code for bugfiler from the Net/2 tape
authorRodney W. Grimes <rgrimes@cdrom.com>
Sun, 4 Apr 1993 00:00:00 +0000 (00:00 +0000)
committerRodney W. Grimes <rgrimes@cdrom.com>
Sun, 4 Apr 1993 00:00:00 +0000 (00:00 +0000)
Add the source code for uucpd from the Net/2 tape

This patch adds the source code for the bugfiler program from
the Net/2 release tape.

This code was modified to use the bugfiler daemon that is being
maintained by me (Rodney W. Grimes) at bsd.coe.montana.edu.  I would like
to thank Nate for the use of his machine to mantain the bug achive on for
386bsd.  There is also a backup system of the bugfiler running on
sun-lamp.cs.berkeley.edu provided by Chris.

AUTHOR: Rodney W. Grimes (rgrimes@agora.rain.com)
386BSD-Patchkit: patch00116

17 files changed:
usr/src/libexec/Makefile
usr/src/libexec/bugfiler/Makefile [new file with mode: 0644]
usr/src/libexec/bugfiler/bug.h [new file with mode: 0644]
usr/src/libexec/bugfiler/bugfiler.8 [new file with mode: 0644]
usr/src/libexec/bugfiler/bugfiler.c [new file with mode: 0644]
usr/src/libexec/bugfiler/bugformat [new file with mode: 0644]
usr/src/libexec/bugfiler/error.c [new file with mode: 0644]
usr/src/libexec/bugfiler/gethead.c [new file with mode: 0644]
usr/src/libexec/bugfiler/pathnames.h [new file with mode: 0644]
usr/src/libexec/bugfiler/process.c [new file with mode: 0644]
usr/src/libexec/bugfiler/redist.c [new file with mode: 0644]
usr/src/libexec/bugfiler/reply.c [new file with mode: 0644]
usr/src/libexec/bugfiler/sendbug.1 [new file with mode: 0644]
usr/src/libexec/bugfiler/sendbug.sh [new file with mode: 0644]
usr/src/libexec/uucpd/Makefile [new file with mode: 0644]
usr/src/libexec/uucpd/pathnames.h [new file with mode: 0644]
usr/src/libexec/uucpd/uucpd.c [new file with mode: 0644]

index babbc9c..c680f68 100644 (file)
@@ -1,6 +1,18 @@
 #      @(#)Makefile    5.7 (Berkeley) 4/1/91
 #      @(#)Makefile    5.7 (Berkeley) 4/1/91
+#
+# PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+# --------------------         -----   ----------------------
+# CURRENT PATCH LEVEL:         1       00116
+# --------------------         -----   ----------------------
+#
+# 04 Apr 93    Rodney W. Grimes        Add bugfiler, uucpd, uucp comment,
+#                                      kpasswdd comment
+#
 
 
-SUBDIR=        comsat crond elvispreserve fingerd ftpd getNAME getty mail.local \
-       makekey rexecd rlogind rshd talkd telnetd tftpd
+SUBDIR=        bugfiler comsat crond elvispreserve fingerd ftpd getNAME getty \
+       mail.local makekey rexecd rlogind rshd talkd telnetd tftpd uucpd
+
+# uucp has old style Makefiles, needs to be updated.
+# kpasswdd not ported, it is old kerberosIV
 
 .include <bsd.subdir.mk>
 
 .include <bsd.subdir.mk>
diff --git a/usr/src/libexec/bugfiler/Makefile b/usr/src/libexec/bugfiler/Makefile
new file mode 100644 (file)
index 0000000..d24fc70
--- /dev/null
@@ -0,0 +1,18 @@
+#      @(#)Makefile    5.17 (Berkeley) 5/24/90
+# Fixed to use bsd.coe.montana.edu as a bugs host - rgrimes 4/04/93
+
+PROG=  bugfiler
+CFLAGS+=-I${.CURDIR} -D"BUGS_HOME \"owner-386bsd_bugs@bsd.coe.montana.edu\""
+SRCS=  bugfiler.c error.c gethead.c process.c redist.c reply.c
+BINOWN=        root
+BINMODE=4555
+MAN1=  sendbug.0
+MAN8=  bugfiler.0
+
+beforeinstall:
+       install -c -o bin -g ${BINGRP} -m 555 \
+           ${.CURDIR}/sendbug.sh ${DESTDIR}/usr/bin/sendbug
+       install -c -o bin -g ${BINGRP} -m 444 ${.CURDIR}/bugformat \
+           ${DESTDIR}/usr/share/misc
+
+.include <bsd.prog.mk>
diff --git a/usr/src/libexec/bugfiler/bug.h b/usr/src/libexec/bugfiler/bug.h
new file mode 100644 (file)
index 0000000..91a4c57
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ *     @(#)bug.h       5.10 (Berkeley) 2/25/91
+ *
+ *  4/01/93 Fixed BUGS_HOME so it can be defined from the Makefile - rgrimes
+ */
+
+#ifndef        BUGS_HOME
+#define BUGS_HOME      "owner-bugs@ucbvax.Berkeley.EDU"
+#endif /* BUGS_HOME */
+#define BUGS_ID                "bugs"
+
+/*
+ * the METOO definition has the bugfiler exit with an error (-1) status
+ * if there's a problem.  This causes sendmail to send off a copy of the
+ * report (as failed mail) to the "owner" of the mail alias that executed
+ * the bugfiler.  This is great if you would have otherwise lost the bug
+ * report.  It's not so great if you get a whole bunch of mail that you
+ * really don't want.
+ */
+#define METOO
+
+/* files */
+#define ACK_FILE       "bug:ack"               /* acknowledge file */
+#define DIST_FILE      "bug:redist"            /* redistribution file */
+#define ERROR_FILE     "log"                   /* error file */
+#define LOCK_FILE      "bug:lock"              /* lock file name */
+#define SUMMARY_FILE   "summary"               /* summary file */
+#define TMP_BUG                "errors/BUG_XXXXXX"     /* tmp bug report */
+#define TMP_DIR                "errors"                /* tmp directory */
+
+#define CHN            (char *)NULL    /* null arg string */
+#define COMMENT                '#'             /* comment in redist file */
+#define EOS            (char)NULL      /* end of string */
+#define ERR            -1              /* error return */
+#define MAXLINELEN     200             /* max line length in message */
+#define NO             0               /* no/false */
+#define OK             0               /* okay return */
+#define YES            1               /* yes/true */
+
+typedef struct {
+       short   found,                  /* line number if found */
+               redist;                 /* if part of redist headers */
+       int     (*valid)();             /* validation routine */
+       short   len;                    /* length of tag */
+       char    *tag,                   /* leading tag */
+               *line;                  /* actual line */
+} HEADER;
+extern HEADER  mailhead[];
+
+#define DATE_TAG       0               /* "Date:" offset */
+#define FROM_TAG       1               /* "From " offset */
+#define CFROM_TAG      2               /* "From:" offset */
+#define INDX_TAG       3               /* "Index:" offset */
+#define MSG_TAG                4               /* "Message-Id:" offset */
+#define RPLY_TAG       5               /* "Reply-To:" offset */
+#define RET_TAG                6               /* "Return-Path:" offset */
+#define SUBJ_TAG       7               /* "Subject:" offset */
+#define TO_TAG         8               /* "To:" offset */
+#define APPAR_TO_TAG   9               /* "Apparently-To:" offset */
+
+/* so sizeof doesn't return 0 */
+extern char    bfr[MAXBSIZE],                  /* general I/O buffer */
+               dir[MAXNAMLEN],                 /* subject and folder */
+               folder[MAXNAMLEN],
+               tmpname[sizeof(TMP_BUG) + 5];   /* temp bug file */
diff --git a/usr/src/libexec/bugfiler/bugfiler.8 b/usr/src/libexec/bugfiler/bugfiler.8
new file mode 100644 (file)
index 0000000..f13fbbb
--- /dev/null
@@ -0,0 +1,294 @@
+.\" Copyright (c) 1983, 1991 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. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. 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.
+.\"
+.\"     @(#)bugfiler.8 6.11 (Berkeley) 3/16/91
+.\"
+.Dd March 16, 1991
+.Dt BUGFILER 8
+.Os BSD 4.2
+.Sh NAME
+.Nm bugfiler
+.Nd file bug reports in folders automatically
+.Sh SYNOPSIS
+.Nm bugfiler
+.Op Fl ar
+.Op Fl v Ar version
+.Sh DESCRIPTION
+.Nm Bugfiler
+is a program to automatically intercept, acknowledge,
+redistribute and store bug reports.
+.Nm Bugfiler
+is normally invoked
+by the mail delivery program with a line similar to the following in
+.Pa /etc/aliases .
+.Bd -literal -offset indent
+bugs:  "|bugfiler"
+.Ed
+.Pp
+It should be noted that the login
+.Dq bugs
+must exist for the bugfiler
+to run.  Unless otherwise noted all paths used by
+.Nm bugfiler
+are
+relative to the home directory of this login.
+.Nm Bugfiler
+also
+expects all of its files and directories to be owned by
+.Dq bugs .
+.Pp
+Available options.
+.Bl -tag -width Ds
+.It Fl a
+Do not send automatic mail acknowledgement to the bug report filer.
+(The default is to send the acknowledgement with the file
+.Pa ~bugs/version/bug:ack
+appended).
+.It Fl r
+Do not redistribute.
+.It Fl v Ar version
+Override the
+.Ar version
+provided within the bug report itself.
+.El
+.Pp
+For the bug report to be correctly filed, it must contain a line
+in the following format:
+.Pp
+.Bd -filled -offset indent -compact
+.Bl -column Index folder
+.It Index: Ta Em folder Ta Ar version
+.El
+.Ed
+.Pp
+The directories
+.Pa ~bugs/ Ns Ar version
+and
+.Pa ~bugs/ Ns Ar version/ Ns Em folder
+must exist before
+.Nm bugfiler
+attempts to store the bug report.  Bug
+reports will be stored in files named by the concatenation of
+.Ar version ,
+.Em folder ,
+and sequential numbers, i.e. if
+.Ar version
+is
+.Dq 4.3 Tn BSD
+and
+.Em folder
+is
+.Dq ucb
+the first bug report will be placed in
+.Pa ~bugs/4.3BSD/ucb/1 .
+If
+.Em folder
+contains more than one component only
+the first one will be used, e.g. if
+.Em folder
+is
+.Dq bin/from.c
+or
+.Dq bin/adb/con.c
+it will be treated as if it were simply
+.Dq bin .
+.Pp
+.Pp
+If the
+.Fl r
+flag is not supplied, redistribution of the bug reports
+is done as specified in the file
+.Pa ~bugs/version/bug:redist .
+This file
+is in the format of the
+.Xr aliases 5
+file, including comments and
+entries requiring multiple lines, with the single exception that the
+.Em folder
+component of the
+.Dq Index:
+line replaces the name to alias.
+The special folder
+.Dq all:
+receives a redistribution of all bug reports
+sent to this
+.Ar version .
+For example, the
+.Pa bug:redist
+file
+.Pp
+.Bd -literal -offset indent -compact
+#      bigbug gets a copy of everything
+all:   bigbug
+#      ucb folder redistribution list
+ucb:   karels, kjd@coke.berkeley.edu
+       ra@beno.css.gov
+.Ed
+.Pp
+will send copies of all bug reports with
+.Dq ucb
+as the
+.Em folder
+to bigbug, karels, kjd, and ra.
+.Pp
+Reports that cannot be filed, due to an invalid
+.Dq Index:
+line or
+some other error, are placed in the directory
+.Pa ~bugs/errors .
+The
+.Nm bugfiler
+maintainer should correct these bug reports and then
+run
+.Nm bugfiler ,
+with the corrected report as its standard input,
+as bug reports with errors are neither acknowledged or redistributed.
+All reports that
+.Nm bugfiler
+handles are logged in
+.Pa ~bugs/log.
+.Pp
+Valid bugs are also logged in the file
+.Pa ~bugs/version/summary.
+This file has an entry for each bug report for
+.Ar version
+in the
+format:
+.Pp
+.Bd -literal -offset indent -compact
+Filename       Date
+     Subject:
+     Index:
+     Owner:    Bugs Bunny
+     Status:   Received
+.Ed
+.Pp
+.Li Filename
+is the concatenation of
+.Ar version ,
+.Em folder ,
+and a number
+as described above.
+.Xr Date
+is the date as reported by the system
+clock, using
+.Xr ctime 3 .
+.Li The Subject:
+and
+.Li Index:
+lines are
+The
+.Dq Subject:
+and
+.Dq Index:
+lines are
+copies of the
+.Dq Subject:
+and
+.Dq index:
+lines contained in the bug
+report.  The
+.Li Owner
+and
+.Li Status
+fields are intended to provide a
+rudimentary method of tracking the status of bug reports.
+.Pp
+The file
+.Pa ~bugs/bug:lock
+is the focus of all locking for
+.Nm bugfiler .
+If you wish to manipulate any of the log or error files, rename or remove
+it and
+.Nm bugfiler
+will treat all bug reports that it receives as if
+they were incorrectly formatted, i.e. it will place them in the directory
+.Pa ~bugs/errors ,
+for later recovery by the
+.Nm bugfiler
+maintainer.
+Obviously, this file must be created when you first install
+.Nm bugfiler .
+.Pp
+All errors that occur before
+.Pa ~bugs/log
+is found are logged into the system
+log file, using
+.Xr syslog 8 .
+.Sh FILES
+.Bl -tag -width /usr/share/misc/bugformatxx -compact
+.It Pa ~bugs/bug:ack
+the acknowledgement message
+.It Pa ~bugs/bug:redist
+the redistribution list
+.It Pa ~bugs/bug:lock
+the locking file
+.It Pa ~bugs/errors/BUG_??????
+bug reports with format errors
+.It Pa ~bugs/log
+the log file
+.It Pa ~bugs/folder/summary
+the summary files
+.It Pa /usr/sbin/sendmail
+the mail delivery program
+.It Pa /usr/share/misc/bugformat
+a sample bug report format
+.El
+.Sh SEE ALSO
+.Xr sendbug 1 ,
+.Xr aliases 5 ,
+.Xr syslog 8
+.Sh BUGS
+Since mail can be forwarded in a number of different ways,
+.Nm bugfiler
+does not recognize forwarded mail and will acknowledge to the forwarder
+instead of the original sender unless there is a
+.Dq Reply-To
+field in the
+header.
+.Pp
+This version of
+.Nm bugfiler
+is not compatible with the version
+released with
+.Bx 4.3
+in that it doesn't complain to the sender about
+incorrectly formatted bug reports.
+Frankly, we got tired of the profanity, not to mention the extended
+conversations
+.Nm bugfiler
+was holding with
+.Xr vacation 1 .
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Bx 4.2 .
diff --git a/usr/src/libexec/bugfiler/bugfiler.c b/usr/src/libexec/bugfiler/bugfiler.c
new file mode 100644 (file)
index 0000000..c9aa4c5
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 1983, 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983, 1986, 1987 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)bugfiler.c 5.16 (Berkeley) 2/25/91";
+#endif /* not lint */
+
+/*
+ * Bug report processing program, designed to be invoked
+ * through aliases(5).
+ */
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "bug.h"
+
+char   bfr[MAXBSIZE],                  /* general I/O buffer */
+       tmpname[sizeof(TMP_BUG) + 5];   /* temp bug file */
+
+main(argc, argv)
+       int     argc;
+       char    **argv;
+{
+       extern char     *optarg;        /* getopt arguments */
+       register struct passwd  *pwd;   /* bugs password entry */
+       register int    ch;             /* getopts char */
+       int     do_ack,                 /* acknowledge bug report */
+               do_redist;              /* redistribut BR */
+       char    *argversion;            /* folder name provided */
+       static void logit(), make_copy();
+
+       do_ack = do_redist = YES;
+       argversion = NULL;
+       while ((ch = getopt(argc, argv, "av:r")) != EOF)
+               switch((char)ch) {
+               case 'a':
+                       do_ack = NO;
+                       break;
+               case 'v':
+                       argversion = optarg;
+                       break;
+               case 'r':
+                       do_redist = NO;
+                       break;
+               case '?':
+               default:
+                       fputs("usage: bugfiler [-ar] [-v version]\n", stderr);
+                       error("usage: bugfiler [-ar] [-v version]", CHN);
+               }
+
+       if (!(pwd = getpwnam(BUGS_ID)))
+               error("can't find bugs login.", BUGS_ID);
+
+       if (chdir(pwd->pw_dir))         /* change to bugs home directory */
+               error("can't chdir to %s.", pwd->pw_dir);
+
+       if (setreuid(0, pwd->pw_uid))
+               error("can't set id to %s.", BUGS_ID);
+
+       (void)umask(02);                /* everything is 664 */
+       seterr();                       /* redirect to log file */
+       logit();                        /* log report arrival */
+       make_copy();                    /* save copy in case */
+       gethead(do_redist);
+
+       if (argversion)                 /* specific folder requested */
+               (void)strcpy(dir, argversion);
+
+       process();
+
+       if (setuid(0))
+               error("can't set id to root.", CHN);
+       if (do_ack)
+               reply();
+       if (do_redist)
+               redist();
+       (void)unlink(tmpname);
+       exit(OK);
+}
+
+/*
+ * make_copy --
+ *     make a copy of bug report in error folder
+ */
+static void
+make_copy()
+{
+       register int    cnt,                    /* read return value */
+                       tfd;                    /* temp file descriptor */
+       char    *strcpy();
+
+       if (access(TMP_DIR, F_OK))
+               (void)mkdir(TMP_DIR, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
+       (void)strcpy(tmpname, TMP_BUG);
+       if (tfd = mkstemp(tmpname)) {
+               while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt)
+                       write(tfd, bfr, cnt);
+               (void)close(tfd);
+               return;
+       }
+       error("can't make copy using %s.", tmpname);
+}
+
+/*
+ * logit --
+ *     log this run of the bugfiler
+ */
+static void
+logit()
+{
+       struct timeval  tp;
+       char    *C1, *C2,
+               *ctime();
+
+       if (gettimeofday(&tp, (struct timezone *)NULL))
+               error("can't get time of day.", CHN);
+       for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1);
+       *C1 = EOS;
+       fputs(C2, stderr);
+}
diff --git a/usr/src/libexec/bugfiler/bugformat b/usr/src/libexec/bugfiler/bugformat
new file mode 100644 (file)
index 0000000..9d9c3ca
--- /dev/null
@@ -0,0 +1,41 @@
+Subject: Short summary of the problem (please make this meaningful!)
+Index: folder 386BSD-0.1.2.3
+
+Description:
+       Detailed description of the problem, suggestion, or complaint.
+Repeat-By:
+       Describe the sequence of events that causes the problem
+       to occur.  If you can provide a shell script or program do
+       duplicate the problem please do so.
+Fix:
+       Description of how to fix the problem.  If you don't know a
+       fix for the problem, don't include this section.  If you can
+       provide context diffs (diff -c oldfile newfile) please do so.
+
+-------- Remove this line and what's below it, for reference only. --------
+
+To ensure that your bug report is handled correctly by bugfiler(8),
+you must replace "folder" (on the line above starting with "Index:")
+with one of the following values:
+
+       folder  ::= bin | doc | etc | games | ideas | include | lib
+                       | libexec | man | misc | sbin | share | sys.386bsd
+                       | usr.bin | usr.sbin
+
+This value should match the part of directory that the bug is in
+under /usr/src.  If it appears in more than one directory, use the
+first one on the list.  If the place that it appears is not on the list
+use the "misc" value.  If it is a suggestion use the "ideas" value.  If
+it is a manual page problem use the "man" value.
+
+If you're not running 386BSD-0.1.2.3, you should also replace
+"386BSD-0.1.2.3" on the same line with one of the following values.
+
+       version ::= 386BSD-0.1 | 386BSD-0.1.1 | 386BSD-0.1.2 | 386BSD-0.1.2.1
+                              | 386BSD-0.1.2.2 | 386BSD-0.1.2.3
+
+For example, if your bug concerns the program "/usr/bin/file" and
+you're currently running 386BSD-0.1.2.4, you should replace "folder"
+with "usr.bin/file", and "386BSD-0.1.2.3" with "386BSD-0.1.2.4".
+Thus, your Index line would look like this:
+Index: usr.bin/file 386BSD-0.1.2.4
diff --git a/usr/src/libexec/bugfiler/error.c b/usr/src/libexec/bugfiler/error.c
new file mode 100644 (file)
index 0000000..cb2122b
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)error.c    5.8 (Berkeley) 2/25/91";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <dirent.h>
+#include <syslog.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "bug.h"
+
+static short   err_redir;                      /* stderr redirected */
+
+/*
+ * seterr --
+ *     redirect stderr for error processing
+ */
+seterr()
+{
+       if (!freopen(ERROR_FILE, "a", stderr))
+               error("can't open error file %s.", ERROR_FILE);
+       err_redir = YES;
+}
+
+/*
+ * error --
+ *     write errors to log file and die
+ */
+error(fmt, arg)
+       register char   *fmt,
+                       *arg;
+{
+       static char     logmsg[MAXLINELEN];     /* syslog message */
+       char    *strcpy(), *strcat();
+
+       if (err_redir) {
+               /* don't combine these, "fmt" may not require "arg" */
+               fprintf(stderr, "\t%s\n\t", tmpname);
+               fprintf(stderr, fmt, arg);
+               fputc('\n', stderr);
+       }
+       else {
+               sprintf(logmsg, "bugfiler: %s", fmt);
+               syslog(LOG_ERR, logmsg, arg);
+       }
+#ifdef METOO
+       exit(ERR);
+#else
+       exit(OK);
+#endif
+}
diff --git a/usr/src/libexec/bugfiler/gethead.c b/usr/src/libexec/bugfiler/gethead.c
new file mode 100644 (file)
index 0000000..e718ff7
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)gethead.c  5.10 (Berkeley) 3/7/91";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pathnames.h"
+#include "bug.h"
+
+static int     chk1(), pbuf();
+
+#define ENT(X) sizeof(X) - 1, X
+HEADER mailhead[] = {                          /* mail headers */
+       { NO, YES,  NULL, ENT("Date:"), },
+       { NO,  NO,  NULL, ENT("From "), },
+       { NO, YES,  NULL, ENT("From:"), },
+       { NO,  NO,  chk1, ENT("Index:"), },
+       { NO, YES,  NULL, ENT("Message-Id:"), },
+       { NO, YES,  NULL, ENT("Reply-To:"), },
+       { NO, YES,  NULL, ENT("Return-Path:"), },
+       { NO,  NO,  pbuf, ENT("Subject:"), },
+       { NO, YES,  NULL, ENT("To:"), },
+       { NO,  NO,  NULL, ENT("Apparently-To:"), },
+       { ERR, }
+};
+
+FILE   *dfp;                           /* distf file pointer */
+char   dir[MAXNAMLEN],                 /* subject and folder */
+       folder[MAXNAMLEN];
+
+/*
+ * gethead --
+ *     read mail and bug headers from bug report, construct redist headers
+ */
+gethead(redist)
+       int     redist;
+{
+       register HEADER *hp;            /* mail header pointer */
+
+       if (redist) {
+               int     fd;
+               char    *distf;
+
+               distf = strdup(_PATH_TMP);
+               if (!(fd = mkstemp(distf)) || !(dfp = fdopen(fd, "w+")))
+                       error("can't create redistribution file %s.", distf);
+               /* disappear after last reference is closed */
+               (void)unlink(distf);
+               free(distf);
+       }
+       if (!freopen(tmpname, "r", stdin))
+               error("can't read temporary bug file %s.", tmpname);
+
+       while (fgets(bfr, sizeof(bfr), stdin)) {
+               for (hp = mailhead; hp->found != ERR; ++hp)
+                       if (!hp->found)
+                               if (!strncmp(hp->tag, bfr, hp->len)) {
+                                       if (hp->valid && !((*(hp->valid))(bfr)))
+                                               break;
+                                       if (!(hp->line = malloc((u_int)(strlen(bfr) + 1))))
+                                               error("malloc failed.", CHN);
+                                       (void)strcpy(hp->line, bfr);
+                                       hp->found = YES;
+                                       break;
+                               }
+               if ((hp->found == ERR || hp->redist) && redist)
+                       fputs(bfr, dfp);
+       }
+
+       if (!mailhead[INDX_TAG].found)
+               error("no readable \"Index:\" header in bug report.", CHN);
+}
+
+/*
+ * chk1 --
+ *     parse the "Index:" line into folder and directory
+ */
+static
+chk1(line)
+       char    *line;
+{
+       register char   *C;             /* tmp pointer */
+       struct stat     sbuf;           /* existence check */
+       char    *index();
+
+       if (sscanf(line, " Index: %s %s ", folder, dir) != 2)
+               return(NO);
+       if (C = index(folder, '/')) {   /* deal with "bin/from.c" */
+               if (C == folder)
+                       return(NO);
+               *C = EOS;
+       }
+       if (stat(dir, &sbuf) || (sbuf.st_mode & S_IFMT) != S_IFDIR)
+               return(NO);
+       (void)pbuf(line);
+       return(YES);
+}
+
+/*
+ * pbuf --
+ *     kludge so that summary file looks pretty
+ */
+static
+pbuf(line)
+       char    *line;
+{
+       register char   *rp,                    /* tmp pointers */
+                       *wp;
+
+       for (rp = line; *rp == ' ' || *rp == '\t'; ++rp);
+       for (wp = line; *rp; ++wp) {
+               if ((*wp = *rp++) != ' ' && *wp != '\t')
+                       continue;
+               *wp = ' ';
+               while (*rp == ' ' || *rp == '\t')
+                       ++rp;
+       }
+       if (wp[-1] == ' ')                      /* wp can't == line */
+               --wp;
+       *wp = EOS;
+       return(YES);
+}
diff --git a/usr/src/libexec/bugfiler/pathnames.h b/usr/src/libexec/bugfiler/pathnames.h
new file mode 100644 (file)
index 0000000..406aa0e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 1989 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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 5.4 (Berkeley) 3/7/91
+ */
+
+#define        MAIL_CMD        "/usr/sbin/sendmail -i -t -F \"Bugs Bunny\" -f owner-bugs"
+#undef _PATH_TMP
+#define        _PATH_TMP       "/tmp/BUG_XXXXXX"
diff --git a/usr/src/libexec/bugfiler/process.c b/usr/src/libexec/bugfiler/process.c
new file mode 100644 (file)
index 0000000..6988584
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)process.c  5.9 (Berkeley) 2/25/91";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include "bug.h"
+
+char   pfile[MAXPATHLEN];                      /* permanent file name */
+
+/*
+ * process --
+ *     copy report to permanent file,
+ *     update summary file.
+ */
+process()
+{
+       register int    rval;                   /* read return value */
+       struct timeval  tp;                     /* time of day */
+       int     lfd;                            /* lock file descriptor */
+       static int getnext();
+
+       if (access(LOCK_FILE, R_OK) || (lfd = open(LOCK_FILE, O_RDONLY, 0)) < 0)
+               error("can't find lock file %s.", LOCK_FILE);
+       if (flock(lfd, LOCK_EX))
+               error("can't get lock.", CHN);
+       sprintf(pfile, "%s/%s/%d", dir, folder, getnext());
+       fprintf(stderr, "\t%s\n", pfile);
+       if (!(freopen(pfile, "w", stdout)))
+               error("can't create %s.", pfile);
+       rewind(stdin);
+       while ((rval = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && rval)
+               if (write(fileno(stdout), bfr, rval) != rval)
+                       error("write to %s failed.", pfile);
+
+       /* append information to the summary file */
+       sprintf(bfr, "%s/%s", dir, SUMMARY_FILE);
+       if (!(freopen(bfr, "a", stdout)))
+               error("can't append to summary file %s.", bfr);
+       if (gettimeofday(&tp, (struct timezone *)NULL))
+               error("can't get time of day.", CHN);
+       printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tStatus: Received\n", pfile, ctime(&tp.tv_sec), mailhead[INDX_TAG].line, mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n");
+       (void)flock(lfd, LOCK_UN);
+       (void)fclose(stdout);
+}
+
+/*
+ * getnext --
+ *     get next file name (number)
+ */
+static int
+getnext()
+{
+       register struct dirent *d;              /* directory structure */
+       register DIR *dirp;                     /* directory pointer */
+       register int highval, newval;
+       register char *p;
+
+       (void)sprintf(bfr, "%s/%s", dir, folder);
+       if (!(dirp = opendir(bfr)))
+               error("can't read folder directory %s.", bfr);
+       for (highval = -1; d = readdir(dirp);) {
+               for (p = d->d_name; *p && isdigit(*p); ++p);
+               if (!*p && (newval = atoi(d->d_name)) > highval)
+                       highval = newval;
+       }
+       closedir(dirp);
+       return(++highval);
+}
diff --git a/usr/src/libexec/bugfiler/redist.c b/usr/src/libexec/bugfiler/redist.c
new file mode 100644 (file)
index 0000000..1301b0d
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)redist.c   5.12 (Berkeley) 4/1/91";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include "bug.h"
+#include "pathnames.h"
+
+/*
+ * redist --
+ *     Redistribute a bug report to those people indicated in the
+ *     redistribution list file.
+ */
+redist()
+{
+       extern FILE     *dfp;           /* dist file fp */
+       extern char     pfile[];        /* permanent bug file */
+       register char   *C1, *C2;
+       FILE    *pf, *popen();
+       int     group;
+       char    *p, *index();
+
+       (void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
+       if (!freopen(bfr, "r", stdin))
+               return;
+       for (pf = NULL, group = 0; fgets(bfr, sizeof(bfr), stdin);) {
+               if (C1 = index(bfr, '\n'))
+                       *C1 = '\0';
+nextline:      if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
+                       continue;
+               *C1 = EOS;
+               if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
+                       for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
+                       if (!*C1)                       /* if empty list */
+                               continue;
+                       if (!pf) {
+                               if (!(pf = popen(MAIL_CMD, "w")))
+                                       error("sendmail pipe failed.", CHN);
+                               if (mailhead[SUBJ_TAG].found)
+                                       fprintf(pf,
+                                           "%s", mailhead[SUBJ_TAG].line);
+                               else
+                                       fprintf(pf,
+                                           "Subject: Untitled Bug Report\n");
+                               if (!mailhead[TO_TAG].line) {
+                                       if (mailhead[APPAR_TO_TAG].line)
+                                           fprintf(pf, "To%s",
+                                             index(mailhead[APPAR_TO_TAG].line,
+                                             ':'));
+                                       else
+                                           fprintf(pf, "To: %s\n",  BUGS_ID);
+                               }
+                               fputs("Resent-To: ", pf);
+                       }
+                       /*
+                        * write out first entry, then succeeding entries
+                        * backward compatible, handles back slashes at end
+                        * of line
+                        */
+                       if (group++)
+                               fputs(", ", pf);
+                       for (;;) {
+                               if (C2 = index(C1, '\\'))
+                                       *C2 = EOS;
+                               fputs(C1, pf);
+                               if (!fgets(bfr, sizeof(bfr), stdin))
+                                       break;
+                               if (C1 = index(bfr, '\n'))
+                                       *C1 = '\0';
+                               if (*bfr != ' ' && *bfr != '\t')
+                                       goto nextline;
+                               for (C1 = bfr;
+                                   *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
+                       }
+               }
+       }
+       if (!pf)
+               return;
+
+       putc('\n', pf);
+
+       rewind(dfp);
+       /* add Reference header and copy bug report out */
+       while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
+               fputs(bfr, pf);
+       fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
+       while (fgets(bfr, sizeof(bfr), dfp))
+               fputs(bfr, pf);
+       (void)pclose(pf);
+}
diff --git a/usr/src/libexec/bugfiler/reply.c b/usr/src/libexec/bugfiler/reply.c
new file mode 100644 (file)
index 0000000..2c5c71d
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 1986, 1987 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)reply.c    5.9 (Berkeley) 2/25/91";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include "bug.h"
+#include "pathnames.h"
+
+/*
+ * reply --
+ *     tell the user we got their silly little bug report
+ */
+reply()
+{
+       register char   *C,                     /* traveling pointer */
+                       *to;                    /* who we're replying to */
+       register int    afd,                    /* ack file descriptor */
+                       rval;                   /* return value */
+       FILE    *pf,                            /* pipe pointer */
+               *popen();
+       char    *index();
+
+       if (mailhead[RPLY_TAG].found) {
+               for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
+               if (*C)
+                       goto gotone;
+       }
+       if (mailhead[FROM_TAG].found) {
+               for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
+               if (*C)
+                       goto gotone;
+       }
+       if (mailhead[CFROM_TAG].found) {
+               for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
+               if (*C)
+                       goto gotone;
+       }
+       return;
+
+       /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
+gotone:        if (to = index(C, '<'))
+               for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
+       else {
+               to = C;
+               for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
+       }
+       *C = EOS;
+
+       if (!(pf = popen(MAIL_CMD, "w")))
+               error("sendmail pipe failed.", CHN);
+
+       fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
+       if (mailhead[SUBJ_TAG].found)
+               fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
+       else
+               fputs("Subject: Bug report acknowledgement.\n", pf);
+       if (mailhead[DATE_TAG].found)
+               fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
+       if (mailhead[MSG_TAG].found)
+               fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
+       fputs("Precedence: bulk\n\n", pf);      /* vacation(1) uses this... */
+       fflush(pf);
+
+       (void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
+       if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
+               while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
+                       (void)write(fileno(pf), bfr, rval);
+               (void)close(afd);
+       }
+       pclose(pf);
+}
diff --git a/usr/src/libexec/bugfiler/sendbug.1 b/usr/src/libexec/bugfiler/sendbug.1
new file mode 100644 (file)
index 0000000..aad2cb7
--- /dev/null
@@ -0,0 +1,85 @@
+.\" Copyright (c) 1983, 1990 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. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. 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.
+.\"
+.\"     @(#)sendbug.1  6.8 (Berkeley) 5/9/91
+.\"
+.Dd May 9, 1991
+.Dt SENDBUG 1
+.Os BSD 4.2
+.Sh NAME
+.Nm sendbug
+.Nd mail a system bug report to 386bsd_bugs
+.Sh SYNOPSIS
+.Nm sendbug
+.Op Ar address
+.Sh DESCRIPTION
+Bug reports sent to `386bsd_bugs@bsd.coe.montana.edu' are intercepted
+by a program which expects bug reports to conform to a standard format.
+.Nm Sendbug
+is a shell script to help the user compose and mail bug reports
+in the correct format.
+.Nm Sendbug
+works by invoking the editor specified by the environment variable
+.Ev EDITOR
+on a temporary copy of the bug report format outline. The user must fill in the
+appropriate fields and exit the editor.
+.Nm Sendbug
+then mails the completed report to `386bsd_bugs@bsd.coe.montana.edu' or the
+.Ar address
+specified on the command line.
+.Sh ENVIRONMENT
+.Nm Sendbug
+will utilize the following environment variable if it exists:
+.Bl -tag -width EDITOR
+.It Ev EDITOR
+Specifies the preferred editor. If
+.Ev EDITOR
+is not set,
+.Nm
+defaults to
+.Xr vi 1 .
+.El
+.Sh FILES
+.Bl -tag -width /usr/share/misc/bugformat -compact
+.It Pa /usr/share/misc/bugformat
+Contains the bug report outline.
+.El
+.Sh SEE ALSO
+.Xr vi 1 ,
+.Xr environ 7 ,
+.Xr bugfiler 8 ,
+.Xr sendmail 8
+.Sh HISTORY
+The
+.Nm sendbug
+command
+appeared in
+.Bx 4.2 .
diff --git a/usr/src/libexec/bugfiler/sendbug.sh b/usr/src/libexec/bugfiler/sendbug.sh
new file mode 100644 (file)
index 0000000..395cc3e
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh -
+#
+# Copyright (c) 1983 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. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by the University of
+#      California, Berkeley and its contributors.
+# 4. 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.
+#
+#      @(#)sendbug.sh  5.11 (Berkeley) 7/25/90
+#
+#  Modified to support 386bsd bugfiler running at bsd.coe.montana.edu
+#  by Rodney W. Grimes on April 4, 1993.
+#
+
+# create a bug report and mail it to 'bugs'.
+
+PATH=/bin:/sbin:/usr/sbin:/usr/bin
+export PATH
+
+TEMP=/tmp/bug$$
+FORMAT=/usr/share/misc/bugformat
+
+# uucp sites should use:
+#      ": ${BUGADDR=bsd.coe.montana.edu!386bsd_bugs}" with a suitable path.
+: ${BUGADDR=386bsd_bugs@bsd.coe.montana.edu}
+: ${EDITOR=vi}
+
+trap 'rm -f $TEMP ; exit 1' 1 2 3 13 15
+
+cp $FORMAT $TEMP
+chmod u+w $TEMP
+if $EDITOR $TEMP
+then
+       if cmp -s $FORMAT $TEMP
+       then
+               echo "File not changed, no bug report submitted."
+               exit
+       fi
+       case "$#" in
+       0) sendmail -t -oi $BUGADDR  < $TEMP ;;
+       *) sendmail -t -oi "$@" < $TEMP ;;
+       esac
+fi
+
+rm -f $TEMP
diff --git a/usr/src/libexec/uucpd/Makefile b/usr/src/libexec/uucpd/Makefile
new file mode 100644 (file)
index 0000000..3f3e1fa
--- /dev/null
@@ -0,0 +1,6 @@
+#      @(#)Makefile    5.3 (Berkeley) 6/25/90
+
+PROG=  uucpd
+NOMAN= noman
+
+.include <bsd.prog.mk>
diff --git a/usr/src/libexec/uucpd/pathnames.h b/usr/src/libexec/uucpd/pathnames.h
new file mode 100644 (file)
index 0000000..380c7ef
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 1989 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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 5.2 (Berkeley) 6/1/90
+ */
+
+#include <paths.h>
+
+#define        _PATH_UUCICO    "/usr/lib/uucp/uucico"
diff --git a/usr/src/libexec/uucpd/uucpd.c b/usr/src/libexec/uucpd/uucpd.c
new file mode 100644 (file)
index 0000000..76a994c
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 1985 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Adams.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)uucpd.c    5.10 (Berkeley) 2/26/91";
+#endif /* not lint */
+
+/*
+ * 4.2BSD TCP/IP server for uucico
+ * uucico's TCP channel causes this server to be run at the remote end.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <time.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pathnames.h"
+
+struct sockaddr_in hisctladdr;
+int hisaddrlen = sizeof hisctladdr;
+struct sockaddr_in myctladdr;
+int mypid;
+
+char Username[64];
+char *nenv[] = {
+       Username,
+       NULL,
+};
+extern char **environ;
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+#ifndef BSDINETD
+       register int s, tcp_socket;
+       struct servent *sp;
+#endif !BSDINETD
+       extern int errno;
+       int dologout();
+
+       environ = nenv;
+#ifdef BSDINETD
+       close(1); close(2);
+       dup(0); dup(0);
+       hisaddrlen = sizeof (hisctladdr);
+       if (getpeername(0, &hisctladdr, &hisaddrlen) < 0) {
+               fprintf(stderr, "%s: ", argv[0]);
+               perror("getpeername");
+               _exit(1);
+       }
+       if (fork() == 0)
+               doit(&hisctladdr);
+       dologout();
+       exit(1);
+#else !BSDINETD
+       sp = getservbyname("uucp", "tcp");
+       if (sp == NULL){
+               perror("uucpd: getservbyname");
+               exit(1);
+       }
+       if (fork())
+               exit(0);
+       if ((s=open(_PATH_TTY, 2)) >= 0){
+               ioctl(s, TIOCNOTTY, (char *)0);
+               close(s);
+       }
+
+       bzero((char *)&myctladdr, sizeof (myctladdr));
+       myctladdr.sin_family = AF_INET;
+       myctladdr.sin_port = sp->s_port;
+#ifdef BSD4_2
+       tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
+       if (tcp_socket < 0) {
+               perror("uucpd: socket");
+               exit(1);
+       }
+       if (bind(tcp_socket, (char *)&myctladdr, sizeof (myctladdr)) < 0) {
+               perror("uucpd: bind");
+               exit(1);
+       }
+       listen(tcp_socket, 3);  /* at most 3 simultaneuos uucp connections */
+       signal(SIGCHLD, dologout);
+
+       for(;;) {
+               s = accept(tcp_socket, &hisctladdr, &hisaddrlen);
+               if (s < 0){
+                       if (errno == EINTR) 
+                               continue;
+                       perror("uucpd: accept");
+                       exit(1);
+               }
+               if (fork() == 0) {
+                       close(0); close(1); close(2);
+                       dup(s); dup(s); dup(s);
+                       close(tcp_socket); close(s);
+                       doit(&hisctladdr);
+                       exit(1);
+               }
+               close(s);
+       }
+#endif BSD4_2
+
+#endif !BSDINETD
+}
+
+doit(sinp)
+struct sockaddr_in *sinp;
+{
+       char user[64], passwd[64];
+       char *xpasswd, *crypt();
+       struct passwd *pw, *getpwnam();
+
+       alarm(60);
+       printf("login: "); fflush(stdout);
+       if (readline(user, sizeof user) < 0) {
+               fprintf(stderr, "user read\n");
+               return;
+       }
+       /* truncate username to 8 characters */
+       user[8] = '\0';
+       pw = getpwnam(user);
+       if (pw == NULL) {
+               fprintf(stderr, "user unknown\n");
+               return;
+       }
+       if (strcmp(pw->pw_shell, _PATH_UUCICO)) {
+               fprintf(stderr, "Login incorrect.");
+               return;
+       }
+       if (pw->pw_passwd && *pw->pw_passwd != '\0') {
+               printf("Password: "); fflush(stdout);
+               if (readline(passwd, sizeof passwd) < 0) {
+                       fprintf(stderr, "passwd read\n");
+                       return;
+               }
+               xpasswd = crypt(passwd, pw->pw_passwd);
+               if (strcmp(xpasswd, pw->pw_passwd)) {
+                       fprintf(stderr, "Login incorrect.");
+                       return;
+               }
+       }
+       alarm(0);
+       sprintf(Username, "USER=%s", user);
+       dologin(pw, sinp);
+       setgid(pw->pw_gid);
+#ifdef BSD4_2
+       initgroups(pw->pw_name, pw->pw_gid);
+#endif BSD4_2
+       chdir(pw->pw_dir);
+       setuid(pw->pw_uid);
+#ifdef BSD4_2
+       execl(UUCICO, "uucico", (char *)0);
+#endif BSD4_2
+       perror("uucico server: execl");
+}
+
+readline(p, n)
+register char *p;
+register int n;
+{
+       char c;
+
+       while (n-- > 0) {
+               if (read(0, &c, 1) <= 0)
+                       return(-1);
+               c &= 0177;
+               if (c == '\n' || c == '\r') {
+                       *p = '\0';
+                       return(0);
+               }
+               *p++ = c;
+       }
+       return(-1);
+}
+
+#include <utmp.h>
+#ifdef BSD4_2
+#include <fcntl.h>
+#endif BSD4_2
+
+#define        SCPYN(a, b)     strncpy(a, b, sizeof (a))
+
+struct utmp utmp;
+
+dologout()
+{
+       union wait status;
+       int pid, wtmp;
+
+#ifdef BSDINETD
+       while ((pid=wait((int *)&status)) > 0) {
+#else  !BSDINETD
+       while ((pid=wait3((int *)&status,WNOHANG,0)) > 0) {
+#endif !BSDINETD
+               wtmp = open(_PATH_WTMP, O_WRONLY|O_APPEND);
+               if (wtmp >= 0) {
+                       sprintf(utmp.ut_line, "uucp%.4d", pid);
+                       SCPYN(utmp.ut_name, "");
+                       SCPYN(utmp.ut_host, "");
+                       (void) time(&utmp.ut_time);
+                       (void) write(wtmp, (char *)&utmp, sizeof (utmp));
+                       (void) close(wtmp);
+               }
+       }
+}
+
+/*
+ * Record login in wtmp file.
+ */
+dologin(pw, sin)
+struct passwd *pw;
+struct sockaddr_in *sin;
+{
+       char line[32];
+       char remotehost[32];
+       int wtmp, f;
+       struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
+               sizeof (struct in_addr), AF_INET);
+
+       if (hp) {
+               strncpy(remotehost, hp->h_name, sizeof (remotehost));
+               endhostent();
+       } else
+               strncpy(remotehost, inet_ntoa(sin->sin_addr),
+                   sizeof (remotehost));
+       wtmp = open(_PATH_WTMP, O_WRONLY|O_APPEND);
+       if (wtmp >= 0) {
+               /* hack, but must be unique and no tty line */
+               sprintf(line, "uucp%.4d", getpid());
+               SCPYN(utmp.ut_line, line);
+               SCPYN(utmp.ut_name, pw->pw_name);
+               SCPYN(utmp.ut_host, remotehost);
+               time(&utmp.ut_time);
+               (void) write(wtmp, (char *)&utmp, sizeof (utmp));
+               (void) close(wtmp);
+       }
+       if ((f = open(_PATH_LASTLOG, O_RDWR)) >= 0) {
+               struct lastlog ll;
+
+               time(&ll.ll_time);
+               lseek(f, (long)pw->pw_uid * sizeof(struct lastlog), 0);
+               strcpy(line, remotehost);
+               SCPYN(ll.ll_line, line);
+               SCPYN(ll.ll_host, remotehost);
+               (void) write(f, (char *) &ll, sizeof ll);
+               (void) close(f);
+       }
+}