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