[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1601-gb9f3a78

Stefan Metzmacher metze at samba.org
Wed May 13 18:16:56 GMT 2009


The branch, master has been updated
       via  b9f3a78169be962c4f1fce625ca3a291d9f93c7c (commit)
       via  ca6ec5ecd78d98ef841981b2ea124b1d772e4ceb (commit)
       via  6ff09b323e1bb3b82a27f6015ba94ccce36993af (commit)
      from  83ff460401dd3ebd4daed5cb5f611adf44e184da (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b9f3a78169be962c4f1fce625ca3a291d9f93c7c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed May 13 08:33:33 2009 +0200

    s3:libsmb: move read_smb_send/recv() static in async_smb.c
    
    metze

commit ca6ec5ecd78d98ef841981b2ea124b1d772e4ceb
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue May 12 14:47:02 2009 +0200

    s3:libsmb: let cli_smb_chain_send() also return NTSTATUS
    
    metze

commit 6ff09b323e1bb3b82a27f6015ba94ccce36993af
Author: Bo Yang <boyang at samba.org>
Date:   Tue May 12 13:51:25 2009 +0800

    s3:libsmb: return NT_STATUS_CONNECTION_INVALID if the fd is -1
    
    This way we can destinguish between requests which failed
    because the connection broke after they were triggered
    and the requests which are started on an already broken
    connection.
    
    This also moves the check to cli_smb_req_iov_send()
    where it really belongs.
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 source3/include/async_smb.h |    2 +-
 source3/include/proto.h     |    5 --
 source3/lib/util_sock.c     |   87 -------------------------------
 source3/libsmb/async_smb.c  |  120 ++++++++++++++++++++++++++++++++++++++-----
 source3/torture/torture.c   |    8 ++-
 5 files changed, 113 insertions(+), 109 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h
index c27dd2b..03dd274 100644
--- a/source3/include/async_smb.h
+++ b/source3/include/async_smb.h
@@ -49,7 +49,7 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
 				      struct iovec *bytes_iov);
 NTSTATUS cli_smb_req_send(struct tevent_req *req);
 size_t cli_smb_wct_ofs(struct tevent_req **reqs, int num_reqs);
-bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs);
+NTSTATUS cli_smb_chain_send(struct tevent_req **reqs, int num_reqs);
 uint8_t *cli_smb_inbuf(struct tevent_req *req);
 bool cli_has_async_calls(struct cli_state *cli);
 void cli_smb_req_unset_pending(struct tevent_req *req);
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 95613ad..fd49050 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1415,11 +1415,6 @@ int create_pipe_sock(const char *socket_dir,
 		     mode_t dir_perms);
 const char *get_mydnsfullname(void);
 bool is_myname_or_ipaddr(const char *s);
-struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
-				 struct tevent_context *ev,
-				 int fd);
-ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-		      uint8_t **pbuf, int *perrno);
 struct tevent_req *getaddrinfo_send(TALLOC_CTX *mem_ctx,
 				    struct tevent_context *ev,
 				    struct fncall_context *ctx,
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 92e373b..1d7a82d 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1967,93 +1967,6 @@ bool is_myname_or_ipaddr(const char *s)
 	return false;
 }
 
-/*
- * Read an smb packet asynchronously, discard keepalives
- */
-
-struct read_smb_state {
-	struct tevent_context *ev;
-	int fd;
-	uint8_t *buf;
-};
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data);
-static void read_smb_done(struct tevent_req *subreq);
-
-struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
-				 struct tevent_context *ev,
-				 int fd)
-{
-	struct tevent_req *result, *subreq;
-	struct read_smb_state *state;
-
-	result = tevent_req_create(mem_ctx, &state, struct read_smb_state);
-	if (result == NULL) {
-		return NULL;
-	}
-	state->ev = ev;
-	state->fd = fd;
-
-	subreq = read_packet_send(state, ev, fd, 4, read_smb_more, NULL);
-	if (subreq == NULL) {
-		goto fail;
-	}
-	tevent_req_set_callback(subreq, read_smb_done, result);
-	return result;
- fail:
-	TALLOC_FREE(result);
-	return NULL;
-}
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data)
-{
-	if (buflen > 4) {
-		return 0;	/* We've been here, we're done */
-	}
-	return smb_len_large(buf);
-}
-
-static void read_smb_done(struct tevent_req *subreq)
-{
-	struct tevent_req *req = tevent_req_callback_data(
-		subreq, struct tevent_req);
-	struct read_smb_state *state = tevent_req_data(
-		req, struct read_smb_state);
-	ssize_t len;
-	int err;
-
-	len = read_packet_recv(subreq, state, &state->buf, &err);
-	TALLOC_FREE(subreq);
-	if (len == -1) {
-		tevent_req_error(req, err);
-		return;
-	}
-
-	if (CVAL(state->buf, 0) == SMBkeepalive) {
-		subreq = read_packet_send(state, state->ev, state->fd, 4,
-					  read_smb_more, NULL);
-		if (tevent_req_nomem(subreq, req)) {
-			return;
-		}
-		tevent_req_set_callback(subreq, read_smb_done, req);
-		return;
-	}
-	tevent_req_done(req);
-}
-
-ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-		      uint8_t **pbuf, int *perrno)
-{
-	struct read_smb_state *state = tevent_req_data(
-		req, struct read_smb_state);
-
-	if (tevent_req_is_unix_error(req, perrno)) {
-		return -1;
-	}
-	*pbuf = talloc_move(mem_ctx, &state->buf);
-	return talloc_get_size(*pbuf);
-}
-
 struct getaddrinfo_state {
 	const char *node;
 	const char *service;
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 0d82894..7afba0d 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -19,6 +19,93 @@
 
 #include "includes.h"
 
+/*
+ * Read an smb packet asynchronously, discard keepalives
+ */
+
+struct read_smb_state {
+	struct tevent_context *ev;
+	int fd;
+	uint8_t *buf;
+};
+
+static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data);
+static void read_smb_done(struct tevent_req *subreq);
+
+static struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
+					struct tevent_context *ev,
+					int fd)
+{
+	struct tevent_req *result, *subreq;
+	struct read_smb_state *state;
+
+	result = tevent_req_create(mem_ctx, &state, struct read_smb_state);
+	if (result == NULL) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->fd = fd;
+
+	subreq = read_packet_send(state, ev, fd, 4, read_smb_more, NULL);
+	if (subreq == NULL) {
+		goto fail;
+	}
+	tevent_req_set_callback(subreq, read_smb_done, result);
+	return result;
+ fail:
+	TALLOC_FREE(result);
+	return NULL;
+}
+
+static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data)
+{
+	if (buflen > 4) {
+		return 0;	/* We've been here, we're done */
+	}
+	return smb_len_large(buf);
+}
+
+static void read_smb_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct read_smb_state *state = tevent_req_data(
+		req, struct read_smb_state);
+	ssize_t len;
+	int err;
+
+	len = read_packet_recv(subreq, state, &state->buf, &err);
+	TALLOC_FREE(subreq);
+	if (len == -1) {
+		tevent_req_error(req, err);
+		return;
+	}
+
+	if (CVAL(state->buf, 0) == SMBkeepalive) {
+		subreq = read_packet_send(state, state->ev, state->fd, 4,
+					  read_smb_more, NULL);
+		if (tevent_req_nomem(subreq, req)) {
+			return;
+		}
+		tevent_req_set_callback(subreq, read_smb_done, req);
+		return;
+	}
+	tevent_req_done(req);
+}
+
+static ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+			     uint8_t **pbuf, int *perrno)
+{
+	struct read_smb_state *state = tevent_req_data(
+		req, struct read_smb_state);
+
+	if (tevent_req_is_unix_error(req, perrno)) {
+		return -1;
+	}
+	*pbuf = talloc_move(mem_ctx, &state->buf);
+	return talloc_get_size(*pbuf);
+}
+
 /**
  * Fetch an error out of a NBT packet
  * @param[in] buf	The SMB packet
@@ -547,6 +634,10 @@ static NTSTATUS cli_smb_req_iov_send(struct tevent_req *req,
 	struct tevent_req *subreq;
 	NTSTATUS status;
 
+	if (state->cli->fd == -1) {
+		return NT_STATUS_CONNECTION_INVALID;
+	}
+
 	if (iov[0].iov_len < smb_wct) {
 		return NT_STATUS_INVALID_PARAMETER;
 	}
@@ -606,10 +697,6 @@ NTSTATUS cli_smb_req_send(struct tevent_req *req)
 	struct cli_smb_state *state = tevent_req_data(
 		req, struct cli_smb_state);
 
-	if (state->cli->fd == -1) {
-		return NT_STATUS_CONNECTION_DISCONNECTED;
-	}
-
 	return cli_smb_req_iov_send(req, state, state->iov, state->iov_count);
 }
 
@@ -951,7 +1038,7 @@ size_t cli_smb_wct_ofs(struct tevent_req **reqs, int num_reqs)
 	return wct_ofs;
 }
 
-bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
+NTSTATUS cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
 {
 	struct cli_smb_state *first_state = tevent_req_data(
 		reqs[0], struct cli_smb_state);
@@ -963,6 +1050,7 @@ bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
 	int i, iovlen;
 	struct iovec *iov = NULL;
 	struct iovec *this_iov;
+	NTSTATUS status;
 
 	iovlen = 0;
 	for (i=0; i<num_reqs; i++) {
@@ -972,13 +1060,14 @@ bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
 
 	iov = talloc_array(last_state, struct iovec, iovlen);
 	if (iov == NULL) {
-		goto fail;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	first_state->chained_requests = (struct tevent_req **)talloc_memdup(
 		last_state, reqs, sizeof(*reqs) * num_reqs);
 	if (first_state->chained_requests == NULL) {
-		goto fail;
+		TALLOC_FREE(iov);
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	wct_offset = smb_wct - 4;
@@ -993,7 +1082,9 @@ bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
 		if (i < num_reqs-1) {
 			if (!is_andx_req(CVAL(state->header, smb_com))
 			    || CVAL(state->header, smb_wct) < 2) {
-				goto fail;
+				TALLOC_FREE(iov);
+				TALLOC_FREE(first_state->chained_requests);
+				return NT_STATUS_INVALID_PARAMETER;
 			}
 		}
 
@@ -1039,13 +1130,14 @@ bool cli_smb_chain_send(struct tevent_req **reqs, int num_reqs)
 		chain_padding = next_padding;
 	}
 
-	if (!NT_STATUS_IS_OK(cli_smb_req_iov_send(reqs[0], last_state, iov, iovlen))) {
-		goto fail;
+	status = cli_smb_req_iov_send(reqs[0], last_state, iov, iovlen);
+	if (!NT_STATUS_IS_OK(status)) {
+		TALLOC_FREE(iov);
+		TALLOC_FREE(first_state->chained_requests);
+		return status;
 	}
-	return true;
- fail:
-	TALLOC_FREE(iov);
-	return false;
+
+	return NT_STATUS_OK;
 }
 
 uint8_t *cli_smb_inbuf(struct tevent_req *req)
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 53a39c6..578f6a3 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -4959,6 +4959,7 @@ static bool run_chain1(int dummy)
 	struct tevent_req *reqs[3], *smbreqs[3];
 	bool done = false;
 	const char *str = "foobar";
+	NTSTATUS status;
 
 	printf("starting chain1 test\n");
 	if (!torture_open_connection(&cli1, 0)) {
@@ -4983,7 +4984,8 @@ static bool run_chain1(int dummy)
 	if (reqs[2] == NULL) return false;
 	tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
 
-	if (!cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs))) {
+	status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+	if (!NT_STATUS_IS_OK(status)) {
 		return false;
 	}
 
@@ -5017,6 +5019,7 @@ static bool run_chain2(int dummy)
 	struct event_context *evt = event_context_init(NULL);
 	struct tevent_req *reqs[2], *smbreqs[2];
 	bool done = false;
+	NTSTATUS status;
 
 	printf("starting chain2 test\n");
 	if (!torture_open_connection(&cli1, 0)) {
@@ -5035,7 +5038,8 @@ static bool run_chain2(int dummy)
 	if (reqs[1] == NULL) return false;
 	tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
 
-	if (!cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs))) {
+	status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+	if (!NT_STATUS_IS_OK(status)) {
 		return false;
 	}
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list