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