diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2001-09-24 19:46:13 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2001-09-24 19:46:13 +0000 |
commit | f5ece9304c6f778f8888860b50d431dca147074c (patch) | |
tree | a35514b2d2495490a7358c4f9d06debf70f796f8 | |
parent | 2cd4f64310af7463c16cc5928a081f108e5f4687 (diff) | |
download | fetchmail-f5ece9304c6f778f8888860b50d431dca147074c.tar.gz fetchmail-f5ece9304c6f778f8888860b50d431dca147074c.tar.bz2 fetchmail-f5ece9304c6f778f8888860b50d431dca147074c.zip |
Moved the DNS lookup.
svn path=/trunk/; revision=3477
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | driver.c | 61 | ||||
-rw-r--r-- | fetchmail.c | 87 |
3 files changed, 67 insertions, 84 deletions
@@ -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: @@ -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")); diff --git a/fetchmail.c b/fetchmail.c index b533b1c2..12ce98da 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -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); } |