125388Sbloom /* 230157Sbostic * Copyright (c) 1983, 1986 Regents of the University of California. 325388Sbloom * All rights reserved. The Berkeley software License Agreement 425388Sbloom * specifies the terms and conditions for redistribution. 525388Sbloom */ 625388Sbloom 714552Ssam #ifndef lint 825388Sbloom char copyright[] = 930157Sbostic "@(#) Copyright (c) 1983, 1986 Regents of the University of California.\n\ 1025388Sbloom All rights reserved.\n"; 1125388Sbloom #endif not lint 1214552Ssam 1325388Sbloom #ifndef lint 14*30895Sbostic static char sccsid[] = "@(#)bugfiler.c 5.8 (Berkeley) 87/04/11"; 1525388Sbloom #endif not lint 1625388Sbloom 1712375Sralph /* 1830157Sbostic * Bug report processing program, designed to be invoked 1930157Sbostic * through aliases(5). 2012375Sralph */ 2130157Sbostic #include <bug.h> 2230157Sbostic #include <sys/time.h> 2330890Sbostic #include <sys/file.h> 2430890Sbostic #include <pwd.h> 2512375Sralph #include <stdio.h> 2614809Ssam 2730157Sbostic char bfr[MAXBSIZE], /* general I/O buffer */ 2830157Sbostic tmpname[sizeof(TMP_BUG) + 5]; /* temp bug file */ 2914809Ssam 3030890Sbostic main(argc, argv) 3130890Sbostic int argc; 3230890Sbostic char **argv; 3312375Sralph { 3430890Sbostic extern char *optarg; /* getopt arguments */ 3530157Sbostic register struct passwd *pwd; /* bugs password entry */ 3630157Sbostic register int ch; /* getopts char */ 3730890Sbostic int do_ack, /* acknowledge bug report */ 3830890Sbostic do_redist; /* redistribut BR */ 39*30895Sbostic char *argversion, /* folder name provided */ 4030890Sbostic *strcpy(); 4130157Sbostic struct passwd *getpwnam(); 4212375Sralph 4330890Sbostic do_ack = do_redist = YES; 44*30895Sbostic argversion = NULL; 45*30895Sbostic while ((ch = getopt(argc, argv, "av:r")) != EOF) 4630157Sbostic switch((char)ch) { 4730890Sbostic case 'a': 4830890Sbostic do_ack = NO; 4930890Sbostic break; 50*30895Sbostic case 'v': 51*30895Sbostic argversion = optarg; 5230890Sbostic break; 5330890Sbostic case 'r': 5430890Sbostic do_redist = NO; 5530890Sbostic break; 5630890Sbostic case '?': 5730890Sbostic default: 58*30895Sbostic error("usage: bugfiler [-ar] [-v version]", CHN); 5914809Ssam } 6012695Sralph 6130157Sbostic if (!(pwd = getpwnam(BUGS_ID))) 6230890Sbostic error("can't find bugs login.", BUGS_ID); 6312375Sralph 6430890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 6530890Sbostic error("can't chdir to %s.", pwd->pw_dir); 6612695Sralph 6730890Sbostic if (setreuid(0, pwd->pw_uid)) 6830890Sbostic error("can't set id to %s.", BUGS_ID); 6912695Sralph 7030890Sbostic (void)umask(2); /* everything is 664 */ 7130890Sbostic seterr(); /* redirect to log file */ 7230890Sbostic logit(); /* log report arrival */ 7330890Sbostic make_copy(); /* save copy in case */ 7430890Sbostic gethead(do_redist); 7512375Sralph 76*30895Sbostic if (argversion) /* specific folder requested */ 77*30895Sbostic (void)strcpy(dir, argversion); 7812375Sralph 7930157Sbostic process(); 8012375Sralph 8130890Sbostic if (setuid(0, 0)) 8230890Sbostic error("can't set id to root.", CHN); 8330157Sbostic if (do_ack) 8430157Sbostic reply(); 8530157Sbostic if (do_redist) 8630157Sbostic redist(); 8730890Sbostic (void)unlink(tmpname); 8830157Sbostic exit(OK); 8912375Sralph } 9012375Sralph 9112375Sralph /* 9230157Sbostic * make_copy -- 9330890Sbostic * make a copy of bug report in error folder 9412695Sralph */ 9530157Sbostic static 9630157Sbostic make_copy() 9712695Sralph { 9830157Sbostic register int cnt, /* read return value */ 9930157Sbostic tfd; /* temp file descriptor */ 10030890Sbostic char *strcpy(); 10112695Sralph 10230890Sbostic (void)strcpy(tmpname, TMP_BUG); 10330890Sbostic if (tfd = mkstemp(tmpname)) { 10430890Sbostic while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 10530890Sbostic write(tfd, bfr, cnt); 10630890Sbostic (void)close(tfd); 10730890Sbostic return; 10830890Sbostic } 10930890Sbostic error("can't make copy using %s.\n", tmpname); 11012375Sralph } 11112375Sralph 11212375Sralph /* 11330157Sbostic * logit -- 11430157Sbostic * log this run of the bugfiler 11514809Ssam */ 11630157Sbostic static 11730157Sbostic logit() 11814809Ssam { 11930157Sbostic struct timeval tp; 12030157Sbostic char *ctime(); 12114809Ssam 12230890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL)) 12330890Sbostic error("can't get time of day.", CHN); 12430890Sbostic fprintf(stderr, "\n>>> BUGFILER <<<\n\t%s", ctime(&tp.tv_sec)); 12514809Ssam } 126