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