diff options
author | Samuel Cabrero <scabrero@samba.org> | 2022-05-26 17:28:34 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-06-27 15:50:30 +0000 |
commit | d0dc0171ad6abd969e834f8eb2bbfc08bef4547a (patch) | |
tree | 7291496f38d5f26f4b3e4d822a87350b54193f0c /source3/libads | |
parent | 50934b85ffe57ba35e6558a2b54097e64f464419 (diff) | |
download | samba-d0dc0171ad6abd969e834f8eb2bbfc08bef4547a.tar.gz |
s3:libads: Allocate ADS_STRUCT under a talloc context
The ads_destroy() function is now static and only called from the
ADS_STRUCT destructor.
Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/libads')
-rw-r--r-- | source3/libads/ads_proto.h | 4 | ||||
-rw-r--r-- | source3/libads/ads_struct.c | 32 | ||||
-rwxr-xr-x | source3/libads/ldap.c | 18 | ||||
-rw-r--r-- | source3/libads/ldap_utils.c | 6 |
4 files changed, 25 insertions, 35 deletions
diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index 5701a5d79d4..8f75e77a94e 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -43,12 +43,12 @@ enum ads_sasl_state_e { char *ads_build_path(const char *realm, const char *sep, const char *field, int reverse); char *ads_build_dn(const char *realm); char *ads_build_domain(const char *dn); -ADS_STRUCT *ads_init(const char *realm, +ADS_STRUCT *ads_init(TALLOC_CTX *mem_ctx, + const char *realm, const char *workgroup, const char *ldap_server, enum ads_sasl_state_e sasl_state); bool ads_set_sasl_wrap_flags(ADS_STRUCT *ads, unsigned flags); -void ads_destroy(ADS_STRUCT **ads); /* The following definitions come from libads/disp_sec.c */ diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index 1d3f41f0269..184185fa148 100644 --- a/source3/libads/ads_struct.c +++ b/source3/libads/ads_struct.c @@ -124,12 +124,9 @@ char *ads_build_domain(const char *dn) /* free the memory used by the ADS structure initialized with 'ads_init(...)' */ -void ads_destroy(ADS_STRUCT **ads) +static void ads_destroy(ADS_STRUCT **ads) { if (ads && *ads) { - bool is_mine; - - is_mine = (*ads)->is_mine; #ifdef HAVE_LDAP ads_disconnect(*ads); #endif @@ -150,30 +147,33 @@ void ads_destroy(ADS_STRUCT **ads) SAFE_FREE((*ads)->config.client_site_name); SAFE_FREE((*ads)->config.schema_path); SAFE_FREE((*ads)->config.config_path); - - ZERO_STRUCTP(*ads); -#ifdef HAVE_LDAP - ads_zero_ldap(*ads); -#endif - - if ( is_mine ) - SAFE_FREE(*ads); } } +static int ads_destructor(ADS_STRUCT *ads) +{ + ads_destroy(&ads); + return 0; +} + /* initialise a ADS_STRUCT, ready for some ads_ ops */ -ADS_STRUCT *ads_init(const char *realm, +ADS_STRUCT *ads_init(TALLOC_CTX *mem_ctx, + const char *realm, const char *workgroup, const char *ldap_server, enum ads_sasl_state_e sasl_state) { - ADS_STRUCT *ads; + ADS_STRUCT *ads = NULL; int wrap_flags; - ads = SMB_XMALLOC_P(ADS_STRUCT); - ZERO_STRUCTP(ads); + ads = talloc_zero(mem_ctx, ADS_STRUCT); + if (ads == NULL) { + return NULL; + } + talloc_set_destructor(ads, ads_destructor); + #ifdef HAVE_LDAP ads_zero_ldap(ads); #endif diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 23a2dacfb4c..acec42be166 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -622,8 +622,8 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads) * to ads_find_dc() in the reuse case. * * If a caller wants a clean ADS_STRUCT they - * will re-initialize by calling ads_init(), or - * call ads_destroy() both of which ensures + * will TALLOC_FREE it and allocate a new one + * by calling ads_init(), which ensures * ads->ldap.ss is a properly zero'ed out valid IP * address. */ @@ -3292,7 +3292,8 @@ ADS_STATUS ads_current_time(ADS_STRUCT *ads) * through ads_find_dc() again we want to avoid repeating. */ if (is_zero_addr(&ads->ldap.ss)) { - ads_s = ads_init(ads->server.realm, + ads_s = ads_init(tmp_ctx, + ads->server.realm, ads->server.workgroup, ads->server.ldap_server, ADS_SASL_PLAIN ); @@ -3340,10 +3341,6 @@ ADS_STATUS ads_current_time(ADS_STRUCT *ads) status = ADS_SUCCESS; done: - /* free any temporary ads connections */ - if ( ads_s != ads ) { - ads_destroy( &ads_s ); - } TALLOC_FREE(tmp_ctx); return status; @@ -3379,7 +3376,8 @@ ADS_STATUS ads_domain_func_level(ADS_STRUCT *ads, uint32_t *val) * through ads_find_dc() again we want to avoid repeating. */ if (is_zero_addr(&ads->ldap.ss)) { - ads_s = ads_init(ads->server.realm, + ads_s = ads_init(tmp_ctx, + ads->server.realm, ads->server.workgroup, ads->server.ldap_server, ADS_SASL_PLAIN ); @@ -3421,10 +3419,6 @@ ADS_STATUS ads_domain_func_level(ADS_STRUCT *ads, uint32_t *val) ads_msgfree(ads_s, res); done: - /* free any temporary ads connections */ - if ( ads_s != ads ) { - ads_destroy( &ads_s ); - } TALLOC_FREE(tmp_ctx); return status; diff --git a/source3/libads/ldap_utils.c b/source3/libads/ldap_utils.c index c9039684bf0..c08f046a405 100644 --- a/source3/libads/ldap_utils.c +++ b/source3/libads/ldap_utils.c @@ -105,8 +105,6 @@ static ADS_STATUS ads_do_search_retry_internal(ADS_STRUCT *ads, const char *bind status = ads_connect(ads); if (!ADS_ERR_OK(status)) { - bool orig_is_mine = ads->is_mine; - DEBUG(1,("ads_search_retry: failed to reconnect (%s)\n", ads_errstr(status))); /* @@ -114,9 +112,7 @@ static ADS_STATUS ads_do_search_retry_internal(ADS_STRUCT *ads, const char *bind * from being freed here as we don't own it and * callers depend on it being around. */ - ads->is_mine = false; - ads_destroy(&ads); - ads->is_mine = orig_is_mine; + ads_disconnect(ads); SAFE_FREE(bp); return status; } |