]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add in (currently unused) function dns_lookup_list().
authorJeremy Allison <jra@samba.org>
Tue, 21 Jul 2020 01:31:16 +0000 (18:31 -0700)
committerIsaac Boukris <iboukris@sn-devel-184>
Tue, 4 Aug 2020 08:51:42 +0000 (08:51 +0000)
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 <jra@samba.org>
Reviewed-by: Isaac Boukris <iboukris@samba.org>
source3/libsmb/namequery.c

index e1c95c8996ff964e7483523398990b2bb0bf1a7e..feef0c7439511a6d9e11962705ea39a65bf12e09 100644 (file)
@@ -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.
 *********************************************************/