125388Sbloom /* 233416Sbostic * Copyright (c) 1983, 1986, 1987 Regents of the University of California. 333416Sbostic * All rights reserved. 433416Sbostic * 542663Sbostic * %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*46667Sbostic static char sccsid[] = "@(#)bugfiler.c 5.16 (Berkeley) 02/25/91"; 1633416Sbostic #endif /* not lint */ 1725388Sbloom 1812375Sralph /* 1930157Sbostic * Bug report processing program, designed to be invoked 2030157Sbostic * through aliases(5). 2112375Sralph */ 22*46667Sbostic #include <sys/param.h> 2330157Sbostic #include <sys/time.h> 24*46667Sbostic #include <sys/stat.h> 25*46667Sbostic #include <dirent.h> 2630890Sbostic #include <pwd.h> 27*46667Sbostic #include <unistd.h> 2812375Sralph #include <stdio.h> 29*46667Sbostic #include <stdlib.h> 30*46667Sbostic #include <string.h> 31*46667Sbostic #include "bug.h" 3214809Ssam 3330157Sbostic char bfr[MAXBSIZE], /* general I/O buffer */ 3430157Sbostic tmpname[sizeof(TMP_BUG) + 5]; /* temp bug file */ 3514809Ssam 3630890Sbostic main(argc, argv) 3730890Sbostic int argc; 3830890Sbostic char **argv; 3912375Sralph { 4030890Sbostic extern char *optarg; /* getopt arguments */ 4130157Sbostic register struct passwd *pwd; /* bugs password entry */ 4230157Sbostic register int ch; /* getopts char */ 4330890Sbostic int do_ack, /* acknowledge bug report */ 4430890Sbostic do_redist; /* redistribut BR */ 45*46667Sbostic char *argversion; /* folder name provided */ 46*46667Sbostic static void logit(), make_copy(); 4712375Sralph 4830890Sbostic do_ack = do_redist = YES; 4930895Sbostic argversion = NULL; 5030895Sbostic while ((ch = getopt(argc, argv, "av:r")) != EOF) 5130157Sbostic switch((char)ch) { 5230890Sbostic case 'a': 5330890Sbostic do_ack = NO; 5430890Sbostic break; 5530895Sbostic case 'v': 5630895Sbostic argversion = optarg; 5730890Sbostic break; 5830890Sbostic case 'r': 5930890Sbostic do_redist = NO; 6030890Sbostic break; 6130890Sbostic case '?': 6230890Sbostic default: 6332274Sbostic fputs("usage: bugfiler [-ar] [-v version]\n", stderr); 6430895Sbostic error("usage: bugfiler [-ar] [-v version]", CHN); 6514809Ssam } 6612695Sralph 6730157Sbostic if (!(pwd = getpwnam(BUGS_ID))) 6830890Sbostic error("can't find bugs login.", BUGS_ID); 6912375Sralph 7030890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 7130890Sbostic error("can't chdir to %s.", pwd->pw_dir); 7212695Sralph 7330890Sbostic if (setreuid(0, pwd->pw_uid)) 7430890Sbostic error("can't set id to %s.", BUGS_ID); 7512695Sralph 7630948Sbostic (void)umask(02); /* everything is 664 */ 7730890Sbostic seterr(); /* redirect to log file */ 7830890Sbostic logit(); /* log report arrival */ 7930890Sbostic make_copy(); /* save copy in case */ 8030890Sbostic gethead(do_redist); 8112375Sralph 8230895Sbostic if (argversion) /* specific folder requested */ 8330895Sbostic (void)strcpy(dir, argversion); 8412375Sralph 8530157Sbostic process(); 8612375Sralph 87*46667Sbostic if (setuid(0)) 8830890Sbostic error("can't set id to root.", CHN); 8930157Sbostic if (do_ack) 9030157Sbostic reply(); 9130157Sbostic if (do_redist) 9230157Sbostic redist(); 9330890Sbostic (void)unlink(tmpname); 9430157Sbostic exit(OK); 9512375Sralph } 9612375Sralph 9712375Sralph /* 9830157Sbostic * make_copy -- 9930890Sbostic * make a copy of bug report in error folder 10012695Sralph */ 101*46667Sbostic static void 10230157Sbostic make_copy() 10312695Sralph { 10430157Sbostic register int cnt, /* read return value */ 10530157Sbostic tfd; /* temp file descriptor */ 10630890Sbostic char *strcpy(); 10712695Sralph 108*46667Sbostic if (access(TMP_DIR, F_OK)) 109*46667Sbostic (void)mkdir(TMP_DIR, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH); 11030890Sbostic (void)strcpy(tmpname, TMP_BUG); 11130890Sbostic if (tfd = mkstemp(tmpname)) { 11230890Sbostic while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 11330890Sbostic write(tfd, bfr, cnt); 11430890Sbostic (void)close(tfd); 11530890Sbostic return; 11630890Sbostic } 11731917Sbostic error("can't make copy using %s.", tmpname); 11812375Sralph } 11912375Sralph 12012375Sralph /* 12130157Sbostic * logit -- 12230157Sbostic * log this run of the bugfiler 12314809Ssam */ 124*46667Sbostic static void 12530157Sbostic logit() 12614809Ssam { 12730157Sbostic struct timeval tp; 12831917Sbostic char *C1, *C2, 12931917Sbostic *ctime(); 13014809Ssam 13130890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL)) 13230890Sbostic error("can't get time of day.", CHN); 13331917Sbostic for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1); 13431917Sbostic *C1 = EOS; 13531917Sbostic fputs(C2, stderr); 13614809Ssam } 137