From: Samuel Cabrero Date: Mon, 13 Jun 2022 15:44:02 +0000 (+0200) Subject: s3:libads: Allocate ads->config.realm under ADS_STRUCT talloc context X-Git-Tag: tevent-0.13.0~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8a0446a4da2c220c8c3bf1ce17842bbce732c9d;p=thirdparty%2Fsamba.git s3:libads: Allocate ads->config.realm under ADS_STRUCT talloc context Signed-off-by: Samuel Cabrero Reviewed-by: Jeremy Allison --- diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index 4e9a2d33c08..5453a00a853 100644 --- a/source3/libads/ads_struct.c +++ b/source3/libads/ads_struct.c @@ -130,7 +130,6 @@ static void ads_destroy(ADS_STRUCT **ads) #ifdef HAVE_LDAP ads_disconnect(*ads); #endif - SAFE_FREE((*ads)->config.realm); SAFE_FREE((*ads)->config.bind_path); SAFE_FREE((*ads)->config.ldap_server_name); SAFE_FREE((*ads)->config.server_site_name); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 5ac5b1b0e12..e7117b79ede 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -291,7 +291,7 @@ static bool ads_try_connect(ADS_STRUCT *ads, bool gc, /* Fill in the ads->config values */ - SAFE_FREE(ads->config.realm); + TALLOC_FREE(ads->config.realm); SAFE_FREE(ads->config.bind_path); SAFE_FREE(ads->config.ldap_server_name); SAFE_FREE(ads->config.server_site_name); @@ -305,8 +305,11 @@ static bool ads_try_connect(ADS_STRUCT *ads, bool gc, } ads->config.ldap_server_name = SMB_STRDUP(cldap_reply.pdc_dns_name); - ads->config.realm = SMB_STRDUP(cldap_reply.dns_domain); - if (!strupper_m(ads->config.realm)) { + ads->config.realm = talloc_asprintf_strupper_m(ads, + "%s", + cldap_reply.dns_domain); + if (ads->config.realm == NULL) { + DBG_WARNING("Out of memory\n"); ret = false; goto out; } diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index b842171d892..3086652706f 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -436,7 +436,11 @@ static int net_ads_lookup(struct net_context *c, int argc, const char **argv) } if (!ads->config.realm) { - ads->config.realm = discard_const_p(char, c->opt_target_workgroup); + ads->config.realm = talloc_strdup(ads, c->opt_target_workgroup); + if (ads->config.realm == NULL) { + d_fprintf(stderr, _("Out of memory\n")); + goto out; + } ads->ldap.port = 389; } @@ -844,7 +848,11 @@ static int net_ads_workgroup(struct net_context *c, int argc, const char **argv) } if (!ads->config.realm) { - ads->config.realm = discard_const_p(char, c->opt_target_workgroup); + ads->config.realm = talloc_strdup(ads, c->opt_target_workgroup); + if (ads->config.realm == NULL) { + d_fprintf(stderr, _("Out of memory\n")); + goto out; + } ads->ldap.port = 389; }