]> Pileus Git - ~andy/fetchmail/blobdiff - driver.c
Change name of string-saver functions.
[~andy/fetchmail] / driver.c
index cd09c1e116fc0cc6f5d3148731a2b07c64fca472..70192ac59b468e3d0e24332948ff793551ae7386 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -104,28 +104,25 @@ static int is_host_alias(const char *name, struct query *ctl)
 
     /*
      * The first two checks are optimizations that will catch a good
-     * many cases.  First, check against the hostname the user specified.
-     * Odds are good this will either be the mailserver's FQDN or a
-     * suffix of it with the mailserver's domain's default host name
-     * omitted.  Next, check against the mailserver's FQDN, in case
+     * many cases.  (1) check against the hostname the user
+     * specified.  Odds are good this will either be the mailserver's
+     * FQDN or a suffix of it with the mailserver's domain's default
+     * host name omitted.  Then check the rest of the `also known as'
+     * cache accumulated by previous DNS checks.  This cache is primed
+     * by the aka list option.
+     *
+     * (2) check against the mailserver's FQDN, in case
      * it's not the same as the declared hostname.
      *
      * Either of these on a mail address is definitive.  Only if the
      * name doesn't match either is it time to call the bind library.
      * If this happens odds are good we're looking at an MX name.
      */
-    if (strcmp(name, ctl->servername) == 0)
+    if (str_in_list(&ctl->lead_server->servernames, name))
        return(TRUE);
     else if (strcmp(name, ctl->canonical_name) == 0)
        return(TRUE);
 
-    /*
-     * Is it in the `also known as' cache accumulated by previous DNS checks?
-     * This cache may someday be primed by an aka option.
-     */
-    else if (uid_in_list(&ctl->lead_server->aka, name))
-       return(TRUE);
-
     /*
      * We know DNS service was up at the beginning of this poll cycle.
      * If it's down, our nameserver has crashed.  We don't want to try
@@ -153,7 +150,7 @@ static int is_host_alias(const char *name, struct query *ctl)
                putchar('\n');  /* terminate the progress message */
            fprintf(stderr,
                "fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
-               name, ctl->servername);
+               name, ctl->servernames->id);
            ctl->errcount++;
            longjmp(restart, 2);        /* try again next poll cycle */
            break;
@@ -182,7 +179,7 @@ static int is_host_alias(const char *name, struct query *ctl)
        default:
            fprintf(stderr,
                "fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
-               name, ctl->servername);
+               name, ctl->servernames->id);
            ctl->errcount++;
            longjmp(restart, 2);        /* try again next poll cycle */
            break;
@@ -192,10 +189,32 @@ static int is_host_alias(const char *name, struct query *ctl)
 
 match:
     /* add this name to relevant server's `also known as' list */
-    save_uid(&ctl->lead_server->aka, -1, name);
+    save_str(&ctl->lead_server->servernames, -1, name);
     return(TRUE);
 }
 
+static void map_name(name, ctl, xmit_names)
+/* add given name to xmit_names if it matches declared localnames */
+const char *name;              /* name to map */
+struct query *ctl;             /* list of permissible aliases */
+struct idlist **xmit_names;    /* list of recipient names parsed out */
+{
+    const char *lname;
+
+    lname = idpair_find(&ctl->localnames, name);
+    if (!lname && ctl->wildcard)
+       lname = name;
+
+    if (lname != (char *)NULL)
+    {
+       if (outlevel == O_VERBOSE)
+           fprintf(stderr,
+                   "fetchmail: mapped %s to local %s\n",
+                   name, lname);
+       save_str(xmit_names, -1, lname);
+    }
+}
+
 void find_server_names(hdr, ctl, xmit_names)
 /* parse names out of a RFC822 header into an ID list */
 const char *hdr;               /* RFC822 header in question */
@@ -225,15 +244,7 @@ struct idlist **xmit_names;        /* list of recipient names parsed out */
                    atsign[0] = '\0';
                }
 
-               lname = idpair_find(&ctl->localnames, cp);
-               if (lname != (char *)NULL)
-               {
-                   if (outlevel == O_VERBOSE)
-                       fprintf(stderr,
-                               "fetchmail: mapped %s to local %s\n",
-                               cp, lname);
-                   save_uid(xmit_names, -1, lname);
-               }
+               map_name(cp, ctl, xmit_names);
            } while
                ((cp = nxtaddr((char *)NULL)) != (char *)NULL);
     }
@@ -259,7 +270,7 @@ static FILE *smtp_open(struct query *ctl)
        if ((ctl->smtp_sockfp = Socket(ctl->smtphost, SMTP_PORT)) == (FILE *)NULL)
            return((FILE *)NULL);
        else if (SMTP_ok(ctl->smtp_sockfp) != SM_OK
-                || SMTP_helo(ctl->smtp_sockfp, ctl->servername) != SM_OK)
+                || SMTP_helo(ctl->smtp_sockfp, ctl->servernames->id) != SM_OK)
        {
            fclose(ctl->smtp_sockfp);
            ctl->smtp_sockfp = (FILE *)NULL;
@@ -322,7 +333,7 @@ struct query *ctl;  /* query control record */
        if (inheaders)
         {
            if (!ctl->norewrite)
-               reply_hack(bufp, ctl->servername);
+               reply_hack(bufp, ctl->servernames->id);
 
            if (!lines)
            {
@@ -395,11 +406,19 @@ struct query *ctl;        /* query control record */
                    char        *sp, *tp;
 
                    tp = rbuf;
-                   for (sp = ok + 5; *sp && *sp != '>' && *sp != '@'; sp++)
-                       *tp++ = *sp;
+                   sp = ok + 4;
+                   if (*sp == '<')
+                       sp++;
+                   while (*sp && *sp != '>' && *sp != '@' && *sp != ';')
+                       if (!isspace(*sp))
+                           *tp++ = *sp++;
+                       else
+                       {
+                           /* uh oh -- whitespace here can't be right! */
+                           ok = (char *)NULL;
+                           break;
+                       }
                    *tp = '\0';
-                   if (*sp != ';' && *sp != '@')
-                       ok = (char *)NULL;
                }
 
                if (ok)
@@ -440,7 +459,7 @@ struct query *ctl;  /* query control record */
                     * It has to be a mailserver address, or we
                     * wouldn't have got here.
                     */
-                   find_server_names(received_for, ctl, &xmit_names);
+                   map_name(received_for, ctl, &xmit_names);
                else
                {
                    /*
@@ -454,7 +473,7 @@ struct query *ctl;  /* query control record */
                if (!xmit_names)
                {
                    no_local_matches = TRUE;
-                   save_uid(&xmit_names, -1, user);
+                   save_str(&xmit_names, -1, user);
                    if (outlevel == O_VERBOSE)
                        fprintf(stderr, 
                                "fetchmail: no local matches, forwarding to %s\n",
@@ -463,7 +482,7 @@ struct query *ctl;  /* query control record */
            }
            else        /* it's a single-drop box, use first localname */
 #endif /* HAVE_RES_SEARCH */
-               save_uid(&xmit_names, -1, ctl->localnames->id);
+               save_str(&xmit_names, -1, ctl->localnames->id);
 
            /* time to address the message */
            if (ctl->mda[0])    /* we have a declared MDA */
@@ -516,7 +535,7 @@ struct query *ctl;  /* query control record */
                /* build a connection to the SMTP listener */
                if (ctl->mda[0] == '\0' && ((sinkfp = smtp_open(ctl)) == NULL))
                {
-                   free_uid_list(&xmit_names);
+                   free_str_list(&xmit_names);
                    fprintf(stderr, "fetchmail: SMTP connect failed\n");
                    return(PS_SMTP);
                }
@@ -638,7 +657,7 @@ struct query *ctl;  /* query control record */
                    SockWrite(errmsg, strlen(errmsg), sinkfp);
            }
 
-           free_uid_list(&xmit_names);
+           free_str_list(&xmit_names);
        }
 
        /* SMTP byte-stuffing */
@@ -782,7 +801,7 @@ const struct method *proto; /* protocol method table */
     {
        fprintf(stderr,
                "fetchmail: timeout after %d seconds waiting for %s.\n",
-               ctl->timeout, ctl->servername);
+               ctl->timeout, ctl->servernames->id);
        ok = PS_ERROR;
     }
     else if (js == 2)
@@ -797,7 +816,7 @@ const struct method *proto; /* protocol method table */
        FILE *sockfp;
 
        /* open a socket to the mail server */
-       if ((sockfp = Socket(ctl->servername,
+       if ((sockfp = Socket(ctl->servernames->id,
                             ctl->port ? ctl->port : protocol->port)) == NULL)
        {
            perror("fetchmail, connecting to host");
@@ -841,7 +860,7 @@ const struct method *proto; /* protocol method table */
            if (count == 0)
                fprintf(stderr, "No mail from %s@%s\n", 
                        ctl->remotename,
-                       ctl->servername);
+                       ctl->servernames->id);
            else
            {
                fprintf(stderr, "%d message%s", count, count > 1 ? "s" : ""); 
@@ -850,7 +869,7 @@ const struct method *proto; /* protocol method table */
                fprintf(stderr,
                        " from %s@%s.\n",
                        ctl->remotename,
-                       ctl->servername);
+                       ctl->servernames->id);
            }
 
        /* we may need to get sizes in order to check message limits */
@@ -964,7 +983,7 @@ const struct method *proto; /* protocol method table */
                    vtalarm(ctl->timeout);
                    if (ok != 0)
                        goto cleanUp;
-                   delete_uid(&ctl->newsaved, num);
+                   delete_str(&ctl->newsaved, num);
                }
                else if (outlevel > O_SILENT) 
                    fprintf(stderr, " not flushed\n");
@@ -1029,7 +1048,7 @@ const struct method *proto;       /* protocol method table */
     }
     if (ok==PS_SOCKET || ok==PS_AUTHFAIL || ok==PS_SYNTAX || ok==PS_IOERR
                || ok==PS_ERROR || ok==PS_PROTOCOL || ok==PS_SMTP)
-       fprintf(stderr, " error while talking to %s\n", ctl->servername);
+       fprintf(stderr, " error while talking to %s\n", ctl->servernames->id);
 
 closeUp:
     signal(SIGVTALRM, sigsave);