Annotation of 43BSDReno/contrib/mh/conf/config/mts.c, revision 1.1

1.1     ! root        1: /* @(MHWARNING) */
        !             2: /* @(#) $Header: mts.c,v 1.3 89/12/15 23:53:32 leres Locked $ (LBL) */
        !             3: /* mts.c - definitions for the mail transport system */
        !             4: 
        !             5: /* LINTLIBRARY */
        !             6: 
        !             7: #undef NETWORK
        !             8: #if    defined(BSD41A) || defined(BSD42)
        !             9: #define        NETWORK
        !            10: #endif not (defined(BSD41A) || defined(BSD42))
        !            11: 
        !            12: #include "../h/strings.h"
        !            13: #include <ctype.h>
        !            14: #include <stdio.h>
        !            15: #include "mts.h"
        !            16: #ifdef NETWORK
        !            17: #ifdef BSD42
        !            18: #include <netdb.h>
        !            19: #endif BSD42
        !            20: #else  not NETWORK
        !            21: #ifndef SYS5
        !            22: #include <whoami.h>
        !            23: #else SYS5
        !            24: #include <sys/utsname.h>
        !            25: #endif SYS5
        !            26: #endif not NETWORK
        !            27: #include <pwd.h>
        !            28: 
        !            29: 
        !            30: #define        NOTOK   (-1)
        !            31: #define        OK      0
        !            32: 
        !            33: #define        NULLCP  ((char *) 0)
        !            34: 
        !            35: extern int  errno;
        !            36: 
        !            37: static char *tailor_value();
        !            38: 
        !            39: 
        !            40: #ifdef SYS5
        !            41: #define        index   strchr
        !            42: #define        rindex  strrchr
        !            43: #endif SYS5
        !            44: 
        !            45: char   *index (), *malloc (), *mktemp (), *rindex (), *strcpy ();
        !            46: 
        !            47: struct passwd  *getpwuid ();
        !            48: 
        !            49: /*  */
        !            50: 
        !            51: /*
        !            52:    *mmdfldir and *uucpldir are the maildrop directories.  If maildrops
        !            53:    are kept in the user's home directory, then these should be empty
        !            54:    strings.  In this case, the appropriate ...lfil array should contain
        !            55:    the name of the file in the user's home directory.  Usually, this is
        !            56:    something like ".mail".
        !            57:  */
        !            58: 
        !            59: static char *mtstailor = "@(MHETCPATH)/mtstailor";
        !            60: 
        !            61: static char    *localname = "";
        !            62: static char    *systemname = "";
        !            63: #ifdef MF
        !            64: static char    *UUCPchan = "";
        !            65: #endif MF
        !            66: char   *mmdfldir = "@(MHDROPATH)";
        !            67: char   *mmdflfil = "@(MHDROPFIL)";
        !            68: char   *uucpldir = "@(MHDROPATH)";
        !            69: char   *uucplfil = "";
        !            70: 
        !            71: 
        !            72: char   *mmdlm1 = "\001\001\001\001\n";
        !            73: char   *mmdlm2 = "\001\001\001\001\n";
        !            74: 
        !            75: 
        !            76: static int  MMailids = 0;
        !            77: static char *mmailid = "0";
        !            78: 
        !            79: 
        !            80: #ifdef MF
        !            81: char   *umincproc = "@(MHETCPATH)/uminc";
        !            82: #else  MF
        !            83: char   *umincproc = NULL;
        !            84: #endif MF
        !            85: 
        !            86: 
        !            87: int    lockstyle = LOK_UNIX;
        !            88: static char *lkstyle = "0";
        !            89: char   *lockldir = "";
        !            90: 
        !            91: /*  */
        !            92: 
        !            93: /* MTS specific variables */
        !            94: 
        !            95: #ifdef MHMTS
        !            96: char   *Mailqdir = "/usr/spool/netmail";
        !            97: char   *TMailqdir = "/usr/tmp";
        !            98: int     Syscpy = 1;
        !            99: static char *syscpy = "1";
        !           100: char   *Overseer = "root";
        !           101: char   *Mailer = "root";
        !           102: char   *Fromtmp = "/tmp/rml.f.XXXXXX";
        !           103: char   *Msgtmp = "/tmp/rml.m.XXXXXX";
        !           104: char   *Errtmp = "/tmp/rml.e.XXXXXX";
        !           105: int     Tmpmode = 0600;
        !           106: static char *tmpmode = "0600";
        !           107: char   *Okhosts = "@(MHETCPATH)/Rmail.OkHosts";
        !           108: char   *Okdests = "@(MHETCPATH)/Rmail.OkDests";
        !           109: #endif MHMTS
        !           110: 
        !           111: #ifdef MMDFMTS
        !           112: #endif MMDFMTS
        !           113: 
        !           114: #ifdef SENDMTS
        !           115: char   *hostable = "@(MHETCPATH)/hosts";
        !           116: char   *sendmail = "/usr/sbin/sendmail";
        !           117: #endif SENDMTS
        !           118: 
        !           119: 
        !           120: /* SMTP/POP stuff */
        !           121: 
        !           122: char   *servers = "localhost \01localnet";
        !           123: char   *pophost = "";
        !           124: 
        !           125: 
        !           126: /* BBoards-specific variables */
        !           127: 
        !           128: char   *bb_domain = "";
        !           129: 
        !           130: 
        !           131: /* POP BBoards-specific variables */
        !           132: 
        !           133: #ifdef BPOP
        !           134: char    *popbbhost = "";
        !           135: char    *popbbuser = "";
        !           136: char    *popbblist = "@(MHETCPATH)/hosts.popbb";
        !           137: #endif BPOP
        !           138: 
        !           139: 
        !           140: /* MailDelivery */
        !           141: 
        !           142: char   *maildelivery = "@(MHETCPATH)/maildelivery";
        !           143: 
        !           144: 
        !           145: /* Aliasing Facility (doesn't belong here) */
        !           146: 
        !           147: int    Everyone = NOTOK;
        !           148: static char *everyone = "-1";
        !           149: char   *NoShell = "";
        !           150: 
        !           151: /*  */
        !           152: 
        !           153: /* customize the MTS settings for MH by reading @(MHETCPATH)/mtstailor */
        !           154: 
        !           155: static  struct bind {
        !           156:     char   *keyword;
        !           157:     char  **value;
        !           158: }       binds[] = {
        !           159:     "localname", &localname,
        !           160:     "systemname", &systemname,
        !           161: #ifdef MF
        !           162:     "uucpchan", &UUCPchan,
        !           163: #endif MF
        !           164:     "mmdfldir", &mmdfldir,
        !           165:     "mmdflfil", &mmdflfil,
        !           166:     "uucpldir", &uucpldir,
        !           167:     "uucplfil", &uucplfil,
        !           168:     "mmdelim1", &mmdlm1,
        !           169:     "mmdelim2", &mmdlm2,
        !           170:     "mmailid", &mmailid,
        !           171:     "umincproc", &umincproc,
        !           172:     "lockstyle", &lkstyle,
        !           173:     "lockldir", &lockldir,
        !           174: 
        !           175: #ifdef MHMTS
        !           176:     "mailqdir", &Mailqdir,
        !           177:     "tmailqdir", &TMailqdir,
        !           178:     "syscpy", &syscpy,
        !           179:     "overseer", &Overseer,
        !           180:     "mailer", &Mailer,
        !           181:     "fromtmp", &Fromtmp,
        !           182:     "msgtmp", &Msgtmp,
        !           183:     "errtmp", &Errtmp,
        !           184:     "tmpmode", &tmpmode,
        !           185:     "okhosts", &Okhosts,
        !           186:     "okdests", &Okdests,
        !           187: #endif MHMTS
        !           188: 
        !           189: #ifdef MMDFMTS
        !           190: #endif MMDFMTS
        !           191: 
        !           192: #ifdef SENDMTS
        !           193:     "hostable", &hostable,
        !           194:     "sendmail", &sendmail,
        !           195: #endif SENDMTS
        !           196: 
        !           197:     "servers", &servers,
        !           198:     "pophost", &pophost,
        !           199: 
        !           200:     "bbdomain", &bb_domain,
        !           201: 
        !           202: #ifdef BPOP
        !           203:     "popbbhost", &popbbhost,
        !           204:     "popbbuser", &popbbuser,
        !           205:     "popbblist", &popbblist,
        !           206: #endif BPOP
        !           207: 
        !           208:     "maildelivery", &maildelivery,
        !           209: 
        !           210:     "everyone", &everyone,
        !           211:     "noshell", &NoShell,
        !           212: 
        !           213:     NULL
        !           214: };
        !           215: 
        !           216: /*  */
        !           217: 
        !           218: /* I'd like to use m_getfld() here, but not all programs loading mts.o may be
        !           219:    MH-style programs... */
        !           220: 
        !           221: /* ARGSUSED */
        !           222: 
        !           223: mts_init(name)
        !           224:        char *name;
        !           225: {
        !           226:     register char  *bp,
        !           227:                    *cp;
        !           228:     char    buffer[BUFSIZ];
        !           229:     register struct bind   *b;
        !           230:     register    FILE *fp;
        !           231:     static int  inited = 0;
        !           232: 
        !           233:     if (inited++ || (fp = fopen (mtstailor, "r")) == NULL)
        !           234:        return;
        !           235: 
        !           236:     while (fgets (buffer, sizeof buffer, fp)) {
        !           237:        if ((cp = index (buffer, '\n')) == NULL)
        !           238:            break;
        !           239:        *cp = NULL;
        !           240:        if (*buffer == '#' || *buffer == NULL)
        !           241:            continue;
        !           242:        if ((bp = index (buffer, ':')) == NULL)
        !           243:            break;
        !           244:        *bp++ = NULL;
        !           245:        while (isspace (*bp))
        !           246:            *bp++ = NULL;
        !           247: 
        !           248:        for (b = binds; b -> keyword; b++)
        !           249:            if (strcmp (buffer, b -> keyword) == 0)
        !           250:                break;
        !           251:        if (b -> keyword && (cp = tailor_value (bp)))
        !           252:            *b -> value = cp;
        !           253:     }
        !           254: 
        !           255:     (void) fclose (fp);
        !           256: 
        !           257:     MMailids = atoi (mmailid);
        !           258:     if ((lockstyle = atoi (lkstyle)) < LOK_UNIX || lockstyle > LOK_MMDF)
        !           259:        lockstyle = LOK_UNIX;
        !           260: #ifdef MHMTS
        !           261:     Syscpy = atoi (syscpy);
        !           262:     (void) sscanf (tmpmode, "0%o", &Tmpmode);
        !           263: #endif MHMTS
        !           264:     Everyone = atoi (everyone);
        !           265: }
        !           266: 
        !           267: /*  */
        !           268: 
        !           269: #define        QUOTE   '\\'
        !           270: 
        !           271: static char *
        !           272: tailor_value(s)
        !           273:        register char *s;
        !           274: {
        !           275:     register int    i,
        !           276:                     r;
        !           277:     register char  *bp;
        !           278:     char    buffer[BUFSIZ];
        !           279: 
        !           280:     for (bp = buffer; *s; bp++, s++)
        !           281:        if (*s != QUOTE)
        !           282:            *bp = *s;
        !           283:        else
        !           284:            switch (*++s) {
        !           285:                case 'b': *bp = '\b'; break;
        !           286:                case 'f': *bp = '\f'; break;
        !           287:                case 'n': *bp = '\n'; break;
        !           288:                case 't': *bp = '\t'; break;
        !           289: 
        !           290:                case NULL: s--;
        !           291:                case QUOTE:
        !           292:                    *bp = QUOTE;
        !           293:                    break;
        !           294: 
        !           295:                default:
        !           296:                    if (!isdigit (*s)) {
        !           297:                        *bp++ = QUOTE;
        !           298:                        *bp = *s;
        !           299:                    }
        !           300:                    r = *s != '0' ? 10 : 8;
        !           301:                    for (i = 0; isdigit (*s); s++)
        !           302:                        i = i * r + *s - '0';
        !           303:                    s--;
        !           304:                    *bp = toascii (i);
        !           305:                    break;
        !           306:            }
        !           307:     *bp = NULL;
        !           308: 
        !           309:     bp = malloc ((unsigned) (strlen (buffer) + 1));
        !           310:     if (bp != NULL)
        !           311:        (void) strcpy (bp, buffer);
        !           312: 
        !           313:     return bp;
        !           314: }
        !           315: 
        !           316: /*  */
        !           317: 
        !           318: char *
        !           319: LocalName()
        !           320: {
        !           321: #ifdef BSD41A
        !           322:     char  *myname;
        !           323: #endif BSD41A
        !           324: #ifdef BSD42
        !           325:     register struct hostent *hp;
        !           326: #endif BSD42
        !           327: #ifdef SYS5
        !           328:     struct utsname name;
        !           329: #endif SYS5
        !           330:     static char buffer[BUFSIZ] = "";
        !           331: 
        !           332:     if (buffer[0])
        !           333:        return buffer;
        !           334: 
        !           335:     mts_init ("mts");
        !           336:     if (*localname)
        !           337:        return strcpy (buffer, localname);
        !           338: 
        !           339: #ifdef locname
        !           340:     (void) strcpy (buffer, locname);
        !           341: #else  not locname
        !           342: #ifdef NETWORK
        !           343: #ifdef BSD41A
        !           344:     myname = "myname";
        !           345:     if (rhost (&myname) == -1)
        !           346:        (void) gethostname (buffer, sizeof buffer);
        !           347:     else {
        !           348:        (void) strcpy (buffer, myname);
        !           349:        free (myname);
        !           350:     }
        !           351: #endif BSD41A
        !           352: #ifdef BSD42
        !           353:     (void) gethostname (buffer, sizeof buffer);
        !           354:     sethostent (1);
        !           355:     if (hp = gethostbyname (buffer))
        !           356:        (void) strcpy (buffer, hp -> h_name);
        !           357: #endif BSD42
        !           358: #else  not NETWORK
        !           359: #ifndef        SYS5
        !           360:     (void) strcpy (buffer, SystemName ());
        !           361: #else  SYS5
        !           362:     (void) uname (&name);
        !           363:     (void) strcpy (buffer, name.nodename);
        !           364: #endif SYS5
        !           365: #endif not NETWORK
        !           366: #endif not locname
        !           367: 
        !           368:     return buffer;
        !           369: }
        !           370: 
        !           371: /*  */
        !           372: 
        !           373: char *
        !           374: SystemName()
        !           375: {
        !           376: #ifdef SYS5
        !           377:     struct utsname name;
        !           378: #endif SYS5
        !           379:     static char buffer[BUFSIZ] = "";
        !           380: 
        !           381:     if (buffer[0])
        !           382:        return buffer;
        !           383: 
        !           384:     mts_init ("mts");
        !           385:     if (*systemname)
        !           386:        return strcpy (buffer, systemname);
        !           387: 
        !           388: #ifdef sysname
        !           389:     (void) strcpy (buffer, sysname);
        !           390: #else  sysname
        !           391: #ifndef        SYS5
        !           392:     (void) gethostname (buffer, sizeof buffer);
        !           393: #else   SYS5
        !           394:     (void) uname (&name);
        !           395:     (void) strcpy (buffer, name.nodename);
        !           396: #endif  SYS5
        !           397: #endif sysname
        !           398: 
        !           399:     return buffer;
        !           400: }
        !           401: 
        !           402: /*  */
        !           403: 
        !           404: char *
        !           405: UucpChan()
        !           406: {
        !           407: #ifdef MF
        !           408:     static char buffer[BUFSIZ] = "";
        !           409: #endif MF
        !           410: 
        !           411: #ifndef        MF
        !           412:     return NULL;
        !           413: #else  MF
        !           414:     if (buffer[0])
        !           415:        return buffer;
        !           416: 
        !           417:     mts_init ("mts");
        !           418:     if (*UUCPchan)
        !           419:        return strcpy (buffer, UUCPchan);
        !           420: 
        !           421: #ifdef uucpchan
        !           422:     (void) strcpy (buffer, uucpchan);
        !           423: #else  uucpchan
        !           424:     (void) strcpy (buffer, "uucp");
        !           425: #endif uucpchan
        !           426:     return buffer;
        !           427: #endif MF
        !           428: }
        !           429: 
        !           430: /*  */
        !           431: 
        !           432: #ifdef ALTOS
        !           433: gethostname(name, len)
        !           434:        register char *name;
        !           435:        register int len;
        !           436: {
        !           437:     register char  *cp;
        !           438:     register FILE  *fp;
        !           439: 
        !           440:     if (fp = fopen ("/etc/systemid", "r")) {
        !           441:        if (fgets (name, len, fp)) {
        !           442:            if (cp = index (name, '\n'))
        !           443:                *cp = NULL;
        !           444:            (void) fclose (fp);
        !           445:            return OK;
        !           446:        }
        !           447:        (void) fclose (fp);
        !           448:     }
        !           449:     (void) strncpy (name, "altos", len);
        !           450: 
        !           451:     return OK;
        !           452: }
        !           453: #endif ALTOS
        !           454: 
        !           455: /*  */
        !           456: 
        !           457: static char username[BUFSIZ] = "";
        !           458: static char fullname[BUFSIZ] = "";
        !           459: 
        !           460: 
        !           461: char *
        !           462: getusr()
        !           463: {
        !           464:     register char  *cp,
        !           465:                    *np;
        !           466:     register struct passwd *pw;
        !           467: 
        !           468:     if (username[0])
        !           469:        return username;
        !           470: 
        !           471:     if ((pw = getpwuid (getuid ())) == NULL
        !           472:            || pw -> pw_name == NULL
        !           473:            || *pw -> pw_name == NULL) {
        !           474:        (void) strcpy (username, "intruder");
        !           475:        (void) sprintf (fullname, "The Unknown User-ID (%d)", getuid ());
        !           476:        return username;
        !           477:     }
        !           478: 
        !           479:     if (MMailids) {
        !           480:        np = pw -> pw_gecos;
        !           481:        for (cp = fullname; *np && *np != '<'; *cp++ = *np++)
        !           482:            continue;
        !           483:        *cp = NULL;
        !           484:        if (*np)
        !           485:            np++;
        !           486:        for (cp = username; *np && *np != '>'; *cp++ = *np++)
        !           487:            continue;
        !           488:        *cp = NULL;
        !           489:     }
        !           490:     if (MMailids == 0 || *np == NULL) {
        !           491:        (void) strcpy (username, pw -> pw_name);
        !           492:        fullname[0] = NULL;
        !           493:     }
        !           494:     if ((cp = getenv ("SIGNATURE")) && *cp)
        !           495:        (void) strcpy (fullname, cp);
        !           496: 
        !           497:     return username;
        !           498: }
        !           499: 
        !           500: 
        !           501: char *
        !           502: getfullname()
        !           503: {
        !           504:     if (username[0] == NULL)
        !           505:        (void) getusr ();
        !           506: 
        !           507:     return fullname;
        !           508: }
        !           509: 
        !           510: /*  */
        !           511: 
        !           512: #ifdef SYS5
        !           513: #ifndef        notdef                  /* Supposedly this works, I prefer the
        !           514:                                   recursive solution... */
        !           515: 
        !           516: #include <fcntl.h>
        !           517: 
        !           518: dup2(d1, d2)
        !           519:        register int d1, d2;
        !           520: {
        !           521:     int     d;
        !           522: 
        !           523:     if (d1 == d2)
        !           524:        return OK;
        !           525: 
        !           526:     (void) close (d2);
        !           527:     if ((d = fcntl (d1, F_DUPFD, d2)) == NOTOK)
        !           528:        return NOTOK;
        !           529:     if (d == d2)
        !           530:        return OK;
        !           531: 
        !           532:     errno = 0;
        !           533:     return NOTOK;
        !           534: }
        !           535: 
        !           536: #else  notdef
        !           537: dup2(d1, d2)
        !           538:        register int d1, d2;
        !           539: {
        !           540:     if (d1 == d2)
        !           541:        return OK;
        !           542: 
        !           543:     (void) close (d2);
        !           544:     return dup2aux (d1, d2);
        !           545: }
        !           546: 
        !           547: 
        !           548: static int
        !           549: dup2aux(d1, d2)
        !           550:        register int d1, d2;
        !           551: {
        !           552:     int     d,
        !           553:             i,
        !           554:             eindex;
        !           555: 
        !           556:     if ((d = dup (d1)) == NOTOK)
        !           557:        return NOTOK;
        !           558:     if (d == d2)
        !           559:        return OK;
        !           560: 
        !           561:     i = dup2aux (d1, d2);
        !           562:     eindex = errno;
        !           563:     (void) close (d);
        !           564:     errno = eindex;
        !           565:     return i;
        !           566: }
        !           567: #endif notdef
        !           568: #endif SYS5

unix.superglobalmegacorp.com

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