[PATCHES] small cleanups for smbd and winbindd

Christof Schmitt cs at samba.org
Fri Oct 3 13:42:19 MDT 2014


Here are some small cleanup patches for smbd and winbindd.

Christof
-------------- next part --------------
From d84b41ee6b601d36c01e1bc8e4c925c765098a98 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 29 Aug 2014 18:04:27 -0700
Subject: [PATCH 1/6] s3-winbindd: Remove extern declaration for cache_methods from winbindd_dual.c

cache_methods is not used in winbindd_dual.c

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/winbindd/winbindd_dual.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index de254e9..ed081d0 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -43,7 +43,6 @@
 #define DBGC_CLASS DBGC_WINBIND
 
 extern bool override_logfile;
-extern struct winbindd_methods cache_methods;
 
 static struct winbindd_child *winbindd_children = NULL;
 
-- 
1.7.1


From e9569e26f082b304300d0d4e9d1313283609b84c Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 29 Aug 2014 18:05:43 -0700
Subject: [PATCH 2/6] s3-winbindd: Make wcache_sid_to_name static

It is only used in winbindd_cache.c

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/winbindd/winbindd_cache.c |   12 ++++++------
 source3/winbindd/winbindd_proto.h |    6 ------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 9ec46cf..06b29de 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -1908,12 +1908,12 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
 	return status;
 }
 
-NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,
-			    const struct dom_sid *sid,
-			    TALLOC_CTX *mem_ctx,
-			    char **domain_name,
-			    char **name,
-			    enum lsa_SidType *type)
+static NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,
+				   const struct dom_sid *sid,
+				   TALLOC_CTX *mem_ctx,
+				   char **domain_name,
+				   char **name,
+				   enum lsa_SidType *type)
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 42fffc0..3081aa1 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -73,12 +73,6 @@ bool wcache_invalidate_cache_noinit(void);
 bool init_wcache(void);
 bool initialize_winbindd_cache(void);
 void close_winbindd_cache(void);
-NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,
-			    const struct dom_sid *sid,
-			    TALLOC_CTX *mem_ctx,
-			    char **domain_name,
-			    char **name,
-			    enum lsa_SidType *type);
 NTSTATUS wcache_lookup_groupmem(struct winbindd_domain *domain,
 				TALLOC_CTX *mem_ctx,
 				const struct dom_sid *group_sid,
-- 
1.7.1


From 3b51d251b429313dd5e267b4c0dc461280e1c31f Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Mon, 11 Aug 2014 13:19:46 -0700
Subject: [PATCH 3/6] smbd: Use MIN macro in fake_sendfile

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/smbd/reply.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 21be320..9b3ed65 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3107,11 +3107,7 @@ ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
 		ssize_t ret;
 		size_t cur_read;
 
-		if (tosend > bufsize) {
-			cur_read = bufsize;
-		} else {
-			cur_read = tosend;
-		}
+		cur_read = MIN(tosend, bufsize);
 		ret = read_file(fsp,buf,startpos,cur_read);
 		if (ret == -1) {
 			SAFE_FREE(buf);
-- 
1.7.1


From 2fed6546c71984266fd63e0ea7eec2edd4e94462 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Tue, 2 Sep 2014 12:18:30 -0700
Subject: [PATCH 4/6] smbd: Pass only cmd to construct_reply_common instead of complete req

construct_reply_common only needs the commands code and the inbuf field,
not the complete request.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/smbd/process.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 74e7afc..3fb5b73 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -57,7 +57,7 @@ struct pending_message_list {
 	struct deferred_open_record *open_rec;
 };
 
-static void construct_reply_common(struct smb_request *req, const char *inbuf,
+static void construct_reply_common(uint8_t cmd, const char *inbuf,
 				   char *outbuf);
 static struct pending_message_list *get_deferred_open_message_smb(
 	struct smbd_server_connection *sconn, uint64_t mid);
@@ -1368,7 +1368,7 @@ static bool create_outbuf(TALLOC_CTX *mem_ctx, struct smb_request *req,
 		return false;
 	}
 
-	construct_reply_common(req, inbuf, *outbuf);
+	construct_reply_common(req->cmd, inbuf, *outbuf);
 	srv_set_message(*outbuf, num_words, num_bytes, false);
 	/*
 	 * Zero out the word area, the caller has to take care of the bcc area
@@ -1978,8 +1978,7 @@ void remove_from_common_flags2(uint32 v)
 	common_flags2 &= ~v;
 }
 
-static void construct_reply_common(struct smb_request *req, const char *inbuf,
-				   char *outbuf)
+static void construct_reply_common(uint8_t cmd, const char *inbuf, char *outbuf)
 {
 	uint16_t in_flags2 = SVAL(inbuf,smb_flg2);
 	uint16_t out_flags2 = common_flags2;
@@ -1990,7 +1989,7 @@ static void construct_reply_common(struct smb_request *req, const char *inbuf,
 
 	srv_set_message(outbuf,0,0,false);
 
-	SCVAL(outbuf, smb_com, req->cmd);
+	SCVAL(outbuf, smb_com, cmd);
 	SIVAL(outbuf,smb_rcls,0);
 	SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); 
 	SSVAL(outbuf,smb_flg2, out_flags2);
@@ -2005,7 +2004,7 @@ static void construct_reply_common(struct smb_request *req, const char *inbuf,
 
 void construct_reply_common_req(struct smb_request *req, char *outbuf)
 {
-	construct_reply_common(req, (const char *)req->inbuf, outbuf);
+	construct_reply_common(req->cmd, (const char *)req->inbuf, outbuf);
 }
 
 /**
-- 
1.7.1


From bd48bbe1b775f19528d4a280075fbcf407e96537 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Tue, 2 Sep 2014 12:24:29 -0700
Subject: [PATCH 5/6] smbd: Always use uint8_t for inbuf pointer

This avoids some casts from char pointers.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/smbd/process.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 3fb5b73..8370155 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -57,7 +57,7 @@ struct pending_message_list {
 	struct deferred_open_record *open_rec;
 };
 
-static void construct_reply_common(uint8_t cmd, const char *inbuf,
+static void construct_reply_common(uint8_t cmd, const uint8_t *inbuf,
 				   char *outbuf);
 static struct pending_message_list *get_deferred_open_message_smb(
 	struct smbd_server_connection *sconn, uint64_t mid);
@@ -1341,8 +1341,8 @@ static const struct smb_message_struct {
 ********************************************************************/
 
 static bool create_outbuf(TALLOC_CTX *mem_ctx, struct smb_request *req,
-			  const char *inbuf, char **outbuf, uint8_t num_words,
-			  uint32_t num_bytes)
+			  const uint8_t *inbuf, char **outbuf,
+			  uint8_t num_words, uint32_t num_bytes)
 {
 	size_t smb_len = MIN_SMB_SIZE + VWV(num_words) + num_bytes;
 
@@ -1384,7 +1384,7 @@ static bool create_outbuf(TALLOC_CTX *mem_ctx, struct smb_request *req,
 void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes)
 {
 	char *outbuf;
-	if (!create_outbuf(req, req, (const char *)req->inbuf, &outbuf, num_words,
+	if (!create_outbuf(req, req, req->inbuf, &outbuf, num_words,
 			   num_bytes)) {
 		smb_panic("could not allocate output buffer\n");
 	}
@@ -1978,7 +1978,8 @@ void remove_from_common_flags2(uint32 v)
 	common_flags2 &= ~v;
 }
 
-static void construct_reply_common(uint8_t cmd, const char *inbuf, char *outbuf)
+static void construct_reply_common(uint8_t cmd, const uint8_t *inbuf,
+				   char *outbuf)
 {
 	uint16_t in_flags2 = SVAL(inbuf,smb_flg2);
 	uint16_t out_flags2 = common_flags2;
@@ -2004,7 +2005,7 @@ static void construct_reply_common(uint8_t cmd, const char *inbuf, char *outbuf)
 
 void construct_reply_common_req(struct smb_request *req, char *outbuf)
 {
-	construct_reply_common(req->cmd, (const char *)req->inbuf, outbuf);
+	construct_reply_common(req->cmd, req->inbuf, outbuf);
 }
 
 /**
@@ -3078,7 +3079,7 @@ static bool smbd_echo_reply(struct smbd_echo_state *state,
 		return false;
 	}
 
-	if (!create_outbuf(talloc_tos(), &req, (const char *)req.inbuf, &outbuf,
+	if (!create_outbuf(talloc_tos(), &req, req.inbuf, &outbuf,
 			   1, req.buflen)) {
 		DEBUG(10, ("create_outbuf failed\n"));
 		return false;
-- 
1.7.1


From fd03732660a0c7fe45159f2796711d2c83f1ab59 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Fri, 3 Oct 2014 10:36:02 -0700
Subject: [PATCH 6/6] windbindd: Make cm_connect_lsa_tcp static

It is only used in winbindd_cm.c

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/winbindd/winbindd_cm.c    |    6 +++---
 source3/winbindd/winbindd_proto.h |    3 ---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 3a9780e..43147cb 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -2655,9 +2655,9 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
  open an schanneld ncacn_ip_tcp connection to LSA
 ***********************************************************************/
 
-NTSTATUS cm_connect_lsa_tcp(struct winbindd_domain *domain,
-			    TALLOC_CTX *mem_ctx,
-			    struct rpc_pipe_client **cli)
+static NTSTATUS cm_connect_lsa_tcp(struct winbindd_domain *domain,
+				   TALLOC_CTX *mem_ctx,
+				   struct rpc_pipe_client **cli)
 {
 	struct winbindd_cm_conn *conn;
 	struct netlogon_creds_cli_context *creds;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 3081aa1..9ba379e 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -175,9 +175,6 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 			struct rpc_pipe_client **cli, struct policy_handle *sam_handle);
 NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
 			struct rpc_pipe_client **cli, struct policy_handle *lsa_policy);
-NTSTATUS cm_connect_lsa_tcp(struct winbindd_domain *domain,
-			    TALLOC_CTX *mem_ctx,
-			    struct rpc_pipe_client **cli);
 NTSTATUS cm_connect_lsat(struct winbindd_domain *domain,
 			 TALLOC_CTX *mem_ctx,
 			 struct rpc_pipe_client **cli,
-- 
1.7.1



More information about the samba-technical mailing list