[PATCH] Minor cleanup of libnet_LookupName_recv

Swen Schillig swen at vnet.ibm.com
Fri Jan 26 12:38:14 UTC 2018


Hi

Another minor cleanup.

Please review.

Thanks.

Cheers Swen.
-------------- next part --------------
From 04c66afd2fa8a38877ffac0e2774f91e59607003 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Fri, 26 Jan 2018 13:28:58 +0100
Subject: [PATCH] Minor cleanup of libnet_LookupName_recv

Zero libnet_LookupName out struct before setting results,
preventing false result interpretation.
Reduce indentation level.
Comply with 80 column rule.

Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
 source4/libnet/libnet_lookup.c | 59 ++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/source4/libnet/libnet_lookup.c b/source4/libnet/libnet_lookup.c
index bdb99950493..3b91379087f 100644
--- a/source4/libnet/libnet_lookup.c
+++ b/source4/libnet/libnet_lookup.c
@@ -383,43 +383,46 @@ NTSTATUS libnet_LookupName_recv(struct composite_context *c, TALLOC_CTX *mem_ctx
 	NTSTATUS status;
 	struct lookup_name_state *s;
 
+	memset(&io->out, 0, sizeof(io->out));
+
 	status = composite_wait(c);
 
-	if (NT_STATUS_IS_OK(status)) {
-		s = talloc_get_type(c->private_data, struct lookup_name_state);
+	if (!NT_STATUS_IS_OK(status)) {
+		io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s",
+						       nt_errstr(status));
+		goto done;
+	}
 
-		io->out.rid = 0;
-		io->out.sid = NULL;
-		io->out.sidstr = NULL;
+	s = talloc_get_type(c->private_data, struct lookup_name_state);
 
-		if (*s->lookup.out.count > 0) {
-			struct lsa_RefDomainList *domains = *s->lookup.out.domains;
-			struct lsa_TransSidArray *sids = s->lookup.out.sids;
+	if (*s->lookup.out.count > 0) {
+		struct lsa_RefDomainList *domains = *s->lookup.out.domains;
+		struct lsa_TransSidArray *sids = s->lookup.out.sids;
 
-			if (domains == NULL || sids == NULL) {
-				status = NT_STATUS_UNSUCCESSFUL;
-				io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s", nt_errstr(status));
-				goto done;
-			}
+		if (domains == NULL || sids == NULL) {
+			status = NT_STATUS_UNSUCCESSFUL;
+			io->out.error_string =
+				talloc_asprintf(mem_ctx, "Error: %s",
+						nt_errstr(status));
+			goto done;
+		}
 
-			if (sids->count > 0) {
-				io->out.rid        = sids->sids[0].rid;
-				io->out.sid_type   = sids->sids[0].sid_type;
-				if (domains->count > 0) {
-					io->out.sid = dom_sid_add_rid(mem_ctx, domains->domains[0].sid, io->out.rid);
-					NT_STATUS_HAVE_NO_MEMORY(io->out.sid);
-					io->out.sidstr = dom_sid_string(mem_ctx, io->out.sid);
-					NT_STATUS_HAVE_NO_MEMORY(io->out.sidstr);
-				}
+		if (sids->count > 0) {
+			io->out.rid        = sids->sids[0].rid;
+			io->out.sid_type   = sids->sids[0].sid_type;
+			if (domains->count > 0) {
+				io->out.sid =
+					dom_sid_add_rid(mem_ctx,
+							domains->domains[0].sid,
+							io->out.rid);
+				NT_STATUS_HAVE_NO_MEMORY(io->out.sid);
+				io->out.sidstr = dom_sid_string(mem_ctx,
+								io->out.sid);
+				NT_STATUS_HAVE_NO_MEMORY(io->out.sidstr);
 			}
 		}
-
-		io->out.error_string = talloc_strdup(mem_ctx, "Success");
-
-	} else if (!NT_STATUS_IS_OK(status)) {
-		io->out.error_string = talloc_asprintf(mem_ctx, "Error: %s", nt_errstr(status));
 	}
-
+	io->out.error_string = talloc_strdup(mem_ctx, "Success");
 done:
 	talloc_free(c);
 	return status;
-- 
2.14.3



More information about the samba-technical mailing list