]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:net: Refactor net_ads_keytab_add(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 11:29:56 +0000 (13:29 +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 2a071c8cf48bdc96706aa6e2f9558a98491bd964..db011eb7f2f97e53673fef1c1e09da636428ae93 100644 (file)
@@ -2928,9 +2928,11 @@ static int net_ads_keytab_add(struct net_context *c,
                              const char **argv,
                              bool update_ads)
 {
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       ADS_STRUCT *ads = NULL;
+       ADS_STATUS status;
        int i;
-       int ret = 0;
-       ADS_STRUCT *ads;
+       int ret = -1;
 
        if (c->display_usage) {
                d_printf("%s\n%s",
@@ -2939,6 +2941,7 @@ static int net_ads_keytab_add(struct net_context *c,
                           "  Add principals to local keytab\n"
                           "    principal\tKerberos principal to add to "
                           "keytab\n"));
+               TALLOC_FREE(tmp_ctx);
                return 0;
        }
 
@@ -2948,13 +2951,17 @@ static int net_ads_keytab_add(struct net_context *c,
                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;
        }
-       for (i = 0; i < argc; i++) {
+
+       for (ret = 0, i = 0; i < argc; i++) {
                ret |= ads_keytab_add_entry(ads, argv[i], update_ads);
        }
+out:
        ads_destroy(&ads);
+       TALLOC_FREE(tmp_ctx);
        return ret;
 }