1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3: libsmb: Make get_dc_list() use internal_resolve_name_talloc().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
This commit is contained in:
Jeremy Allison 2020-08-26 13:41:15 -07:00 committed by Noel Power
parent 37eaee03e0
commit fed4b6341c

View File

@ -3784,7 +3784,7 @@ static NTSTATUS get_dc_list(TALLOC_CTX *ctx,
struct ip_service *return_iplist = NULL; struct ip_service *return_iplist = NULL;
struct ip_service *auto_ip_list = NULL; struct ip_service *auto_ip_list = NULL;
bool done_auto_lookup = false; bool done_auto_lookup = false;
int auto_count = 0; size_t auto_count = 0;
NTSTATUS status; NTSTATUS status;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
int auto_name_type = 0x1C; int auto_name_type = 0x1C;
@ -3859,43 +3859,31 @@ static NTSTATUS get_dc_list(TALLOC_CTX *ctx,
p = pserver; p = pserver;
while (next_token_talloc(frame, &p, &name, LIST_SEP)) { while (next_token_talloc(frame, &p, &name, LIST_SEP)) {
if (!done_auto_lookup && strequal(name, "*")) { if (!done_auto_lookup && strequal(name, "*")) {
struct ip_service *auto_ip_list_malloc = NULL;
done_auto_lookup = true; done_auto_lookup = true;
status = internal_resolve_name(domain, auto_name_type,
sitename, status = internal_resolve_name_talloc(frame,
&auto_ip_list_malloc, domain,
&auto_count, auto_name_type,
resolve_order); sitename,
&auto_ip_list,
&auto_count,
resolve_order);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
continue; continue;
} }
/* Paranoia. */
if (auto_count < 0) {
SAFE_FREE(auto_ip_list_malloc);
status = NT_STATUS_INVALID_PARAMETER;
goto out;
}
/* Wrap check. */ /* Wrap check. */
if (num_addresses + auto_count < num_addresses) { if (num_addresses + auto_count < num_addresses) {
SAFE_FREE(auto_ip_list_malloc); TALLOC_FREE(auto_ip_list);
status = NT_STATUS_INVALID_PARAMETER; status = NT_STATUS_INVALID_PARAMETER;
goto out; goto out;
} }
status = dup_ip_service_array(ctx,
&auto_ip_list,
auto_ip_list_malloc,
auto_count);
SAFE_FREE(auto_ip_list_malloc);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
num_addresses += auto_count; num_addresses += auto_count;
DEBUG(8,("Adding %d DC's from auto lookup\n", DBG_DEBUG("Adding %zu DC's from auto lookup\n",
auto_count)); auto_count);
} else { } else {
/* Wrap check. */ /* Wrap check. */
if (num_addresses + 1 < num_addresses) { if (num_addresses + 1 < num_addresses) {
TALLOC_FREE(auto_ip_list);
status = NT_STATUS_INVALID_PARAMETER; status = NT_STATUS_INVALID_PARAMETER;
goto out; goto out;
} }
@ -3907,37 +3895,27 @@ static NTSTATUS get_dc_list(TALLOC_CTX *ctx,
just return the list of DC's. Or maybe we just failed. */ just return the list of DC's. Or maybe we just failed. */
if (num_addresses == 0) { if (num_addresses == 0) {
int tmp_count = 0; struct ip_service *dc_iplist = NULL;
struct ip_service *ip_list_malloc = NULL; size_t dc_count = 0;
if (done_auto_lookup) { if (done_auto_lookup) {
DEBUG(4,("get_dc_list: no servers found\n")); DEBUG(4,("get_dc_list: no servers found\n"));
status = NT_STATUS_NO_LOGON_SERVERS; status = NT_STATUS_NO_LOGON_SERVERS;
goto out; goto out;
} }
status = internal_resolve_name(domain, /* talloc off frame, only move to ctx on success. */
auto_name_type, status = internal_resolve_name_talloc(frame,
sitename, domain,
&ip_list_malloc, auto_name_type,
&tmp_count, sitename,
resolve_order); &dc_iplist,
/* Paranoia. */ &dc_count,
if (tmp_count < 0) { resolve_order);
SAFE_FREE(ip_list_malloc); if (NT_STATUS_IS_OK(status)) {
status = NT_STATUS_INVALID_PARAMETER; *ip_list = talloc_move(ctx, &dc_iplist);
goto out; *ret_count = dc_count;
} }
if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(dc_iplist);
goto out;
}
status = dup_ip_service_array(ctx,
ip_list,
ip_list_malloc,
tmp_count);
SAFE_FREE(ip_list_malloc);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
*ret_count = (size_t)tmp_count;
goto out; goto out;
} }
@ -3962,7 +3940,7 @@ static NTSTATUS get_dc_list(TALLOC_CTX *ctx,
/* copy any addresses from the auto lookup */ /* copy any addresses from the auto lookup */
if (strequal(name, "*")) { if (strequal(name, "*")) {
int j; size_t j;
for (j=0; j<auto_count; j++) { for (j=0; j<auto_count; j++) {
char addr[INET6_ADDRSTRLEN]; char addr[INET6_ADDRSTRLEN];
print_sockaddr(addr, print_sockaddr(addr,