2 * checkalias.c -- check to see if two hostnames or IP addresses are equivalent
4 * Copyright 1997 by Eric S. Raymond
5 * For license terms, see the file COPYING in this directory.
11 #include <sys/types.h>
13 #include "fetchmail.h"
15 int is_host_alias(const char *name, struct query *ctl, struct addrinfo **res)
16 /* determine whether name is a DNS alias of the mailserver for this query */
21 struct hostdata *lead_server =
22 ctl->server.lead_server ? ctl->server.lead_server : &ctl->server;
25 * The first two checks are optimizations that will catch a good
28 * (1) check against the `true name' deduced from the poll label
29 * and the via option (if present) at the beginning of the poll cycle.
30 * Odds are good this will either be the mailserver's FQDN or a suffix of
31 * it with the mailserver's domain's default host name omitted.
33 * (2) Then check the rest of the `also known as'
34 * cache accumulated by previous DNS checks. This cache is primed
35 * by the aka list option.
37 * Any of these on a mail address is definitive. Only if the
38 * name doesn't match any is it time to call the bind library.
39 * If this happens odds are good we're looking at an MX name.
41 if (strcasecmp(lead_server->truename, name) == 0)
43 else if (str_in_list(&lead_server->akalist, name, TRUE))
47 * Now check for a suffix match on the akalist. The theory here is
48 * that if the user says `aka netaxs.com', we actually want to match
49 * foo.netaxs.com and bar.netaxs.com.
51 namelen = strlen(name);
52 for (idl = lead_server->akalist; idl; idl = idl->next)
57 * Test is >= here because str_in_list() should have caught the
58 * equal-length case above. Doing it this way guarantees that
59 * ep[-1] is a valid reference.
61 if (strlen(idl->id) >= namelen)
63 ep = name + (namelen - strlen(idl->id));
64 /* a suffix led by . must match */
65 if (ep[-1] == '.' && !strcasecmp(ep, idl->id))
75 /* checkalias.c ends here */