1 /* 2 * Copyright (c) 1983, 1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 char copyright[] = 9 "@(#) Copyright (c) 1983, 1986 Regents of the University of California.\n\ 10 All rights reserved.\n"; 11 #endif not lint 12 13 #ifndef lint 14 static char sccsid[] = "@(#)bugfiler.c 5.7 (Berkeley) 87/04/11"; 15 #endif not lint 16 17 /* 18 * Bug report processing program, designed to be invoked 19 * through aliases(5). 20 */ 21 #include <bug.h> 22 #include <sys/time.h> 23 #include <sys/file.h> 24 #include <pwd.h> 25 #include <stdio.h> 26 27 char bfr[MAXBSIZE], /* general I/O buffer */ 28 tmpname[sizeof(TMP_BUG) + 5]; /* temp bug file */ 29 30 main(argc, argv) 31 int argc; 32 char **argv; 33 { 34 extern char *optarg; /* getopt arguments */ 35 register struct passwd *pwd; /* bugs password entry */ 36 register int ch; /* getopts char */ 37 int do_ack, /* acknowledge bug report */ 38 do_redist; /* redistribut BR */ 39 char *argfolder, /* folder name provided */ 40 *strcpy(); 41 struct passwd *getpwnam(); 42 43 do_ack = do_redist = YES; 44 argfolder = NULL; 45 while ((ch = getopt(argc, argv, "af:r")) != EOF) 46 switch((char)ch) { 47 case 'a': 48 do_ack = NO; 49 break; 50 case 'f': 51 argfolder = optarg; 52 break; 53 case 'r': 54 do_redist = NO; 55 break; 56 case '?': 57 default: 58 error("usage: bugfiler [-ar] [-f folder]", CHN); 59 } 60 61 if (!(pwd = getpwnam(BUGS_ID))) 62 error("can't find bugs login.", BUGS_ID); 63 64 if (chdir(pwd->pw_dir)) /* change to bugs home directory */ 65 error("can't chdir to %s.", pwd->pw_dir); 66 67 if (setreuid(0, pwd->pw_uid)) 68 error("can't set id to %s.", BUGS_ID); 69 70 (void)umask(2); /* everything is 664 */ 71 seterr(); /* redirect to log file */ 72 logit(); /* log report arrival */ 73 make_copy(); /* save copy in case */ 74 gethead(do_redist); 75 76 if (argfolder) /* specific folder requested */ 77 (void)strcpy(dir, argfolder); 78 79 process(); 80 81 if (setuid(0, 0)) 82 error("can't set id to root.", CHN); 83 if (do_ack) 84 reply(); 85 if (do_redist) 86 redist(); 87 (void)unlink(tmpname); 88 exit(OK); 89 } 90 91 /* 92 * make_copy -- 93 * make a copy of bug report in error folder 94 */ 95 static 96 make_copy() 97 { 98 register int cnt, /* read return value */ 99 tfd; /* temp file descriptor */ 100 char *strcpy(); 101 102 (void)strcpy(tmpname, TMP_BUG); 103 if (tfd = mkstemp(tmpname)) { 104 while ((cnt = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && cnt) 105 write(tfd, bfr, cnt); 106 (void)close(tfd); 107 return; 108 } 109 error("can't make copy using %s.\n", tmpname); 110 } 111 112 /* 113 * logit -- 114 * log this run of the bugfiler 115 */ 116 static 117 logit() 118 { 119 struct timeval tp; 120 char *ctime(); 121 122 if (gettimeofday(&tp, (struct timezone *)NULL)) 123 error("can't get time of day.", CHN); 124 fprintf(stderr, "\n>>> BUGFILER <<<\n\t%s", ctime(&tp.tv_sec)); 125 } 126