]> Pileus Git - ~andy/fetchmail/commitdiff
Moved the DNS lookup.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 24 Sep 2001 19:46:13 +0000 (19:46 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 24 Sep 2001 19:46:13 +0000 (19:46 -0000)
svn path=/trunk/; revision=3477

NEWS
driver.c
fetchmail.c

diff --git a/NEWS b/NEWS
index 13d9cb031d8c413538f10ff3d5484200ae3534f4..ab7af1f2412ade9287e775646db710b5ab399812 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,9 @@
 * Sanity check now rejects SSL option if SSL support is not compiled in
   (resolves Debian bug #109796).
 * HMH's fix for the LMTP localhost/foo problem.
+* Mike Warfield's fix for using a combined SSL cert and key in a single file.
+* DNS lookups moved to just before te mailserver socket open, so fetchmail
+  now works OK even if started up without Internet access.
 
 fetchmail-5.9.0 (Sun Aug 12 23:52:16 EDT 2001), 21062 lines:
 
index 6a8a228439dac0a5121aaf335ce525aeb363d890..d3ea352f10fd3a122f20d31c2925d5ed177d045f 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -805,6 +805,65 @@ const int maxfetch;                /* maximum number of messages to fetch */
        port = ctl->server.port ? ctl->server.port : ctl->server.base_protocol->port;
 #endif
 #endif /* !INET6_ENABLE */
+
+#ifdef HAVE_GETHOSTBYNAME
+       /*
+        * Canonicalize the server truename for later use.  This also
+        * functions as a probe for whether the mailserver is accessible.
+        * We try it on each poll cycle until we get a result.  This way,
+        * fetchmail won't fail if started up when the network is inaccessible.
+        */
+       if (ctl->server.dns && !ctl->server.trueaddr)
+       {
+           if (ctl->server.lead_server)
+           {
+               char    *leadname = ctl->server.lead_server->truename;
+
+               /* prevent core dump from ill-formed or duplicate entry */
+               if (!leadname)
+               {
+                   report(stderr, _("Lead server has no name.\n"));
+                   err = PS_DNS;
+                   set_timeout(0);
+                   phase = oldphase;
+                   goto closeUp;
+               }
+
+               ctl->server.truename = xstrdup(leadname);
+           }
+           else
+           {
+               struct hostent  *namerec;
+                   
+               /* 
+                * Get the host's IP, so we can report it like this:
+                *
+                * Received: from hostname [10.0.0.1]
+                */
+               errno = 0;
+               namerec = gethostbyname(ctl->server.queryname);
+               if (namerec == (struct hostent *)NULL)
+               {
+                   report(stderr,
+                          _("couldn't find canonical DNS name of %s\n"),
+                          ctl->server.pollname);
+                   err = PS_DNS;
+                   set_timeout(0);
+                   phase = oldphase;
+                   goto closeUp;
+               }
+               else 
+               {
+                   ctl->server.truename=xstrdup((char *)namerec->h_name);
+                   ctl->server.trueaddr=xmalloc(namerec->h_length);
+                   memcpy(ctl->server.trueaddr, 
+                          namerec->h_addr_list[0],
+                          namerec->h_length);
+               }
+           }
+       }
+#endif /* HAVE_GETHOSTBYNAME */
+
        realhost = ctl->server.via ? ctl->server.via : ctl->server.pollname;
 
        /* allow time for the port to be set up if we have a plugin */
@@ -894,7 +953,7 @@ const int maxfetch;         /* maximum number of messages to fetch */
        /* perform initial SSL handshake on open connection */
        /* Note:  We pass the realhost name over for certificate
                verification.  We may want to make this configurable */
-       if (ctl->use_ssl && SSLOpen(mailserver_socket,ctl->sslkey,ctl->sslcert,ctl->sslproto,ctl->sslcertck,
+       if (ctl->use_ssl && SSLOpen(mailserver_socket,ctl->sslcert,ctl->sslkey,ctl->sslproto,ctl->sslcertck,
            ctl->sslcertpath,ctl->sslfingerprint,realhost,ctl->server.pollname) == -1) 
        {
            report(stderr, _("SSL connection failed.\n"));
index b533b1c23c16fefec8903e3ba791fbd5f72b1076..12ce98da48b2655c71b74f2e4590ea5446b41306 100644 (file)
@@ -1108,72 +1108,11 @@ static int load_params(int argc, char **argv, int optind)
 #endif /* HESIOD */
 
            /*
-            * We may have to canonicalize the server truename for later use.
-            * Do this just once for each lead server, if necessary, in order
-            * to minimize DNS round trips.
+            * We no longer do DNS lookups at startup.
+            * This is a kluge.  It enables users to edit their
+            * configurations when DNS isn't available.
             */
-           if (ctl->server.lead_server)
-           {
-               char    *leadname = ctl->server.lead_server->truename;
-
-               /* prevent core dump from ill-formed or duplicate entry */
-               if (!leadname)
-               {
-                   report(stderr, _("Lead server has no name.\n"));
-                   exit(PS_SYNTAX);
-               }
-
-               ctl->server.truename = xstrdup(leadname);
-           }
-           else if (ctl->active && ctl->server.dns && !configdump)
-           {
-#ifndef HAVE_GETHOSTBYNAME
-               ctl->server.truename = xstrdup(ctl->server.queryname);
-               ctl->server.trueaddr = NULL;
-#else
-               struct hostent  *namerec;
-                   
-               /* 
-                * Get the host's IP, so we can report it like this:
-                *
-                * Received: from hostname [10.0.0.1]
-                *
-                * For ultra-efficiency, we should find the IP later, when
-                * we are actually resolving the hostname for a connection.
-                * Problem is this would have to be done inside SockOpen
-                * and there's no way to do that that wouldn't both (a)
-                * be horribly complicated, and (b) blow a couple of
-                * layers of modularity all to hell.
-                */
-               errno = 0;
-               namerec = gethostbyname(ctl->server.queryname);
-               if (namerec == (struct hostent *)NULL)
-               {
-                   report(stderr,
-                          _("couldn't find canonical DNS name of %s\n"),
-                          ctl->server.pollname);
-                   ctl->server.truename = xstrdup(ctl->server.queryname);
-                   ctl->server.trueaddr = NULL;
-                   ctl->active = FALSE;
-                   /* use this initially to flag DNS errors */
-                   ctl->wedged = TRUE;
-               }
-               else {
-                   ctl->server.truename=xstrdup((char *)namerec->h_name);
-                   ctl->server.trueaddr=xmalloc(namerec->h_length);
-                   memcpy(ctl->server.trueaddr, 
-                          namerec->h_addr_list[0],
-                          namerec->h_length);
-                   ctl->wedged = FALSE;
-               }
-#endif /* HAVE_GETHOSTBYNAME */
-           }
-           else
-               /*
-                * This is a kluge.  It enables users to edit their
-                * configurations when DNS isn't available.
-                */
-               ctl->server.truename = xstrdup(ctl->server.queryname);
+           ctl->server.truename = xstrdup(ctl->server.queryname);
 
            /* if no folders were specified, set up the null one as default */
            if (!ctl->mailboxes)
@@ -1252,24 +1191,6 @@ static int load_params(int argc, char **argv, int optind)
            run.postmaster = "postmaster";
     }
 
-    /*
-     * If all connections are wedged due to DNS errors, quit.  This is
-     * important for the common case that you just have one connection.
-     */
-    if (querylist)
-    {
-       st = PS_DNS;
-       for (ctl = querylist; ctl; ctl = ctl->next)
-           if (!ctl->wedged)
-               st = 0;
-       if (st == PS_DNS)
-       {
-           (void) fprintf(stderr,
-                          _("all mailserver name lookups failed, exiting\n"));
-           exit(PS_DNS);
-       }
-    }
-
     return(implicitmode);
 }