[PATCH] some cleanups for tldap

Volker Lendecke Volker.Lendecke at SerNet.DE
Sun Jan 10 11:06:05 UTC 2016


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From a9ebf5a12907ccd9c123a8a3fcfde850b9bab3ca Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 27 Dec 2015 15:31:58 +0100
Subject: [PATCH 1/8] tldap: Remove unneeded vars

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index 17238a5..ee46c66 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -57,9 +57,6 @@ struct tldap_ctx_attribute {
 
 struct tldap_context {
 	int ld_version;
-	int ld_deref;
-	int ld_sizelimit;
-	int ld_timelimit;
 	struct tstream_context *conn;
 	bool server_down;
 	int msgid;
-- 
1.9.1


From db46d332f8845d5ebc6c50ace4270356da9f45ef Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 10 Jan 2016 11:33:01 +0100
Subject: [PATCH 2/8] tldap: Remove an unneeded "return;"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index ee46c66..9732fd6 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -482,7 +482,6 @@ static void tldap_msg_unset_pending(struct tevent_req *req)
 	 */
 	ld->pending = talloc_realloc(NULL, ld->pending, struct tevent_req *,
 				     num_pending - 1);
-	return;
 }
 
 static void tldap_msg_cleanup(struct tevent_req *req,
-- 
1.9.1


From 6a7c18abefbec18e0e4c56d104b70b98fa6da08e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 10 Jan 2016 11:29:40 +0100
Subject: [PATCH 3/8] tldap: Use "size_t" for talloc_array_length result

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index 9732fd6..85d3d47 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -168,7 +168,7 @@ bool tldap_connection_ok(struct tldap_context *ld)
 static struct tldap_ctx_attribute *tldap_context_findattr(
 	struct tldap_context *ld, const char *name)
 {
-	int i, num_attrs;
+	size_t i, num_attrs;
 
 	num_attrs = talloc_array_length(ld->ctx_attrs);
 
-- 
1.9.1


From 249f49509e463d1034dde0ec2806a05b32fe7548 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 22 Dec 2015 13:44:02 +0100
Subject: [PATCH 4/8] tldap: tevent_req_create NULLs out "state"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index 85d3d47..9a418dd 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -719,12 +719,10 @@ static struct tevent_req *tldap_req_create(TALLOC_CTX *mem_ctx,
 	if (req == NULL) {
 		return NULL;
 	}
-	ZERO_STRUCTP(state);
 	state->out = asn1_init(state);
 	if (state->out == NULL) {
 		goto err;
 	}
-	state->result = NULL;
 	state->id = tldap_next_msgid(ld);
 
 	if (!asn1_push_tag(state->out, ASN1_SEQUENCE(0))) goto err;
-- 
1.9.1


From 8475da3a4dbb46787d7cbced6d1f6b773b86d22c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 21 Dec 2015 10:50:59 +0100
Subject: [PATCH 5/8] lib: Introduce util_tsock.h

This avoids includes.h in source3/lib/util_tsock.c

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h     | 11 -----------
 source3/lib/tldap.c         |  1 +
 source3/lib/util_tsock.c    |  5 ++++-
 source3/lib/util_tsock.h    | 38 ++++++++++++++++++++++++++++++++++++++
 source3/libsmb/unexpected.c |  1 +
 5 files changed, 44 insertions(+), 12 deletions(-)
 create mode 100644 source3/lib/util_tsock.h

diff --git a/source3/include/proto.h b/source3/include/proto.h
index cc00a84..a53aabd 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -600,17 +600,6 @@ struct tevent_req *getaddrinfo_send(TALLOC_CTX *mem_ctx,
 int getaddrinfo_recv(struct tevent_req *req, struct addrinfo **res);
 int poll_one_fd(int fd, int events, int timeout, int *revents);
 int poll_intr_one_fd(int fd, int events, int timeout, int *revents);
-struct tstream_context;
-struct tevent_req *tstream_read_packet_send(TALLOC_CTX *mem_ctx,
-					    struct tevent_context *ev,
-					    struct tstream_context *stream,
-					    size_t initial,
-					    ssize_t (*more)(uint8_t *buf,
-							    size_t buflen,
-							    void *private_data),
-					    void *private_data);
-ssize_t tstream_read_packet_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-				 uint8_t **pbuf, int *perrno);
 
 /* The following definitions come from lib/util_str.c  */
 
diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index 9a418dd..c628409 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "tldap.h"
+#include "lib/util_tsock.h"
 #include "../lib/util/asn1.h"
 #include "../lib/tsocket/tsocket.h"
 #include "../lib/util/tevent_unix.h"
diff --git a/source3/lib/util_tsock.c b/source3/lib/util_tsock.c
index 03380ef..6432ce4 100644
--- a/source3/lib/util_tsock.c
+++ b/source3/lib/util_tsock.c
@@ -17,7 +17,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
+#include "replace.h"
+#include "system/network.h"
+#include <tevent.h>
+#include "lib/util_tsock.h"
 #include "../lib/tsocket/tsocket.h"
 #include "../lib/util/tevent_unix.h"
 
diff --git a/source3/lib/util_tsock.h b/source3/lib/util_tsock.h
new file mode 100644
index 0000000..de4381a
--- /dev/null
+++ b/source3/lib/util_tsock.h
@@ -0,0 +1,38 @@
+/*
+   Unix SMB/CIFS implementation.
+   Utilities around tsocket
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __UTIL_TSOCK_H__
+#define __UTIL_TSOCK_H__
+
+#include "replace.h"
+#include <tevent.h>
+
+struct tstream_context;
+struct tevent_req *tstream_read_packet_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    struct tstream_context *stream,
+					    size_t initial,
+					    ssize_t (*more)(uint8_t *buf,
+							    size_t buflen,
+							    void *private_data),
+					    void *private_data);
+ssize_t tstream_read_packet_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+				 uint8_t **pbuf, int *perrno);
+
+#endif
diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
index 27d21b6..c645fbc 100644
--- a/source3/libsmb/unexpected.c
+++ b/source3/libsmb/unexpected.c
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "../lib/util/tevent_ntstatus.h"
+#include "lib/util_tsock.h"
 #include "lib/tsocket/tsocket.h"
 #include "libsmb/nmblib.h"
 #include "lib/util/sys_rw.h"
-- 
1.9.1


From d061182bbba2794049605c9ae721e4039566144a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 10 Jan 2016 12:00:52 +0100
Subject: [PATCH 6/8] tldap.h: References DATA_BLOB

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/tldap.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/source3/include/tldap.h b/source3/include/tldap.h
index 36cbdce..1c704b4 100644
--- a/source3/include/tldap.h
+++ b/source3/include/tldap.h
@@ -22,6 +22,7 @@
 
 #include <talloc.h>
 #include <tevent.h>
+#include "lib/util/data_blob.h"
 
 struct tldap_context;
 struct tldap_message;
-- 
1.9.1


From 32153a865c7ff3f550ac904492f92ab709aa3178 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 21 Dec 2015 11:17:28 +0100
Subject: [PATCH 7/8] tldap: Avoid includes.h

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index c628409..a1e11a3 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -17,8 +17,12 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
+#include "replace.h"
 #include "tldap.h"
+#include "system/network.h"
+#include "system/locale.h"
+#include "lib/util/talloc_stack.h"
+#include "lib/util/samba_util.h"
 #include "lib/util_tsock.h"
 #include "../lib/util/asn1.h"
 #include "../lib/tsocket/tsocket.h"
-- 
1.9.1


From e260a9da39f6629225f2f86d9e63fbce111cbb0f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 21 Dec 2015 21:29:13 +0100
Subject: [PATCH 8/8] tldap: Use struct initializer in tldap_search

Avoids a call to ZERO_STRUCT

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/tldap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index a1e11a3..d8b4f24 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -1840,11 +1840,9 @@ int tldap_search(struct tldap_context *ld,
 	TALLOC_CTX *frame = talloc_stackframe();
 	struct tevent_context *ev;
 	struct tevent_req *req;
-	struct tldap_sync_search_state state;
-
-	ZERO_STRUCT(state);
-	state.mem_ctx = mem_ctx;
-	state.rc = TLDAP_SUCCESS;
+	struct tldap_sync_search_state state = {
+		.mem_ctx = mem_ctx, .rc = TLDAP_SUCCESS
+	};
 
 	ev = samba_tevent_context_init(frame);
 	if (ev == NULL) {
-- 
1.9.1



More information about the samba-technical mailing list