]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:net: Refactor net_ads_keytab_create(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 11:31:57 +0000 (13:31 +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 db011eb7f2f97e53673fef1c1e09da636428ae93..5949ee961687a5a5f12b2a5e50eb3d993cb7462e 100644 (file)
@@ -2981,8 +2981,10 @@ static int net_ads_keytab_add_update_ads(struct net_context *c,
 
 static int net_ads_keytab_create(struct net_context *c, int argc, const char **argv)
 {
-       ADS_STRUCT *ads;
-       int ret;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       ADS_STRUCT *ads = NULL;
+       ADS_STATUS status;
+       int ret = -1;
 
        if (c->display_usage) {
                d_printf(  "%s\n"
@@ -2990,6 +2992,7 @@ static int net_ads_keytab_create(struct net_context *c, int argc, const char **a
                           "    %s\n",
                         _("Usage:"),
                         _("Create new default keytab"));
+               TALLOC_FREE(tmp_ctx);
                return 0;
        }
 
@@ -2997,11 +3000,15 @@ static int net_ads_keytab_create(struct net_context *c, int argc, const char **a
                net_use_krb_machine_account(c);
        }
 
-       if (!ADS_ERR_OK(ads_startup(c, true, &ads))) {
-               return -1;
+       status = ads_startup(c, true, &ads);
+       if (!ADS_ERR_OK(status)) {
+               goto out;
        }
+
        ret = ads_keytab_create_default(ads);
+out:
        ads_destroy(&ads);
+       TALLOC_FREE(tmp_ctx);
        return ret;
 }