125388Sbloom /*
2*61420Sbostic * Copyright (c) 1983, 1986, 1987, 1993
3*61420Sbostic * The Regents of the University of California. All rights reserved.
433416Sbostic *
542663Sbostic * %sccs.include.redist.c%
625388Sbloom */
725388Sbloom
814552Ssam #ifndef lint
9*61420Sbostic static char copyright[] =
10*61420Sbostic "@(#) Copyright (c) 1983, 1986, 1987, 1993\n\
11*61420Sbostic The Regents of the University of California. All rights reserved.\n";
1233416Sbostic #endif /* not lint */
1314552Ssam
1425388Sbloom #ifndef lint
15*61420Sbostic static char sccsid[] = "@(#)bugfiler.c 8.1 (Berkeley) 06/04/93";
1633416Sbostic #endif /* not lint */
1725388Sbloom
1812375Sralph /*
1930157Sbostic * Bug report processing program, designed to be invoked
2030157Sbostic * through aliases(5).
2112375Sralph */
2246667Sbostic #include <sys/param.h>
2330157Sbostic #include <sys/time.h>
2446667Sbostic #include <sys/stat.h>
2560083Sbostic
2646667Sbostic #include <dirent.h>
2730890Sbostic #include <pwd.h>
2812375Sralph #include <stdio.h>
2946667Sbostic #include <stdlib.h>
3046667Sbostic #include <string.h>
3160083Sbostic #include <unistd.h>
3260083Sbostic
3346667Sbostic #include "bug.h"
3460083Sbostic #include "extern.h"
3514809Ssam
3630157Sbostic char bfr[MAXBSIZE], /* general I/O buffer */
3730157Sbostic tmpname[sizeof(TMP_BUG) + 5]; /* temp bug file */
3814809Ssam
3960083Sbostic static void logit __P((void));
4060083Sbostic static void make_copy __P((void));
4160083Sbostic
4260083Sbostic int
main(argc,argv)4330890Sbostic main(argc, argv)
4430890Sbostic int argc;
4560083Sbostic char *argv[];
4612375Sralph {
4730890Sbostic extern char *optarg; /* getopt arguments */
4830157Sbostic register struct passwd *pwd; /* bugs password entry */
4930157Sbostic register int ch; /* getopts char */
5030890Sbostic int do_ack, /* acknowledge bug report */
5130890Sbostic do_redist; /* redistribut BR */
5246667Sbostic char *argversion; /* folder name provided */
5312375Sralph
5430890Sbostic do_ack = do_redist = YES;
5530895Sbostic argversion = NULL;
5630895Sbostic while ((ch = getopt(argc, argv, "av:r")) != EOF)
5760083Sbostic switch(ch) {
5830890Sbostic case 'a':
5930890Sbostic do_ack = NO;
6030890Sbostic break;
6130895Sbostic case 'v':
6230895Sbostic argversion = optarg;
6330890Sbostic break;
6430890Sbostic case 'r':
6530890Sbostic do_redist = NO;
6630890Sbostic break;
6730890Sbostic case '?':
6830890Sbostic default:
6932274Sbostic fputs("usage: bugfiler [-ar] [-v version]\n", stderr);
7030895Sbostic error("usage: bugfiler [-ar] [-v version]", CHN);
7114809Ssam }
7212695Sralph
7330157Sbostic if (!(pwd = getpwnam(BUGS_ID)))
7430890Sbostic error("can't find bugs login.", BUGS_ID);
7512375Sralph
7630890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */
7730890Sbostic error("can't chdir to %s.", pwd->pw_dir);
7812695Sralph
7955695Sbostic if (seteuid(pwd->pw_uid))
8030890Sbostic error("can't set id to %s.", BUGS_ID);
8112695Sralph
8230948Sbostic (void)umask(02); /* everything is 664 */
8330890Sbostic seterr(); /* redirect to log file */
8430890Sbostic logit(); /* log report arrival */
8530890Sbostic make_copy(); /* save copy in case */
8630890Sbostic gethead(do_redist);
8712375Sralph
8830895Sbostic if (argversion) /* specific folder requested */
8930895Sbostic (void)strcpy(dir, argversion);
9012375Sralph
9130157Sbostic process();
9212375Sralph
9355695Sbostic if (seteuid(0))
9430890Sbostic error("can't set id to root.", CHN);
9530157Sbostic if (do_ack)
9630157Sbostic reply();
9730157Sbostic if (do_redist)
9830157Sbostic redist();
9930890Sbostic (void)unlink(tmpname);
10030157Sbostic exit(OK);
10112375Sralph }
10212375Sralph
10312375Sralph /*
10430157Sbostic * make_copy --
10530890Sbostic * make a copy of bug report in error folder
10612695Sralph */
10746667Sbostic static void
make_copy()10830157Sbostic make_copy()
10912695Sralph {
11030157Sbostic register int cnt, /* read return value */
11130157Sbostic tfd; /* temp file descriptor */
11212695Sralph
11346667Sbostic if (access(TMP_DIR, F_OK))
11446667Sbostic (void)mkdir(TMP_DIR, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
11530890Sbostic (void)strcpy(tmpname, TMP_BUG);
11630890Sbostic if (tfd = mkstemp(tmpname)) {
11760083Sbostic while ((cnt = read(fileno(stdin),
11860083Sbostic bfr, sizeof(bfr))) != ERR && cnt)
11930890Sbostic write(tfd, bfr, cnt);
12030890Sbostic (void)close(tfd);
12130890Sbostic return;
12230890Sbostic }
12331917Sbostic error("can't make copy using %s.", tmpname);
12412375Sralph }
12512375Sralph
12612375Sralph /*
12730157Sbostic * logit --
12830157Sbostic * log this run of the bugfiler
12914809Ssam */
13046667Sbostic static void
logit()13130157Sbostic logit()
13214809Ssam {
13330157Sbostic struct timeval tp;
13460083Sbostic char *C1, *C2;
13514809Ssam
13630890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL))
13730890Sbostic error("can't get time of day.", CHN);
13831917Sbostic for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1);
13931917Sbostic *C1 = EOS;
14031917Sbostic fputs(C2, stderr);
14114809Ssam }
142