From: Jeremy Allison Date: Tue, 21 Jul 2020 01:31:16 +0000 (-0700) Subject: s3: libsmb: Add in (currently unused) function dns_lookup_list(). X-Git-Tag: talloc-2.3.2~945 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0fa32bdcda523df628a7ab96e6598d5f8ea41d4;p=thirdparty%2Fsamba.git s3: libsmb: Add in (currently unused) function dns_lookup_list(). This function takes a list of names returned from a DNS SRV query which didn't have returned IP addresses and returns an array of struct sockaddr_storage. Currently synchronous, but this is the function that will be changed to be asynchronous later. Compiles but commented out for now so we don't get "unused function" warnings. Signed-off-by: Jeremy Allison Reviewed-by: Isaac Boukris --- diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index e1c95c8996f..feef0c74395 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -2280,6 +2280,88 @@ fail: return status; } +#if 0 +/******************************************************** + Resolve a list of DNS names to a list of IP addresses. + As this is a DC / LDAP / KDC lookup any IP address will + do, the requested names don't have to match the returned + IP address list. +*********************************************************/ + +static NTSTATUS dns_lookup_list(TALLOC_CTX *ctx, + size_t num_dns_names, + const char **dns_lookup_names, + size_t *p_num_addrs, + struct sockaddr_storage **pp_addrs) +{ + size_t total_num_addrs = 0; + size_t i; + struct sockaddr_storage *ret_addrs = NULL; + + /* FIXME - make this asnyc using our async DNS code. */ + + for (i = 0; i < num_dns_names; i++ ) { + struct addrinfo *res = NULL; + struct addrinfo *p = NULL; + size_t num_addrs = 0; + bool ok = interpret_string_addr_internal(&res, + dns_lookup_names[i], + 0); + if (!ok) { + continue; + } + /* Count the IP's returned from the lookup. */ + for (p = res; p; p = p->ai_next) { + /* Wrap check. */ + if (num_addrs + 1 < num_addrs) { + freeaddrinfo(res); + return NT_STATUS_INVALID_PARAMETER; + } + num_addrs++; + } + + /* Wrap check. */ + if (total_num_addrs + num_addrs < total_num_addrs) { + freeaddrinfo(res); + return NT_STATUS_INVALID_PARAMETER; + } + ret_addrs = talloc_realloc(ctx, + ret_addrs, + struct sockaddr_storage, + total_num_addrs + num_addrs); + if (ret_addrs == NULL) { + freeaddrinfo(res); + return NT_STATUS_NO_MEMORY; + } + + for (p = res; p; p = p->ai_next) { + char addr[INET6_ADDRSTRLEN]; + + memcpy(&ret_addrs[total_num_addrs], + p->ai_addr, + p->ai_addrlen); + + if (is_zero_addr(&ret_addrs[total_num_addrs])) { + continue; + } + + DBG_DEBUG("getaddrinfo name %s returned IP %s\n", + dns_lookup_names[i], + print_sockaddr(addr, + sizeof(addr), + &ret_addrs[total_num_addrs])); + + total_num_addrs++; + } + freeaddrinfo(res); + } + + *p_num_addrs = total_num_addrs; + *pp_addrs = ret_addrs; + return NT_STATUS_OK; +} +#endif + /******************************************************** Resolve via "hosts" method. *********************************************************/