s3:net: Refactor net_ads_join_ok(), allocate a talloc context
authorSamuel Cabrero <scabrero@samba.org>
Thu, 26 May 2022 07:25:34 +0000 (09:25 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Jun 2022 15:50:29 +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 cad0b61b91197e9e63e8433e3c545a28981746b2..e9eb39a1c92ba409a4c9840ae569df1bb1f1cf4f 100644 (file)
@@ -1517,8 +1517,9 @@ static int net_ads_leave(struct net_context *c, int argc, const char **argv)
        return ret;
 }
 
-static NTSTATUS net_ads_join_ok(struct net_context *c)
+static ADS_STATUS net_ads_join_ok(struct net_context *c)
 {
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        ADS_STRUCT *ads = NULL;
        ADS_STATUS status;
        fstring dc_name;
@@ -1526,7 +1527,8 @@ static NTSTATUS net_ads_join_ok(struct net_context *c)
 
        if (!secrets_init()) {
                DEBUG(1,("Failed to initialise secrets database\n"));
-               return NT_STATUS_ACCESS_DENIED;
+               TALLOC_FREE(tmp_ctx);
+               return ADS_ERROR_NT(NT_STATUS_ACCESS_DENIED);
        }
 
        net_use_krb_machine_account(c);
@@ -1535,11 +1537,14 @@ static NTSTATUS net_ads_join_ok(struct net_context *c)
 
        status = ads_startup(c, true, &ads);
        if (!ADS_ERR_OK(status)) {
-               return ads_ntstatus(status);
+               goto out;
        }
 
+       status = ADS_ERROR_NT(NT_STATUS_OK);
+out:
        ads_destroy(&ads);
-       return NT_STATUS_OK;
+       TALLOC_FREE(tmp_ctx);
+       return  status;
 }
 
 /*
@@ -1547,7 +1552,7 @@ static NTSTATUS net_ads_join_ok(struct net_context *c)
  */
 int net_ads_testjoin(struct net_context *c, int argc, const char **argv)
 {
-       NTSTATUS status;
+       ADS_STATUS status;
        use_in_memory_ccache();
 
        if (c->display_usage) {
@@ -1561,9 +1566,9 @@ int net_ads_testjoin(struct net_context *c, int argc, const char **argv)
 
        /* Display success or failure */
        status = net_ads_join_ok(c);
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!ADS_ERR_OK(status)) {
                fprintf(stderr, _("Join to domain is not valid: %s\n"),
-                       get_friendly_nt_error_msg(status));
+                       get_friendly_nt_error_msg(ads_ntstatus(status)));
                return -1;
        }