Annotation of 43BSD/contrib/mh/mts/sendmail/hosts.c, revision 1.1.1.1

1.1       root        1: /* hosts.c - find out the official name of a host */
                      2: 
                      3: /* LINTLIBRARY */
                      4: 
                      5: /* In the SendMail world, we really don't know what the valid hosts are.
                      6:    We could poke around in the sendmail.cf file, but that still isn't a
                      7:    guarantee.  As a result, we'll say that everything is a valid host, and
                      8:    let SendMail worry about it. */
                      9: 
                     10: 
                     11: #include "../h/strings.h"
                     12: #include <stdio.h>
                     13: #include "../zotnet/mts.h"
                     14: #include <ctype.h>
                     15: #ifdef BSD42
                     16: #include <netdb.h>
                     17: #endif BSD42
                     18: 
                     19: 
                     20: #define        NOTOK   (-1)
                     21: 
                     22: 
                     23: static struct host {
                     24:     char   *h_name;
                     25:     char  **h_aliases;
                     26:     struct host   *h_next;
                     27: }                   hosts;
                     28: 
                     29: char   *getcpy ();
                     30: 
                     31: /*  */
                     32: 
                     33: char   *OfficialName (name)
                     34: register char   *name;
                     35: {
                     36:     register char  *p;
                     37:     char   *q,
                     38:             site[BUFSIZ];
                     39: #ifdef BSD42
                     40:     register struct hostent *hp;
                     41: #endif BSD42
                     42:     static char buffer[BUFSIZ];
                     43:     register char **r;
                     44:     register struct host   *h;
                     45: 
                     46:     for (p = name, q = site; *p; p++, q++)
                     47:        *q = isupper (*p) ? tolower (*p) : *p;
                     48:     *q = NULL;
                     49:     q = site;
                     50: 
                     51:     if (uleq (LocalName (), site))
                     52:        return LocalName ();
                     53: 
                     54: #ifdef BSD41A
                     55:     if (rhost (&q) != NOTOK) {
                     56:        (void) strcpy (buffer, q);
                     57:        free (q);
                     58:        return buffer;
                     59:     }
                     60: #endif BSD41A
                     61: #ifdef BSD42
                     62:     sethostent (1);
                     63:     if (hp = gethostbyname (q)) {
                     64:        (void) strcpy (buffer, hp -> h_name);
                     65:        return buffer;
                     66:     }
                     67: #endif BSD42
                     68: 
                     69:     if (hosts.h_name || init_hs ())
                     70:        for (h = hosts.h_next; h; h = h -> h_next)
                     71:            if (uleq (h -> h_name, q))
                     72:                return h -> h_name;
                     73:            else
                     74:                for (r = h -> h_aliases; *r; r++)
                     75:                    if (uleq (*r, q))
                     76:                        return h -> h_name;
                     77: 
                     78:     (void) strcpy (buffer, site);
                     79:     return buffer;
                     80: }
                     81: 
                     82: /*  */
                     83: 
                     84: /* Use hostable as an exception file for those hosts that aren't on the
                     85:    Internet (listed in /etc/hosts).  These are usually PhoneNet and UUCP
                     86:    sites. */
                     87: 
                     88: 
                     89: #define        NALIASES        50
                     90: 
                     91: static int  init_hs () {
                     92:     register char  *cp,
                     93:                    *dp,
                     94:                   **q,
                     95:                   **r;
                     96:     char    buffer[BUFSIZ],
                     97:            *aliases[NALIASES];
                     98:     register struct host   *h;
                     99:     register FILE  *fp;
                    100: 
                    101:     if ((fp = fopen (hostable, "r")) == NULL)
                    102:        return 0;
                    103: 
                    104:     h = &hosts;
                    105:     while (fgets (buffer, sizeof buffer, fp) != NULL) {
                    106:        if (cp = index (buffer, '#'))
                    107:            *cp = NULL;
                    108:        if (cp = index (buffer, '\n'))
                    109:            *cp = NULL;
                    110:        for (cp = buffer; *cp; cp++)
                    111:            if (isspace (*cp))
                    112:                *cp = ' ';
                    113:        for (cp = buffer; isspace (*cp); cp++)
                    114:            continue;
                    115:        if (*cp == NULL)
                    116:            continue;
                    117: 
                    118:        q = aliases;
                    119:        if (cp = index (dp = cp, ' ')) {
                    120:            *cp = NULL;
                    121:            for (cp++; *cp; cp++) {
                    122:                while (isspace (*cp))
                    123:                    cp++;
                    124:                if (*cp == NULL)
                    125:                    break;
                    126:                if (cp = index (*q++ = cp, ' '))
                    127:                    *cp = NULL;
                    128:                else
                    129:                    break;
                    130:                if (q >= aliases + NALIASES)
                    131:                    break;
                    132:            }
                    133:        }
                    134: 
                    135:        *q = NULL;
                    136: 
                    137:        h -> h_next = (struct host *) calloc (1, sizeof *h);
                    138:        h = h -> h_next;
                    139:        h -> h_name = getcpy (dp);
                    140:        r = h -> h_aliases =
                    141:                (char **) calloc ((unsigned) (q - aliases + 1), sizeof *q);
                    142:        for (q = aliases; *q; q++)
                    143:            *r++ = getcpy (*q);
                    144:        *r = NULL;
                    145:     }
                    146: 
                    147:     (void) fclose (fp);
                    148:     return 1;
                    149: }

unix.superglobalmegacorp.com

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