]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:winbind: Allocate a temporary memory context for dcip_check_name_ads()
authorSamuel Cabrero <scabrero@samba.org>
Tue, 24 May 2022 14:17:42 +0000 (16:17 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Jun 2022 15:50:29 +0000 (15:50 +0000)
Prepare to allocate ADS_STRUCT under a talloc context.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/winbindd/winbindd_cm.c

index 5fbc137bf1403764075bac45a8a8650752a9aeb2..4595be280eb8fefeb14b3a6f65c7c6a03a028498 100644 (file)
@@ -1080,12 +1080,14 @@ static bool add_sockaddr_to_array(TALLOC_CTX *mem_ctx,
 }
 
 #ifdef HAVE_ADS
-static bool dcip_check_name_ads(TALLOC_CTX *mem_ctx,
-                               const struct winbindd_domain *domain,
+static bool dcip_check_name_ads(const struct winbindd_domain *domain,
                                struct samba_sockaddr *sa,
-                               char **name,
-                               uint32_t request_flags)
+                               uint32_t request_flags,
+                               TALLOC_CTX *mem_ctx,
+                               char **namep)
 {
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       char *name = NULL;
        ADS_STRUCT *ads = NULL;
        ADS_STATUS ads_status;
        char addr[INET6_ADDRSTRLEN];
@@ -1106,18 +1108,19 @@ static bool dcip_check_name_ads(TALLOC_CTX *mem_ctx,
        }
 
        /* We got a cldap packet. */
-       *name = talloc_strdup(mem_ctx,
-                            ads->config.ldap_server_name);
-       if (*name == NULL) {
-               return false;
+       name = talloc_strdup(tmp_ctx, ads->config.ldap_server_name);
+       if (name == NULL) {
+               ads_status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+               goto out;
        }
-       namecache_store(*name, 0x20, 1, sa);
+       namecache_store(name, 0x20, 1, sa);
 
        DBG_DEBUG("CLDAP flags = 0x%"PRIx32"\n", ads->config.flags);
 
        if (domain->primary && (ads->config.flags & NBT_SERVER_KDC)) {
                if (ads_closest_dc(ads)) {
-                       char *sitename = sitename_fetch(mem_ctx, ads->config.realm);
+                       char *sitename = sitename_fetch(tmp_ctx,
+                                                       ads->config.realm);
 
                        /* We're going to use this KDC for this realm/domain.
                           If we are using sites, then force the krb5 libs
@@ -1139,13 +1142,17 @@ static bool dcip_check_name_ads(TALLOC_CTX *mem_ctx,
                winbindd_set_locator_kdc_envs(domain);
 
                /* Ensure we contact this DC also. */
-               saf_store(domain->name, *name);
-               saf_store(domain->alt_name, *name);
+               saf_store(domain->name, name);
+               saf_store(domain->alt_name, name);
        }
 
+       *namep = talloc_move(mem_ctx, &name);
+
 out:
        ads_destroy( &ads );
 
+       TALLOC_FREE(tmp_ctx);
+
        return ADS_ERR_OK(ads_status) ? true : false;
 }
 #endif
@@ -1184,11 +1191,11 @@ static bool dcip_check_name(TALLOC_CTX *mem_ctx,
        }
 
        if (is_ad_domain) {
-               return dcip_check_name_ads(mem_ctx,
-                                          domain,
+               return dcip_check_name_ads(domain,
                                           &sa,
-                                          name,
-                                          request_flags);
+                                          request_flags,
+                                          mem_ctx,
+                                          name);
        }
 #endif