[PATCH] Minor cleanup to libnet_join_member

Swen Schillig swen at vnet.ibm.com
Thu Jan 25 10:23:26 UTC 2018


Hi

Minor cleanup to function libnet_join_member.

Please review.

Thanks.

Cheers Swen
-------------- next part --------------
From 4f1e86e4a07e74c1726507ea5d36a0b1171da165 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Thu, 25 Jan 2018 11:18:50 +0100
Subject: [PATCH] Minor cleanup to libnet_join_member

Prevent code duplication by consolidating cleanup task
at the end of the function.

Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
 source4/libnet/libnet_join.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c
index 6cd18e02c9b..8226d4b47d7 100644
--- a/source4/libnet/libnet_join.c
+++ b/source4/libnet/libnet_join.c
@@ -922,7 +922,7 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 			    TALLOC_CTX *mem_ctx,
 			    struct libnet_Join_member *r)
 {
-	NTSTATUS status;
+	NTSTATUS status = NT_STATUS_NO_MEMORY;;
 	TALLOC_CTX *tmp_mem;
 	struct libnet_JoinDomain *r2;
 	struct provision_store_self_join_settings *set_secrets;
@@ -940,11 +940,9 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 
 	r2 = talloc_zero(tmp_mem, struct libnet_JoinDomain);
 	if (!r2) {
-		r->out.error_string = NULL;
-		talloc_free(tmp_mem);
-		return NT_STATUS_NO_MEMORY;
+		goto out;
 	}
-	
+
 	acct_type = ACB_WSTRUST;
 
 	if (r->in.netbios_name != NULL) {
@@ -952,19 +950,15 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 	} else {
 		netbios_name = talloc_strdup(tmp_mem, lpcfg_netbios_name(ctx->lp_ctx));
 		if (!netbios_name) {
-			r->out.error_string = NULL;
-			talloc_free(tmp_mem);
-			return NT_STATUS_NO_MEMORY;
+			goto out;
 		}
 	}
 
 	account_name = talloc_asprintf(tmp_mem, "%s$", netbios_name);
 	if (!account_name) {
-		r->out.error_string = NULL;
-		talloc_free(tmp_mem);
-		return NT_STATUS_NO_MEMORY;
+		goto out;
 	}
-	
+
 	/*
 	 * join the domain
 	 */
@@ -978,16 +972,13 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 	status = libnet_JoinDomain(ctx, r2, r2);
 	if (!NT_STATUS_IS_OK(status)) {
 		r->out.error_string = talloc_steal(mem_ctx, r2->out.error_string);
-		talloc_free(tmp_mem);
-		return status;
+		goto out;
 	}
 
 	set_secrets = talloc_zero(tmp_mem,
 				  struct provision_store_self_join_settings);
 	if (!set_secrets) {
-		r->out.error_string = NULL;
-		talloc_free(tmp_mem);
-		return NT_STATUS_NO_MEMORY;
+		goto out;
 	}
 
 	set_secrets->domain_name = r2->out.domain_name;
@@ -997,7 +988,7 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 	set_secrets->machine_password = r2->out.join_password;
 	set_secrets->key_version_number = r2->out.kvno;
 	set_secrets->domain_sid = r2->out.domain_sid;
-	
+
 	status = provision_store_self_join(ctx, ctx->lp_ctx, ctx->event_ctx, set_secrets, &error_string);
 	if (!NT_STATUS_IS_OK(status)) {
 		if (error_string) {
@@ -1008,8 +999,7 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 						  "provision_store_self_join failed with %s",
 						  nt_errstr(status));
 		}
-		talloc_free(tmp_mem);
-		return status;
+		goto out;
 	}
 
 	/* move all out parameter to the callers TALLOC_CTX */
@@ -1020,7 +1010,9 @@ NTSTATUS libnet_Join_member(struct libnet_context *ctx,
 	talloc_reparent(r2, mem_ctx, r2->out.domain_sid);
 	r->out.domain_name      = r2->out.domain_name;
 	talloc_reparent(r2, mem_ctx, r2->out.domain_name);
+	status = NT_STATUS_OK;
+out:
 	talloc_free(tmp_mem);
-	return NT_STATUS_OK;
+	return status;
 }
 
-- 
2.14.3



More information about the samba-technical mailing list