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