s3:net: Refactor net_ads_enctypes_delete(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 11:51:44 +0000 (13:51 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Jun 2022 15:50:30 +0000 (15:50 +0000)
ADS_STRUCT will be allocated in the talloc context.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/net_ads.c

index f8b7ba86dc5ed7e76362571bb9068779cd22cc2c..17e56b19adc3905e34d37190f0071b5ab90674d6 100644 (file)
@@ -3725,12 +3725,13 @@ static int net_ads_enctypes_set(struct net_context *c, int argc, const char **ar
 
 static int net_ads_enctypes_delete(struct net_context *c, int argc, const char **argv)
 {
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        int ret = -1;
        ADS_STATUS status;
-       ADS_STRUCT *ads;
+       ADS_STRUCT *ads = NULL;
        LDAPMessage *res = NULL;
-       const char *dn;
-       ADS_MODLIST mods;
+       const char *dn = NULL;
+       ADS_MODLIST mods = NULL;
 
        if (c->display_usage || argc < 1) {
                d_printf(  "%s\n"
@@ -3738,13 +3739,13 @@ static int net_ads_enctypes_delete(struct net_context *c, int argc, const char *
                           "    %s\n",
                         _("Usage:"),
                         _("Delete supported enctypes"));
+               TALLOC_FREE(tmp_ctx);
                return 0;
        }
 
        status = ads_startup(c, false, &ads);
        if (!ADS_ERR_OK(status)) {
-               printf("startup failed\n");
-               return ret;
+               goto done;
        }
 
        ret = net_ads_enctype_lookup_account(c, ads, argv[0], &res, NULL);
@@ -3752,17 +3753,17 @@ static int net_ads_enctypes_delete(struct net_context *c, int argc, const char *
                goto done;
        }
 
-       dn = ads_get_dn(ads, c, res);
+       dn = ads_get_dn(ads, tmp_ctx, res);
        if (dn == NULL) {
                goto done;
        }
 
-       mods = ads_init_mods(c);
+       mods = ads_init_mods(tmp_ctx);
        if (!mods) {
                goto done;
        }
 
-       status = ads_mod_str(c, &mods, "msDS-SupportedEncryptionTypes", NULL);
+       status = ads_mod_str(tmp_ctx, &mods, "msDS-SupportedEncryptionTypes", NULL);
        if (!ADS_ERR_OK(status)) {
                goto done;
        }
@@ -3779,6 +3780,7 @@ static int net_ads_enctypes_delete(struct net_context *c, int argc, const char *
  done:
        ads_msgfree(ads, res);
        ads_destroy(&ads);
+       TALLOC_FREE(tmp_ctx);
        return ret;
 }