]> Pileus Git - ~andy/fetchmail/blobdiff - checkalias.c
Fix typo repsonsible -> responsible.
[~andy/fetchmail] / checkalias.c
index 2849213e136c93c7bf8668759d5fd2f41d143b6c..6437db4c7c7f979b535e564bc9e5859fb7a583b2 100644 (file)
  * For license terms, see the file COPYING in this directory.
  */
 #include "config.h"
-#ifdef HAVE_GETHOSTBYNAME
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
-#ifdef HAVE_NET_SOCKET_H
-#include <net/socket.h>
-#else
-#include <sys/socket.h>
-#endif
-#include <netinet/in.h>
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#include <netdb.h>
-#include "i18n.h"
-#include "mx.h"
-#include "fetchmail.h"
-
-#define MX_RETRIES     3
-
-typedef unsigned char address_t[sizeof (struct in_addr)];
-
-typedef struct _address_e
-{
-    struct _address_e *next;
-    address_t address;
-} address_e;
-
-static void free_addrlst(address_e *lst)
-{
-    address_e *i;
-    while(lst) {
-       i = lst->next;
-       free(lst);
-       lst = i;
-    }
-}
-
-/* XXX FIXME: This junk isn't IPv6 aware */
-static int is_ip_alias(const char *name1,const char *name2)
-/*
- * Given two hostnames as arguments, returns TRUE if they
- * have at least one IP address in common.
- * No check is done on errors returned by gethostbyname,
- * the calling function does them.
- */
-{
-    address_e *host_a_addr=0, *host_b_addr=0;
-    address_e *dummy_addr, *ii, *ij;
-
-    int rc = FALSE;
-    struct hostent *hp;
-    char **p;
-
-    hp = gethostbyname((char*)name1);
-
-    dummy_addr = (address_e *)NULL;
-
-    if (hp)
-       for (p = hp->h_addr_list; *p != 0; p++) {
-           struct in_addr in;
-
-           host_a_addr = xmalloc(sizeof (address_e));
-           memset (host_a_addr,0, sizeof (address_e));
-           host_a_addr->next = dummy_addr;
-           (void) memcpy(&host_a_addr->address, *p, sizeof (in.s_addr));
-           dummy_addr = host_a_addr;
-       }
-
-    hp = gethostbyname((char*)name2);
-
-    dummy_addr = (address_e *)NULL;
 
-    if (hp)
-       for (p = hp->h_addr_list; *p != 0; p++) {
-           struct in_addr in;
-
-           host_b_addr = xmalloc(sizeof (address_e));
-           memset (host_b_addr,0, sizeof (address_e));
-           host_b_addr->next = dummy_addr;
-           (void) memcpy(&host_b_addr->address, *p, sizeof (in.s_addr));
-           dummy_addr = host_b_addr;
-       }
-
-    for (ii = host_a_addr ; ii ; ii = ii -> next) {
-       for (ij = host_b_addr ; ij ; ij = ij -> next) {
-           if (!memcmp(ii->address, ij->address, sizeof (address_t))) {
-               rc = TRUE;
-               goto found;
-           }
-       }
-    }
-
-found:
-    free_addrlst(host_b_addr);
-    free_addrlst(host_a_addr);
-    return rc;
-}
+#include "fetchmail.h"
 
-int is_host_alias(const char *name, struct query *ctl)
+int is_host_alias(const char *name, struct query *ctl, struct addrinfo **res)
 /* determine whether name is a DNS alias of the mailserver for this query */
 {
-    struct hostent     *he,*he_st;
-    struct mxentry     *mxp, *mxrecords;
     struct idlist      *idl;
-    int                        namelen;
+    size_t             namelen;
 
     struct hostdata *lead_server =
        ctl->server.lead_server ? ctl->server.lead_server : &ctl->server;
@@ -146,7 +51,7 @@ int is_host_alias(const char *name, struct query *ctl)
     namelen = strlen(name);
     for (idl = lead_server->akalist; idl; idl = idl->next)
     {
-       char    *ep;
+       const char      *ep;
 
        /*
         * Test is >= here because str_in_list() should have caught the
@@ -155,7 +60,7 @@ int is_host_alias(const char *name, struct query *ctl)
         */
        if (strlen(idl->id) >= namelen)
            continue;
-       ep = (char *)name + (namelen - strlen(idl->id));
+       ep = name + (namelen - strlen(idl->id));
        /* a suffix led by . must match */
        if (ep[-1] == '.' && !strcasecmp(ep, idl->id))
            return(TRUE);
@@ -163,99 +68,8 @@ int is_host_alias(const char *name, struct query *ctl)
 
     if (!ctl->server.dns)
        return(FALSE);
-#ifndef HAVE_RES_SEARCH
+    (void)res;
     return(FALSE);
-#else
-    /*
-     * The only code that calls the BIND library is here and in the
-     * start-of-run probe with gethostbyname(3) under ETRN/Kerberos.
-     *
-     * We know DNS service was up at the beginning of the run.
-     * If it's down, our nameserver has crashed.  We don't want to try
-     * delivering the current message or anything else from the
-     * current server until it's back up.
-     */
-    if ((he = gethostbyname((char*)name)) != (struct hostent *)NULL)
-    {
-       if (strcasecmp(ctl->server.truename, he->h_name) == 0)
-           goto match;
-        else if (((he_st = gethostbyname(ctl->server.truename)) != (struct hostent *)NULL) && ctl->server.checkalias)
-       {
-           if (outlevel >= O_DEBUG)
-               report(stdout, GT_("Checking if %s is really the same node as %s\n"),ctl->server.truename,name);
-           if (is_ip_alias(ctl->server.truename,name) == TRUE)
-           {
-               if (outlevel >= O_DEBUG)
-                   report(stdout, GT_("Yes, their IP addresses match\n"));
-               goto match;
-           }
-           if (outlevel >= O_DEBUG)
-               report(stdout, GT_("No, their IP addresses don't match\n"));
-           return(FALSE);
-       }
-       else
-           return(FALSE);
-    }
-    else
-       switch (h_errno)
-       {
-       case HOST_NOT_FOUND:    /* specified host is unknown */
-#ifndef __BEOS__
-       case NO_ADDRESS:        /* valid, but does not have an IP address */
-           break;
-#endif
-       case NO_RECOVERY:       /* non-recoverable name server error */
-       case TRY_AGAIN:         /* temporary error on authoritative server */
-       default:
-           if (outlevel != O_SILENT)
-               report_complete(stdout, "\n");  /* terminate the progress message */
-           report(stderr,
-               GT_("nameserver failure while looking for `%s' during poll of %s.\n"),
-               name, ctl->server.pollname);
-           ctl->errcount++;
-           break;
-       }
-
-    /*
-     * We're only here if DNS was OK but the gethostbyname() failed
-     * with a HOST_NOT_FOUND or NO_ADDRESS error.
-     * Search for a name match on MX records pointing to the server.
-     */
-    h_errno = 0;
-    if ((mxrecords = getmxrecords(name)) == (struct mxentry *)NULL)
-    {
-       switch (h_errno)
-       {
-       case HOST_NOT_FOUND:    /* specified host is unknown */
-#ifndef __BEOS__
-       case NO_ADDRESS:        /* valid, but does not have an IP address */
-           return(FALSE);
-#endif
-       case NO_RECOVERY:       /* non-recoverable name server error */
-       case TRY_AGAIN:         /* temporary error on authoritative server */
-       default:
-           report(stderr,
-               GT_("nameserver failure while looking for `%s' during poll of %s.\n"),
-               name, ctl->server.pollname);
-           ctl->errcount++;
-           break;
-       }
-    }
-    else
-    {
-       for (mxp = mxrecords; mxp->name; mxp++)
-           if (strcasecmp(ctl->server.truename, mxp->name) == 0
-                   || is_ip_alias(ctl->server.truename, mxp->name) == TRUE)
-               goto match;
-       return(FALSE);
-    match:;
-    }
-
-    /* add this name to relevant server's `also known as' list */
-    save_str(&lead_server->akalist, name, 0);
-    return(TRUE);
-#endif /* HAVE_RES_SEARCH */
 }
-#endif /* HAVE_GETHOSTBYNAME */
 
 /* checkalias.c ends here */