|
|
1.1 root 1: /* bbexp.c - expunge the BBoards area */
2:
3: #include "../h/mh.h"
4: #include "../h/dropsbr.h"
5: #include "../zotnet/bboards.h"
6: #include <pwd.h>
7: #include <signal.h>
8: #include <stdio.h>
9: #include <sys/types.h>
10: #include <sys/stat.h>
11:
12:
13: #define FIRST 12
14: #define SECOND 20
15:
16:
17: static int broken_pipe;
18:
19: int pipeser ();
20:
21:
22: struct passwd *getpwnam ();
23:
24: /* */
25:
26: /* ARGSUSED */
27:
28: main (argc, argv)
29: int argc;
30: char **argv;
31: {
32: int first = FIRST,
33: second = SECOND;
34: char *cp;
35: struct bboard *bb;
36: struct passwd *pw;
37:
38: invo_name = r1bindex (*argv++, '/');
39: m_foil (NULLCP);
40:
41: if ((pw = getpwnam (BBOARDS)) == NULL)
42: adios (NULLCP, "no entry for ~%s", BBOARDS);
43: if (pw -> pw_uid != geteuid ())
44: adios (NULLCP, "not running setuid to %s", BBOARDS);
45:
46: if (*argv && **argv == '-') {
47: if ((first = atoi (*argv + 1)) < 1)
48: first = FIRST;
49: argv++;
50: }
51: if (*argv && **argv == '-') {
52: if ((second = atoi (*argv + 1)) < 1)
53: second = SECOND;
54: argv++;
55: }
56:
57: (void) setbbent (SB_STAY);
58: if (*argv == NULL)
59: while (bb = getbbent ()) {
60: if ((bb -> bb_flags & BB_ARCH) & (BB_ASAV | BB_AREM))
61: process (bb, pw, first, second);
62: }
63: else
64: while (cp = *argv++)
65: if ((bb = getbbnam (cp)) || (bb = getbbaka (cp))) {
66: if ((bb -> bb_flags & BB_ARCH) & (BB_ASAV | BB_AREM))
67: process (bb, pw, first, second);
68: }
69: else
70: advise (NULLCP, "no such BBoard as %s", cp);
71: (void) endbbent ();
72:
73: exit (0);
74: }
75:
76: /* */
77:
78: static process(bb, pw, first, second)
79: struct bboard *bb;
80: struct passwd *pw;
81: int first,
82: second;
83: {
84: int fd,
85: td;
86: char *cp,
87: command[BUFSIZ],
88: tmpfil[BUFSIZ];
89: FILE * pf;
90:
91: if ((fd = lkopen (bb -> bb_file, 6)) == NOTOK) {
92: advise (bb -> bb_file, "unable to lock and open");
93: return;
94: }
95:
96: (void) sprintf (tmpfil, "%s/#bbexpXXXXXX", pw -> pw_dir);
97: (void) unlink (mktemp (tmpfil));
98: if ((td = creat (tmpfil, 0600)) == NOTOK) {
99: advise (tmpfil, "unable to create");
100: goto out1;
101: }
102: (void) close (td);
103: if ((td = creat (cp = map_name (tmpfil), 0600)) == NOTOK) {
104: advise (cp, "unable to create");
105: goto out2;
106: }
107: (void) close (td);
108:
109: (void) sprintf (command, "%s %s%s", mshproc, bb -> bb_file,
110: isatty (fileno (stdout)) ? " 2>&1 | cat" : "");
111: printf ("%s (%s old messages)\n", command,
112: (bb -> bb_flags & BB_ARCH) == BB_ASAV ? "archive" : "remove");
113: (void) fflush (stdout);
114: if ((pf = popen (command, "w")) == NULL) {
115: advise (NULLCP, "unable to popen \"%s\" for writing", command);
116: goto out3;
117: }
118: (void) signal (SIGPIPE, pipeser);
119: broken_pipe = 0;
120:
121: fprintf (pf, "pick %s -before -%d -sequence select -zero\n",
122: "-datefield BB-Posted", first);
123: fprintf (pf, "pick -before -%d -sequence select -nozero\n", second);
124: fprintf (pf, "scan select\n");
125: if ((bb -> bb_flags & BB_ARCH) == BB_ASAV)
126: fprintf (pf, "pack select -file %s\n", bb -> bb_archive);
127: fprintf (pf, "rmm select\n");
128: fprintf (pf, "pack all -file %s\n", tmpfil);
129: fprintf (pf, "quit\n");
130: if (td = pclose (pf))
131: advise (NULLCP, "msh returns %d", td);
132: (void) signal (SIGPIPE, SIG_DFL);
133:
134: if (move (tmpfil, bb -> bb_file) != NOTOK)
135: (void) move (cp, bb -> bb_map);
136:
137: out3: ;
138: (void) unlink (cp);
139: out2: ;
140: (void) unlink (tmpfil);
141: out1: ;
142: (void) lkclose (fd, bb -> bb_file);
143: }
144:
145: /* */
146:
147: static int move (input, output)
148: char *input,
149: *output;
150: {
151: int i,
152: in,
153: out;
154: struct stat st1,
155: st2;
156:
157: if ((in = open (input, 0)) == NOTOK) {
158: advise (input, "unable to re-open");
159: return NOTOK;
160: }
161:
162: i = stat (output, &st1);
163: if ((out = creat (output, BBMODE)) == NOTOK) {
164: advise (output, "unable to re-create");
165: return NOTOK;
166: }
167: if (i != NOTOK && chmod (output, (int) (st1.st_mode & 0777)) == NOTOK)
168: admonish (output, "unable to change mode of");
169: if (i != NOTOK && stat (output, &st2) != NOTOK && st2.st_gid != st1.st_gid)
170: chgrp (output, st1.st_gid);
171:
172: cpydata (in, out, input, output);
173:
174: (void) close (in);
175: (void) close (out);
176:
177: return OK;
178: }
179:
180: /* */
181:
182: static chgrp (file, gid)
183: char *file;
184: short gid;
185: {
186: int child_id;
187: char group[BUFSIZ];
188:
189: switch (child_id = fork ()) {
190: case NOTOK:
191: admonish ("fork", "unable to");
192: return;
193:
194: case OK:
195: (void) setuid (geteuid ());
196: (void) sprintf (group, "%d", gid);
197: execlp ("/bin/chgrp", chgrp, group, file, NULLCP);
198: fprintf (stderr, "unable to exec ");
199: perror ("/bin/chgrp");
200: _exit (1);
201:
202: default:
203: (void) pidwait (child_id, OK);
204: break;
205: }
206: }
207:
208: /* */
209:
210: /* ARGSUSED */
211:
212: static int pipeser (i)
213: int i;
214: {
215: #ifndef BSD42
216: (void) signal (SIGPIPE, pipeser);
217: #endif not BSD42
218:
219: if (!broken_pipe++)
220: advise (NULLCP, "broken pipe");
221: }
222:
223: /* */
224:
225: #ifdef notdef
226:
227: /* This is the OLD way of doing it */
228:
229: bbremove.sh
230: : run this script through /bin/sh
231: pick +bbl -before -12 -datefield BB-Posted -sequence select -zero
232: pick +bbl -before -20 -sequence select -nozero
233: scan select; refile -src +bbl select +bbl/arc
234: rmf +bbl/arc
235:
236: bbsave.sh
237: : run this script through /bin/sh
238: pick +bbl -before -12 -datefield BB-Posted -sequence select -zero
239: pick +bbl -before -20 -sequence select -nozero
240: scan select; refile -src +bbl select +bbl/arc
241:
242: /* bbexp.c - generate a script to archive the BBoards area */
243:
244: #include <stdio.h>
245: #include "../zotnet/bboards.h"
246:
247: /* */
248:
249: /* ARGSUSED */
250:
251: main (argc, argv)
252: int argc;
253: char **argv;
254: {
255: struct bboard *bb;
256:
257: printf ("#! /bin/sh\n");
258:
259: (void) setbbent (SB_STAY);
260: while (bb = getbbent ())
261: switch (bb -> bb_flags & BB_ARCH) {
262: case BB_ASAV:
263: printf ("bbl -shell bbsave %s\n", bb -> bb_name);
264: break;
265:
266: case BB_AREM:
267: printf ("bbl -shell bbremove %s\n", bb -> bb_name);
268: break;
269: }
270:
271: (void) endbbent ();
272:
273: exit (0);
274: }
275: #endif notdef
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.