s3:libads: Allocate ads->auth.realm under ADS_STRUCT talloc context
authorSamuel Cabrero <scabrero@suse.de>
Mon, 13 Jun 2022 10:38:24 +0000 (12:38 +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/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
source3/winbindd/winbindd_ads.c

index 710f7fa896d9b8d994af216f308082b55f2c0c30..85a4aaa1581b1daa59ac6668c6321d66b355134b 100644 (file)
@@ -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;
index 2d9bc9435fa38769510cd35d4e3be83084984742..e344d42ae43911cf2b49311fdf75975e38f1a75e 100644 (file)
@@ -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);
index 9a838756598c56bf6b53756d1005fefbf51b35cb..c1a26ddd4760cfd8619acb13128f31e3297b8af3 100755 (executable)
@@ -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) {
index f2fa2e5f60b1d47f8b47c83cd3197f934d0071ca..4dd6ab5410a1c4ed4568426f61f62cc3367f77c1 100644 (file)
@@ -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;
                        }
index 4718d4bed9719663e96b6f95bc7edaad8a19a6ee..11efde7947f3c44cd060596001f84b2a580eedca 100644 (file)
@@ -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);
                }
index 59bf17ed1022f30d3d796d82688abd06cf4af99d..286a77c5c9d667c5c14c70e627e6aacc61811ff6 100644 (file)
@@ -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;
        }
 
index 8425dbc16931db3d059a001d95d2e829773c1798..4da52a40f935d59f063a30215d8d96e287eabeed 100644 (file)
@@ -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;
        }