]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:winbind: Allocate a temporary talloc context for ads_idmap_cached_connection()
authorSamuel Cabrero <scabrero@samba.org>
Wed, 25 May 2022 14:12:03 +0000 (16:12 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Jun 2022 15:50:29 +0000 (15:50 +0000)
Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/winbindd/winbindd_ads.c

index 1bdb9a0f29aac3bd7da3320d00e767ba3244dfd7..ff9ba437d600aa160945e32c906482badd3c36f7 100644 (file)
@@ -178,6 +178,7 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
                                       TALLOC_CTX *mem_ctx,
                                       ADS_STRUCT **adsp)
 {
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        char *ldap_server = NULL;
        char *realm = NULL;
        char *password = NULL;
@@ -189,11 +190,13 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
                 * Make sure we never try to use LDAP against
                 * a trusted domain as AD DC.
                 */
+               TALLOC_FREE(tmp_ctx);
                return ADS_ERROR_NT(NT_STATUS_REQUEST_NOT_ACCEPTED);
        }
 
        ads_cached_connection_reuse(adsp);
        if (*adsp != NULL) {
+               TALLOC_FREE(tmp_ctx);
                return ADS_SUCCESS;
        }
 
@@ -202,7 +205,8 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
         * Check if we can get server nam and realm from SAF cache
         * and the domain list.
         */
-       ldap_server = saf_fetch(talloc_tos(), dom_name);
+       ldap_server = saf_fetch(tmp_ctx, dom_name);
+
        DBG_DEBUG("ldap_server from saf cache: '%s'\n",
                   ldap_server ? ldap_server : "");
 
@@ -223,7 +227,7 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
 
        if (IS_DC) {
                SMB_ASSERT(wb_dom->alt_name != NULL);
-               realm = SMB_STRDUP(wb_dom->alt_name);
+               realm = talloc_strdup(tmp_ctx, wb_dom->alt_name);
        } else {
                struct winbindd_domain *our_domain = wb_dom;
 
@@ -235,12 +239,17 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
                }
 
                if (our_domain->alt_name != NULL) {
-                       realm = SMB_STRDUP(our_domain->alt_name);
+                       realm = talloc_strdup(tmp_ctx, our_domain->alt_name);
                } else {
-                       realm = SMB_STRDUP(lp_realm());
+                       realm = talloc_strdup(tmp_ctx, lp_realm());
                }
        }
 
+       if (realm == NULL) {
+               status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+               goto out;
+       }
+
        status = ads_cached_connection_connect(
                adsp,                   /* Returns ads struct. */
                wb_dom->alt_name,       /* realm to connect to. */
@@ -251,9 +260,8 @@ ADS_STATUS ads_idmap_cached_connection(const char *dom_name,
                0);                     /* renewable ticket time. */
 
 out:
-       SAFE_FREE(realm);
+       TALLOC_FREE(tmp_ctx);
        SAFE_FREE(password);
-       TALLOC_FREE(ldap_server);
 
        return status;
 }