diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1998-07-20 04:32:12 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1998-07-20 04:32:12 +0000 |
commit | b01e554d2043e8c85036b483c515c3df854a3a98 (patch) | |
tree | 1d7772458aa19b1998159bbb932194f2bfc083e8 | |
parent | b75b43db636a92444be6224e56c765edece19fc3 (diff) | |
download | fetchmail-b01e554d2043e8c85036b483c515c3df854a3a98.tar.gz fetchmail-b01e554d2043e8c85036b483c515c3df854a3a98.tar.bz2 fetchmail-b01e554d2043e8c85036b483c515c3df854a3a98.zip |
is_ip_alias -> checkalias.
svn path=/trunk/; revision=1983
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | checkalias.c | 141 | ||||
-rw-r--r-- | driver.c | 129 | ||||
-rw-r--r-- | fetchmail.h | 1 |
4 files changed, 138 insertions, 137 deletions
diff --git a/Makefile.in b/Makefile.in index d7fe944b..b7428af0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -81,7 +81,7 @@ CTAGS = ctags protobjs = rcfile_y.o rcfile_l.o socket.o getpass.o pop2.o pop3.o imap.o \ etrn.o fetchmail.o env.o options.o daemon.o driver.o rfc822.o smtp.o \ xmalloc.o uid.o mxget.o md5c.o md5ify.o rpa.o interface.o netrc.o \ - base64.o error.o unmime.o conf.o is_ip_alias.o + base64.o error.o unmime.o conf.o checkalias.o objs = $(protobjs) $(extras) $(EXTRAOBJ) @@ -94,7 +94,7 @@ srcs = $(srcdir)/socket.c $(srcdir)/getpass.c $(srcdir)/pop2.c \ $(srcdir)/md5c.c $(srcdir)/md5ify.c $(srcdir)/rpa.c \ $(srcdir)/interface.c $(srcdir)/netrc.c $(srcdir)/base64.c \ $(srcdir)/error.c $(srcdir)/unmime.c $(srcdir)/conf.c \ - $(srcdir)/is_ip_alias.c + $(srcdir)/checkalias.c .SUFFIXES: .SUFFIXES: .o .c .h .y .l .ps .dvi .info .texi diff --git a/checkalias.c b/checkalias.c index 1eca63da..80e3f007 100644 --- a/checkalias.c +++ b/checkalias.c @@ -4,7 +4,8 @@ * Copyright 1997 by Eric S. Raymond * For license terms, see the file COPYING in this directory. */ - +#include "config.h" +#ifdef HAVE_GETHOSTBYNAME #include <stdio.h> #include <string.h> #include <sys/types.h> @@ -12,10 +13,14 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> +#include "mx.h" #include "fetchmail.h" - -int is_ip_alias(const char *name1,const char *name2) -/* Given two hostnames as arguments, returns TRUE if they + +#define MX_RETRIES 3 + +static int is_ip_alias(const char *name1,const char *name2) +/* + * Given two hostnames as arguments, returns TRUE if they * have at least one IP address in common. * It is meant to be called by the is_host_alias() function in driver.c * No check is done on errors returned by gethostbyname, @@ -50,11 +55,9 @@ int is_ip_alias(const char *name1,const char *name2) dummy_addr = host_a_addr; } - hp = gethostbyname(name2); dummy_addr = (address_e *)NULL; - for (i=0,p = hp->h_addr_list; *p != 0; i++,p++) { struct in_addr in; @@ -80,3 +83,129 @@ int is_ip_alias(const char *name1,const char *name2) return (FALSE); } +int is_host_alias(const char *name, struct query *ctl) +/* determine whether name is a DNS alias of the hostname */ +{ + struct hostent *he,*he_st; + struct mxentry *mxp, *mxrecords; + + struct hostdata *lead_server = + ctl->server.lead_server ? ctl->server.lead_server : &ctl->server; + + /* + * The first two checks are optimizations that will catch a good + * many cases. + * + * (1) check against the `true name' deduced from the poll label + * and the via option (if present) at the beginning of the poll cycle. + * 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. + * + * (2) Then check the rest of the `also known as' + * cache accumulated by previous DNS checks. This cache is primed + * by the aka list option. + * + * Any of these on a mail address is definitive. Only if the + * name doesn't match any is it time to call the bind library. + * If this happens odds are good we're looking at an MX name. + */ + if (strcasecmp(lead_server->truename, name) == 0) + return(TRUE); + else if (str_in_list(&lead_server->akalist, name, TRUE)) + return(TRUE); + else if (!ctl->server.dns) + return(FALSE); + +#ifndef HAVE_RES_SEARCH + return(FALSE); +#else + /* + * The only code that calls the BIND library is here and in the + * start-of-query probe with gethostbyname(3). + * + * 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 + * delivering the current message or anything else from this + * mailbox until it's back up. + */ + else 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_VERBOSE) + error(0, 0, "Checking if %s is really the same node as %s",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"); + goto match; + } + if (outlevel == O_VERBOSE) + error(0, 0, "No, their IP addresses don't match"); + } + else + return(FALSE); + } + else + switch (h_errno) + { + case HOST_NOT_FOUND: /* specified host is unknown */ + case NO_ADDRESS: /* valid, but does not have an IP address */ + break; + + 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.", + name, ctl->server.pollname); + ctl->errcount++; + break; + } + + /* + * We're only here if DNS was OK but the gethostbyname() failed + * with a HOST_NOT_FOUND or NO_ADDRESS error. + * Search for a name match on MX records pointing to the server. + */ + h_errno = 0; + if ((mxrecords = getmxrecords(name)) == (struct mxentry *)NULL) + { + switch (h_errno) + { + case HOST_NOT_FOUND: /* specified host is unknown */ + case NO_ADDRESS: /* valid, but does not have an IP address */ + return(FALSE); + break; + + 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.", + name, ctl->server.pollname); + ctl->errcount++; + break; + } + } + else + { + for (mxp = mxrecords; mxp->name; mxp++) + if (strcasecmp(ctl->server.truename, mxp->name) == 0) + goto match; + return(FALSE); + match:; + } + + /* add this name to relevant server's `also known as' list */ + save_str(&lead_server->akalist, name, 0); + return(TRUE); +#endif /* HAVE_RES_SEARCH */ +} +#endif /* HAVE_GETHOSTBYNAME */ + +/* checkalias.c ends here */ @@ -45,7 +45,6 @@ #ifdef HAVE_GETHOSTBYNAME #include <netdb.h> -#include "mx.h" #endif /* HAVE_GETHOSTBYNAME */ #ifdef KERBEROS_V4 @@ -138,134 +137,6 @@ static void timeout_handler (int signal) #define XMIT_ANTISPAM 3 static int accept_count, reject_count; -#define MX_RETRIES 3 - -extern int is_ip_alias(); - -static int is_host_alias(const char *name, struct query *ctl) -/* determine whether name is a DNS alias of the hostname */ -{ - struct hostent *he,*he_st; - struct mxentry *mxp, *mxrecords; - - struct hostdata *lead_server = - ctl->server.lead_server ? ctl->server.lead_server : &ctl->server; - - /* - * The first two checks are optimizations that will catch a good - * many cases. - * - * (1) check against the `true name' deduced from the poll label - * and the via option (if present) at the beginning of the poll cycle. - * 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. - * - * (2) Then check the rest of the `also known as' - * cache accumulated by previous DNS checks. This cache is primed - * by the aka list option. - * - * Any of these on a mail address is definitive. Only if the - * name doesn't match any is it time to call the bind library. - * If this happens odds are good we're looking at an MX name. - */ - if (strcasecmp(lead_server->truename, name) == 0) - return(TRUE); - else if (str_in_list(&lead_server->akalist, name, TRUE)) - return(TRUE); - else if (!ctl->server.dns) - return(FALSE); - -#ifndef HAVE_RES_SEARCH - return(FALSE); -#else - /* - * The only code that calls the BIND library is here and in the - * start-of-query probe with gethostbyname(3). - * - * 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 - * delivering the current message or anything else from this - * mailbox until it's back up. - */ - else 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_VERBOSE) - error(0, 0, "Checking if %s is really the same node as %s",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"); - goto match; - } - if (outlevel == O_VERBOSE) - error(0, 0, "No, their IP addresses don't match"); - } - else - return(FALSE); - } - else - switch (h_errno) - { - case HOST_NOT_FOUND: /* specified host is unknown */ - case NO_ADDRESS: /* valid, but does not have an IP address */ - break; - - 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.", - name, ctl->server.pollname); - ctl->errcount++; - break; - } - - /* - * We're only here if DNS was OK but the gethostbyname() failed - * with a HOST_NOT_FOUND or NO_ADDRESS error. - * Search for a name match on MX records pointing to the server. - */ - h_errno = 0; - if ((mxrecords = getmxrecords(name)) == (struct mxentry *)NULL) - { - switch (h_errno) - { - case HOST_NOT_FOUND: /* specified host is unknown */ - case NO_ADDRESS: /* valid, but does not have an IP address */ - return(FALSE); - break; - - 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.", - name, ctl->server.pollname); - ctl->errcount++; - break; - } - } - else - { - for (mxp = mxrecords; mxp->name; mxp++) - if (strcasecmp(ctl->server.truename, mxp->name) == 0) - goto match; - return(FALSE); - match:; - } - - /* add this name to relevant server's `also known as' list */ - save_str(&lead_server->akalist, name, 0); - return(TRUE); -#endif /* HAVE_RES_SEARCH */ -} - 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 */ diff --git a/fetchmail.h b/fetchmail.h index 5f9eef5a..a1f27b54 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -380,6 +380,7 @@ void escapes(const char *, char *); char *visbuf(const char *); char *showproto(int); void dump_config(struct runctl *runp, struct query *querylist); +int is_host_alias(const char *, struct query *); void yyerror(const char *); int yylex(void); |