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*32274Sbostic static char sccsid[] = "@(#)bugfiler.c 5.12 (Berkeley) 87/09/29"; 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 */ 3930895Sbostic char *argversion, /* folder name provided */ 4030890Sbostic *strcpy(); 4130157Sbostic struct passwd *getpwnam(); 4212375Sralph 4330890Sbostic do_ack = do_redist = YES; 4430895Sbostic argversion = NULL; 4530895Sbostic while ((ch = getopt(argc, argv, "av:r")) != EOF) 4630157Sbostic switch((char)ch) { 4730890Sbostic case 'a': 4830890Sbostic do_ack = NO; 4930890Sbostic break; 5030895Sbostic case 'v': 5130895Sbostic argversion = optarg; 5230890Sbostic break; 5330890Sbostic case 'r': 5430890Sbostic do_redist = NO; 5530890Sbostic break; 5630890Sbostic case '?': 5730890Sbostic default: 58*32274Sbostic fputs("usage: bugfiler [-ar] [-v version]\n", stderr); 5930895Sbostic error("usage: bugfiler [-ar] [-v version]", CHN); 6014809Ssam } 6112695Sralph 6230157Sbostic if (!(pwd = getpwnam(BUGS_ID))) 6330890Sbostic error("can't find bugs login.", BUGS_ID); 6412375Sralph 6530890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 6630890Sbostic error("can't chdir to %s.", pwd->pw_dir); 6712695Sralph 6830890Sbostic if (setreuid(0, pwd->pw_uid)) 6930890Sbostic error("can't set id to %s.", BUGS_ID); 7012695Sralph 7130948Sbostic (void)umask(02); /* everything is 664 */ 7230890Sbostic seterr(); /* redirect to log file */ 7330890Sbostic logit(); /* log report arrival */ 7430890Sbostic make_copy(); /* save copy in case */ 7530890Sbostic gethead(do_redist); 7612375Sralph 7730895Sbostic if (argversion) /* specific folder requested */ 7830895Sbostic (void)strcpy(dir, argversion); 7912375Sralph 8030157Sbostic process(); 8112375Sralph 8230890Sbostic if (setuid(0, 0)) 8330890Sbostic error("can't set id to root.", CHN); 8430157Sbostic if (do_ack) 8530157Sbostic reply(); 8630157Sbostic if (do_redist) 8730157Sbostic redist(); 8830890Sbostic (void)unlink(tmpname); 8930157Sbostic exit(OK); 9012375Sralph } 9112375Sralph 9212375Sralph /* 9330157Sbostic * make_copy -- 9430890Sbostic * make a copy of bug report in error folder 9512695Sralph */ 9630157Sbostic static 9730157Sbostic make_copy() 9812695Sralph { 9930157Sbostic register int cnt, /* read return value */ 10030157Sbostic tfd; /* temp file descriptor */ 10130890Sbostic char *strcpy(); 10212695Sralph 10331911Sbostic if (access(TMP_DIR, F_OK)) { 10431911Sbostic (void)mkdir(TMP_DIR); 10531911Sbostic (void)chmod(TMP_DIR, 0775); 10631911Sbostic } 10730890Sbostic (void)strcpy(tmpname, TMP_BUG); 10830890Sbostic if (tfd = mkstemp(tmpname)) { 10930890Sbostic while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 11030890Sbostic write(tfd, bfr, cnt); 11130890Sbostic (void)close(tfd); 11230890Sbostic return; 11330890Sbostic } 11431917Sbostic error("can't make copy using %s.", tmpname); 11512375Sralph } 11612375Sralph 11712375Sralph /* 11830157Sbostic * logit -- 11930157Sbostic * log this run of the bugfiler 12014809Ssam */ 12130157Sbostic static 12230157Sbostic logit() 12314809Ssam { 12430157Sbostic struct timeval tp; 12531917Sbostic char *C1, *C2, 12631917Sbostic *ctime(); 12714809Ssam 12830890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL)) 12930890Sbostic error("can't get time of day.", CHN); 13031917Sbostic for (C1 = C2 = ctime(&tp.tv_sec); *C1 && *C1 != '\n'; ++C1); 13131917Sbostic *C1 = EOS; 13231917Sbostic fputs(C2, stderr); 13314809Ssam } 134