BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / domain.c
index a17c3aa..61570ed 100644 (file)
@@ -1,18 +1,44 @@
 /*
 /*
- * Copyright (c) 1986 Eric P. Allman
+ * Copyright (c) 1986, 1995 Eric P. Allman
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #include "sendmail.h"
 
 #ifndef lint
 #if NAMED_BIND
  */
 
 #include "sendmail.h"
 
 #ifndef lint
 #if NAMED_BIND
-static char sccsid[] = "@(#)domain.c   8.26 (Berkeley) %G% (with name server)";
+static char sccsid[] = "@(#)domain.c   8.47 (Berkeley) 6/20/95 (with name server)";
 #else
 #else
-static char sccsid[] = "@(#)domain.c   8.26 (Berkeley) %G% (without name server)";
+static char sccsid[] = "@(#)domain.c   8.47 (Berkeley) 6/20/95 (without name server)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -20,7 +46,6 @@ static char sccsid[] = "@(#)domain.c  8.26 (Berkeley) %G% (without name server)";
 
 #include <errno.h>
 #include <resolv.h>
 
 #include <errno.h>
 #include <resolv.h>
-#include <netdb.h>
 
 typedef union
 {
 
 typedef union
 {
@@ -71,13 +96,13 @@ static char MXHostBuf[MAXMXHOSTS*PACKETSZ];
 **                     and 1 is returned.
 */
 
 **                     and 1 is returned.
 */
 
+int
 getmxrr(host, mxhosts, droplocalhost, rcode)
        char *host;
        char **mxhosts;
        bool droplocalhost;
        int *rcode;
 {
 getmxrr(host, mxhosts, droplocalhost, rcode)
        char *host;
        char **mxhosts;
        bool droplocalhost;
        int *rcode;
 {
-       extern int h_errno;
        register u_char *eom, *cp;
        register int i, j, n;
        int nmx = 0;
        register u_char *eom, *cp;
        register int i, j, n;
        int nmx = 0;
@@ -86,15 +111,16 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
        querybuf answer;
        int ancount, qdcount, buflen;
        bool seenlocal = FALSE;
        querybuf answer;
        int ancount, qdcount, buflen;
        bool seenlocal = FALSE;
-       u_short pref, localpref, type;
+       u_short pref, type;
+       u_short localpref = 256;
        char *fallbackMX = FallBackMX;
        static bool firsttime = TRUE;
        char *fallbackMX = FallBackMX;
        static bool firsttime = TRUE;
-       STAB *st;
        bool trycanon = FALSE;
        bool trycanon = FALSE;
+       int (*resfunc)();
+       extern int res_query(), res_search();
        u_short prefer[MAXMXHOSTS];
        int weight[MAXMXHOSTS];
        extern bool getcanonname();
        u_short prefer[MAXMXHOSTS];
        int weight[MAXMXHOSTS];
        extern bool getcanonname();
-       extern bool mx_enabled();
 
        if (tTd(8, 2))
                printf("getmxrr(%s, droplocalhost=%d)\n", host, droplocalhost);
 
        if (tTd(8, 2))
                printf("getmxrr(%s, droplocalhost=%d)\n", host, droplocalhost);
@@ -108,9 +134,7 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
                        /* this entry is bogus */
                        fallbackMX = FallBackMX = NULL;
                }
                        /* this entry is bogus */
                        fallbackMX = FallBackMX = NULL;
                }
-               else if (droplocalhost &&
-                        (st = stab(fallbackMX, ST_CLASS, ST_FIND)) != NULL &&
-                        bitnset('w', st->s_class))
+               else if (droplocalhost && wordinclass(fallbackMX, 'w'))
                {
                        /* don't use fallback for this pass */
                        fallbackMX = NULL;
                {
                        /* don't use fallback for this pass */
                        fallbackMX = NULL;
@@ -118,6 +142,8 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
                firsttime = FALSE;
        }
 
                firsttime = FALSE;
        }
 
+       *rcode = EX_OK;
+
        /* efficiency hack -- numeric or non-MX lookups */
        if (host[0] == '[')
                goto punt;
        /* efficiency hack -- numeric or non-MX lookups */
        if (host[0] == '[')
                goto punt;
@@ -130,11 +156,15 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
        **  MX lookups.  However, that should be a degenerate case.
        */
 
        **  MX lookups.  However, that should be a degenerate case.
        */
 
-       if (!mx_enabled())
+       if (!UseNameServer)
                goto punt;
                goto punt;
+       if (HasWildcardMX && ConfigLevel >= 6)
+               resfunc = res_query;
+       else
+               resfunc = res_search;
 
        errno = 0;
 
        errno = 0;
-       n = res_search(host, C_IN, T_MX, (u_char *) &answer, sizeof(answer));
+       n = (*resfunc)(host, C_IN, T_MX, (u_char *) &answer, sizeof(answer));
        if (n < 0)
        {
                if (tTd(8, 1))
        if (n < 0)
        {
                if (tTd(8, 1))
@@ -151,25 +181,15 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
                        goto punt;
 
                  case HOST_NOT_FOUND:
                        goto punt;
 
                  case HOST_NOT_FOUND:
-#ifdef BROKEN_RES_SEARCH
-                       /* Ultrix resolver returns failure w/ h_errno=0 */
-                 case 0:
+#if BROKEN_RES_SEARCH
+                 case 0:       /* Ultrix resolver retns failure w/ h_errno=0 */
 #endif
 #endif
-                       /* the host just doesn't exist */
+                       /* host doesn't exist in DNS; might be in /etc/hosts */
                        *rcode = EX_NOHOST;
                        *rcode = EX_NOHOST;
-
-                       if (!UseNameServer)
-                       {
-                               /* might exist in /etc/hosts */
-                               goto punt;
-                       }
-                       break;
+                       goto punt;
 
                  case TRY_AGAIN:
                        /* couldn't connect to the name server */
 
                  case TRY_AGAIN:
                        /* couldn't connect to the name server */
-                       if (!UseNameServer && errno == ECONNREFUSED)
-                               goto punt;
-
                        /* it might come up later; better queue it up */
                        *rcode = EX_TEMPFAIL;
                        break;
                        /* it might come up later; better queue it up */
                        *rcode = EX_TEMPFAIL;
                        break;
@@ -217,9 +237,7 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
                                   (RES_UNC_T) bp, buflen)) < 0)
                        break;
                cp += n;
                                   (RES_UNC_T) bp, buflen)) < 0)
                        break;
                cp += n;
-               if (droplocalhost &&
-                   (st = stab(bp, ST_CLASS, ST_FIND)) != NULL &&
-                   bitnset('w', st->s_class))
+               if (droplocalhost && wordinclass(bp, 'w'))
                {
                        if (tTd(8, 3))
                                printf("found localhost (%s) in MX list, pref=%d\n",
                {
                        if (tTd(8, 3))
                                printf("found localhost (%s) in MX list, pref=%d\n",
@@ -229,8 +247,6 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
                        seenlocal = TRUE;
                        continue;
                }
                        seenlocal = TRUE;
                        continue;
                }
-               if (fallbackMX != NULL && strcasecmp(bp, fallbackMX) == 0)
-                       fallbackMX = NULL;
                weight[nmx] = mxrand(bp);
                prefer[nmx] = pref;
                mxhosts[nmx++] = bp;
                weight[nmx] = mxrand(bp);
                prefer[nmx] = pref;
                mxhosts[nmx++] = bp;
@@ -278,7 +294,7 @@ getmxrr(host, mxhosts, droplocalhost, rcode)
        {
 punt:
                if (seenlocal &&
        {
 punt:
                if (seenlocal &&
-                   (!TryNullMXList || gethostbyname(host) == NULL))
+                   (!TryNullMXList || sm_gethostbyname(host) == NULL))
                {
                        /*
                        **  If we have deleted all MX entries, this is
                {
                        /*
                        **  If we have deleted all MX entries, this is
@@ -317,35 +333,22 @@ punt:
                                }
                        }
                }
                                }
                        }
                }
-               n = strlen(MXHostBuf);
-               bp = &MXHostBuf[n];
-               buflen = sizeof MXHostBuf - n - 1;
                if (trycanon &&
                    getcanonname(mxhosts[0], sizeof MXHostBuf - 2, FALSE))
                {
                if (trycanon &&
                    getcanonname(mxhosts[0], sizeof MXHostBuf - 2, FALSE))
                {
+                       bp = &MXHostBuf[strlen(MXHostBuf)];
                        if (bp[-1] != '.')
                        {
                                *bp++ = '.';
                                *bp = '\0';
                        if (bp[-1] != '.')
                        {
                                *bp++ = '.';
                                *bp = '\0';
-                               buflen--;
                        }
                        }
+                       nmx = 1;
                }
                }
-               bp++;
-               nmx = 1;
        }
 
        /* if we have a default lowest preference, include that */
        }
 
        /* if we have a default lowest preference, include that */
-       if (fallbackMX != NULL && !seenlocal && strlen(fallbackMX) < buflen)
-       {
-               strcpy(bp, fallbackMX);
-               mxhosts[nmx++] = bp;
-               bp += strlen(bp);
-               if (bp[-1] != '.')
-               {
-                       *bp++ = '.';
-                       *bp = '\0';
-               }
-       }
+       if (fallbackMX != NULL && !seenlocal)
+               mxhosts[nmx++] = fallbackMX;
 
        return (nmx);
 }
 
        return (nmx);
 }
@@ -367,6 +370,7 @@ punt:
 **             none.
 */
 
 **             none.
 */
 
+int
 mxrand(host)
        register char *host;
 {
 mxrand(host)
        register char *host;
 {
@@ -400,41 +404,36 @@ mxrand(host)
        return hfunc;
 }
 \f/*
        return hfunc;
 }
 \f/*
-**  MX_ENABLED -- check to see if MX records apply
+**  BESTMX -- find the best MX for a name
 **
 **
-**     This is done by seeing if "dns" is listed in the hosts
-**     service switch.
+**     This is really a hack, but I don't see any obvious way
+**     to generalize it at the moment.
 */
 
 */
 
-bool
-mx_enabled()
+char *
+bestmx_map_lookup(map, name, av, statp)
+       MAP *map;
+       char *name;
+       char **av;
+       int *statp;
 {
 {
-       static bool firsttime = TRUE;
-       static bool hasmx;
-       char *maptype[MAXMAPSTACK];
-
-       if (firsttime)
-       {
-               int nmaps;
-
-               nmaps = switch_map_find("hosts", maptype);
-               hasmx = FALSE;
-               if (nmaps > 0 && nmaps <= MAXMAPSTACK)
-               {
-                       register int mapno;
-
-                       for (mapno = 0; mapno < nmaps && !hasmx; mapno++)
-                       {
-                               if (strcmp(maptype[mapno], "dns") == 0)
-                                       hasmx = TRUE;
-                       }
-               }
-               firsttime = FALSE;
-       }
-       return hasmx;
+       int nmx;
+       auto int rcode;
+       int saveopts = _res.options;
+       char *mxhosts[MAXMXHOSTS + 1];
+
+       _res.options &= ~(RES_DNSRCH|RES_DEFNAMES);
+       nmx = getmxrr(name, mxhosts, FALSE, &rcode);
+       _res.options = saveopts;
+       if (nmx <= 0)
+               return NULL;
+       if (bitset(MF_MATCHONLY, map->map_mflags))
+               return map_rewrite(map, name, strlen(name), NULL);
+       else
+               return map_rewrite(map, mxhosts[0], strlen(mxhosts[0]), av);
 }
 \f/*
 }
 \f/*
-**  GETCANONNAME -- get the canonical name for named host
+**  DNS_GETCANONNAME -- get the canonical name for named host using DNS
 **
 **     This algorithm tries to be smart about wildcard MX records.
 **     This is hard to do because DNS doesn't tell is if we matched
 **
 **     This algorithm tries to be smart about wildcard MX records.
 **     This is hard to do because DNS doesn't tell is if we matched
@@ -456,6 +455,7 @@ mx_enabled()
 **                     This is a value-result parameter.
 **             hbsize -- the size of the host buffer.
 **             trymx -- if set, try MX records as well as A and CNAME.
 **                     This is a value-result parameter.
 **             hbsize -- the size of the host buffer.
 **             trymx -- if set, try MX records as well as A and CNAME.
+**             statp -- pointer to place to store status.
 **
 **     Returns:
 **             TRUE -- if the host matched.
 **
 **     Returns:
 **             TRUE -- if the host matched.
@@ -463,12 +463,12 @@ mx_enabled()
 */
 
 bool
 */
 
 bool
-getcanonname(host, hbsize, trymx)
+dns_getcanonname(host, hbsize, trymx, statp)
        char *host;
        int hbsize;
        bool trymx;
        char *host;
        int hbsize;
        bool trymx;
+       int *statp;
 {
 {
-       extern int h_errno;
        register u_char *eom, *ap;
        register char *cp;
        register int n; 
        register u_char *eom, *ap;
        register char *cp;
        register int n; 
@@ -481,7 +481,7 @@ getcanonname(host, hbsize, trymx)
        char **dp;
        char *mxmatch;
        bool amatch;
        char **dp;
        char *mxmatch;
        bool amatch;
-       bool gotmx;
+       bool gotmx = FALSE;
        int qtype;
        int loopcnt;
        char *xp;
        int qtype;
        int loopcnt;
        char *xp;
@@ -490,10 +490,13 @@ getcanonname(host, hbsize, trymx)
        extern char *gethostalias();
 
        if (tTd(8, 2))
        extern char *gethostalias();
 
        if (tTd(8, 2))
-               printf("getcanonname(%s)\n", host);
+               printf("dns_getcanonname(%s, trymx=%d)\n", host, trymx);
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1)
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1)
-               return (FALSE);
+       {
+               *statp = EX_UNAVAILABLE;
+               return FALSE;
+       }
 
        /*
        **  Initialize domain search list.  If there is at least one
 
        /*
        **  Initialize domain search list.  If there is at least one
@@ -507,7 +510,7 @@ getcanonname(host, hbsize, trymx)
 
        loopcnt = 0;
 cnameloop:
 
        loopcnt = 0;
 cnameloop:
-       for (cp = host, n = 0; *cp; cp++)
+       for (cp = host, n = 0; *cp != '\0'; cp++)
                if (*cp == '.')
                        n++;
 
                if (*cp == '.')
                        n++;
 
@@ -543,6 +546,10 @@ cnameloop:
        }
        *dp = NULL;
 
        }
        *dp = NULL;
 
+       /* if we have a wildcard MX and no dots, try MX anyhow */
+       if (n == 0)
+               trymx = TRUE;
+
        /*
        **  Now run through the search list for the name in question.
        */
        /*
        **  Now run through the search list for the name in question.
        */
@@ -555,7 +562,8 @@ cnameloop:
                if (qtype == T_ANY)
                        gotmx = FALSE;
                if (tTd(8, 5))
                if (qtype == T_ANY)
                        gotmx = FALSE;
                if (tTd(8, 5))
-                       printf("getcanonname: trying %s.%s (%s)\n", host, *dp,
+                       printf("dns_getcanonname: trying %s.%s (%s)\n",
+                               host, *dp,
                                qtype == T_ANY ? "ANY" : qtype == T_A ? "A" :
                                qtype == T_MX ? "MX" : "???");
                ret = res_querydomain(host, *dp, C_IN, qtype,
                                qtype == T_ANY ? "ANY" : qtype == T_A ? "A" :
                                qtype == T_MX ? "MX" : "???");
                ret = res_querydomain(host, *dp, C_IN, qtype,
@@ -570,6 +578,7 @@ cnameloop:
                        {
                                /* the name server seems to be down */
                                h_errno = TRY_AGAIN;
                        {
                                /* the name server seems to be down */
                                h_errno = TRY_AGAIN;
+                               *statp = EX_TEMPFAIL;
                                return FALSE;
                        }
 
                                return FALSE;
                        }
 
@@ -588,13 +597,7 @@ cnameloop:
                                }
                        }
 
                                }
                        }
 
-                       if (mxmatch != NULL)
-                       {
-                               /* we matched before -- use that one */
-                               break;
-                       }
-
-                       /* otherwise, try the next name */
+                       /* try the next name */
                        dp++;
                        qtype = T_ANY;
                        continue;
                        dp++;
                        qtype = T_ANY;
                        continue;
@@ -620,6 +623,7 @@ cnameloop:
                                if (tTd(8, 20))
                                        printf("qdcount failure (%d)\n",
                                                ntohs(hp->qdcount));
                                if (tTd(8, 20))
                                        printf("qdcount failure (%d)\n",
                                                ntohs(hp->qdcount));
+                               *statp = EX_SOFTWARE;
                                return FALSE;           /* ???XXX??? */
                        }
                }
                                return FALSE;           /* ???XXX??? */
                        }
                }
@@ -639,7 +643,7 @@ cnameloop:
                        {
                          case T_MX:
                                gotmx = TRUE;
                        {
                          case T_MX:
                                gotmx = TRUE;
-                               if (**dp != '\0')
+                               if (**dp != '\0' || !HasWildcardMX)
                                {
                                        /* got a match -- save that info */
                                        if (trymx && mxmatch == NULL)
                                {
                                        /* got a match -- save that info */
                                        if (trymx && mxmatch == NULL)
@@ -658,6 +662,13 @@ cnameloop:
                                continue;
 
                          case T_CNAME:
                                continue;
 
                          case T_CNAME:
+                               if (DontExpandCnames)
+                               {
+                                       /* got CNAME -- guaranteed canonical */
+                                       amatch = TRUE;
+                                       break;
+                               }
+
                                if (loopcnt++ > MAXCNAMEDEPTH)
                                {
                                        /*XXX should notify postmaster XXX*/
                                if (loopcnt++ > MAXCNAMEDEPTH)
                                {
                                        /*XXX should notify postmaster XXX*/
@@ -672,6 +683,7 @@ cnameloop:
                                                CurEnv->e_message = newstr(ebuf);
                                        }
                                        h_errno = NO_RECOVERY;
                                                CurEnv->e_message = newstr(ebuf);
                                        }
                                        h_errno = NO_RECOVERY;
+                                       *statp = EX_CONFIG;
                                        return FALSE;
                                }
 
                                        return FALSE;
                                }
 
@@ -721,7 +733,10 @@ cnameloop:
        }
 
        if (mxmatch == NULL)
        }
 
        if (mxmatch == NULL)
+       {
+               *statp = EX_NOHOST;
                return FALSE;
                return FALSE;
+       }
 
        /* create matching name and return */
        (void) sprintf(nbuf, "%.*s%s%.*s", MAXDNAME, host,
 
        /* create matching name and return */
        (void) sprintf(nbuf, "%.*s%s%.*s", MAXDNAME, host,
@@ -729,6 +744,7 @@ cnameloop:
                        MAXDNAME, mxmatch);
        strncpy(host, nbuf, hbsize);
        host[hbsize - 1] = '\0';
                        MAXDNAME, mxmatch);
        strncpy(host, nbuf, hbsize);
        host[hbsize - 1] = '\0';
+       *statp = EX_OK;
        return TRUE;
 }
 
        return TRUE;
 }
 
@@ -739,12 +755,13 @@ gethostalias(host)
 {
        char *fname;
        FILE *fp;
 {
        char *fname;
        FILE *fp;
-       register char *p;
+       register char *p = NULL;
        char buf[MAXLINE];
        static char hbuf[MAXDNAME];
 
        fname = getenv("HOSTALIASES");
        char buf[MAXLINE];
        static char hbuf[MAXDNAME];
 
        fname = getenv("HOSTALIASES");
-       if (fname == NULL || (fp = fopen(fname, "r")) == NULL)
+       if (fname == NULL ||
+           (fp = safefopen(fname, O_RDONLY, 0, SFF_REGONLY)) == NULL)
                return NULL;
        while (fgets(buf, sizeof buf, fp) != NULL)
        {
                return NULL;
        while (fgets(buf, sizeof buf, fp) != NULL)
        {
@@ -779,165 +796,4 @@ gethostalias(host)
        return hbuf;
 }
 
        return hbuf;
 }
 
-\f/*
-**  MAILB_LOOKUP -- do DNS mailbox lookup
-*/
-
-#ifdef DNS_MAILB
-
-mailb_lookup(addr)
-       char *addr;
-{
-       /*
-       **  Convert addr to DNS form (user.host).
-       */
-
-       /* figure out how much space it needs */
-       atp = strchr(addr, '@');
-       if (atp == NULL)
-               atp = &addr(strlen(addr));
-       i = strlen(addr);
-       for (p = addr; (p = strchr(p, '.')) != NULL; p++)
-       {
-               if (p > atp)
-                       break;
-               i++;
-       }
-       if (i < sizeof abuf)
-               bufp = abuf;
-       else
-               bufp = xalloc(i + 1);
-
-       lhsmode = TRUE;
-       for (p = addr, q = bufp; (c = *p++) != '\0'; )
-       {
-               if (c == '.' && lhsmode)
-                       *q++ = '\\';
-               if (c == '@')
-                       lhsmode = FALSE;
-               *q++ = c;
-       }
-       *q = '\0';
-
-       /*
-       **  Now do a MAILB lookup.
-       */
-
-retry:
-       if (res_query(bufp, C_IN, T_MAILB, (char *) &answer, sizeof answer < 0)
-       {
-               /* no match -- just continue as usual */
-               return FALSE;
-       }
-
-       /* find first satisfactory answer */
-       hp = (HEADER *)&answer;
-       ap = (u_char *)&answer + sizeof(HEADER);
-       eom = (u_char *)&answer + n;
-       for (qdcount = ntohs(hp->qdcount); qdcount--; ap += n + QFIXEDSZ)
-               if ((n = dn_skipname(ap, eom)) < 0)
-                       return FALSE;
-       for (ancount = ntohs(hp->ancount); --ancount >= 0 && ap < eom; ap += n)
-       {
-               n = dn_expand((u_char *)&answer, eom, ap, (u_char *)bp, buflen);
-               if (n < 0)
-                       break;
-               ap += n;
-               GETSHORT(type, ap);
-               ap += SHORTSIZE + LONGSIZE;
-               GETSHORT(n, ap);
-               switch (type)
-               {
-                 case T_MR:
-                       /* rename: try again */
-                       i = dn_expand((u_char *) &answer, eom, ap,
-                                       (u_char) abuf, sizeof abuf);
-                       if (i < 0)
-                               break;
-                       if (bufp != abuf)
-                       {
-                               free(bufp);
-                               bufp = abuf;
-                       }
-                       goto retry;
-
-                 case T_MB:
-                       i = dn_expand((u_char *) &answer, eom, ap,
-                                       (u_char) hbuf, sizeof hbuf);
-                       if (i < 0)
-                               break;
-
-                       /* hbuf now has the host to deliver to */
-                       break;
-
-                 case T_MG:
-                       i = dn_expand((u_char *) &answer, eom, ap,
-                                       (u_char) gbuf, sizeof gbuf);
-                       if (i < 0)
-                               break;
-                       AliasLevel++;
-                       naddrs += sendtolist(ubuf, a, sendq, e);
-                       AliasLevel--;
-                       break;
-
-                 case T_MINFO:
-                       /* bleach */
-                       XXX;
-               }
-
-
-
-               if (type != T_MX)
-               {
-                       if (tTd(8, 8) || _res.options & RES_DEBUG)
-                               printf("unexpected answer type %d, size %d\n",
-                                   type, n);
-                       cp += n;
-                       continue;
-               }
-               GETSHORT(pref, cp);
-               if ((n = dn_expand((u_char *)&answer, eom, cp,
-                                  (u_char *)bp, buflen)) < 0)
-                       break;
-               cp += n;
-
-
-#endif /* DNS_MAILB */
-
-#else /* not NAMED_BIND */
-
-#include <netdb.h>
-
-bool
-getcanonname(host, hbsize, trymx)
-       char *host;
-       int hbsize;
-       bool trymx;
-{
-       struct hostent *hp;
-       char *p;
-
-       hp = gethostbyname(host);
-       if (hp == NULL)
-               return (FALSE);
-       p = hp->h_name;
-       if (strchr(p, '.') == NULL)
-       {
-               /* first word is a short name -- try to find a long one */
-               char **ap;
-
-               for (ap = hp->h_aliases; *ap != NULL; ap++)
-                       if (strchr(*ap, '.') != NULL)
-                               break;
-               if (*ap != NULL)
-                       p = *ap;
-       }
-
-       if (strlen(p) >= hbsize)
-               return (FALSE);
-
-       (void) strcpy(host, p);
-       return (TRUE);
-}
-
-#endif /* not NAMED_BIND */
+#endif /* NAMED_BIND */