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*30890Sbostic static char sccsid[] = "@(#)bugfiler.c 5.7 (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> 23*30890Sbostic #include <sys/file.h> 24*30890Sbostic #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 30*30890Sbostic main(argc, argv) 31*30890Sbostic int argc; 32*30890Sbostic char **argv; 3312375Sralph { 34*30890Sbostic extern char *optarg; /* getopt arguments */ 3530157Sbostic register struct passwd *pwd; /* bugs password entry */ 3630157Sbostic register int ch; /* getopts char */ 37*30890Sbostic int do_ack, /* acknowledge bug report */ 38*30890Sbostic do_redist; /* redistribut BR */ 39*30890Sbostic char *argfolder, /* folder name provided */ 40*30890Sbostic *strcpy(); 4130157Sbostic struct passwd *getpwnam(); 4212375Sralph 43*30890Sbostic do_ack = do_redist = YES; 44*30890Sbostic argfolder = NULL; 45*30890Sbostic while ((ch = getopt(argc, argv, "af:r")) != EOF) 4630157Sbostic switch((char)ch) { 47*30890Sbostic case 'a': 48*30890Sbostic do_ack = NO; 49*30890Sbostic break; 50*30890Sbostic case 'f': 51*30890Sbostic argfolder = optarg; 52*30890Sbostic break; 53*30890Sbostic case 'r': 54*30890Sbostic do_redist = NO; 55*30890Sbostic break; 56*30890Sbostic case '?': 57*30890Sbostic default: 58*30890Sbostic error("usage: bugfiler [-ar] [-f folder]", CHN); 5914809Ssam } 6012695Sralph 6130157Sbostic if (!(pwd = getpwnam(BUGS_ID))) 62*30890Sbostic error("can't find bugs login.", BUGS_ID); 6312375Sralph 64*30890Sbostic if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 65*30890Sbostic error("can't chdir to %s.", pwd->pw_dir); 6612695Sralph 67*30890Sbostic if (setreuid(0, pwd->pw_uid)) 68*30890Sbostic error("can't set id to %s.", BUGS_ID); 6912695Sralph 70*30890Sbostic (void)umask(2); /* everything is 664 */ 71*30890Sbostic seterr(); /* redirect to log file */ 72*30890Sbostic logit(); /* log report arrival */ 73*30890Sbostic make_copy(); /* save copy in case */ 74*30890Sbostic gethead(do_redist); 7512375Sralph 76*30890Sbostic if (argfolder) /* specific folder requested */ 77*30890Sbostic (void)strcpy(dir, argfolder); 7812375Sralph 7930157Sbostic process(); 8012375Sralph 81*30890Sbostic if (setuid(0, 0)) 82*30890Sbostic error("can't set id to root.", CHN); 8330157Sbostic if (do_ack) 8430157Sbostic reply(); 8530157Sbostic if (do_redist) 8630157Sbostic redist(); 87*30890Sbostic (void)unlink(tmpname); 8830157Sbostic exit(OK); 8912375Sralph } 9012375Sralph 9112375Sralph /* 9230157Sbostic * make_copy -- 93*30890Sbostic * 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 */ 100*30890Sbostic char *strcpy(); 10112695Sralph 102*30890Sbostic (void)strcpy(tmpname, TMP_BUG); 103*30890Sbostic if (tfd = mkstemp(tmpname)) { 104*30890Sbostic while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 105*30890Sbostic write(tfd, bfr, cnt); 106*30890Sbostic (void)close(tfd); 107*30890Sbostic return; 108*30890Sbostic } 109*30890Sbostic 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 122*30890Sbostic if (gettimeofday(&tp, (struct timezone *)NULL)) 123*30890Sbostic error("can't get time of day.", CHN); 124*30890Sbostic fprintf(stderr, "\n>>> BUGFILER <<<\n\t%s", ctime(&tp.tv_sec)); 12514809Ssam } 126