Subject: Re: [Patch] Inability to override search domains

Re: [Patch] Inability to override search domains

From: David Drysdale <drysdale_at_google.com>
Date: Mon, 24 Feb 2014 09:53:39 +0000

Hi Daniel,

Any thoughts about these potential patches?

Thanks,
David

On Fri, Jan 24, 2014 at 3:38 PM, David Drysdale <drysdale_at_google.com> wrote:

> Hi Daniel,
>
> I don't think it's currently possible to explicitly set the search domains
> for c-ares -- any values specified in ares_options get overwritten by the
> values from /etc/resolv.conf. Looking back through the history, this seems
> to be a side effect of the change in commit 125b1a8619eb27<https://github.com/bagder/c-ares/commit/125b1a8619eb27>,
> which fixed an earlier problem where the first domain/search entry in
> /etc/resolv.conf was used rather than the last.
>
> I've attached a couple of potential patches below:
> - The first adds a "-s domain" option to ahost to allow a search domain
> to be specified, to allow the problem to be exhibited (e.g with './ahost -s
> icann.org. www')
> - The second fixes init_by_resolv_conf() so it only updates the domains
> if they were missing at function entry.
>
> Regards,
> David
>
> =========================
>
> From 26f738145ff6e41b86b19119258ae42baee4d62f Mon Sep 17 00:00:00 2001
> From: David Drysdale <drysdale_at_google.com>
> Date: Wed, 8 Jan 2014 16:12:47 +0000
> Subject: [PATCH 1/2] Allow specification of search domain in ahost
>
> Add the "-s domain" command line option to override the search
> domains.
> ---
> ahost.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/ahost.c b/ahost.c
> index fd6e50d..a4ac753 100644
> --- a/ahost.c
> +++ b/ahost.c
> @@ -52,6 +52,8 @@ static void usage(void);
>
> int main(int argc, char **argv)
> {
> + struct ares_options options;
> + int optmask = 0;
> ares_channel channel;
> int status, nfds, c, addr_family = AF_INET;
> fd_set read_fds, write_fds;
> @@ -59,6 +61,8 @@ int main(int argc, char **argv)
> struct in_addr addr4;
> struct ares_in6_addr addr6;
>
> + memset(&options, 0, sizeof(options));
> +
> #ifdef USE_WINSOCK
> WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
> WSADATA wsaData;
> @@ -72,7 +76,7 @@ int main(int argc, char **argv)
> return 1;
> }
>
> - while ((c = ares_getopt(argc,argv,"dt:h")) != -1)
> + while ((c = ares_getopt(argc,argv,"dt:hs:")) != -1)
> {
> switch (c)
> {
> @@ -81,6 +85,12 @@ int main(int argc, char **argv)
> dbug_init();
> #endif
> break;
> + case 's':
> + optmask |= ARES_OPT_DOMAINS;
> + options.ndomains = 1;
> + options.domains = malloc(options.ndomains * sizeof(char *));
> + options.domains[0] = strdup(optarg);
> + break;
> case 't':
> if (!strcasecmp(optarg,"a"))
> addr_family = AF_INET;
> @@ -101,7 +111,7 @@ int main(int argc, char **argv)
> if (argc < 1)
> usage();
>
> - status = ares_init(&channel);
> + status = ares_init_options(&channel, &options, optmask);
> if (status != ARES_SUCCESS)
> {
> fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
> --
> 1.8.5.3
>
>
> From a1935eb0e0e9936714f255623f398beb5c90207b Mon Sep 17 00:00:00 2001
> From: David Drysdale <drysdale_at_google.com>
> Date: Wed, 8 Jan 2014 16:14:07 +0000
> Subject: [PATCH 2/2] Don't override explicitly specified search domains
>
> Only set search domains from /etc/resolv.conf if there isn't a value
> already present in the channel.
> ---
> ares_init.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/ares_init.c b/ares_init.c
> index d23c1b0..db1f697 100644
> --- a/ares_init.c
> +++ b/ares_init.c
> @@ -1153,20 +1153,24 @@ static int init_by_resolv_conf(ares_channel
> channel)
> FILE *fp;
> size_t linesize;
> int error;
> + int update_domains;
>
> /* Don't read resolv.conf and friends if we don't have to */
> if (ARES_CONFIG_CHECK(channel))
> return ARES_SUCCESS;
>
> + /* Only update search domains if they're not already specified */
> + update_domains = (channel->ndomains == -1);
> +
> fp = fopen(PATH_RESOLV_CONF, "r");
> if (fp) {
> while ((status = ares__read_line(fp, &line, &linesize)) ==
> ARES_SUCCESS)
> {
> - if ((p = try_config(line, "domain", ';')))
> + if ((p = try_config(line, "domain", ';')) && update_domains)
> status = config_domain(channel, p);
> else if ((p = try_config(line, "lookup", ';')) &&
> !channel->lookups)
> status = config_lookup(channel, p, "bind", "file");
> - else if ((p = try_config(line, "search", ';')))
> + else if ((p = try_config(line, "search", ';')) && update_domains)
> status = set_search(channel, p);
> else if ((p = try_config(line, "nameserver", ';')) &&
> channel->nservers == -1)
> --
> 1.8.5.3
>
>
Received on 2014-02-24