9 date 93.08.25.17.28.24; author jromine; state Exp;
14 date 93.08.20.15.55.23; author jromine; state Exp;
19 date 92.11.04.01.04.35; author jromine; state Exp;
24 date 92.02.03.17.57.22; author jromine; state Exp;
29 date 90.04.05.15.02.39; author sources; state Exp;
34 date 90.04.02.16.34.57; author sources; state Exp;
39 date 90.02.06.13.32.29; author sources; state Exp;
44 date 90.02.06.13.32.13; author sources; state Exp;
55 @off_t fixes for BSD44
59 /* sbboards.c - MH style mailer to write to a ZOTnet BBoard */
61 /* spop.c - MH style mailer to write to a POP subscriber */
64 static char ident[] = "@@(#)$Id: spop.c,v 1.7 1993/08/20 15:55:23 jromine Exp jromine $";
69 /* This program acts like the MMDF ch_bboards channel: it does local
70 delivery to a ZOTnet BBoard and/or addition re-distribution to other
71 recipients of the BBoard. This program can function both as a SendMail
72 mailer and an MH .mh_receive file, depending on whether SENDMTS or
73 MHMTS is set. Currently, the MHMTS version of this program does not do
76 This program should be used ONLY if you have "bboards on" set in your
77 MH configuration, and if you have "mts sendmail" or "mts mh" set as well.
82 /* This program acts like the MMDF-II ch_pop channel: it does local
83 delivery for non-local users. These users are known as POP subscribers
84 and use the Post Office Protocol with a POP server in order to access
99 #include "../h/addrsbr.h"
101 #include "../h/dropsbr.h"
102 #include "../zotnet/bboards.h"
103 #include "../zotnet/tws.h"
105 #include "../zotnet/mts.h"
108 #include <sysexits.h>
110 #define EX_CANTCREAT 1
117 #define EX_UNAVAILABLE 1
121 #include "../mts/sendmail/smail.h"
131 #define ENTITY "bboard"
133 #define ENTITY "subscriber"
147 static char bb_from[BUFSIZ];
148 static char bb_head[BUFSIZ];
149 static char bb_home[BUFSIZ];
150 static char bb_time[BUFSIZ];
152 static char bb_rept[BUFSIZ];
155 #define bb_head NULLCP
158 static struct bboard *bb[NBB];
165 struct passwd *getpwnam ();
170 #define adios my_adios
171 static localmail(), arginit();
172 static int lose(), copyfile();
178 main (argc, argv, envp)
187 setlocale(LC_ALL, "");
191 adios (EX_USAGE, NULL, "you lose really big");
196 discard (stdout); /* XXX: reference discard to help loader */
198 fd = copyfile (fileno (stdin), tmpfil);
199 (void) unlink (tmpfil);
212 static localmail (fd)
217 register struct bboard *bp;
219 for (i = 0; bp = bb[i]; i++)
220 if (bp -> bb_file && *bp -> bb_file) {
221 (void) lseek (fd, (off_t)0, 0);
223 if ((md = mbx_open (bp -> bb_file, bb_uid, bb_gid, BBMODE))
225 if ((md = mbx_open (bp -> bb_file, bb_uid, bb_gid, POMODE))
228 (void) lose ("unable to open %s", bp -> bb_file);
232 if (mbx_init (bp) != NOTOK)
234 (void) mbx_copy (bp -> bb_file, md, fd, 1, bb_head, 0);
235 (void) mbx_close (bp -> bb_file, md);
242 static int mbx_init (bp)
243 register struct bboard *bp;
247 register struct bboard *ip;
250 if ((fd = mbx_Xopen (bp -> bb_info, bb_uid, bb_gid, BBMODE, &clear))
252 return lose ("unable to lock and open %s", bp -> bb_info);
253 if ((fp = fdopen (fd, "w")) == NULL) {
254 (void) mbx_close (bp -> bb_info, fd);
255 return lose ("unable to fdopen %s", bp -> bb_info);
258 if ((ip = getbbnam (bp -> bb_name)) == NULL) {
259 (void) lkfclose (fp, bp -> bb_info);
260 return lose ("unable to get information on BBoard %s", bp -> bb_name);
262 (void) strcpy (bb_time, dtimenow ());
263 (void) sprintf (bb_head, "BBoard-ID: %d\nBB-Posted: %s\n",
264 bp -> bb_maxima = ++ip -> bb_maxima, bb_time);
266 fprintf (fp, "%d\n%s\n", bp -> bb_maxima, bb_time);
267 (void) lkfclose (fp, bp -> bb_info);
276 static distribute (fd)
280 register struct bboard *bp;
282 for (i = 0; bp = bb[i]; i++)
283 if (bp -> bb_dist && *bp -> bb_dist)
288 if (dst_init () == NOTOK) {
292 for (i = 0; bp = bb[i]; i++)
293 if (bp -> bb_dist && *bp -> bb_dist)
294 if (dst_adrs (bp) == NOTOK) {
298 if (dst_text (fd) == NOTOK || dst_end () == NOTOK)
304 static int dst_init ()
308 if (rp_isbad (retval = sm_init (NULLCP, NULLCP, 0, 0, 0, 0, 0))
309 || rp_isbad (retval = sm_winit (S_MAIL, bb_from)))
310 return lose ("problem initializing SendMail; %s",
318 static int dst_adrs (bp)
319 register struct bboard *bp;
321 if (getbbdist (bp, dst_rcpt))
322 return lose ("getbbdist failed: %s", getbberr ());
329 static int dst_rcpt (mbox, host)
335 switch (retval = sm_wadr (mbox, host, NULLCP)) {
341 (void) lose ("%s@@%s: loses; %s", mbox, host, rp_string (retval));
342 return OK; /* fail-soft */
345 return lose ("%s@@%s: unexpected response; %s",
346 mbox, host, rp_string (retval));
352 static int dst_text (fd)
359 if (rp_isbad (retval = sm_waend ()))
360 return lose ("problem ending addresses; %s", rp_string (retval));
362 (void) lseek (fd, (off_t)0, 0);
363 while ((i = read (fd, buffer, sizeof buffer)) > 0)
364 if (rp_isbad (retval = sm_wtxt (buffer, i)))
365 return lose ("problem writing text; %s", rp_string (retval));
367 return (i != NOTOK ? OK : lose ("error reading from file"));
372 static int dst_end ()
376 switch (retval = sm_wtend ()) {
383 return lose ("posting failed; %s", rp_string (retval));
386 return lose ("unexpected response; %s", rp_string (retval));
394 (void) sm_end (NOTOK);
401 static int lose (fmt, a, b, c, d)
413 if (bb_fderr == NOTOK) {
414 if ((fd = open ("/dev/null", 0)) == NOTOK)
415 adios (EX_OSERR, "/dev/null", "unable to open");
416 bb_fderr = copyfile (fd, bb_rept);
419 (void) sprintf (bp = buffer, fmt, a, b, c, d);
421 bp += strlen (strcpy(bp, "\n"));
423 if (write (bb_fderr, buffer, i) != i)
424 adios (EX_IOERR, bb_rept, "error writing");
437 if (bb_fderr == NOTOK)
440 if (rp_isbad (sm_init (NULLCP, NULLCP, 0, 0, 0, 0, 0))
441 || rp_isbad (sm_winit (S_MAIL, bb_from)))
444 switch (sm_wadr (bb_from, NULLCP, NULLCP)) {
446 for (i = 0; bb[i]; i++) {
447 (void) sprintf (buffer, "local-%s-request", bb[i] -> bb_name);
448 (void) sm_wadr (buffer, LocalName (), NULLCP);
456 if (rp_isbad (sm_waend ()))
459 (void) sprintf (buffer,
460 "Date: %s\nFrom: %s\nTo: %s\nSubject: BBoards Failure\n\n",
461 dtimenow (), bb_from, bb_from);
462 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
465 for (i = 0; bb[i]; i++) {
466 (void) sprintf (buffer, "BBoard %s\n", bb[i] -> bb_name);
467 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
471 (void) lseek (bb_fderr, (off_t)0, 0);
472 while ((i = read (bb_fderr, buffer, sizeof buffer)) > 0)
473 if (rp_isbad (sm_wtxt (buffer, i)))
476 (void) strcpy (buffer, "\n------- Forwarded Message\n\n");
477 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))) || encap (fd) == NOTOK)
479 (void) strcpy (buffer, "\n------- End of Forwarded Message\n\n");
480 if (rp_isbad (sm_wtxt (buffer, strlen (buffer))))
483 switch (sm_wtend ()) {
485 (void) unlink (bb_rept);
491 adios (EX_UNAVAILABLE, NULLCP,
492 "failed and unable to post advisory, see %s for details",
499 /* very similar to sbr/cpydgst.c */
504 #define output(c) if (bp >= dp) flush (), *bp++ = c; else *bp++ = c
505 #define flush() if ((j = bp - outbuf) \
506 && rp_isbad (sm_wtxt (outbuf, j))) \
511 static int encap (fd)
524 (void) lseek (fd, (off_t)0, 0);
526 dp = (bp = outbuf) + sizeof outbuf;
527 for (state = S1; (i = read (fd, buffer, sizeof buffer)) > 0;)
528 for (ep = (cp = buffer) + i; cp < ep; cp++) {
537 state = S2; /* fall */
560 static int lose (fmt, a, b, c, d)
567 adios (EX_UNAVAILABLE, NULLCP, fmt, a, b, c, d);/* NOTREACHED */
569 #endif not DISTRIBUTE
581 register struct bboard *bp;
582 register struct passwd *pw;
584 invo_name = r1bindex (*vec++, '/');
586 mts_init (invo_name);
589 if ((pw = getpwnam (BBOARDS)) == NULL)
590 adios (EX_OSFILE, NULLCP, "no entry for ~%s", BBOARDS);
592 if ((pw = getpwnam (POPUID)) == NULL || !setpwinfo (pw, POPDB, 1))
593 adios (EX_OSFILE, NULLCP, "%s", pw ? getbberr () : "POP user-id unknown");
596 if (pw -> pw_uid != geteuid ())
598 adios (EX_OSERR, NULLCP, "not running setuid to %s", BBOARDS);
600 adios (EX_OSERR, NULLCP, "not running setuid to %s", POPUID);
603 bb_uid = pw -> pw_uid;
604 bb_gid = pw -> pw_gid;
606 (void) strcpy (bb_from, adrsprintf (pw -> pw_name, LocalName ()));
607 (void) strcpy (bb_home, pw -> pw_dir);
614 adios (EX_USAGE, NULLCP, "usage: %s %s [%s ...]",
615 invo_name, ENTITY, ENTITY);
617 for (i = 0; *vec; vec++) {
619 if (ap = index (*vec, '.'))
622 make_lower (addr, *vec);
624 if ((bp = getbbnam (addr)) == NULL
625 && (bp = getbbaka (addr)) == NULL)
626 adios (EX_NOUSER, NULLCP, "no such %s as %s", ENTITY, *vec);
627 if ((bb[i++] = getbbcpy (bp)) == NULL)
628 adios (EX_UNAVAILABLE, NULLCP, "insufficient memory on %s", *vec);
631 adios (EX_USAGE, NULLCP, "too many %ss, starting with %s",
643 static int copyfile (qd, tmpfil)
645 register char *tmpfil;
651 (void) strcpy (tmpfil, m_tmpfil (invo_name));
652 if ((fd = creat (tmpfil, 0600)) == NOTOK)
653 adios (EX_CANTCREAT, tmpfil, "unable to create");
655 if ((fd = open (tmpfil, 2)) == NOTOK)
656 adios (EX_NOINPUT, tmpfil, "unable to re-open");
658 (void) lseek (qd, (off_t)0, 0);
659 while ((i = read (qd, buffer, sizeof buffer)) > 0)
660 if (write (fd, buffer, i) != i)
661 adios (EX_IOERR, tmpfil, "error writing");
663 adios (EX_IOERR, "input", "error reading");
665 (void) lseek (fd, (off_t)0, 0);
678 static void adios (code, what, fmt, a, b, c, d, e, f)
689 advise (what, fmt, a, b, c, d, e, f);
702 @fixup for onex/queued interface
707 static char ident[] = "@@(#)$Id: spop.c,v 1.6 1992/11/04 01:04:35 jromine Exp jromine $";
713 (void) lseek (fd, 0L, 0);
716 (void) lseek (fd, 0L, 0);
719 (void) lseek (bb_fderr, 0L, 0);
722 (void) lseek (fd, 0L, 0);
725 (void) lseek (qd, 0L, 0);
728 (void) lseek (fd, 0L, 0);
740 static char ident[] = "@@(#)$Id: spop.c,v 1.5 1992/02/03 17:57:22 jromine Exp jromine $";
743 if (rp_isbad (retval = sm_init (NULLCP, NULLCP, 0, 0, 0))
746 if (rp_isbad (sm_init (NULLCP, NULLCP, 0, 0, 0))
757 static char ident[] = "@@(#)$Id: spop.c,v 1.4 1990/04/05 15:02:39 sources Exp jromine $";
770 static char ident[] = "@@(#)$Id:$";