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