s3:net: Refactor net_ads_setspn_list(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 11:35:11 +0000 (13:35 +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 5949ee961687a5a5f12b2a5e50eb3d993cb7462e..68352c0ad1c801f05adefe3e0a029c73512cfe12 100644 (file)
@@ -3378,34 +3378,39 @@ int net_ads_kerberos(struct net_context *c, int argc, const char **argv)
        return net_run_function(c, argc, argv, "net ads kerberos", func);
 }
 
-static int net_ads_setspn_list(struct net_context *c, int argc, const char **argv)
+static int net_ads_setspn_list(struct net_context *c,
+                              int argc,
+                              const char **argv)
 {
-       int ret = 0;
-       bool ok = false;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        ADS_STRUCT *ads = NULL;
+       ADS_STATUS status;
+       bool ok = false;
+       int ret = -1;
+
        if (c->display_usage) {
                d_printf("%s\n%s",
                         _("Usage:"),
                         _("net ads setspn list <machinename>\n"));
-               ret = 0;
-               goto done;
+               TALLOC_FREE(tmp_ctx);
+               return 0;
        }
-       if (!ADS_ERR_OK(ads_startup(c, true, &ads))) {
-               ret = -1;
-               goto done;
+
+       status = ads_startup(c, true, &ads);
+       if (!ADS_ERR_OK(status)) {
+               goto out;
        }
+
        if (argc) {
                ok = ads_setspn_list(ads, argv[0]);
        } else {
                ok = ads_setspn_list(ads, lp_netbios_name());
        }
-       if (!ok) {
-            ret = -1;
-       }
-done:
-       if (ads) {
-               ads_destroy(&ads);
-       }
+
+       ret = ok ? 0 : -1;
+out:
+       ads_destroy(&ads);
+       TALLOC_FREE(tmp_ctx);
        return ret;
 }