125388Sbloom /* 2*33416Sbostic * Copyright (c) 1983, 1986, 1987 Regents of the University of California. 3*33416Sbostic * All rights reserved. 4*33416Sbostic * 5*33416Sbostic * Redistribution and use in source and binary forms are permitted 6*33416Sbostic * provided that this notice is preserved and that due credit is given 7*33416Sbostic * to the University of California at Berkeley. The name of the University 8*33416Sbostic * may not be used to endorse or promote products derived from this 9*33416Sbostic * software without specific prior written permission. This software 10*33416Sbostic * is provided ``as is'' without express or implied warranty. 1125388Sbloom */ 1225388Sbloom 1314552Ssam #ifndef lint 1425388Sbloom char copyright[] = 15*33416Sbostic "@(#) Copyright (c) 1983, 1986, 1987 Regents of the University of California.\n\ 1625388Sbloom All rights reserved.\n"; 17*33416Sbostic #endif /* not lint */ 1814552Ssam 1925388Sbloom #ifndef lint 20*33416Sbostic static char sccsid[] = "@(#)bugfiler.c 5.13 (Berkeley) 02/01/88"; 21*33416Sbostic #endif /* not lint */ 2225388Sbloom 23*33416Sbostic 2412375Sralph /* 2530157Sbostic * Bug report processing program, designed to be invoked 2630157Sbostic * through aliases(5). 2712375Sralph */ 2830157Sbostic #include <bug.h> 2930157Sbostic #include <sys/time.h> 3030890Sbostic #include <sys/file.h> 3130890Sbostic #include <pwd.h> 3212375Sralph #include <stdio.h> 3314809Ssam 3430157Sbostic char bfr[MAXBSIZE], /* general I/O buffer */ 3530157Sbostic tmpname[sizeof(TMP_BUG) + 5]; /* temp bug file */ 3614809Ssam 3730890Sbostic main(argc, argv) 3830890Sbostic int argc; 3930890Sbostic char **argv; 4012375Sralph { 4130890Sbostic extern char *optarg; /* getopt arguments */ 4230157Sbostic register struct passwd *pwd; /* bugs password entry */ 4330157Sbostic register int ch; /* getopts char */ 4430890Sbostic int do_ack, /* acknowledge bug report */ 4530890Sbostic do_redist; /* redistribut BR */ 4630895Sbostic char *argversion, /* folder name provided */ 4730890Sbostic *strcpy(); 4830157Sbostic struct passwd *getpwnam(); 4912375Sralph 5030890Sbostic do_ack = do_redist = YES; 5130895Sbostic argversion = NULL; 5230895Sbostic while ((ch = getopt(argc, argv, "av:r")) != EOF) 5330157Sbostic switch((char)ch) { 5430890Sbostic case 'a': 5530890Sbostic do_ack = NO; 5630890Sbostic break; 5730895Sbostic case 'v': 5830895Sbostic argversion = optarg; 5930890Sbostic break; 6030890Sbostic case 'r': 6130890Sbostic do_redist = NO; 6230890Sbostic break; 6330890Sbostic case '?': 6430890Sbostic default: 6532274Sbostic fputs("usage: bugfiler [-ar] [-v version]\n", stderr); 6630895Sbostic error("usage: bugfiler [-ar] [-v version]", CHN); 6714809Ssam } 6812695Sralph 6930157Sbostic if (!(pwd = getpwnam(BUGS_ID))) 7030890Sbostic error("can't find bugs login.", BUGS_ID); 7112375Sralph 7230890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 7330890Sbostic error("can't chdir to %s.", pwd->pw_dir); 7412695Sralph 7530890Sbostic if (setreuid(0, pwd->pw_uid)) 7630890Sbostic error("can't set id to %s.", BUGS_ID); 7712695Sralph 7830948Sbostic (void)umask(02); /* everything is 664 */ 7930890Sbostic seterr(); /* redirect to log file */ 8030890Sbostic logit(); /* log report arrival */ 8130890Sbostic make_copy(); /* save copy in case */ 8230890Sbostic gethead(do_redist); 8312375Sralph 8430895Sbostic if (argversion) /* specific folder requested */ 8530895Sbostic (void)strcpy(dir, argversion); 8612375Sralph 8730157Sbostic process(); 8812375Sralph 8930890Sbostic if (setuid(0, 0)) 9030890Sbostic error("can't set id to root.", CHN); 9130157Sbostic if (do_ack) 9230157Sbostic reply(); 9330157Sbostic if (do_redist) 9430157Sbostic redist(); 9530890Sbostic (void)unlink(tmpname); 9630157Sbostic exit(OK); 9712375Sralph } 9812375Sralph 9912375Sralph /* 10030157Sbostic * make_copy -- 10130890Sbostic * make a copy of bug report in error folder 10212695Sralph */ 10330157Sbostic static 10430157Sbostic make_copy() 10512695Sralph { 10630157Sbostic register int cnt, /* read return value */ 10730157Sbostic tfd; /* temp file descriptor */ 10830890Sbostic char *strcpy(); 10912695Sralph 11031911Sbostic if (access(TMP_DIR, F_OK)) { 11131911Sbostic (void)mkdir(TMP_DIR); 11231911Sbostic (void)chmod(TMP_DIR, 0775); 11331911Sbostic } 11430890Sbostic (void)strcpy(tmpname, TMP_BUG); 11530890Sbostic if (tfd = mkstemp(tmpname)) { 11630890Sbostic while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 11730890Sbostic write(tfd, bfr, cnt); 11830890Sbostic (void)close(tfd); 11930890Sbostic return; 12030890Sbostic } 12131917Sbostic error("can't make copy using %s.", tmpname); 12212375Sralph } 12312375Sralph 12412375Sralph /* 12530157Sbostic * logit -- 12630157Sbostic * log this run of the bugfiler 12714809Ssam */ 12830157Sbostic static 12930157Sbostic logit() 13014809Ssam { 13130157Sbostic struct timeval tp; 13231917Sbostic char *C1, *C2, 13331917Sbostic *ctime(); 13414809Ssam 13530890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL)) 13630890Sbostic error("can't get time of day.", CHN); 13731917Sbostic for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1); 13831917Sbostic *C1 = EOS; 13931917Sbostic fputs(C2, stderr); 14014809Ssam } 141