Skip to content

Commit

Permalink
Don't suppress DNS search list by appending '.'
Browse files Browse the repository at this point in the history
The original motivation was to avoid extra timeouts when the network is
broken.  However this doesn't avoid one of the timeouts and adds
complexity and introduced bugs.

To really suppress search lists use ndots.
  • Loading branch information
nicowilliams committed Nov 10, 2016
1 parent 99b79d1 commit 616aaf9
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions lib/krb5/krbhst.c
Expand Up @@ -403,48 +403,11 @@ krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host,
if (host->ai == NULL) {
struct addrinfo hints;
char portstr[NI_MAXSERV];
char *hostname = host->hostname;

snprintf (portstr, sizeof(portstr), "%d", host->port);
make_hints(&hints, host->proto);

/**
* First try this as an IP address, this allows us to add a
* dot at the end to stop using the search domains.
*/

hints.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;

ret = getaddrinfo(host->hostname, portstr, &hints, &host->ai);
if (ret == 0)
goto out;

/**
* If the hostname contains a dot, assumes it's a FQDN and
* don't use search domains since that might be painfully slow
* when machine is disconnected from that network.
*
* This does, however, inhibit /etc/hosts matches on some
* systems. So we want to try it twice.
*/

hints.ai_flags &= ~(AI_NUMERICHOST | AI_NUMERICSERV);

if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] != '.') {
ret = asprintf(&hostname, "%s.", host->hostname);
if (ret < 0 || hostname == NULL)
return ENOMEM;
}

ret = getaddrinfo(hostname, portstr, &hints, &host->ai);
/*
* Retry without the trailing '.' if the lookup failed for any
* reason other than a timeout.
*/
if (ret != 0 && ret != EAI_AGAIN && ret != EAI_FAIL && hostname != host->hostname)
ret = getaddrinfo(host->hostname, portstr, &hints, &host->ai);
if (hostname != host->hostname)
free(hostname);
if (ret) {
ret = krb5_eai_to_heim_errno(ret, errno);
goto out;
Expand Down

0 comments on commit 616aaf9

Please sign in to comment.