/* bb_wtmail.c - write mail to a BBoard */
/* po_wtmail.c - write mail for a POP subscriber */
static char Id
[] = "@(#)$Id: po_wtmail.c,v 1.3 1993/08/25 17:43:26 jromine Exp $";
#define submitopts "vmth%s*"
#define submitopts "vkmth%s*"
#define MBXMODE sentprotect
char *index (), *rindex (), *sprintf ();
struct passwd
*getpwnam ();
ll_log (logptr
, LLOGBTR
, "bb_init(chanptr=%s)", chanptr
-> ch_name
);
chnlname
= chanptr
-> ch_name
;
sprintf (chnlinfo
, submitopts
, chnlname
);
#else notdef /* the following is probably a BAD idea */
if (chanptr
-> ch_host
== NULL
)
chnlinfo
[0] = NULL
; /* local delivery ONLY */
sprintf (chnlinfo
, submitopts
, chanptr
-> ch_host
);
if ((pw
= getpwnam (BBOARDS
)) == NULL
)
err_abrt (RP_BHST
, "no passwd entry for '%s'", BBOARDS
);
if ((pw
= getpwnam (POPUID
)) == NULL
)
err_abrt (RP_BHST
, "no passwd entry for '%s'", POPUID
);
sprintf (bbrdfrom
, "%s@%s.%s.%s", pw
-> pw_name
, locmachine
, locname
,
sprintf (bbrdfrom
, "%s@%s.%s", pw
-> pw_name
, locname
, locdomain
);
ll_log (logptr
, LLOGGEN
, "distributing as '%s'", bbrdfrom
);
sprintf (bbrdhome
, pw
-> pw_dir
);
err_abrt (RP_BHST
, "setbbent() failed");
if (!setpwinfo (pw
, POPDB
, 1))
err_abrt (RP_BHST
, "setbbinfo(%s, %s, 1) failed",
err_abrt (RP_BHST
, "not running as root");
ll_log (logptr
, LLOGBTR
, "bb_end(result=0%o)", result
);
ll_log (logptr
, LLOGBTR
, "bb_sbinit()");
ll_log (logptr
, LLOGBTR
, "bb_sbend()");
ll_log (logptr
, LLOGBTR
, "bb_winit(info='%s',sender='%s')",
ll_log (logptr
, LLOGBTR
, "bb_wtadr(host=%s,adr=%s)", host
, adr
);
if ((cp
= index (adr
, '@')) != NULL
)
if ((curbb
= getbbnam (adr
)) == NULL
)
sprintf (bbrdaddr
, "local-%s-request@%s.%s.%s", curbb
-> bb_name
,
locmachine
, locname
, locdomain
);
sprintf (bbrdaddr
, "local-%s-request@%s.%s", curbb
-> bb_name
, locname
,
ll_log (logptr
, LLOGGEN
, "=> BBoard %s: file='%s' info='%s'",
curbb
-> bb_name
, curbb
-> bb_file
, curbb
-> bb_info
);
if (curbb
-> bb_file
== NULL
|| *curbb
-> bb_file
== NULL
)
ll_log (logptr
, LLOGGEN
, "begin local delivery...");
printx ("\r\nperforming local delivery to file %s...\n",
if ((md
= mbx_open (curbb
-> bb_file
, bbrduid
, bbrdgid
, MBXMODE
)) == NOTOK
)
if (rp_isbad (result
= mbx_init ())) {
mbx_close (curbb
-> bb_file
, md
);
pos
= (long) lseek (md
, (off_t
)0, 1);
if (write (md
, delim1
, count
) != count
) {
ll_log (logptr
, LLOGTMP
, "error writing delim1");
start
= (long) lseek (md
, (off_t
)0, 1);
count
= strlen (bbrdheader
);
if (write (md
, bbrdheader
, count
) != count
) {
ll_log (logptr
, LLOGTMP
, "error writing BBoard information");
for (cp
= bbrdheader
; *cp
; cp
++, size
++)
rp_gval (result
= qu_rtxt (buffer
, &len
)) == RP_OK
;
(offset
= strindex (delim1
, buffer
)) >= 0;
(offset
= strindex (delim2
, buffer
)) >= 0;
if (write (md
, buffer
, len
) != len
) {
ll_log (logptr
, LLOGTMP
, "error writing to file '%s'",
for (offset
= 0, cp
= buffer
; offset
< len
; offset
++, size
++)
ll_log (logptr
, LLOGTMP
, "error reading from message file '%s'",
stop
= (long) lseek (md
, (off_t
)0, 1);
if (write (md
, delim2
, count
) != count
)
ll_log (logptr
, LLOGTMP
, "error writing delim2");
map_write (curbb
-> bb_file
, md
, curbb
-> bb_maxima
, start
, stop
, pos
,
ll_log (logptr
, LLOGGEN
, "end local delivery...");
mbx_close (curbb
-> bb_file
, md
);
result
= mbx_close (curbb
-> bb_file
, md
);
return (result
!= NOTOK
? RP_OK
: RP_FIO
);
ll_log (logptr
, LLOGBTR
, "bb_txtcpy()");
if (curbb
-> bb_dist
== NULL
|| *curbb
-> bb_dist
== NULL
ll_log (logptr
, LLOGGEN
, "begin distribution...");
if (curbb
-> bb_file
== NULL
|| *curbb
-> bb_file
== NULL
)
printx("\rperforming remote distribution\n");
if (rp_isbad (result
= dist_init ())
|| rp_isbad (result
= dist_adrs ())
|| rp_isbad (result
= dist_text ())
|| rp_isbad (result
= dist_end ()))
return dist_lose (result
);
ll_log (logptr
, LLOGGEN
, "end distribution...");
printx ("\rmessage distributed\n");
/* **************** (dist_) BBOARD DISTRIBUTION **************** */
struct rp_bufstruct reply
;
ll_log (logptr
, LLOGBTR
, "dist_init()");
if (rp_isbad (result
= mm_init ()))
return ds_log (result
, LLOGFAT
, "mm_init() failed [%s]",
if (rp_isbad (result
= mm_sbinit ()))
return ds_log (result
, LLOGFAT
, "mm_sbinit() failed [%s]",
if (rp_isbad (result
= mm_winit (chnlname
, chnlinfo
, bbrdaddr
)))
return ds_log (result
, LLOGFAT
,
"mm_winit('%s','%s','%s') failed [%s]",
chnlname
, chnlinfo
, bbrdaddr
, rp_valstr (result
));
if (rp_isbad (result
= mm_rrply (&reply
, &len
)))
return ds_log (result
, LLOGFAT
, "problem with sender address [%s]",
ll_log (logptr
, LLOGBTR
, "dist_adrs()");
if (getbbdist (curbb
, ds_address
))
return ds_log (RP_NO
, LLOGTMP
, "getbbdist failed: %s", getbberr ());
if (rp_isbad (result
= mm_waend ()))
return ds_log (result
, LLOGFAT
, "mm_waend() failed [%s]",
char *addr
, /* local part */
struct rp_bufstruct reply
;
ll_log (logptr
, LLOGBTR
, "ds_address(addr='%s',host='%s')", addr
, host
);
printx ("\rperforming distribution to %s@%s...\n", addr
, host
);
if (rp_isbad (result
= mm_wadr (host
, addr
))) {
ds_log (result
, LLOGFAT
, "mm_wadr('%s','%s') failed [%s]",
host
, addr
, rp_valstr (result
));
if (rp_isbad (result
= mm_rrply (&reply
, &len
))) {
"mm_rrply() failed [%s] getting status of '%s@%s'",
rp_valstr (result
), addr
, host
);
switch (rp_gval (reply
.rp_val
)) {
ll_log (logptr
, LLOGGEN
, "address '%s@%s' [%s] -- %s",
addr
, host
, rp_valstr (reply
.rp_val
), reply
.rp_line
);
ds_log (reply
.rp_val
, LLOGTMP
, "address '%s@%s' [%s] -- %s",
addr
, host
, rp_valstr (reply
.rp_val
), reply
.rp_line
);
return OK
; /* fail-soft */
ds_log (reply
.rp_val
, LLOGFAT
, "unexpected reply [%s] -- %s",
rp_valstr (reply
.rp_val
), reply
.rp_line
);
ll_log (logptr
, LLOGBTR
, "dist_text()");
rp_gval (result
= qu_rtxt (buffer
, &len
)) == RP_OK
;
if (rp_isbad (result
= mm_wtxt (buffer
, len
)))
return ds_log (result
, LLOGFAT
, "mm_wtxt() failed [%s]",
return ds_log (RP_FIO
, LLOGTMP
,
"error reading from message file '%s'", qu_msgfile
);
if (rp_isbad (result
= mm_wtend ()))
return ds_log (result
, LLOGFAT
, "mm_wtend() failed [%s]",
struct rp_bufstruct reply
;
ll_log (logptr
, LLOGBTR
, "dist_end()");
if (rp_isbad (result
= mm_rrply (&reply
, &len
)))
return ds_log (result
, LLOGFAT
,
"mm_rrply() failed [%s] getting final status",
switch (rp_gval (reply
.rp_val
)) {
ll_log (logptr
, LLOGGEN
, "message [%s] -- %s",
rp_valstr (reply
.rp_val
), reply
.rp_line
);
return ds_log (RP_NO
, LLOGTMP
, "not delivered [%s] -- %s",
rp_valstr (reply
.rp_val
), reply
.rp_line
);
return ds_log (RP_RPLY
, LLOGFAT
,
"unexpected final reply [%s] -- %s",
rp_valstr (reply
.rp_val
), reply
.rp_line
);
ll_log (logptr
, LLOGBTR
, "dist_lose(result=0%o)", result
);
printx ("\rerrors during distribution: ");
(void) sprintf (intro
, "bboards%d distribution for %s failed [%s]\n",
getpid (), curbb
-> bb_name
, rp_valstr (result
));
if (loseaux (bbrdaddr
, bbrdfrom
, intro
) != OK
&& loseaux (bbrdfrom
, (char *) 0, intro
) != OK
) {
printx ("unable to post advisory.\n");
ll_log (logptr
, LLOGFAT
, "unable to post failure notice");
(void) lseek (err_fd
, (off_t
)0, 0);
if ((i
= read (err_fd
, buffer
, sizeof buffer
)) > 0) {
if (cp
= index (buffer
, '\n'))
ll_log (logptr
, LLOGFAT
, "info: %s", buffer
);
if (loseaux (supportaddr
, (char *) 0, intro
) != NOTOK
)
ll_log (logptr
, LLOGFAT
, "unable to advise %s of failure!",
printx ("advisory posted.\n");
int loseaux (to
, cc
, intro
)
if (ml_init (NO
, NO
, sitesignature
, "Re-distribution Failure") != OK
if (cc
&& (ml_cc () != OK
|| ml_adr (cc
) != OK
))
if (ml_aend () != OK
|| ml_tinit () != OK
)
lseek (err_fd
, (off_t
)0, 0);
while ((i
= read (err_fd
, buffer
, sizeof buffer
)) > 0) {
/* very similar to sbr/cpydgst.c */
#define output(c) if (bp >= dp) {flush (); *bp++ = c;} else *bp++ = c
#define flush() if (bp - outbuf) \
*bp = NULL, ml_txt (outbuf), bp = outbuf
dp
= (bp
= outbuf
) + sizeof outbuf
;
for (state
= S1
, len
= BUFSIZ
;
rp_gval (result
= qu_rtxt (buffer
, &len
)) == RP_OK
;
for (ep
= (cp
= buffer
) + len
; cp
< ep
; cp
++) {
ml_txt ("\n------- Forwarded Message\n\n");
ml_txt ("\n------- Forwarded Message\n\n");
ll_log (logptr
, LLOGTMP
, "error reading message when noting failure");
ml_txt ("\n------- End of Forwarded Message\n\n");
ml_txt ("[ error reading message ]\n");
ml_txt ("\n------- End of Forwarded Message\n\n");
ll_log (logptr
, LLOGTMP
, "message empty when noting failure");
ml_txt ("[ message empty ]\n");
ds_log (result
, level
, fmt
, a
, b
, c
, d
, e
)
ll_log (logptr
, level
, fmt
, a
, b
, c
, d
, e
);
sprintf (buffer
, fmt
, a
, b
, c
, d
, e
);
printx ("\rerror: %s", buffer
);
unlink (mktemp (strcpy (tmpfil
, "/tmp/bboardsXXXXXX")));
if ((err_fd
= creat (tmpfil
, 0600)) == NOTOK
)
if ((err_fd
= open (tmpfil
, 2)) == NOTOK
)
lseek (err_fd
, (off_t
)0, 0);
write (err_fd
, buffer
, i
);
/* mbx_ local mailbox routines */
if ((fd
= mbx_Xopen (curbb
-> bb_info
, bbrduid
, bbrdgid
, MBXMODE
, &clear
))
printx ("\runable to lock %s\n", curbb
-> bb_info
);
ll_err (logptr
, LLOGTMP
, "unable to lock %s",
printx ("\runable to open '%s'", curbb
-> bb_info
);
ll_log (logptr
, LLOGTMP
, "unable to open '%s'", curbb
-> bb_info
);
if ((fp
= fdopen (fd
, "w")) == (FILE *) NULL
) {
printx ("\runable to fdopen '%s'", curbb
-> bb_info
);
ll_err (logptr
, LLOGTMP
, "unable to fdopen '%s'", curbb
-> bb_info
);
mbx_close (curbb
-> bb_info
, fd
);
strcpy (name
, curbb
-> bb_name
);
if ((curbb
= getbbnam (name
)) == (struct bboard
*) NULL
) {
printx ("\runable to get information on BBoard %s\n", name
);
ll_err (logptr
, LLOGFAT
, "unable to get info on %s", name
);
lkfclose (fp
, curbb
-> bb_info
);
sprintf (bbrdheader
, "BBoard-ID: %d\nBB-Posted: %s\n",
++curbb
-> bb_maxima
, cnvtdate (TIMREG
, bbrdtime
));
fprintf (fp
, "%d\n%s\n", curbb
-> bb_maxima
, bbrdtime
);
lkfclose (fp
, curbb
-> bb_info
);