From c400e35bf52a5ef393ba20ae926e6670bfa41ea6 Mon Sep 17 00:00:00 2001 From: Matt Grant Date: Mon, 7 Nov 2022 10:14:27 -0800 Subject: [PATCH] s4: libcli: Fix reply_to_addrs() to return IPv6 addresses as well as IPv4. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15226 Signed-off-by: Matt Grant Pair-programmed-with: Jeremy Allison --- source4/libcli/resolve/dns_ex.c | 59 ++++++++++++--------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index 0bb3ba02287..57c96739f19 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -107,14 +107,6 @@ static int reply_to_addrs(TALLOC_CTX *mem_ctx, uint32_t *a_num, continue; } - if (rr->type == QTYPE_NS) { - /* - * After the record for NS will come the A or AAAA - * record of the NS. - */ - break; - } - /* verify we actually have a record here */ if (!rr->data) { continue; @@ -151,9 +143,7 @@ static int reply_to_addrs(TALLOC_CTX *mem_ctx, uint32_t *a_num, rr->name->pLabelList->label); if (addrs[total]) { total++; - if (rr->type == QTYPE_A) { - (*a_num)++; - } + (*a_num)++; } } @@ -212,7 +202,6 @@ static struct dns_records_container get_a_aaaa_records(TALLOC_CTX *mem_ctx, struct dns_records_container ret; char **addrs = NULL; uint32_t a_num, total; - uint16_t qtype; TALLOC_CTX *tmp_ctx; DNS_ERROR err; @@ -223,36 +212,33 @@ static struct dns_records_container get_a_aaaa_records(TALLOC_CTX *mem_ctx, return ret; } - qtype = QTYPE_AAAA; + a_num = total = 0; /* this is the blocking call we are going to lots of trouble to avoid them in the parent */ - err = dns_lookup(tmp_ctx, name, qtype, &reply); - if (!ERR_DNS_IS_OK(err)) { - qtype = QTYPE_A; - err = dns_lookup(tmp_ctx, name, qtype, &reply); - if (!ERR_DNS_IS_OK(err)) { - goto done; - } + /* First ask for A records. */ + err = dns_lookup(tmp_ctx, name, QTYPE_A, &reply); + if (ERR_DNS_IS_OK(err)) { + total = reply_to_addrs(tmp_ctx, + &a_num, + &addrs, + total, + reply, + port); } - a_num = total = 0; - total = reply_to_addrs(tmp_ctx, &a_num, &addrs, total, reply, port); - - if (qtype == QTYPE_AAAA && a_num == 0) { - /* - * DNS server didn't returned A when asked for AAAA records. - * Most of the server do it, let's ask for A specificaly. - */ - err = dns_lookup(tmp_ctx, name, QTYPE_A, &reply); - if (!ERR_DNS_IS_OK(err)) { - goto done; - } - - total = reply_to_addrs(tmp_ctx, &a_num, &addrs, total, - reply, port); - +#ifdef HAVE_IPV6 + /* Now ask for AAAA records. */ + err = dns_lookup(tmp_ctx, name, QTYPE_AAAA, &reply); + if (ERR_DNS_IS_OK(err)) { + total = reply_to_addrs(tmp_ctx, + &a_num, + &addrs, + total, + reply, + port); } +#endif if (total) { talloc_steal(mem_ctx, addrs); @@ -260,7 +246,6 @@ static struct dns_records_container get_a_aaaa_records(TALLOC_CTX *mem_ctx, ret.list = addrs; } -done: TALLOC_FREE(tmp_ctx); return ret; } -- 2.34.1