]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add get_sorted_dc_list_talloc().
authorJeremy Allison <jra@samba.org>
Wed, 26 Aug 2020 18:47:44 +0000 (11:47 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:40 +0000 (13:23 +0000)
Talloc version of get_sorted_dc_list_talloc().
Makes use of dup_ip_service_array().
Now to move the callers.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/libsmb/namequery.c
source3/libsmb/namequery.h

index dcc1b026b5073558cfdb02c0f8fd79736960f42d..3d35c9d4cb6b103eafc84e559a096effda3a62d8 100644 (file)
@@ -4013,6 +4013,85 @@ NTSTATUS get_sorted_dc_list( const char *domain,
        return NT_STATUS_OK;
 }
 
+/*********************************************************************
+ Talloc version.
+ Small wrapper function to get the DC list and sort it if neccessary.
+*********************************************************************/
+
+NTSTATUS get_sorted_dc_list_talloc(TALLOC_CTX *ctx,
+                               const char *domain,
+                               const char *sitename,
+                               struct ip_service **ip_list_ret,
+                               size_t *ret_count,
+                               bool ads_only)
+{
+       bool ordered = false;
+       NTSTATUS status;
+       enum dc_lookup_type lookup_type = DC_NORMAL_LOOKUP;
+       struct ip_service *ip_list_malloc = NULL;
+       struct ip_service *ip_list = NULL;
+       int count = 0;
+
+       DBG_INFO("attempting lookup for name %s (sitename %s)\n",
+               domain,
+               sitename ? sitename : "NULL");
+
+       if (ads_only) {
+               lookup_type = DC_ADS_ONLY;
+       }
+
+       status = get_dc_list(domain,
+                       sitename,
+                       &ip_list_malloc,
+                       &count,
+                       lookup_type,
+                       &ordered);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_NO_LOGON_SERVERS)
+                       && sitename) {
+               DBG_NOTICE("no server for name %s available"
+                       " in site %s, fallback to all servers\n",
+                       domain,
+                       sitename);
+               status = get_dc_list(domain,
+                               NULL,
+                               &ip_list_malloc,
+                               &count,
+                               lookup_type,
+                               &ordered);
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
+
+       /* Paranoia check. */
+       if (count < 0) {
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto out;
+       }
+
+       /* only sort if we don't already have an ordered list */
+       if (!ordered) {
+               sort_service_list(ip_list_malloc, count);
+       }
+
+       status = dup_ip_service_array(ctx,
+                               &ip_list,
+                               ip_list_malloc,
+                               (size_t)count);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
+
+       *ret_count = (size_t)count;
+       *ip_list_ret = ip_list;
+
+  out:
+
+       SAFE_FREE(ip_list_malloc);
+       return status;
+}
+
 /*********************************************************************
  Talloc version.
  Get the KDC list - re-use all the logic in get_dc_list.
index b726f2529576c1fc6aef7e1d7fd1d9e4c2b00e97..9c4b2ecdf458513f494c32c2dcc10d90bd9124c8 100644 (file)
@@ -114,6 +114,12 @@ NTSTATUS get_sorted_dc_list( const char *domain,
                        struct ip_service **ip_list,
                        int *count,
                        bool ads_only );
+NTSTATUS get_sorted_dc_list_talloc(TALLOC_CTX *ctx,
+                       const char *domain,
+                       const char *sitename,
+                       struct ip_service **ip_list_ret,
+                       size_t *ret_count,
+                       bool ads_only);
 NTSTATUS get_kdc_list(TALLOC_CTX *ctx,
                        const char *realm,
                        const char *sitename,