Minor cleanup to libnet_join_member
authorSwen Schillig <swen@vnet.ibm.com>
Thu, 25 Jan 2018 10:18:50 +0000 (11:18 +0100)
committerJeremy Allison <jra@samba.org>
Sat, 24 Feb 2018 22:19:05 +0000 (23:19 +0100)
Prevent code duplication by consolidating cleanup task
at the end of the function.

Signed-off-by: Swen Schillig <swen@vnet.ibm.com>
Reviewed-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Feb 24 23:19:05 CET 2018 on sn-devel-144

source4/libnet/libnet_join.c

index 6cd18e02c9b9c2eb7b5fa817307adc9c6a64ac71..245485f69cd377aa58a3c81fc2b6781991c83958 100644 (file)
@@ -940,11 +940,10 @@ 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;
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
        }
-       
+
        acct_type = ACB_WSTRUST;
 
        if (r->in.netbios_name != NULL) {
@@ -952,19 +951,17 @@ 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;
+                       status = 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;
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
        }
-       
+
        /*
         * join the domain
         */
@@ -978,16 +975,14 @@ 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;
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
        }
 
        set_secrets->domain_name = r2->out.domain_name;
@@ -997,7 +992,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,19 +1003,16 @@ 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 */
-       r->out.error_string     = NULL;
-       r->out.join_password    = r2->out.join_password;
-       talloc_reparent(r2, mem_ctx, r2->out.join_password);
-       r->out.domain_sid       = r2->out.domain_sid;
-       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);
+       r->out.join_password    = talloc_move(mem_ctx, &r2->out.join_password);
+       r->out.domain_sid       = talloc_move(mem_ctx, &r2->out.domain_sid);
+       r->out.domain_name      = talloc_move(mem_ctx, &r2->out.domain_name);
+       status = NT_STATUS_OK;
+out:
        talloc_free(tmp_mem);
-       return NT_STATUS_OK;
+       return status;
 }