9 date 93.08.25.17.43.26; author jromine; state Exp;
14 date 93.08.25.17.22.29; author jromine; state Exp;
19 date 93.08.25.17.22.22; author jromine; state Exp;
34 /* bb_wtmail.c - write mail to a BBoard */
36 /* po_wtmail.c - write mail for a POP subscriber */
39 static char Id[] = "@@(#)$Id:$";
55 #define submitopts "vmth%s*"
57 #define submitopts "vkmth%s*"
61 #define RP_NOPE RP_AOK
63 #define MBXMODE BBMODE
65 #define RP_NOPE RP_USER
67 #define MBXMODE sentprotect
69 extern int sentprotect;
84 char bbrdaddr[LINESIZE],
91 extern char *qu_msgfile,
101 struct bboard *curbb;
108 char *index (), *rindex (), *sprintf ();
109 struct passwd *getpwnam ();
121 ll_log (logptr, LLOGBTR, "bb_init(chanptr=%s)", chanptr -> ch_name);
124 chnlname = chanptr -> ch_name;
126 sprintf (chnlinfo, submitopts, chnlname);
127 #else notdef /* the following is probably a BAD idea */
128 if (chanptr -> ch_host == NULL)
129 chnlinfo[0] = NULL; /* local delivery ONLY */
131 sprintf (chnlinfo, submitopts, chanptr -> ch_host);
135 if ((pw = getpwnam (BBOARDS)) == NULL)
136 err_abrt (RP_BHST, "no passwd entry for '%s'", BBOARDS);
138 if ((pw = getpwnam (POPUID)) == NULL)
139 err_abrt (RP_BHST, "no passwd entry for '%s'", POPUID);
142 bbrduid = pw -> pw_uid;
143 bbrdgid = pw -> pw_gid;
145 if (isstr (locmachine))
146 sprintf (bbrdfrom, "%s@@%s.%s.%s", pw -> pw_name, locmachine, locname,
149 sprintf (bbrdfrom, "%s@@%s.%s", pw -> pw_name, locname, locdomain);
151 ll_log (logptr, LLOGGEN, "distributing as '%s'", bbrdfrom);
153 sprintf (bbrdhome, pw -> pw_dir);
158 err_abrt (RP_BHST, "setbbent() failed");
160 if (!setpwinfo (pw, POPDB, 1))
161 err_abrt (RP_BHST, "setbbinfo(%s, %s, 1) failed",
162 pw -> pw_name, POPDB);
167 err_abrt (RP_BHST, "not running as root");
177 ll_log (logptr, LLOGBTR, "bb_end(result=0%o)", result);
187 ll_log (logptr, LLOGBTR, "bb_sbinit()");
196 ll_log (logptr, LLOGBTR, "bb_sbend()");
204 bb_winit (info, sender)
209 ll_log (logptr, LLOGBTR, "bb_winit(info='%s',sender='%s')",
235 ll_log (logptr, LLOGBTR, "bb_wtadr(host=%s,adr=%s)", host, adr);
238 if ((cp = index (adr, '@@')) != NULL)
240 make_lower (adr, adr);
241 if ((curbb = getbbnam (adr)) == NULL)
244 if (isstr (locmachine))
245 sprintf (bbrdaddr, "local-%s-request@@%s.%s.%s", curbb -> bb_name,
246 locmachine, locname, locdomain);
248 sprintf (bbrdaddr, "local-%s-request@@%s.%s", curbb -> bb_name, locname,
252 ll_log (logptr, LLOGGEN, "=> BBoard %s: file='%s' info='%s'",
253 curbb -> bb_name, curbb -> bb_file, curbb -> bb_info);
256 if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
259 ll_log (logptr, LLOGGEN, "begin local delivery...");
261 printx ("\r\nperforming local delivery to file %s...\n",
266 if ((md = mbx_open (curbb -> bb_file, bbrduid, bbrdgid, MBXMODE)) == NOTOK)
270 if (rp_isbad (result = mbx_init ())) {
271 mbx_close (curbb -> bb_file, md);
276 pos = (long) lseek (md, (off_t)0, 1);
277 count = strlen (delim1);
278 if (write (md, delim1, count) != count) {
279 ll_log (logptr, LLOGTMP, "error writing delim1");
283 start = (long) lseek (md, (off_t)0, 1);
287 count = strlen (bbrdheader);
288 if (write (md, bbrdheader, count) != count) {
289 ll_log (logptr, LLOGTMP, "error writing BBoard information");
293 for (cp = bbrdheader; *cp; cp++, size++)
299 rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
302 (offset = strindex (delim1, buffer)) >= 0;
306 (offset = strindex (delim2, buffer)) >= 0;
309 if (write (md, buffer, len) != len) {
310 ll_log (logptr, LLOGTMP, "error writing to file '%s'",
315 for (offset = 0, cp = buffer; offset < len; offset++, size++)
321 ll_log (logptr, LLOGTMP, "error reading from message file '%s'",
325 stop = (long) lseek (md, (off_t)0, 1);
326 count = strlen (delim2);
327 if (write (md, delim2, count) != count)
328 ll_log (logptr, LLOGTMP, "error writing delim2");
329 map_write (curbb -> bb_file, md, curbb -> bb_maxima, start, stop, pos,
332 ll_log (logptr, LLOGGEN, "end local delivery...");
336 mbx_close (curbb -> bb_file, md);
338 result = mbx_close (curbb -> bb_file, md);
340 return (result != NOTOK ? RP_OK : RP_FIO);
350 ll_log (logptr, LLOGBTR, "bb_txtcpy()");
353 if (curbb -> bb_dist == NULL
354 || *curbb -> bb_dist == NULL
355 || chnlinfo[0] == NULL)
358 ll_log (logptr, LLOGGEN, "begin distribution...");
360 if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
362 printx("\rperforming remote distribution\n");
364 if (rp_isbad (result = dist_init ())
365 || rp_isbad (result = dist_adrs ())
366 || rp_isbad (result = dist_text ())
367 || rp_isbad (result = dist_end ()))
368 return dist_lose (result);
370 ll_log (logptr, LLOGGEN, "end distribution...");
376 printx ("\rmessage distributed\n");
385 /* **************** (dist_) BBOARD DISTRIBUTION **************** */
391 struct rp_bufstruct reply;
395 ll_log (logptr, LLOGBTR, "dist_init()");
398 if (rp_isbad (result = mm_init ()))
399 return ds_log (result, LLOGFAT, "mm_init() failed [%s]",
401 if (rp_isbad (result = mm_sbinit ()))
402 return ds_log (result, LLOGFAT, "mm_sbinit() failed [%s]",
404 if (rp_isbad (result = mm_winit (chnlname, chnlinfo, bbrdaddr)))
405 return ds_log (result, LLOGFAT,
406 "mm_winit('%s','%s','%s') failed [%s]",
407 chnlname, chnlinfo, bbrdaddr, rp_valstr (result));
409 if (rp_isbad (result = mm_rrply (&reply, &len)))
410 return ds_log (result, LLOGFAT, "problem with sender address [%s]",
424 ll_log (logptr, LLOGBTR, "dist_adrs()");
427 if (getbbdist (curbb, ds_address))
428 return ds_log (RP_NO, LLOGTMP, "getbbdist failed: %s", getbberr ());
430 if (rp_isbad (result = mm_waend ()))
431 return ds_log (result, LLOGFAT, "mm_waend() failed [%s]",
439 ds_address (addr, host)
440 char *addr, /* local part */
445 struct rp_bufstruct reply;
448 ll_log (logptr, LLOGBTR, "ds_address(addr='%s',host='%s')", addr, host);
451 printx ("\rperforming distribution to %s@@%s...\n", addr, host);
452 if (rp_isbad (result = mm_wadr (host, addr))) {
453 ds_log (result, LLOGFAT, "mm_wadr('%s','%s') failed [%s]",
454 host, addr, rp_valstr (result));
457 if (rp_isbad (result = mm_rrply (&reply, &len))) {
458 ds_log (result, LLOGFAT,
459 "mm_rrply() failed [%s] getting status of '%s@@%s'",
460 rp_valstr (result), addr, host);
464 switch (rp_gval (reply.rp_val)) {
470 ll_log (logptr, LLOGGEN, "address '%s@@%s' [%s] -- %s",
471 addr, host, rp_valstr (reply.rp_val), reply.rp_line);
483 ds_log (reply.rp_val, LLOGTMP, "address '%s@@%s' [%s] -- %s",
484 addr, host, rp_valstr (reply.rp_val), reply.rp_line);
485 return OK; /* fail-soft */
488 ds_log (reply.rp_val, LLOGFAT, "unexpected reply [%s] -- %s",
489 rp_valstr (reply.rp_val), reply.rp_line);
503 ll_log (logptr, LLOGBTR, "dist_text()");
508 rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
510 if (rp_isbad (result = mm_wtxt (buffer, len)))
511 return ds_log (result, LLOGFAT, "mm_wtxt() failed [%s]",
515 return ds_log (RP_FIO, LLOGTMP,
516 "error reading from message file '%s'", qu_msgfile);
518 if (rp_isbad (result = mm_wtend ()))
519 return ds_log (result, LLOGFAT, "mm_wtend() failed [%s]",
531 struct rp_bufstruct reply;
534 ll_log (logptr, LLOGBTR, "dist_end()");
537 if (rp_isbad (result = mm_rrply (&reply, &len)))
538 return ds_log (result, LLOGFAT,
539 "mm_rrply() failed [%s] getting final status",
542 switch (rp_gval (reply.rp_val)) {
546 ll_log (logptr, LLOGGEN, "message [%s] -- %s",
547 rp_valstr (reply.rp_val), reply.rp_line);
557 return ds_log (RP_NO, LLOGTMP, "not delivered [%s] -- %s",
558 rp_valstr (reply.rp_val), reply.rp_line);
561 return ds_log (RP_RPLY, LLOGFAT,
562 "unexpected final reply [%s] -- %s",
563 rp_valstr (reply.rp_val), reply.rp_line);
578 ll_log (logptr, LLOGBTR, "dist_lose(result=0%o)", result);
583 printx ("\rerrors during distribution: ");
585 (void) fflush (stdout);
586 (void) sprintf (intro, "bboards%d distribution for %s failed [%s]\n",
587 getpid (), curbb -> bb_name, rp_valstr (result));
588 if (loseaux (bbrdaddr, bbrdfrom, intro) != OK
589 && loseaux (bbrdfrom, (char *) 0, intro) != OK) {
590 printx ("unable to post advisory.\n");
591 ll_log (logptr, LLOGFAT, "unable to post failure notice");
592 if (err_fd != NOTOK) {
593 (void) lseek (err_fd, (off_t)0, 0);
594 if ((i = read (err_fd, buffer, sizeof buffer)) > 0) {
596 if (cp = index (buffer, '\n'))
598 ll_log (logptr, LLOGFAT, "info: %s", buffer);
601 if (loseaux (supportaddr, (char *) 0, intro) != NOTOK)
602 ll_log (logptr, LLOGFAT, "unable to advise %s of failure!",
606 printx ("advisory posted.\n");
608 (void) fflush (stdout);
610 if (err_fd != NOTOK) {
619 int loseaux (to, cc, intro)
627 if (ml_init (NO, NO, sitesignature, "Re-distribution Failure") != OK
628 || ml_adr (to) != OK)
630 if (cc && (ml_cc () != OK || ml_adr (cc) != OK))
632 if (ml_aend () != OK || ml_tinit () != OK)
636 if (err_fd != NOTOK) {
637 lseek (err_fd, (off_t)0, 0);
638 while ((i = read (err_fd, buffer, sizeof buffer)) > 0) {
650 /* very similar to sbr/cpydgst.c */
655 #define output(c) if (bp >= dp) {flush (); *bp++ = c;} else *bp++ = c
656 #define flush() if (bp - outbuf) \
657 *bp = NULL, ml_txt (outbuf), bp = outbuf
673 dp = (bp = outbuf) + sizeof outbuf;
675 for (state = S1, len = BUFSIZ;
676 rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
678 for (ep = (cp = buffer) + len; cp < ep; cp++) {
685 ml_txt ("\n------- Forwarded Message\n\n");
691 state = S2; /* fall */
695 ml_txt ("\n------- Forwarded Message\n\n");
708 ll_log (logptr, LLOGTMP, "error reading message when noting failure");
710 ml_txt ("\n------- End of Forwarded Message\n\n");
711 ml_txt ("[ error reading message ]\n");
715 ml_txt ("\n------- End of Forwarded Message\n\n");
717 ll_log (logptr, LLOGTMP, "message empty when noting failure");
718 ml_txt ("[ message empty ]\n");
726 ds_log (result, level, fmt, a, b, c, d, e)
740 ll_log (logptr, level, fmt, a, b, c, d, e);
742 sprintf (buffer, fmt, a, b, c, d, e);
743 strcat (buffer, "\n");
745 printx ("\rerror: %s", buffer);
747 if (err_fd == NOTOK) {
748 unlink (mktemp (strcpy (tmpfil, "/tmp/bboardsXXXXXX")));
749 if ((err_fd = creat (tmpfil, 0600)) == NOTOK)
752 if ((err_fd = open (tmpfil, 2)) == NOTOK)
755 lseek (err_fd, (off_t)0, 0);
758 write (err_fd, buffer, i);
766 /* mbx_ local mailbox routines */
775 if ((fd = mbx_Xopen (curbb -> bb_info, bbrduid, bbrdgid, MBXMODE, &clear))
777 if (errno == ETXTBSY) {
778 printx ("\runable to lock %s\n", curbb -> bb_info);
779 ll_err (logptr, LLOGTMP, "unable to lock %s",
783 printx ("\runable to open '%s'", curbb -> bb_info);
784 ll_log (logptr, LLOGTMP, "unable to open '%s'", curbb -> bb_info);
787 if ((fp = fdopen (fd, "w")) == (FILE *) NULL) {
788 printx ("\runable to fdopen '%s'", curbb -> bb_info);
789 ll_err (logptr, LLOGTMP, "unable to fdopen '%s'", curbb -> bb_info);
790 mbx_close (curbb -> bb_info, fd);
794 strcpy (name, curbb -> bb_name);
795 if ((curbb = getbbnam (name)) == (struct bboard *) NULL) {
796 printx ("\runable to get information on BBoard %s\n", name);
797 ll_err (logptr, LLOGFAT, "unable to get info on %s", name);
798 lkfclose (fp, curbb -> bb_info);
801 sprintf (bbrdheader, "BBoard-ID: %d\nBB-Posted: %s\n",
802 ++curbb -> bb_maxima, cnvtdate (TIMREG, bbrdtime));
803 fprintf (fp, "%d\n%s\n", curbb -> bb_maxima, bbrdtime);
805 lkfclose (fp, curbb -> bb_info);
815 @off_t fixes for BSD44
832 pos = lseek (md, 0L, 1);
835 start = lseek (md, 0L, 1);
838 stop = lseek (md, 0L, 1);
841 (void) lseek (err_fd, 0L, 0);
844 lseek (err_fd, 0L, 0);
847 lseek (err_fd, 0L, 0);