xref: /csrg-svn/libexec/bugfiler/bugfiler.c (revision 42663)
125388Sbloom /*
233416Sbostic  * Copyright (c) 1983, 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
5*42663Sbostic  * %sccs.include.redist.c%
625388Sbloom  */
725388Sbloom 
814552Ssam #ifndef lint
925388Sbloom char copyright[] =
1033416Sbostic "@(#) Copyright (c) 1983, 1986, 1987 Regents of the University of California.\n\
1125388Sbloom  All rights reserved.\n";
1233416Sbostic #endif /* not lint */
1314552Ssam 
1425388Sbloom #ifndef lint
15*42663Sbostic static char sccsid[] = "@(#)bugfiler.c	5.15 (Berkeley) 06/01/90";
1633416Sbostic #endif /* not lint */
1725388Sbloom 
1812375Sralph /*
1930157Sbostic  * Bug report processing program, designed to be invoked
2030157Sbostic  * through aliases(5).
2112375Sralph  */
2230157Sbostic #include <bug.h>
2330157Sbostic #include <sys/time.h>
2430890Sbostic #include <sys/file.h>
2530890Sbostic #include <pwd.h>
2612375Sralph #include <stdio.h>
2714809Ssam 
2830157Sbostic char	bfr[MAXBSIZE],			/* general I/O buffer */
2930157Sbostic 	tmpname[sizeof(TMP_BUG) + 5];	/* temp bug file */
3014809Ssam 
3130890Sbostic main(argc, argv)
3230890Sbostic 	int	argc;
3330890Sbostic 	char	**argv;
3412375Sralph {
3530890Sbostic 	extern char	*optarg;	/* getopt arguments */
3630157Sbostic 	register struct passwd	*pwd;	/* bugs password entry */
3730157Sbostic 	register int	ch;		/* getopts char */
3830890Sbostic 	int	do_ack,			/* acknowledge bug report */
3930890Sbostic 		do_redist;		/* redistribut BR */
4030895Sbostic 	char	*argversion,		/* folder name provided */
4130890Sbostic 		*strcpy();
4230157Sbostic 	struct passwd	*getpwnam();
4312375Sralph 
4430890Sbostic 	do_ack = do_redist = YES;
4530895Sbostic 	argversion = NULL;
4630895Sbostic 	while ((ch = getopt(argc, argv, "av:r")) != EOF)
4730157Sbostic 		switch((char)ch) {
4830890Sbostic 		case 'a':
4930890Sbostic 			do_ack = NO;
5030890Sbostic 			break;
5130895Sbostic 		case 'v':
5230895Sbostic 			argversion = optarg;
5330890Sbostic 			break;
5430890Sbostic 		case 'r':
5530890Sbostic 			do_redist = NO;
5630890Sbostic 			break;
5730890Sbostic 		case '?':
5830890Sbostic 		default:
5932274Sbostic 			fputs("usage: bugfiler [-ar] [-v version]\n", stderr);
6030895Sbostic 			error("usage: bugfiler [-ar] [-v version]", CHN);
6114809Ssam 		}
6212695Sralph 
6330157Sbostic 	if (!(pwd = getpwnam(BUGS_ID)))
6430890Sbostic 		error("can't find bugs login.", BUGS_ID);
6512375Sralph 
6630890Sbostic 	if (chdir(pwd->pw_dir))		/* change to bugs home directory */
6730890Sbostic 		error("can't chdir to %s.", pwd->pw_dir);
6812695Sralph 
6930890Sbostic 	if (setreuid(0, pwd->pw_uid))
7030890Sbostic 		error("can't set id to %s.", BUGS_ID);
7112695Sralph 
7230948Sbostic 	(void)umask(02);		/* everything is 664 */
7330890Sbostic 	seterr();			/* redirect to log file */
7430890Sbostic 	logit();			/* log report arrival */
7530890Sbostic 	make_copy();			/* save copy in case */
7630890Sbostic 	gethead(do_redist);
7712375Sralph 
7830895Sbostic 	if (argversion)			/* specific folder requested */
7930895Sbostic 		(void)strcpy(dir, argversion);
8012375Sralph 
8130157Sbostic 	process();
8212375Sralph 
8330890Sbostic 	if (setuid(0, 0))
8430890Sbostic 		error("can't set id to root.", CHN);
8530157Sbostic 	if (do_ack)
8630157Sbostic 		reply();
8730157Sbostic 	if (do_redist)
8830157Sbostic 		redist();
8930890Sbostic 	(void)unlink(tmpname);
9030157Sbostic 	exit(OK);
9112375Sralph }
9212375Sralph 
9312375Sralph /*
9430157Sbostic  * make_copy --
9530890Sbostic  *	make a copy of bug report in error folder
9612695Sralph  */
9730157Sbostic static
9830157Sbostic make_copy()
9912695Sralph {
10030157Sbostic 	register int	cnt,			/* read return value */
10130157Sbostic 			tfd;			/* temp file descriptor */
10230890Sbostic 	char	*strcpy();
10312695Sralph 
10431911Sbostic 	if (access(TMP_DIR, F_OK)) {
10531911Sbostic 		(void)mkdir(TMP_DIR);
10631911Sbostic 		(void)chmod(TMP_DIR, 0775);
10731911Sbostic 	}
10830890Sbostic 	(void)strcpy(tmpname, TMP_BUG);
10930890Sbostic 	if (tfd = mkstemp(tmpname)) {
11030890Sbostic 		while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt)
11130890Sbostic 			write(tfd, bfr, cnt);
11230890Sbostic 		(void)close(tfd);
11330890Sbostic 		return;
11430890Sbostic 	}
11531917Sbostic 	error("can't make copy using %s.", tmpname);
11612375Sralph }
11712375Sralph 
11812375Sralph /*
11930157Sbostic  * logit --
12030157Sbostic  *	log this run of the bugfiler
12114809Ssam  */
12230157Sbostic static
12330157Sbostic logit()
12414809Ssam {
12530157Sbostic 	struct timeval	tp;
12631917Sbostic 	char	*C1, *C2,
12731917Sbostic 		*ctime();
12814809Ssam 
12930890Sbostic 	if (gettimeofday(&tp, (struct timezone *)NULL))
13030890Sbostic 		error("can't get time of day.", CHN);
13131917Sbostic 	for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1);
13231917Sbostic 	*C1 = EOS;
13331917Sbostic 	fputs(C2, stderr);
13414809Ssam }
135