9 date 93.08.25.17.43.26; author jromine; state Exp;
14 date 93.08.25.17.22.00; author jromine; state Exp;
19 date 93.08.25.17.21.49; author jromine; state Exp;
33 @/* bb_wtmail.c - write mail to a BBoard */
35 static char Id[] = "@@(#)$Id:$";
57 channelinfo[LINESIZE],
64 extern char *qu_msgfile,
72 extern struct ll_struct *logptr;
76 char *index (), *rindex (), *sprintf ();
77 struct passwd *getpwnam ();
89 ll_log (logptr, LLOGBTR, "bb_init(chanptr=%s)", chanptr -> ch_spec);
92 channelname = chanptr -> ch_spec;
94 sprintf (channelinfo, "vmth%s*", channelname);
95 #else notdef /* the following is probably a BAD idea */
96 if (chanptr -> ch_host == NULL)
97 channelinfo[0] = NULL; /* local delivery ONLY */
99 sprintf (channelinfo, "vmth%s*", chanptr -> ch_host);
102 if ((pw = getpwnam (BBOARDS)) == NULL)
103 err_abrt (RP_BHST, "no passwd entry for '%s'", BBOARDS);
104 bbrduid = pw -> pw_uid;
105 bbrdgid = pw -> pw_gid;
106 sprintf (bbrdfrom, "%s@@%s", pw -> pw_name, locname);
108 ll_log (logptr, LLOGGEN, "distributing as '%s'", bbrdfrom);
110 sprintf (bbrdhome, pw -> pw_dir);
113 err_abrt (RP_BHST, "setbbent() failed");
117 err_abrt (RP_BHST, "not running as root");
127 ll_log (logptr, LLOGBTR, "bb_end(result=0%o)", result);
137 ll_log (logptr, LLOGBTR, "bb_sbinit()");
146 ll_log (logptr, LLOGBTR, "bb_sbend()");
154 bb_winit (info, sender)
159 ll_log (logptr, LLOGBTR, "bb_winit(info='%s',sender='%s')",
186 ll_log (logptr, LLOGBTR, "bb_wtadr(host=%s,adr=%s)", host, adr);
189 make_lower (adr, adr);
190 if ((curbb = getbbnam (adr)) == NULL)
192 sprintf (bbrdaddr, "local-%s-request@@%s", curbb -> bb_name, locname);
194 ll_log (logptr, LLOGGEN, "=> BBoard %s: file='%s' info='%s addr='%s'",
195 curbb -> bb_name, curbb -> bb_file, curbb -> bb_info, bbrdaddr);
198 if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
201 ll_log (logptr, LLOGGEN, "begin local delivery...");
203 printx ("\r\nperforming local delivery to file %s...\n",
207 if ((qd = dup (qu_fileno ())) == NOTOK) {
208 ll_log (logptr, LLOGFAT, "unable to dup qu_fileno()");
212 if ((md = mbx_open (curbb -> bb_file, bbrduid, bbrdgid, BBMODE)) == NOTOK) {
217 if (rp_isbad (result = mbx_init ())) {
219 mbx_close (curbb -> bb_file, md);
223 pos = (long) lseek (md, (off_t)0, 1);
224 count = strlen (delim1);
225 if (write (md, delim1, count) != count) {
226 ll_log (logptr, LLOGTMP, "error writing delim1");
230 start = (long) lseek (md, (off_t)0, 1);
233 count = strlen (bbrdheader);
234 if (write (md, bbrdheader, count) != count) {
235 ll_log (logptr, LLOGTMP, "error writing BBoard information");
239 for (cp = bbrhdheader; *cp; cp++, size++)
245 while ((i = read (qd, buffer, sizeof buffer)) > 0) {
247 (offset = strindex (delim1, buffer)) >= 0;
251 (offset = strindex (delim2, buffer)) >= 0;
254 if (write (md, buffer, i) != i) {
255 ll_log (logptr, LLOGTMP, "error writing to file '%s'",
260 for (offset = 0, cp = buffer; offset < i; offset++, size++)
266 ll_log (logptr, LLOGTMP, "error reading from message file '%s'",
271 stop = (long) lseek (md, (off_t)0, 1);
272 count = strlen (delim2);
273 if (write (md, delim2, count) != count)
274 ll_log (logptr, LLOGTMP, "error writing delim2");
275 map_write (curbb -> bb_file, md, curbb -> bb_maxima, start, stop, pos,
279 ll_log (logptr, LLOGGEN, "end local delivery...");
282 result = mbx_close (curbb -> bb_file, md);
283 return (i < 0 ? RP_FIO : result);
292 ll_log (logptr, LLOGBTR, "bb_txtcpy()");
295 if (curbb -> bb_dist == NULL
296 || *curbb -> bb_dist == NULL
297 || channelinfo[0] == NULL)
300 ll_log (logptr, LLOGGEN, "begin distribution...");
302 if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
304 printx("\rperforming remote distribution\n");
306 if (rp_isbad (result = dist_init ())
307 || rp_isbad (result = dist_adrs ())
308 || rp_isbad (result = dist_text ())
309 || rp_isbad (result = dist_end ()))
310 return dist_lose (result);
313 ll_log (logptr, LLOGGEN, "end distribution...");
318 printx ("\rmessage distributed\n");
325 /* dist_ BBoard distribution routines */
331 ll_log (logptr, LLOGBTR, "dist_init()");
334 if (rp_isbad (result = mm_init ()))
335 return dist_log (result, LLOGFAT, "mm_init() failed [%s]",
337 if (rp_isbad (result = mm_sbinit ()))
338 return dist_log (result, LLOGFAT, "mm_sbinit() failed [%s]",
340 if (rp_isbad (result = mm_winit (chnlname, chnlinfo, bbrdaddr)))
341 return dist_log (result, LLOGFAT,
342 "mm_winit('%s','%s','%s') failed [%s]",
343 chnlname, chnlinfo, bbrdaddr, rp_valstr (result));
354 ll_log (logptr, LLOGBTR, "dist_adrs()");
357 if (getbbdist (curbb, dist_address))
358 return dist_log (RP_NO, LLOGTMP, "getbbdist failed: %s", getbberr ());
360 if (rp_isbad (result = mm_waend ()))
361 return dist_log (result, LLOGFAT, "mm_waend() failed [%s]",
369 dist_address (addr, host)
375 struct rp_bufstruct reply;
378 ll_log (logptr, LLOGBTR, "dist_address(addr='%s',host='%s')", addr, host);
381 printx ("\rperforming distribution to %s@@%s...\n", addr, host);
382 if (rp_isbad (result = mm_wadr (host, addr))) {
383 dist_log (result, LLOGFAT, "mm_wadr('%s','%s') failed [%s]",
384 host, addr, rp_valstr (result));
387 if (rp_isbad (result = mm_rrply (&reply, &len))) {
388 dist_log (result, LLOGFAT,
389 "mm_rrply() failed [%s] getting status of '%s@@%s'",
390 rp_valstr (result), addr, host);
394 switch (rp_gval (reply.rp_val)) {
397 ll_log (logptr, LLOGGEN, "address '%s@@%s' [%s] -- %s",
398 addr, host, rp_valstr (reply.rp_val), reply.rp_line);
407 dist_log (reply.rp_val, LLOGTMP, "address '%s@@%s' [%s] -- %s",
408 addr, host, rp_valstr (reply.rp_val), reply.rp_line);
409 return OK; /* fail-soft */
412 dist_log (reply.rp_val, LLOGFAT, "unexpected reply [%s] -- %s",
413 rp_valstr (reply.rp_val), reply.rp_line);
427 ll_log (logptr, LLOGBTR, "dist_text()");
431 if ((qd = dup (qu_fileno ())) == NOTOK)
432 return dist_log (RP_LIO, LLOGFAT, "unable to dup qu_fileno()");
434 while ((i = read (qd, buffer, sizeof buffer)) > 0)
435 if (rp_isbad (result = mm_wtxt (buffer, i)))
436 return dist_log (result, LLOGFAT, "mm_wtxt() failed [%s]",
441 return dist_log (RP_FIO, LLOGTMP,
442 "error reading from message file '%s'", qu_msgfile);
444 if (rp_isbad (result = mm_wtend ()))
445 return dist_log (result, LLOGFAT, "mm_wtend() failed [%s]",
456 struct rp_bufstruct reply;
459 ll_log (logptr, LLOGBTR, "dist_end()");
462 if (rp_isbad (result = mm_rrply (&reply, &len)))
463 return dist_log (result, LLOGFAT,
464 "mm_rrply() failed [%s] getting final status",
467 switch (rp_gval (reply.rp_val)) {
471 ll_log (logptr, LLOGGEN, "message [%s] -- %s",
472 rp_valstr (reply.rp_val), reply.rp_line);
482 return dist_log (RP_NO, LLOGTMP, "not delivered [%s] -- %s",
483 rp_valstr (reply.rp_val), reply.rp_line);
486 return dist_log (RP_RPLY, LLOGFAT,
487 "unexpected final reply [%s] -- %s",
488 rp_valstr (reply.rp_val), reply.rp_line);
502 ll_log (logptr, LLOGBTR, "dist_lose(result=0%o)", result);
506 printx ("\rerrors during distribution: ");
509 sprintf (buffer, "ch_bboards(%d) distribution for %s failed [%s]\n",
510 getpid (), curbb -> bb_name, rp_valstr (result));
511 if (ml_init (NO, NO, sitesignature, "Re-distribution Failure") != OK
512 || ml_adr (bbrdaddr) != OK
514 || ml_adr (bbrdfrom) != OK
516 || ml_tinit () != OK)
520 if (err_fd != NOTOK) {
521 lseek (err_fd, (off_t)0, 0);
522 if ((qp = fdopen (err_fd, "r")) == NULL) {
523 ml_txt ("unable to fdopen() for diagnostic copy\n");
534 if ((qd = dup (qu_fileno ())) == NOTOK)
535 ml_txt ("unable to dup qu_fileno() for message copy\n");
537 if ((qp = fdopen (qd, "r")) == NULL) {
538 ml_txt ("unable to fdopen() for message copy\n");
542 ml_txt ("\n --Message Follows--\n");
547 if (ml_end (OK) != OK) {
551 if (cp = index (buffer, '\n'))
553 printx ("unable to post advisory.\n");
554 ll_log (logptr, LLOGFAT, "unable to post failure notice");
555 ll_log (logptr, LLOGFAT, "info: %s", buffer);
558 printx ("advisory posted.\n");
569 dist_log (result, level, fmt, a, b, c, d, e)
583 ll_log (logptr, level, fmt, a, b, c, d, e);
585 sprintf (buffer, fmt, a, b, c, d, e);
586 strcat (buffer, "\n");
588 printx ("\rerror: %s", buffer);
590 if (err_fd == NOTOK) {
591 unlink (mktemp (strcpy (tmpfil, "/tmp/bboardsXXXXXX")));
592 if ((err_fd = creat (tmpfil, 0600)) == NOTOK)
595 if ((err_fd = open (tmpfil, 2)) == NOTOK)
598 lseek (err_fd, (off_t)0, 0);
601 write (err_fd, buffer, i);
608 /* mbx_ local mailbox routines */
617 ll_log (logptr, LLOGBTR, "mbx_init()");
620 if ((fd = mbx_Xopen (curbb -> bb_info, bbrduid, bbrdgid, BBMODE, &clear))
622 if (errno == ETXTBSY) {
623 printx ("\runable to lock %s\n", curbb -> bb_info);
624 ll_err (logptr, LLOGTMP, "unable to lock %s",
628 printx ("\runable to open '%s'", curbb -> bb_info);
629 ll_log (logptr, LLOGTMP, "unable to open '%s'", curbb -> bb_info);
632 if ((fp = fdopen (fd, "w")) == (FILE *) NULL) {
633 printx ("\runable to fdopen '%s'", curbb -> bb_info);
634 ll_err (logptr, LLOGTMP, "unable to fdopen '%s'", curbb -> bb_info);
635 mbx_close (curbb -> bb_info, fd);
639 strcpy (name, curbb -> bb_name);
640 if ((curbb = getbbnam (name)) == NULL) {
641 printx ("\runable to get information on BBoard %s\n", name);
642 ll_err (logptr, LLOGFAT, "unable to get info on %s", name);
643 lkfclose (fp, curbb -> bb_info);
647 strcpy (bbrdtime, dtimenow ());
648 sprintf (bbrdheader, "BBoard-ID: %d\nBB-Posted: %s\n",
649 ++curbb -> bb_maxima, bbrdtime);
651 fprintf (fp, "%d\n%s\n", curbb -> bb_maxima, bbrdtime);
652 lkfclose (fp, curbb -> bb_info);
661 @off_t fixes for BSD44
678 pos = lseek (md, 0L, 1);
681 start = lseek (md, 0L, 1);
684 stop = lseek (md, 0L, 1);
687 lseek (err_fd, 0L, 0);
690 lseek (err_fd, 0L, 0);