summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2020-11-29 19:32:33 +0100
committerJeremy Allison <jra@samba.org>2020-12-11 18:29:32 +0000
commit7614cce0bd654da7768ba93f50347513dcd95861 (patch)
tree5cdcac4841698b167a1f72619bce93f4dad23d1a /source3/libsmb
parent9d7c048e0b1d74bea1fddd712df882445dc5aecc (diff)
downloadsamba-7614cce0bd654da7768ba93f50347513dcd95861.tar.gz
libsmb: No need to call dns_lookup_list_async() in discover_dc_dns()
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/dsgetdcname.c145
1 files changed, 6 insertions, 139 deletions
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index aa23213bb5a..ae90e07de77 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -513,11 +513,6 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx,
size_t numdcs = 0;
struct ip_service_name *dclist = NULL;
size_t ret_count = 0;
- size_t num_dns_lookups = 0;
- const char **dns_lookups = NULL;
- size_t num_lookups_ret = 0;
- struct samba_sockaddr *dns_addrs_ret = NULL;
- char **dns_lookups_ret = NULL;
char *query = NULL;
if (flags & DS_PDC_REQUIRED) {
@@ -577,16 +572,6 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx,
for (i = 0; i < numdcs; i++) {
size_t j;
- if (dcs[i].num_ips == 0) {
- /*
- * No addresses returned in the SRV
- * reply, we must look this up via
- * DNS.
- */
- num_dns_lookups++;
- continue;
- }
-
dclist[ret_count].hostname =
talloc_move(dclist, &dcs[i].hostname);
@@ -628,134 +613,16 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx,
ret_count++;
}
- /*
- * Now, create an array of hostnames we
- * will asynchronously look up in DNS.
- */
- dns_lookups = talloc_zero_array(mem_ctx,
- const char *,
- num_dns_lookups);
- if (dns_lookups == NULL) {
- TALLOC_FREE(dcs);
- TALLOC_FREE(dclist);
- return NT_STATUS_NO_MEMORY;
- }
-
- num_dns_lookups = 0;
- for (i = 0; i < numdcs; i++) {
- if (dcs[i].num_ips != 0) {
- /*
- * We already got an address
- * for this via SRV return.
- */
- continue;
- }
- dns_lookups[num_dns_lookups] =
- talloc_strdup(mem_ctx, dcs[i].hostname);
- if (dns_lookups[num_dns_lookups] == NULL) {
- TALLOC_FREE(dcs);
- TALLOC_FREE(dclist);
- TALLOC_FREE(dns_lookups);
- }
- num_dns_lookups++;
- }
+ TALLOC_FREE(dcs);
- status = dns_lookup_list_async(mem_ctx,
- num_dns_lookups,
- dns_lookups,
- &num_lookups_ret,
- &dns_addrs_ret,
- &dns_lookups_ret);
- if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(dcs);
+ if (ret_count == 0) {
TALLOC_FREE(dclist);
- TALLOC_FREE(dns_lookups);
- return status;
- }
-
- /*
- * Remember, if we timed out or some
- * addresses didn't look up then
- * num_dns_lookups > num_lookups_ret,
- * so there isn't a one to one correspondence.
- *
- * The order of the requests is preserved
- * in the replies, but there may be requests
- * for which there are no replies if we
- * timed out.
- *
- * For example this means for looking up
- * names:
- * NAME1
- * NAME2
- * NAME3
- *
- * The replies might look like:
- * NAME1 -> IPv4
- * NAME1 -> IPv4
- * NAME1 -> IPv6
- * NAME1 -> IPv6
- * NAME3 -> IPv6
- *
- * But they will never be in the order:
- *
- * NAME2
- * NAME3
- * NAME1
- *
- * Also in dns_lookup_list_async()
- * we arrange the requests/replies in
- * the order IPv4 followed by IPv6, so in
- * the replies, we can always pick the first
- * reply - we know it will be IPv4 if there
- * is an IPv4 for that name.
- *
- * Here ret_count is the index into the
- * next entry in dclist we must fill (may
- * be zero).
- */
-
- for (i = 0; i < num_lookups_ret; i++) {
- dclist[ret_count].hostname =
- talloc_move(mem_ctx, &dns_lookups_ret[i]);
- dclist[ret_count].sa = dns_addrs_ret[i];
- /*
- * Is this a duplicate name return.
- * Remember we can look up both A and
- * AAAA records which can return multiple
- * addresses and the order of names
- * is preserved.
- */
- if (ret_count > 0) {
- if (strcmp(dclist[ret_count-1].hostname,
- dclist[ret_count].hostname) == 0) {
- /*
- * Same name. Keep the first address
- * which is IPv4 by preference.
- */
- continue;
- }
- }
- ret_count++;
-
- if (ret_count == numdcs) {
- /* We've filled the return array. */
- break;
- }
- }
-
- if (ret_count > 0) {
- TALLOC_FREE(dcs);
- TALLOC_FREE(dns_lookups);
- *returned_dclist = dclist;
- *return_count = ret_count;
- return NT_STATUS_OK;
+ return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
}
- TALLOC_FREE(dcs);
- TALLOC_FREE(dclist);
- TALLOC_FREE(dns_lookups);
- return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
+ *returned_dclist = dclist;
+ *return_count = ret_count;
+ return NT_STATUS_OK;
}
/****************************************************************