9 date 93.08.25.17.27.54; author jromine; state Exp;
14 date 93.08.20.15.53.49; author jromine; state Exp;
19 date 93.02.26.21.59.44; author jromine; state Exp;
24 date 92.11.24.21.00.41; author jromine; state Exp;
29 date 92.11.04.01.01.28; author jromine; state Exp;
34 date 92.02.03.17.57.22; author jromine; state Exp;
39 date 90.04.05.15.04.02; author sources; state Exp;
44 date 90.04.02.16.35.58; author sources; state Exp;
49 date 90.04.02.16.35.41; author sources; state Exp;
60 @off_t fixes for BSD44
64 /* sbboards.c - MH style mailer to write to a ZOTnet BBoard */
66 /* spop.c - MH style mailer to write to a POP subscriber */
69 static char ident[] = "@@(#)$Id: sbboards.c,v 1.8 1993/08/20 15:53:49 jromine Exp jromine $";
74 /* This program acts like the MMDF ch_bboards channel: it does local
75 delivery to a ZOTnet BBoard and/or addition re-distribution to other
76 recipients of the BBoard. This program can function both as a SendMail
77 mailer and an MH .mh_receive file, depending on whether SENDMTS or
78 MHMTS is set. Currently, the MHMTS version of this program does not do
81 This program should be used ONLY if you have "bboards on" set in your
82 MH configuration, and if you have "mts sendmail" or "mts mh" set as well.
87 /* This program acts like the MMDF-II ch_pop channel: it does local
88 delivery for non-local users. These users are known as POP subscribers
89 and use the Post Office Protocol with a POP server in order to access
104 #include "../h/addrsbr.h"
106 #include "../h/dropsbr.h"
107 #include "../zotnet/bboards.h"
108 #include "../zotnet/tws.h"
110 #include "../zotnet/mts.h"
113 #include <sysexits.h>
115 #define EX_CANTCREAT 1
122 #define EX_UNAVAILABLE 1
126 #include "../mts/sendmail/smail.h"
136 #define ENTITY "bboard"
138 #define ENTITY "subscriber"
148 static int dst_rcpt ();
152 static char bb_from[BUFSIZ];
153 static char bb_head[BUFSIZ];
154 static char bb_home[BUFSIZ];
155 static char bb_time[BUFSIZ];
157 static char bb_rept[BUFSIZ];
160 #define bb_head NULLCP
163 static struct bboard *bb[NBB];
170 struct passwd *getpwnam ();
175 static int mbx_init();
178 static int distribute(), notify(), encap(),
179 dst_init(), dst_text(),
180 dst_end(), dst_lose(), dst_adrs();
184 #define adios my_adios
185 static localmail(), arginit();
186 static int lose(), copyfile();
192 main (argc, argv, envp)
201 setlocale(LC_ALL, "");
205 adios (EX_USAGE, NULL, "you lose really big");
210 discard (stdout); /* XXX: reference discard to help loader */
212 fd = copyfile (fileno (stdin), tmpfil);
213 (void) unlink (tmpfil);
226 static localmail (fd)
231 register struct bboard *bp;
233 for (i = 0; bp = bb[i]; i++)
234 if (bp -> bb_file && *bp -> bb_file) {
235 (void) lseek (fd, (off_t)0, 0);
237 if ((md = mbx_open (bp -> bb_file, bb_uid, bb_gid, BBMODE))
239 if ((md = mbx_open (bp -> bb_file, bb_uid, bb_gid, POMODE))
242 (void) lose ("unable to open %s", bp -> bb_file);
246 if (mbx_init (bp) != NOTOK)
248 (void) mbx_copy (bp -> bb_file, md, fd, 1, bb_head, 0);
249 (void) mbx_close (bp -> bb_file, md);
256 static int mbx_init (bp)
257 register struct bboard *bp;
261 register struct bboard *ip;
264 if ((fd = mbx_Xopen (bp -> bb_info, bb_uid, bb_gid, BBMODE, &clear))
266 return lose ("unable to lock and open %s", bp -> bb_info);
267 if ((fp = fdopen (fd, "w")) == NULL) {
268 (void) mbx_close (bp -> bb_info, fd);
269 return lose ("unable to fdopen %s", bp -> bb_info);
272 if ((ip = getbbnam (bp -> bb_name)) == NULL) {
273 (void) lkfclose (fp, bp -> bb_info);
274 return lose ("unable to get information on BBoard %s", bp -> bb_name);
276 (void) strcpy (bb_time, dtimenow ());
277 (void) sprintf (bb_head, "BBoard-ID: %d\nBB-Posted: %s\n",
278 bp -> bb_maxima = ++ip -> bb_maxima, bb_time);
280 fprintf (fp, "%d\n%s\n", bp -> bb_maxima, bb_time);
281 (void) lkfclose (fp, bp -> bb_info);
290 static distribute (fd)
294 register struct bboard *bp;
296 for (i = 0; bp = bb[i]; i++)
297 if (bp -> bb_dist && *bp -> bb_dist)
302 if (dst_init () == NOTOK) {
306 for (i = 0; bp = bb[i]; i++)
307 if (bp -> bb_dist && *bp -> bb_dist)
308 if (dst_adrs (bp) == NOTOK) {
312 if (dst_text (fd) == NOTOK || dst_end () == NOTOK)
318 static int dst_init ()
322 if (rp_isbad (retval = sm_init (NULLCP, NULLCP, 0, 0, 0, 0, 0))
323 || rp_isbad (retval = sm_winit (S_MAIL, bb_from)))
324 return lose ("problem initializing SendMail; %s",
332 static int dst_adrs (bp)
333 register struct bboard *bp;
335 if (getbbdist (bp, dst_rcpt))
336 return lose ("getbbdist failed: %s", getbberr ());
343 static int dst_rcpt (mbox, host)
349 switch (retval = sm_wadr (mbox, host, NULLCP)) {
355 (void) lose ("%s@@%s: loses; %s", mbox, host, rp_string (retval));
356 return OK; /* fail-soft */
359 return lose ("%s@@%s: unexpected response; %s",
360 mbox, host, rp_string (retval));
366 static int dst_text (fd)
373 if (rp_isbad (retval = sm_waend ()))
374 return lose ("problem ending addresses; %s", rp_string (retval));
376 (void) lseek (fd, (off_t)0, 0);
377 while ((i = read (fd, buffer, sizeof buffer)) > 0)
378 if (rp_isbad (retval = sm_wtxt (buffer, i)))
379 return lose ("problem writing text; %s", rp_string (retval));
381 return (i != NOTOK ? OK : lose ("error reading from file"));
386 static int dst_end ()
390 switch (retval = sm_wtend ()) {
397 return lose ("posting failed; %s", rp_string (retval));
400 return lose ("unexpected response; %s", rp_string (retval));
408 (void) sm_end (NOTOK);
415 static int lose (fmt, a, b, c, d)
427 if (bb_fderr == NOTOK) {
428 if ((fd = open ("/dev/null", 0)) == NOTOK)
429 adios (EX_OSERR, "/dev/null", "unable to open");
430 bb_fderr = copyfile (fd, bb_rept);
433 (void) sprintf (bp = buffer, fmt, a, b, c, d);
435 bp += strlen (strcpy(bp, "\n"));
437 if (write (bb_fderr, buffer, i) != i)
438 adios (EX_IOERR, bb_rept, "error writing");
451 if (bb_fderr == NOTOK)
454 if (rp_isbad (sm_init (NULLCP, NULLCP, 0, 0, 0, 0, 0))
455 || rp_isbad (sm_winit (S_MAIL, bb_from)))
458 switch (sm_wadr (bb_from, NULLCP, NULLCP)) {
460 for (i = 0; bb[i]; i++) {
461 (void) sprintf (buffer, "local-%s-request", bb[i] -> bb_name);
462 (void) sm_wadr (buffer, LocalName (), NULLCP);
470 if (rp_isbad (sm_waend ()))
473 (void) sprintf (buffer,
474 "Date: %s\nFrom: %s\nTo: %s\nSubject: BBoards Failure\n\n",
475 dtimenow (), bb_from, bb_from);
476 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
479 for (i = 0; bb[i]; i++) {
480 (void) sprintf (buffer, "BBoard %s\n", bb[i] -> bb_name);
481 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
485 (void) lseek (bb_fderr, (off_t)0, 0);
486 while ((i = read (bb_fderr, buffer, sizeof buffer)) > 0)
487 if (rp_isbad (sm_wtxt (buffer, i)))
490 (void) strcpy (buffer, "\n------- Forwarded Message\n\n");
491 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))) || encap (fd) == NOTOK)
493 (void) strcpy (buffer, "\n------- End of Forwarded Message\n\n");
494 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
497 switch (sm_wtend ()) {
499 (void) unlink (bb_rept);
505 adios (EX_UNAVAILABLE, NULLCP,
506 "failed and unable to post advisory, see %s for details",
513 /* very similar to sbr/cpydgst.c */
518 #define output(c) if (bp >= dp) flush (), *bp++ = c; else *bp++ = c
519 #define flush() if ((j = bp - outbuf) \
520 && rp_isbad (sm_wtxt (outbuf, j))) \
525 static int encap (fd)
538 (void) lseek (fd, (off_t)0, 0);
540 dp = (bp = outbuf) + sizeof outbuf;
541 for (state = S1; (i = read (fd, buffer, sizeof buffer)) > 0;)
542 for (ep = (cp = buffer) + i; cp < ep; cp++) {
551 state = S2; /* fall */
574 static int lose (fmt, a, b, c, d)
581 adios (EX_UNAVAILABLE, NULLCP, fmt, a, b, c, d);/* NOTREACHED */
583 #endif not DISTRIBUTE
595 register struct bboard *bp;
596 register struct passwd *pw;
598 invo_name = r1bindex (*vec++, '/');
600 mts_init (invo_name);
603 if ((pw = getpwnam (BBOARDS)) == NULL)
604 adios (EX_OSFILE, NULLCP, "no entry for ~%s", BBOARDS);
606 if ((pw = getpwnam (POPUID)) == NULL || !setpwinfo (pw, POPDB, 1))
607 adios (EX_OSFILE, NULLCP, "%s", pw ? getbberr () : "POP user-id unknown");
610 if (pw -> pw_uid != geteuid ())
612 adios (EX_OSERR, NULLCP, "not running setuid to %s", BBOARDS);
614 adios (EX_OSERR, NULLCP, "not running setuid to %s", POPUID);
617 bb_uid = pw -> pw_uid;
618 bb_gid = pw -> pw_gid;
620 (void) strcpy (bb_from, adrsprintf (pw -> pw_name, LocalName ()));
621 (void) strcpy (bb_home, pw -> pw_dir);
628 adios (EX_USAGE, NULLCP, "usage: %s %s [%s ...]",
629 invo_name, ENTITY, ENTITY);
631 for (i = 0; *vec; vec++) {
633 if (ap = index (*vec, '.'))
636 make_lower (addr, *vec);
638 if ((bp = getbbnam (addr)) == NULL
639 && (bp = getbbaka (addr)) == NULL)
640 adios (EX_NOUSER, NULLCP, "no such %s as %s", ENTITY, *vec);
641 if ((bb[i++] = getbbcpy (bp)) == NULL)
642 adios (EX_UNAVAILABLE, NULLCP, "insufficient memory on %s", *vec);
645 adios (EX_USAGE, NULLCP, "too many %ss, starting with %s",
657 static int copyfile (qd, tmpfil)
659 register char *tmpfil;
665 (void) strcpy (tmpfil, m_tmpfil (invo_name));
666 if ((fd = creat (tmpfil, 0600)) == NOTOK)
667 adios (EX_CANTCREAT, tmpfil, "unable to create");
669 if ((fd = open (tmpfil, 2)) == NOTOK)
670 adios (EX_NOINPUT, tmpfil, "unable to re-open");
672 (void) lseek (qd, (off_t)0, 0);
673 while ((i = read (qd, buffer, sizeof buffer)) > 0)
674 if (write (fd, buffer, i) != i)
675 adios (EX_IOERR, tmpfil, "error writing");
677 adios (EX_IOERR, "input", "error reading");
679 (void) lseek (fd, (off_t)0, 0);
692 static void adios (code, what, fmt, a, b, c, d, e, f)
703 advise (what, fmt, a, b, c, d, e, f);
716 @fixup for onex/queued interface
721 static char ident[] = "@@(#)$Id: sbboards.c,v 1.7 1993/02/26 21:59:44 jromine Exp jromine $";
727 (void) lseek (fd, 0L, 0);
730 (void) lseek (fd, 0L, 0);
733 (void) lseek (bb_fderr, 0L, 0);
736 (void) lseek (fd, 0L, 0);
739 (void) lseek (qd, 0L, 0);
742 (void) lseek (fd, 0L, 0);
753 static char ident[] = "@@(#)$Id: sbboards.c,v 1.6 1992/11/24 21:00:41 jromine Exp jromine $";
756 if (rp_isbad (retval = sm_init (NULLCP, NULLCP, 0, 0, 0))
759 if (rp_isbad (sm_init (NULLCP, NULLCP, 0, 0, 0))
770 static char ident[] = "@@(#)$Id: sbboards.c,v 1.5 1992/11/04 01:01:28 jromine Exp jromine $";
782 static char ident[] = "@@(#)$Id: sbboards.c,v 1.4 1992/02/03 17:57:22 jromine Exp jromine $";
796 static char ident[] = "@@(#)$Id: sbboards.c,v 1.3 1990/04/05 15:04:02 sources Exp jromine $";
809 static char ident[] = "@@(#)$Id:$";