]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add get_kdc_list_talloc().
authorJeremy Allison <jra@samba.org>
Wed, 26 Aug 2020 18:26:33 +0000 (11:26 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:40 +0000 (13:23 +0000)
Talloc version of get_kdc_list(). 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 d1135e65d3d062979ce4e05573d9ba14b0aebaf3..7c635f40f80bebb430155cb4a34e19476ba69606 100644 (file)
@@ -64,7 +64,6 @@ bool sockaddr_storage_to_samba_sockaddr(struct samba_sockaddr *sa,
        return true;
 }
 
-#if 0
 /*
  * Utility function to convert a MALLOC'ed struct ip_serivce array
  * to a talloc'ed one. This function will go away once all ip_service
@@ -87,7 +86,6 @@ static NTSTATUS dup_ip_service_array(TALLOC_CTX *ctx,
        *array_out = array_copy;
        return NT_STATUS_OK;
 }
-#endif
 
 /****************************
  * SERVER AFFINITY ROUTINES *
@@ -4046,3 +4044,59 @@ NTSTATUS get_kdc_list( const char *realm,
 
        return NT_STATUS_OK;
 }
+
+/*********************************************************************
+ Talloc version.
+ Get the KDC list - re-use all the logic in get_dc_list.
+*********************************************************************/
+
+NTSTATUS get_kdc_list_talloc(TALLOC_CTX *ctx,
+                       const char *realm,
+                       const char *sitename,
+                       struct ip_service **ip_list_ret,
+                       size_t *ret_count)
+{
+       int count = 0;
+       struct ip_service *ip_list_malloc = NULL;
+       struct ip_service *ip_list = NULL;
+       bool ordered = false;
+       NTSTATUS status;
+
+       status = get_dc_list(realm,
+                       sitename,
+                       &ip_list_malloc,
+                       &count,
+                       DC_KDC_ONLY,
+                       &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;
+}
index 81aeb6406e36e9452d528e0dc7937ba20c8fbc0e..94d3c54601763cf34cadf8a20e38f53fd604541b 100644 (file)
@@ -118,5 +118,9 @@ NTSTATUS get_kdc_list( const char *realm,
                        const char *sitename,
                        struct ip_service **ip_list,
                        int *count);
-
+NTSTATUS get_kdc_list_talloc(TALLOC_CTX *ctx,
+                       const char *realm,
+                       const char *sitename,
+                       struct ip_service **ip_list_ret,
+                       size_t *ret_count);
 #endif