]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libads: Allocate ads->auth.user_name under ADS_STRUCT talloc context
authorSamuel Cabrero <scabrero@suse.de>
Mon, 13 Jun 2022 14:53:32 +0000 (16:53 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Jun 2022 15:50:30 +0000 (15:50 +0000)
Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
libgpo/pygpo.c
source3/lib/netapi/joindomain.c
source3/libads/ads_struct.c
source3/libads/ldap.c
source3/libnet/libnet_join.c
source3/utils/net_ads.c
source3/utils/net_ads_join_dns.c

index b9570b24d82982b366f4e4e4a29878f2b114c41f..485c96f4f2db461436bccda45616e3b807cc6a62 100644 (file)
@@ -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;
                }
index aa0cefe163e9223fa467ffcd8062a52b910788f4..ced16031d44e459bc5caf0563cd5fddc885b50cf 100644 (file)
@@ -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;
+                       }
                }
        }
 
index b1ae510aafdcc1d45c5036948714a3fd65ac5702..00134d1a73cac5ccfdce00d71d03087b0fd618cb 100644 (file)
@@ -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);
 
index c1a26ddd4760cfd8619acb13128f31e3297b8af3..00a3c80c60fee9d8f6cbfe0dc9352634fe741878 100755 (executable)
@@ -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;
                }
        }
 
index 0ec5ff4c1d8c09f1702c525eda9f9bb77b537617..2c5e4631e509db4be7825649dcb8141fe86c8bd4 100644 (file)
@@ -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);
index 008e0e89be2ff2d5f2cde2067f329e056441edf4..b842171d892235892c354eece737115d29db7e4c 100644 (file)
@@ -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;
 
index 1009f510e3b360a2ca939f6e8220400086a476bd..7c98b0ee27f82d00a3b4b296bf92350d7bc30b2b 100644 (file)
@@ -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;
        }