Annotation of 43BSDReno/contrib/mh/zotnet/mf/mmdfI/src/uucp/qu2uu_send.c, revision 1.1.1.1

1.1       root        1: #define        MFDEBUG                 /* temporarily */
                      2: 
                      3: /* qu2uu_send.c - manager for qu --> uu */
                      4: 
                      5: #include "util.h"
                      6: #include "mmdf.h"
                      7: 
                      8: /*  */
                      9: 
                     10: extern char *qu_msgfile,
                     11:             sitesignature[],
                     12:             supportaddr[];
                     13: 
                     14: extern struct ll_struct *logptr;
                     15: 
                     16: 
                     17: struct rp_construct rp_aend = {        /* end of address list */
                     18:     RP_OK,
                     19:     'u', 'u', 'c', 'p', ' ', 'e', 'n', 'd', ' ', 'o', 'f', ' ',
                     20:     'a', 'd', 'd', 'r', ' ', 'l', 'i', 's', 't', NULL
                     21: };
                     22: 
                     23: struct rp_construct rp_bhost = {/* no such host */
                     24:     RP_USER,
                     25:     'b', 'a', 'd', ' ', 'h', 'o', 's', 't', ' ', 'n', 'a', 'm', 'e', NULL
                     26: };
                     27: 
                     28: struct rp_construct rp_err = { /* error, you lose */
                     29:     RP_NO,
                     30:     'u', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', NULL
                     31: };
                     32: 
                     33: 
                     34: char   *index (), *strdup ();
                     35: 
                     36: /*  */
                     37: 
                     38: qu2uu_send () {
                     39:     short   result;
                     40:     char    info[LINESIZE],
                     41:             sender[LINESIZE];
                     42: 
                     43: #ifdef DEBUG
                     44:     ll_log (logptr, LLOGBTR, "qu2uu_send ()");
                     45: #endif
                     46: 
                     47:     if (rp_isbad (result = qu_pkinit ()))
                     48:        return result;
                     49:     if (rp_isbad (result = uu_sbinit ()))
                     50:        return result;
                     51: 
                     52:     while (rp_gval ((result = qu_rinit (info, sender))) == RP_OK) {
                     53: #ifdef DEBUG
                     54:        ll_log (logptr, LLOGGEN, "info=%s sender=%s", info, sender);
                     55: #endif
                     56:        if (rp_isbad (result = qu2uu_each (sender)))
                     57:            return result;
                     58:     }
                     59: 
                     60:     if (rp_gval (result) != RP_DONE) {
                     61:        ll_log (logptr, LLOGTMP, "not DONE [%s]", rp_valstr (result));
                     62:        return RP_RPLY;
                     63:     }
                     64: 
                     65:     qu_pkend ();
                     66:     uu_sbend ();
                     67: 
                     68:     return result;
                     69: }
                     70: 
                     71: /*  */
                     72: 
                     73: qu2uu_each (sender)
                     74: char   *sender;
                     75: {
                     76:     short   result;
                     77:     char    adr[LINESIZE],
                     78:             host[LINESIZE];
                     79:     RP_Buf replyval;
                     80: 
                     81: #ifdef DEBUG
                     82:     ll_log (logptr, LLOGBTR, "qu2uu_each(sender='%s')", sender);
                     83: #endif
                     84: 
                     85:     mf_rinit (sender, qu_fileno ());
                     86: 
                     87: /*  */
                     88: 
                     89:     FOREVER
                     90:     {
                     91:        if (rp_isbad (result = qu_radr (host, adr))) {
                     92:            mf_rend ();
                     93:            return result;
                     94:        }
                     95:        if (rp_gval (result) == RP_DONE) {
                     96:            qu_wrply ((RP_Buf *) & rp_aend, rp_conlen (rp_aend));
                     97:            mf_rend ();
                     98:            return RP_OK;
                     99:        }
                    100: 
                    101:        switch (replyval.rp_val = uu_wtadr (host, adr)) {
                    102:            case RP_OK: 
                    103:            case RP_AOK: 
                    104:                replyval.rp_val = uu_txtcpy ();
                    105:                break;
                    106: 
                    107:            case RP_USER: 
                    108:                ll_log (logptr, LLOGFAT, "host (%s) not in table", host);
                    109:                blt (&rp_bhost, (char *) & replyval, sizeof rp_bhost);
                    110:                break;
                    111: 
                    112:            default: 
                    113:                ll_log (logptr, LLOGFAT,
                    114:                        "unknown return from uu_wtadr() [%s]",
                    115:                        rp_valstr (replyval.rp_val));
                    116:                blt (&rp_err, (char *) & replyval, sizeof rp_err);
                    117:                replyval.rp_val = RP_NO;
                    118:                break;
                    119:        }
                    120:        if (replyval.rp_val == RP_MOK)
                    121:            switch (replyval.rp_val = uu_wttend ()) {
                    122:                case RP_OK: 
                    123:                case RP_MOK: 
                    124:                    replyval.rp_line[0] = NULL;
                    125:                    break;
                    126: 
                    127:                case RP_USER: 
                    128:                case RP_LIO: 
                    129:                    ll_log (logptr, LLOGFAT, "host (%s) not in table", host);
                    130:                    blt (&rp_bhost, (char *) & replyval, sizeof rp_bhost);
                    131:                    replyval.rp_val = RP_USER;
                    132:                    break;
                    133: 
                    134:                default: 
                    135:                    ll_log (logptr, LLOGFAT,
                    136:                            "unknown return from uu_wttend() [%s]",
                    137:                            rp_valstr (replyval.rp_val));
                    138:                    blt (&rp_err, (char *) & replyval, sizeof rp_err);
                    139:                    break;
                    140:            }
                    141: 
                    142:        qu_wrply (&replyval,
                    143:                (sizeof replyval.rp_val) + strlen (replyval.rp_line));
                    144:     }
                    145: }
                    146: 
                    147: /*  */
                    148: 
                    149: /* ******************** (mf_) MAIL-FILTERING HANDLING ******************** */
                    150: 
                    151: #include "mf.h"
                    152: 
                    153: 
                    154: static int  mf_fd;
                    155: 
                    156: static char mf_from[BUFSIZ];
                    157: 
                    158: /*  */
                    159: 
                    160: int     mf_rinit (addr, fd)
                    161: char   *addr;
                    162: int     fd;
                    163: {
                    164:     long    timenow;
                    165:     char   *sender,
                    166:             buffer[BUFSIZ];
                    167:     struct adrx *adrxp;
                    168: 
                    169:     mf_from[0] = NULL;
                    170: 
                    171:     if ((mf_fd = mf_get_msg (fd)) == NOTOK) {
                    172:        adrxp = getadrx (addr);
                    173:        sender = adrxp -> err ? addr
                    174:            : lexequ (adrxp -> host, LocalName ())
                    175:            || lexequ (adrxp -> host, SystemName ()) ? adrxp -> mbox
                    176:            : sprintf (buffer, "%s@%s", adrxp -> mbox, adrxp -> host);
                    177:        while (getadrx (NULL))
                    178:            continue;
                    179:        sender = strdup (sender);
                    180:        lowerfy (sender);
                    181:        sprintf (mf_from, "From %s %.24s remote from %s\n",
                    182:                sender, ctime (&timenow), SystemName ());
                    183:        free (sender);
                    184:     }
                    185: 
                    186:     return RP_OK;
                    187: }
                    188: 
                    189: /*  */
                    190: 
                    191: int     mf_rend () {
                    192:     if (mf_fd != NOTOK)
                    193:        close (mf_fd);
                    194:     mf_fd = NOTOK;
                    195:     mf_from[0] = NULL;
                    196: 
                    197:     return RP_OK;
                    198: }
                    199: 
                    200: 
                    201: mf_rtinit (pos)
                    202: long    pos;
                    203: {
                    204:     if (mf_fd == NOTOK)
                    205:        qu_rtinit (pos);
                    206:     else
                    207:        lseek (mf_fd, pos, 0);
                    208: }
                    209: 
                    210: 
                    211: int     mf_rtxt (buffer, len)
                    212: char   *buffer;
                    213: int    *len;
                    214: {
                    215:     if (mf_fd == NOTOK)
                    216:        if (mf_from[0]) {
                    217:            strcpy (buffer, mf_from);
                    218:            buffer[*len = strlen (mf_from)] = NULL;
                    219:            mf_from[0] = NULL;
                    220:            return RP_OK;
                    221:        }
                    222:        else
                    223:            return qu_rtxt (buffer, len);
                    224: 
                    225:     switch (*len = read (mf_fd, buffer, BUFSIZE)) {
                    226:        case NOTOK: 
                    227:            return RP_LIO;
                    228: 
                    229:        case OK: 
                    230:            return RP_DONE;
                    231: 
                    232:        default: 
                    233:            buffer[*len] = NULL;
                    234:            return RP_OK;
                    235:     }
                    236: }
                    237: 
                    238: /*  */
                    239: 
                    240: static int  mf_get_msg (md)
                    241: int     md;
                    242: {
                    243:     int     i,
                    244:             fd,
                    245:             qd;
                    246:     char    buffer[BUFSIZ],
                    247:             tmpfil[BUFSIZ];
                    248: #ifdef MFDEBUG
                    249:     FILE * fp;
                    250: #endif MFDEBUG
                    251: 
                    252:     lseek (md, 0L, 0);
                    253:     if ((qd = dup (md)) == NOTOK)
                    254:        return NOTOK;
                    255: 
                    256:     strcpy (tmpfil, "/tmp/qu2uuXXXXXX");
                    257:     unlink (mktemp (tmpfil));
                    258:     if ((fd = creat (tmpfil, 0600)) == NOTOK) {
                    259:        close (qd);
                    260:        return NOTOK;
                    261:     }
                    262:     close (fd);
                    263:     if ((fd = open (tmpfil, 2)) == NOTOK) {
                    264:        close (qd);
                    265:        return NOTOK;
                    266:     }
                    267:     unlink (tmpfil);
                    268: 
                    269:     if ((i = mmdf_to_uucp (qd, fd, TRUE)) != OK) {
                    270:        close (fd);
                    271: 
                    272:        sprintf (buffer, "ch_uucp(%d) filtering for %s failed (%d)\n",
                    273:                getpid (), qu_msgfile, i);
                    274:        if (ml_1adr (NO, NO, sitesignature, "MF Failure", supportaddr)
                    275:                != OK)
                    276:            goto ml_err;
                    277:        ml_txt (buffer);
                    278: #ifdef MFDEBUG
                    279:        lseek (md, 0L, 0);
                    280:        if ((fd = dup (md)) == NOTOK)
                    281:            ml_txt ("unable to dup() descriptor for message copy\n");
                    282:        else
                    283:            if ((fp = fdopen (fd, "r")) == NULL) {
                    284:                ml_txt ("unable to fdopen() descriptor for message copy\n");
                    285:                close (fd);
                    286:            }
                    287:            else {
                    288:                ml_txt ("\n  --Message Follows--\n");
                    289:                ml_file (fp);
                    290:                fclose (fp);
                    291:            }
                    292: #endif MFDEBUG
                    293:        if (ml_end (OK) != OK) {
                    294:            char   *cp;
                    295: 
                    296:     ml_err: ;
                    297:            if (cp = index (buffer, '\n'))
                    298:                *cp = NULL;
                    299:            ll_log (logptr, LLOGFAT, "Unable to post failure notice");
                    300:            ll_log (logptr, LLOGFAT, "info: %s", buffer);
                    301:        }
                    302: 
                    303:        fd = NOTOK;
                    304:     }
                    305:     close (qd);
                    306: 
                    307:     return fd;
                    308: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.