9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.02.03.17.51.21; author jromine; state Exp;
19 date 90.04.05.15.32.49; author sources; state Exp;
24 date 90.04.05.14.50.34; author sources; state Exp;
29 date 90.03.20.16.25.09; author sources; state Exp;
34 date 90.03.20.16.23.56; author sources; state Exp;
48 @/* bbexp.c - expunge the BBoards area */
50 static char ident[] = "@@(#)$Id: bbexp.c,v 1.5 1992/02/03 17:51:21 jromine Exp jromine $";
54 #include "../h/dropsbr.h"
55 #include "../zotnet/bboards.h"
59 #include <sys/types.h>
67 static int broken_pipe;
70 static process(), chgrp();
76 struct passwd *getpwnam ();
94 invo_name = r1bindex (*argv++, '/');
97 if ((pw = getpwnam (BBOARDS)) == NULL)
98 adios (NULLCP, "no entry for ~%s", BBOARDS);
99 if (pw -> pw_uid != geteuid ())
100 adios (NULLCP, "not running setuid to %s", BBOARDS);
102 if (*argv && **argv == '-') {
103 if ((first = atoi (*argv + 1)) < 1)
107 if (*argv && **argv == '-') {
108 if ((second = atoi (*argv + 1)) < 1)
113 (void) setbbent (SB_STAY);
115 while (bb = getbbent ()) {
116 if ((bb -> bb_flags & BB_ARCH) & (BB_ASAV | BB_AREM))
117 process (bb, pw, first, second);
121 if ((bb = getbbnam (cp)) || (bb = getbbaka (cp))) {
122 if ((bb -> bb_flags & BB_ARCH) & (BB_ASAV | BB_AREM))
123 process (bb, pw, first, second);
126 advise (NULLCP, "no such BBoard as %s", cp);
134 static process (bb, pw, first, second)
148 if ((fd = lkopen (bb -> bb_file, 6)) == NOTOK) {
149 advise (bb -> bb_file, "unable to lock and open");
153 (void) sprintf (tmpfil, "%s/#bbexpXXXXXX", pw -> pw_dir);
154 (void) unlink (mktemp (tmpfil));
155 if ((td = creat (tmpfil, BBMODE)) == NOTOK) {
156 advise (tmpfil, "unable to create");
160 if ((td = creat (cp = map_name (tmpfil), BBMODE)) == NOTOK) {
161 advise (cp, "unable to create");
166 if ((bb -> bb_flags & BB_ARCH)
167 && stat (bb -> bb_archive, &st) == NOTOK
168 && stat (bb -> bb_file, &st) != NOTOK
169 && (td = creat (bb -> bb_archive, (int) (st.st_mode & 0777))) != NOTOK)
172 (void) sprintf (command, "%s %s%s", mshproc, bb -> bb_file,
173 isatty (fileno (stdout)) ? " 2>&1 | cat" : "");
174 printf ("%s (%s old messages)\n", command,
175 (bb -> bb_flags & BB_ARCH) == BB_ASAV ? "archive" : "remove");
176 (void) fflush (stdout);
177 if ((pf = popen (command, "w")) == NULL) {
178 advise (NULLCP, "unable to popen \"%s\" for writing", command);
181 (void) signal (SIGPIPE, pipeser);
184 fprintf (pf, "pick %s -before -%d -sequence select -zero\n",
185 "-datefield BB-Posted", first);
186 fprintf (pf, "pick -before -%d -sequence select -nozero\n", second);
187 fprintf (pf, "scan select\n");
188 if ((bb -> bb_flags & BB_ARCH) == BB_ASAV)
189 fprintf (pf, "pack select -file %s\n", bb -> bb_archive);
190 fprintf (pf, "rmm select\n");
191 fprintf (pf, "packf all -file %s\n", tmpfil);
192 #ifdef notdef /* want real EOF to end it */
193 fprintf (pf, "quit\n");
195 if (td = pclose (pf))
196 advise (NULLCP, "msh returns %d", td);
197 (void) signal (SIGPIPE, SIG_DFL);
199 if (move (tmpfil, bb -> bb_file) != NOTOK)
200 (void) move (cp, bb -> bb_map);
205 (void) unlink (tmpfil);
207 (void) lkclose (fd, bb -> bb_file);
212 static int move (input, output)
222 if ((in = open (input, 0)) == NOTOK) {
223 advise (input, "unable to re-open");
227 i = stat (output, &st1);
228 if ((out = creat (output, BBMODE)) == NOTOK) {
229 advise (output, "unable to re-create");
232 if (i != NOTOK && chmod (output, (int) (st1.st_mode & 0777)) == NOTOK)
233 admonish (output, "unable to change mode of");
234 if (i != NOTOK && stat (output, &st2) != NOTOK && st2.st_gid != st1.st_gid)
235 chgrp (output, st1.st_gid);
237 cpydata (in, out, input, output);
247 static chgrp (file, gid)
254 switch (child_id = fork ()) {
256 admonish ("fork", "unable to");
260 (void) setuid (geteuid ());
261 (void) sprintf (group, "%d", gid);
262 execlp ("/bin/chgrp", chgrp, group, file, NULLCP);
263 fprintf (stderr, "unable to exec ");
264 perror ("/bin/chgrp");
268 (void) pidwait (child_id, OK);
277 static int pipeser (i)
281 (void) signal (SIGPIPE, pipeser);
282 #endif /* not BSD42 */
285 advise (NULLCP, "broken pipe");
298 static char ident[] = "@@(#)$Id: bbexp.c,v 1.4 1990/04/05 15:32:49 sources Exp jromine $";
316 static char ident[] = "@@(#)$Id:$";
329 static char ident[] = "$Id:";