]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:net: Refactor net_ads_keytab_flush(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 11:25:40 +0000 (13:25 +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 2b50a32febbdbc2a432db5082e867c9724641f32..2a071c8cf48bdc96706aa6e2f9558a98491bd964 100644 (file)
@@ -2888,10 +2888,14 @@ out:
        return ret;
 }
 
-static int net_ads_keytab_flush(struct net_context *c, int argc, const char **argv)
+static int net_ads_keytab_flush(struct net_context *c,
+                               int argc,
+                               const char **argv)
 {
-       int ret;
-       ADS_STRUCT *ads;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       ADS_STRUCT *ads = NULL;
+       ADS_STATUS status;
+       int ret = -1;
 
        if (c->display_usage) {
                d_printf(  "%s\n"
@@ -2899,6 +2903,7 @@ static int net_ads_keytab_flush(struct net_context *c, int argc, const char **ar
                           "    %s\n",
                         _("Usage:"),
                         _("Delete the whole keytab"));
+               TALLOC_FREE(tmp_ctx);
                return 0;
        }
 
@@ -2906,11 +2911,15 @@ static int net_ads_keytab_flush(struct net_context *c, int argc, const char **ar
                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_flush(ads);
+out:
        ads_destroy(&ads);
+       TALLOC_FREE(tmp_ctx);
        return ret;
 }