]> Pileus Git - ~andy/fetchmail/blobdiff - checkalias.c
Cosmetic cleanup.
[~andy/fetchmail] / checkalias.c
index 4ddf6789bfbcd77470693fae43efc7c2f4718bff..28d7861f59456191c7b3fd24303a33fcc3208555 100644 (file)
@@ -90,6 +90,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;
@@ -118,6 +120,29 @@ int is_host_alias(const char *name, struct query *ctl)
     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] == '.' && !strcmp(ep, idl->id))
+           return(TRUE);
+    }
+
 #ifndef HAVE_RES_SEARCH
     return(FALSE);
 #else
@@ -130,22 +155,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(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, 0, _("Checking if %s is really the same node as %s\n"),ctl->server.truename,name);
+               report(stdout, _("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, 0, _("Yes, their IP addresses match\n"));
+                   report(stdout, _("Yes, their IP addresses match\n"));
                goto match;
            }
            if (outlevel >= O_DEBUG)
-               report(stdout, 0, _("No, their IP addresses don't match\n"));
+               report(stdout, _("No, their IP addresses don't match\n"));
+           return(FALSE);
        }
        else
            return(FALSE);
@@ -161,8 +187,8 @@ int is_host_alias(const char *name, struct query *ctl)
        case TRY_AGAIN:         /* temporary error on authoritative server */
        default:
            if (outlevel != O_SILENT)
-               report_complete(stdout, 0, "\n");       /* terminate the progress message */
-           report(stderr, 0,
+               report_complete(stdout, "\n");  /* terminate the progress message */
+           report(stderr,
                _("nameserver failure while looking for `%s' during poll of %s.\n"),
                name, ctl->server.pollname);
            ctl->errcount++;
@@ -187,7 +213,7 @@ int is_host_alias(const char *name, struct query *ctl)
        case NO_RECOVERY:       /* non-recoverable name server error */
        case TRY_AGAIN:         /* temporary error on authoritative server */
        default:
-           report(stderr, 0,
+           report(stderr,
                _("nameserver failure while looking for `%s' during poll of %s.\n"),
                name, ctl->server.pollname);
            ctl->errcount++;