diff options
author | Samuel Cabrero <scabrero@suse.de> | 2022-06-13 16:53:32 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-06-27 15:50:30 +0000 |
commit | 633ccc55c0670cfe663ab7bf119feb8b22c92794 (patch) | |
tree | 60ec2420ece0d2fa60734f628e4724deec31a093 | |
parent | d64335eaef5ad690ea923a8e6656b9185a54d9fa (diff) | |
download | samba-633ccc55c0670cfe663ab7bf119feb8b22c92794.tar.gz |
s3:libads: Allocate ads->auth.user_name 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 | 19 | ||||
-rw-r--r-- | source3/lib/netapi/joindomain.c | 14 | ||||
-rw-r--r-- | source3/libads/ads_struct.c | 1 | ||||
-rwxr-xr-x | source3/libads/ldap.c | 11 | ||||
-rw-r--r-- | source3/libnet/libnet_join.c | 8 | ||||
-rw-r--r-- | source3/utils/net_ads.c | 8 | ||||
-rw-r--r-- | source3/utils/net_ads_join_dns.c | 6 |
7 files changed, 46 insertions, 21 deletions
diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index b9570b24d82..485c96f4f2d 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -229,12 +229,16 @@ static PyObject* py_ads_connect(ADS *self, PyErr_SetString(PyExc_RuntimeError, "Uninitialized"); return NULL; } - SAFE_FREE(self->ads_ptr->auth.user_name); + TALLOC_FREE(self->ads_ptr->auth.user_name); TALLOC_FREE(self->ads_ptr->auth.password); 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.user_name = talloc_strdup(self->ads_ptr, + cli_credentials_get_username(self->cli_creds)); + if (self->ads_ptr->auth.user_name == NULL) { + PyErr_NoMemory(); + goto err; + } self->ads_ptr->auth.password = talloc_strdup(self->ads_ptr, cli_credentials_get_password(self->cli_creds)); if (self->ads_ptr->auth.password == NULL) { @@ -251,16 +255,17 @@ static PyObject* py_ads_connect(ADS *self, status = ads_connect_user_creds(self->ads_ptr); } else { char *passwd = NULL; - int ret; + if (!secrets_init()) { PyErr_SetString(PyExc_RuntimeError, "secrets_init() failed"); goto err; } - ret = asprintf(&(self->ads_ptr->auth.user_name), "%s$", - lp_netbios_name()); - if (ret == -1) { + self->ads_ptr->auth.user_name = talloc_asprintf(self->ads_ptr, + "%s$", + lp_netbios_name()); + if (self->ads_ptr->auth.user_name == NULL) { PyErr_NoMemory(); goto err; } diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index aa0cefe163e..ced16031d44 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -434,15 +434,23 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, goto out; } - SAFE_FREE(ads->auth.user_name); + TALLOC_FREE(ads->auth.user_name); if (r->in.account) { - ads->auth.user_name = SMB_STRDUP(r->in.account); + ads->auth.user_name = talloc_strdup(ads, r->in.account); + if (ads->auth.user_name == NULL) { + ret = WERR_NOT_ENOUGH_MEMORY; + goto out; + } } else { const char *username = NULL; libnetapi_get_username(ctx, &username); if (username != NULL) { - ads->auth.user_name = SMB_STRDUP(username); + ads->auth.user_name = talloc_strdup(ads, username); + if (ads->auth.user_name == NULL) { + ret = WERR_NOT_ENOUGH_MEMORY; + goto out; + } } } diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index b1ae510aafd..00134d1a73c 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.user_name); SAFE_FREE((*ads)->auth.kdc_server); SAFE_FREE((*ads)->auth.ccache_name); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index c1a26ddd476..00a3c80c60f 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -713,10 +713,13 @@ got_connection: if (!ads->auth.user_name) { /* Must use the userPrincipalName value here or sAMAccountName and not servicePrincipalName; found by Guenther Deschner */ - - if (asprintf(&ads->auth.user_name, "%s$", lp_netbios_name() ) == -1) { - DEBUG(0,("ads_connect: asprintf fail.\n")); - ads->auth.user_name = NULL; + ads->auth.user_name = talloc_asprintf(ads, + "%s$", + lp_netbios_name()); + if (ads->auth.user_name == NULL) { + DBG_ERR("talloc_asprintf failed\n"); + status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + goto out; } } diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index 0ec5ff4c1d8..2c5e4631e50 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -171,8 +171,12 @@ static ADS_STATUS libnet_connect_ads(const char *dns_domain_name, } if (user_name) { - SAFE_FREE(my_ads->auth.user_name); - my_ads->auth.user_name = SMB_STRDUP(user_name); + TALLOC_FREE(my_ads->auth.user_name); + my_ads->auth.user_name = talloc_strdup(my_ads, user_name); + if (my_ads->auth.user_name == NULL) { + status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + goto out; + } if ((cp = strchr_m(my_ads->auth.user_name, '@'))!=0) { *cp++ = '\0'; TALLOC_FREE(my_ads->auth.realm); diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 008e0e89be2..b842171d892 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -667,8 +667,12 @@ retry: } } - SAFE_FREE(ads->auth.user_name); - ads->auth.user_name = smb_xstrdup(c->opt_user_name); + TALLOC_FREE(ads->auth.user_name); + ads->auth.user_name = talloc_strdup(ads, c->opt_user_name); + if (ads->auth.user_name == NULL) { + TALLOC_FREE(ads); + return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + } ads->auth.flags |= auth_flags; diff --git a/source3/utils/net_ads_join_dns.c b/source3/utils/net_ads_join_dns.c index 1009f510e3b..7c98b0ee27f 100644 --- a/source3/utils/net_ads_join_dns.c +++ b/source3/utils/net_ads_join_dns.c @@ -284,8 +284,10 @@ void net_ads_join_dns_updates(struct net_context *c, TALLOC_CTX *ctx, struct lib use_in_memory_ccache(); - ret = asprintf(&ads_dns->auth.user_name, "%s$", lp_netbios_name()); - if (ret == -1) { + ads_dns->auth.user_name = talloc_asprintf(ads_dns, + "%s$", + lp_netbios_name()); + if (ads_dns->auth.user_name == NULL) { d_fprintf(stderr, _("DNS update failed: out of memory\n")); goto done; } |