diff options
author | Samuel Cabrero <scabrero@suse.de> | 2022-06-13 12:38:24 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-06-27 15:50:30 +0000 |
commit | c1ab39163bbaf8ef9c8dc92b1d14c3f6cb56456c (patch) | |
tree | 03030aff52526c5c1ebea1b42275ceac6c0a682c | |
parent | cc8465f1b79e335d9af6a2c2edf128aa5ce07ec0 (diff) | |
download | samba-c1ab39163bbaf8ef9c8dc92b1d14c3f6cb56456c.tar.gz |
s3:libads: Allocate ads->auth.realm under ADS_STRUCT talloc context
Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | libgpo/pygpo.c | 18 | ||||
-rw-r--r-- | source3/libads/ads_struct.c | 1 | ||||
-rwxr-xr-x | source3/libads/ldap.c | 8 | ||||
-rw-r--r-- | source3/libnet/libnet_join.c | 6 | ||||
-rw-r--r-- | source3/utils/net_ads.c | 6 | ||||
-rw-r--r-- | source3/utils/net_ads_join_dns.c | 10 | ||||
-rw-r--r-- | source3/winbindd/winbindd_ads.c | 6 |
7 files changed, 29 insertions, 26 deletions
diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index 710f7fa896d..85a4aaa1581 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -231,14 +231,18 @@ static PyObject* py_ads_connect(ADS *self, } SAFE_FREE(self->ads_ptr->auth.user_name); SAFE_FREE(self->ads_ptr->auth.password); - SAFE_FREE(self->ads_ptr->auth.realm); + TALLOC_FREE(self->ads_ptr->auth.realm); if (self->cli_creds) { self->ads_ptr->auth.user_name = SMB_STRDUP(cli_credentials_get_username(self->cli_creds)); self->ads_ptr->auth.password = SMB_STRDUP(cli_credentials_get_password(self->cli_creds)); - self->ads_ptr->auth.realm = - SMB_STRDUP(cli_credentials_get_realm(self->cli_creds)); + self->ads_ptr->auth.realm = talloc_strdup(self->ads_ptr, + cli_credentials_get_realm(self->cli_creds)); + if (self->ads_ptr->auth.realm == NULL) { + PyErr_NoMemory(); + goto err; + } self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS; status = ads_connect_user_creds(self->ads_ptr); } else { @@ -266,10 +270,10 @@ static PyObject* py_ads_connect(ADS *self, goto err; } self->ads_ptr->auth.password = passwd; /* take ownership of this data */ - self->ads_ptr->auth.realm = - SMB_STRDUP(self->ads_ptr->server.realm); - if (!strupper_m(self->ads_ptr->auth.realm)) { - PyErr_SetString(PyExc_RuntimeError, "Failed to strupper"); + self->ads_ptr->auth.realm = talloc_asprintf_strupper_m( + self->ads_ptr, "%s", self->ads_ptr->server.realm); + if (self->ads_ptr->auth.realm == NULL) { + PyErr_NoMemory(); goto err; } self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS; diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index 2d9bc9435fa..e344d42ae43 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)->auth.realm); SAFE_FREE((*ads)->auth.password); SAFE_FREE((*ads)->auth.user_name); SAFE_FREE((*ads)->auth.kdc_server); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 9a838756598..c1a26ddd476 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -720,8 +720,12 @@ got_connection: } } - if (!ads->auth.realm) { - ads->auth.realm = SMB_STRDUP(ads->config.realm); + if (ads->auth.realm == NULL) { + ads->auth.realm = talloc_strdup(ads, ads->config.realm); + if (ads->auth.realm == NULL) { + status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + goto out; + } } if (!ads->auth.kdc_server) { diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index f2fa2e5f60b..4dd6ab5410a 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -175,9 +175,9 @@ static ADS_STATUS libnet_connect_ads(const char *dns_domain_name, my_ads->auth.user_name = SMB_STRDUP(user_name); if ((cp = strchr_m(my_ads->auth.user_name, '@'))!=0) { *cp++ = '\0'; - SAFE_FREE(my_ads->auth.realm); - my_ads->auth.realm = smb_xstrdup(cp); - if (!strupper_m(my_ads->auth.realm)) { + TALLOC_FREE(my_ads->auth.realm); + my_ads->auth.realm = talloc_asprintf_strupper_m(my_ads, "%s", cp); + if (my_ads->auth.realm == NULL) { status = ADS_ERROR_LDAP(LDAP_NO_MEMORY); goto out; } diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 4718d4bed97..11efde7947f 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -692,9 +692,9 @@ retry: */ if ((cp = strchr_m(ads->auth.user_name, '@'))!=0) { *cp++ = '\0'; - SAFE_FREE(ads->auth.realm); - ads->auth.realm = smb_xstrdup(cp); - if (!strupper_m(ads->auth.realm)) { + TALLOC_FREE(ads->auth.realm); + ads->auth.realm = talloc_asprintf_strupper_m(ads, "%s", cp); + if (ads->auth.realm == NULL) { TALLOC_FREE(ads); return ADS_ERROR(LDAP_NO_MEMORY); } diff --git a/source3/utils/net_ads_join_dns.c b/source3/utils/net_ads_join_dns.c index 59bf17ed102..286a77c5c9d 100644 --- a/source3/utils/net_ads_join_dns.c +++ b/source3/utils/net_ads_join_dns.c @@ -296,14 +296,10 @@ void net_ads_join_dns_updates(struct net_context *c, TALLOC_CTX *ctx, struct lib goto done; } - ads_dns->auth.realm = SMB_STRDUP(r->out.dns_domain_name); + ads_dns->auth.realm = talloc_asprintf_strupper_m(ads_dns, "%s", r->out.dns_domain_name); if (ads_dns->auth.realm == NULL) { - d_fprintf(stderr, _("DNS update failed: out of memory\n")); - goto done; - } - - if (!strupper_m(ads_dns->auth.realm)) { - d_fprintf(stderr, _("strupper_m %s failed\n"), ads_dns->auth.realm); + d_fprintf(stderr, _("talloc_asprintf_strupper_m %s failed\n"), + ads_dns->auth.realm); goto done; } diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c index 8425dbc1693..4da52a40f93 100644 --- a/source3/winbindd/winbindd_ads.c +++ b/source3/winbindd/winbindd_ads.c @@ -126,7 +126,7 @@ static ADS_STATUS ads_cached_connection_connect(const char *target_realm, } SAFE_FREE(ads->auth.password); - SAFE_FREE(ads->auth.realm); + TALLOC_FREE(ads->auth.realm); ads->auth.renewable = renewable; ads->auth.password = password; @@ -148,8 +148,8 @@ static ADS_STATUS ads_cached_connection_connect(const char *target_realm, break; } - ads->auth.realm = SMB_STRDUP(auth_realm); - if (!strupper_m(ads->auth.realm)) { + ads->auth.realm = talloc_asprintf_strupper_m(ads, "%s", auth_realm); + if (ads->auth.realm == NULL) { status = ADS_ERROR_NT(NT_STATUS_INTERNAL_ERROR); goto out; } |