]> Pileus Git - ~andy/fetchmail/blobdiff - checkalias.c
Free fix to re-enable some text in error messages.
[~andy/fetchmail] / checkalias.c
index a111a39fb4a668e532192a5ffd18020f567c2b7f..cd5caca56bfcdfa811fd28146f9f1bcb1f312b4a 100644 (file)
@@ -6,20 +6,21 @@
  */
 #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>
-#include <netdb.h>
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
 #endif
+#include <netdb.h>
+#include "i18n.h"
 #include "mx.h"
 #include "fetchmail.h"
 
@@ -40,13 +41,14 @@ static int is_ip_alias(const char *name1,const char *name2)
        address_t address;
     } 
     address_e;
-    address_e *host_a_addr, *host_b_addr,*dummy_addr;
+    address_e *host_a_addr=0, *host_b_addr=0;  /* assignments pacify -Wall */
+    address_e *dummy_addr;
 
     int i;
     struct hostent *hp;
     char **p;
  
-    hp = gethostbyname(name1);
+    hp = gethostbyname((char*)name1);
  
     dummy_addr = (address_e *)NULL;
 
@@ -54,21 +56,21 @@ static int is_ip_alias(const char *name1,const char *name2)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_a_addr = (address_e *)alloca(sizeof( address_e));
+       xalloca(host_a_addr, address_e *, 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(name2);
+    hp = gethostbyname((char*)name2);
 
     dummy_addr = (address_e *)NULL;
     for (i=0,p = hp->h_addr_list; *p != 0; i++,p++)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_b_addr = (address_e *)alloca(sizeof( address_e));
+       xalloca(host_b_addr, address_e *, 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));
@@ -94,6 +96,8 @@ int is_host_alias(const char *name, struct query *ctl)
 {
     struct hostent     *he,*he_st;
     struct mxentry     *mxp, *mxrecords;
+    struct idlist      *idl;
+    int                        namelen;
 
     struct hostdata *lead_server = 
        ctl->server.lead_server ? ctl->server.lead_server : &ctl->server;
@@ -119,9 +123,32 @@ int is_host_alias(const char *name, struct query *ctl)
        return(TRUE);
     else if (str_in_list(&lead_server->akalist, name, TRUE))
        return(TRUE);
-    else if (!ctl->server.dns)
-       return(FALSE);
 
+    /*
+     * Now check for a suffix match on the akalist.  The theory here is
+     * that if the user says `aka netaxs.com', we actually want to match
+     * foo.netaxs.com and bar.netaxs.com.
+     */
+    namelen = strlen(name);
+    for (idl = lead_server->akalist; idl; idl = idl->next)
+    {
+       char    *ep;
+
+       /*
+        * Test is >= here because str_in_list() should have caught the
+        * equal-length case above.  Doing it this way guarantees that
+        * ep[-1] is a valid reference.
+        */
+       if (strlen(idl->id) >= namelen)
+           continue;
+       ep = (char *)name + (namelen - strlen(idl->id));
+       /* a suffix led by . must match */
+       if (ep[-1] == '.' && !strcasecmp(ep, idl->id))
+           return(TRUE);
+    }
+
+    if (!ctl->server.dns)
+       return(FALSE);
 #ifndef HAVE_RES_SEARCH
     return(FALSE);
 #else
@@ -134,22 +161,23 @@ int is_host_alias(const char *name, struct query *ctl)
      * delivering the current message or anything else from the
      * current server until it's back up.
      */
-    else if ((he = gethostbyname(name)) != (struct hostent *)NULL)
+    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_VERBOSE)
-               error(0, 0, "Checking if %s is really the same node as %s",ctl->server.truename,name);
+           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_VERBOSE)
-                   error(0, 0, "Yes, their IP addresses match");
+               if (outlevel >= O_DEBUG)
+                   report(stdout, GT_("Yes, their IP addresses match\n"));
                goto match;
            }
-           if (outlevel == O_VERBOSE)
-               error(0, 0, "No, their IP addresses don't match");
+           if (outlevel >= O_DEBUG)
+               report(stdout, GT_("No, their IP addresses don't match\n"));
+           return(FALSE);
        }
        else
            return(FALSE);
@@ -158,16 +186,17 @@ int is_host_alias(const char *name, struct query *ctl)
        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)
-               putchar('\n');  /* terminate the progress message */
-           error(0, 0,
-               "nameserver failure while looking for `%s' during poll of %s.",
+               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;
@@ -184,15 +213,16 @@ int is_host_alias(const char *name, struct query *ctl)
        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);
            break;
-
+#endif
        case NO_RECOVERY:       /* non-recoverable name server error */
        case TRY_AGAIN:         /* temporary error on authoritative server */
        default:
-           error(0, -1,
-               "nameserver failure while looking for `%s' during poll of %s.",
+           report(stderr,
+               GT_("nameserver failure while looking for `%s' during poll of %s.\n"),
                name, ctl->server.pollname);
            ctl->errcount++;
            break;