[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha6-741-g77e3272

Volker Lendecke vlendec at samba.org
Tue Feb 10 17:30:20 GMT 2009


The branch, master has been updated
       via  77e3272092d58f852955327e7c335ce5ee15f52f (commit)
       via  bbb665501a3235cfb63143d2a1945360252ba493 (commit)
       via  f6e9f1e7ea7ac0fddf312f7fcd7a1478bde1c07f (commit)
       via  47cb572d401218d43f5e681fd8820517659b48c4 (commit)
      from  c3baf1529ddd0191e839096ea2e68e3a3457c2d5 (commit)

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


- Log -----------------------------------------------------------------
commit 77e3272092d58f852955327e7c335ce5ee15f52f
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Feb 10 18:09:12 2009 +0100

    Fix an uninitialized variable. Tim, please check!

commit bbb665501a3235cfb63143d2a1945360252ba493
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Feb 10 15:28:56 2009 +0100

    Add queueing to np_write

commit f6e9f1e7ea7ac0fddf312f7fcd7a1478bde1c07f
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Feb 9 08:10:09 2009 +0100

    Add queueing to np_read_state, simulate message-type named pipes.
    
    The problem with msg-type pipes is that we have to return short reads when a
    message ends before the read request. When reading from the unix domain socket,
    the message limits are lost. So we would happily return more than a message,
    which confuses for example the s4 rpc client horribly. I'd expect other np rpc
    clients also to blow up over this.
    
    The real solution is to properly implement a two-byte length field per message
    on the unix domain socket, but this requires more changes there. And as we
    right now only serve DCE/RPC over the named pipes, this implements a hack that
    looks into the fragment headers to figure out hdr.frag_len.

commit 47cb572d401218d43f5e681fd8820517659b48c4
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Feb 10 17:29:02 2009 +0100

    Add read_pkt_send/recv

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

Summary of changes:
 source3/include/proto.h           |    9 ++
 source3/lib/util.c                |   99 +++++++++++++++++++++
 source3/locking/brlock.c          |    2 +-
 source3/rpc_server/srv_pipe_hnd.c |  172 +++++++++++++++++++++++++++++-------
 4 files changed, 247 insertions(+), 35 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index c2391c7..fd6ccce 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1242,6 +1242,15 @@ bool is_valid_policy_hnd(const POLICY_HND *hnd);
 bool policy_hnd_equal(const struct policy_handle *hnd1,
 		      const struct policy_handle *hnd2);
 const char *strip_hostname(const char *s);
+struct async_req *read_pkt_send(TALLOC_CTX *mem_ctx,
+				struct event_context *ev,
+				int fd, size_t initial,
+				ssize_t (*more)(uint8_t *buf, size_t buflen,
+						void *priv),
+				void *priv);
+ssize_t read_pkt_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
+		      uint8_t **pbuf, int *perr);
+
 
 /* The following definitions come from lib/util_file.c  */
 
diff --git a/source3/lib/util.c b/source3/lib/util.c
index df01c03..68d3322 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3234,3 +3234,102 @@ const char *strip_hostname(const char *s)
 
 	return s;
 }
+
+struct read_pkt_state {
+	struct event_context *ev;
+	int fd;
+	uint8_t *buf;
+	ssize_t (*more)(uint8_t *buf, size_t buflen, void *priv);
+	void *priv;
+};
+
+static void read_pkt_done(struct async_req *subreq);
+
+struct async_req *read_pkt_send(TALLOC_CTX *mem_ctx,
+				struct event_context *ev,
+				int fd, size_t initial,
+				ssize_t (*more)(uint8_t *buf, size_t buflen,
+						void *priv),
+				void *priv)
+{
+	struct async_req *result, *subreq;
+	struct read_pkt_state *state;
+
+	if (!async_req_setup(mem_ctx, &result, &state,
+			     struct read_pkt_state)) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->fd = fd;
+	state->more = more;
+
+	state->buf = talloc_array(state, uint8_t, initial);
+	if (state->buf == NULL) {
+		goto fail;
+	}
+	subreq = recvall_send(state, ev, fd, state->buf, initial, 0);
+	if (subreq == NULL) {
+		goto fail;
+	}
+	subreq->async.fn = read_pkt_done;
+	subreq->async.priv = result;
+	return result;
+ fail:
+	TALLOC_FREE(result);
+	return NULL;
+}
+
+static void read_pkt_done(struct async_req *subreq)
+{
+	struct async_req *req = talloc_get_type_abort(
+		subreq->async.priv, struct async_req);
+	struct read_pkt_state *state = talloc_get_type_abort(
+		req->private_data, struct read_pkt_state);
+	size_t current_size;
+	ssize_t received;
+	ssize_t more;
+	int err;
+
+	received = recvall_recv(subreq, &err);
+	TALLOC_FREE(subreq);
+	if (received == -1) {
+		async_req_error(req, err);
+		return;
+	}
+	current_size = talloc_get_size(state->buf);
+
+	more = state->more(state->buf, current_size, state->priv);
+	if (more < 0) {
+		async_req_error(req, EIO);
+		return;
+	}
+	if (more == 0) {
+		async_req_done(req);
+		return;
+	}
+	state->buf = TALLOC_REALLOC_ARRAY(state, state->buf, uint8_t,
+					  current_size + more);
+	if (async_req_nomem(state->buf, req)) {
+		return;
+	}
+	subreq = recvall_send(state, state->ev, state->fd,
+			      state->buf + current_size, more, 0);
+	if (async_req_nomem(subreq, req)) {
+		return;
+	}
+	subreq->async.fn = read_pkt_done;
+	subreq->async.priv = req;
+}
+
+ssize_t read_pkt_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
+		      uint8_t **pbuf, int *perr)
+{
+	struct read_pkt_state *state = talloc_get_type_abort(
+		req->private_data, struct read_pkt_state);
+
+	if (async_req_is_errno(req, perr)) {
+		return -1;
+	}
+	*pbuf = talloc_move(mem_ctx, &state->buf);
+	return talloc_get_size(*pbuf);
+}
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 76496d1..edba4ed 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -652,7 +652,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 			memcpy(&tp[count], curr_lock, sizeof(struct lock_struct));
 			count++;
 		} else {
-			unsigned int tmp_count;
+			unsigned int tmp_count = 0;
 
 			/* POSIX conflict semantics are different. */
 			if (brl_conflict_posix(curr_lock, plock)) {
diff --git a/source3/rpc_server/srv_pipe_hnd.c b/source3/rpc_server/srv_pipe_hnd.c
index 6dfe7a0..0804af7 100644
--- a/source3/rpc_server/srv_pipe_hnd.c
+++ b/source3/rpc_server/srv_pipe_hnd.c
@@ -943,7 +943,12 @@ bool fsp_is_np(struct files_struct *fsp)
 }
 
 struct np_proxy_state {
+	struct async_req_queue *read_queue;
+	struct async_req_queue *write_queue;
 	int fd;
+
+	uint8_t *msg;
+	size_t sent;
 };
 
 static int np_proxy_state_destructor(struct np_proxy_state *state)
@@ -1097,6 +1102,17 @@ static struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
+	result->msg = NULL;
+
+	result->read_queue = async_req_queue_init(result);
+	if (result->read_queue == NULL) {
+		goto fail;
+	}
+	result->write_queue = async_req_queue_init(result);
+	if (result->write_queue == NULL) {
+		goto fail;
+	}
+
 	return result;
 
  fail:
@@ -1153,16 +1169,21 @@ NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
 }
 
 struct np_write_state {
+	struct event_context *ev;
+	struct np_proxy_state *p;
+	const uint8_t *data;
+	size_t len;
 	ssize_t nwritten;
 };
 
+static void np_write_trigger(struct async_req *req);
 static void np_write_done(struct async_req *subreq);
 
 struct async_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 				struct fake_file_handle *handle,
 				const uint8_t *data, size_t len)
 {
-	struct async_req *result, *subreq;
+	struct async_req *result;
 	struct np_write_state *state;
 	NTSTATUS status;
 
@@ -1195,14 +1216,15 @@ struct async_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 		struct np_proxy_state *p = talloc_get_type_abort(
 			handle->private_data, struct np_proxy_state);
 
-		state->nwritten = len;
+		state->ev = ev;
+		state->p = p;
+		state->data = data;
+		state->len = len;
 
-		subreq = sendall_send(state, ev, p->fd, data, len, 0);
-		if (subreq == NULL) {
+		if (!async_req_enqueue(p->write_queue, ev, result,
+				       np_write_trigger)) {
 			goto fail;
 		}
-		subreq->async.fn = np_write_done;
-		subreq->async.priv = result;
 		return result;
 	}
 
@@ -1216,18 +1238,36 @@ struct async_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 	return NULL;
 }
 
+static void np_write_trigger(struct async_req *req)
+{
+	struct np_write_state *state = talloc_get_type_abort(
+		req->private_data, struct np_write_state);
+	struct async_req *subreq;
+
+	subreq = sendall_send(state, state->ev, state->p->fd, state->data,
+			      state->len, 0);
+	if (async_req_nomem(subreq, req)) {
+		return;
+	}
+	subreq->async.fn = np_write_done;
+	subreq->async.priv = req;
+}
+
 static void np_write_done(struct async_req *subreq)
 {
 	struct async_req *req = talloc_get_type_abort(
 		subreq->async.priv, struct async_req);
+	struct np_write_state *state = talloc_get_type_abort(
+		req->private_data, struct np_write_state);
+	ssize_t received;
 	int err;
-	ssize_t ret;
 
-	ret = sendall_recv(subreq, &err);
-	if (ret < 0) {
+	received = sendall_recv(subreq, &err);
+	if (received < 0) {
 		async_req_nterror(req, map_nt_error_from_unix(err));
 		return;
 	}
+	state->nwritten = received;
 	async_req_done(req);
 }
 
@@ -1244,19 +1284,45 @@ NTSTATUS np_write_recv(struct async_req *req, ssize_t *pnwritten)
 	return NT_STATUS_OK;
 }
 
+static ssize_t rpc_frag_more_fn(uint8_t *buf, size_t buflen, void *priv)
+{
+	prs_struct hdr_prs;
+	struct rpc_hdr_info hdr;
+	bool ret;
+
+	if (buflen > RPC_HEADER_LEN) {
+		return 0;
+	}
+	prs_init_empty(&hdr_prs, talloc_tos(), UNMARSHALL);
+	prs_give_memory(&hdr_prs, (char *)buf, RPC_HEADER_LEN, false);
+	ret = smb_io_rpc_hdr("", &hdr, &hdr_prs, 0);
+	prs_mem_free(&hdr_prs);
+
+	if (!ret) {
+		return -1;
+	}
+
+	return (hdr.frag_len - RPC_HEADER_LEN);
+}
+
 struct np_read_state {
-	ssize_t nread;
+	struct event_context *ev;
+	struct np_proxy_state *p;
+	uint8_t *data;
+	size_t len;
+
+	size_t nread;
 	bool is_data_outstanding;
-	int fd;
 };
 
+static void np_read_trigger(struct async_req *req);
 static void np_read_done(struct async_req *subreq);
 
 struct async_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 			       struct fake_file_handle *handle,
 			       uint8_t *data, size_t len)
 {
-	struct async_req *result, *subreq;
+	struct async_req *result;
 	struct np_read_state *state;
 	NTSTATUS status;
 
@@ -1281,14 +1347,35 @@ struct async_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 		struct np_proxy_state *p = talloc_get_type_abort(
 			handle->private_data, struct np_proxy_state);
 
-		state->fd = p->fd;
+		if (p->msg != NULL) {
+			size_t thistime;
+
+			thistime = MIN(talloc_get_size(p->msg) - p->sent,
+				       len);
+
+			memcpy(data, p->msg+p->sent, thistime);
+			state->nread = thistime;
+			p->sent += thistime;
+
+			if (p->sent < talloc_get_size(p->msg)) {
+				state->is_data_outstanding = true;
+			} else {
+				state->is_data_outstanding = false;
+				TALLOC_FREE(p->msg);
+			}
+			status = NT_STATUS_OK;
+			goto post_status;
+		}
 
-		subreq = async_recv(state, ev, p->fd, data, len, 0);
-		if (subreq == NULL) {
+		state->ev = ev;
+		state->p = p;
+		state->data = data;
+		state->len = len;
+
+		if (!async_req_enqueue(p->read_queue, ev, result,
+				       np_read_trigger)) {
 			goto fail;
 		}
-		subreq->async.fn = np_read_done;
-		subreq->async.priv = result;
 		return result;
 	}
 
@@ -1302,36 +1389,53 @@ struct async_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 	return NULL;
 }
 
+static void np_read_trigger(struct async_req *req)
+{
+	struct np_read_state *state = talloc_get_type_abort(
+		req->private_data, struct np_read_state);
+	struct async_req *subreq;
+
+	subreq = read_pkt_send(state, state->ev, state->p->fd, RPC_HEADER_LEN,
+			       rpc_frag_more_fn, NULL);
+	if (async_req_nomem(subreq, req)) {
+		return;
+	}
+	subreq->async.fn = np_read_done;
+	subreq->async.priv = req;
+}
+
 static void np_read_done(struct async_req *subreq)
 {
 	struct async_req *req = talloc_get_type_abort(
 		subreq->async.priv, struct async_req);
 	struct np_read_state *state = talloc_get_type_abort(
 		req->private_data, struct np_read_state);
-	ssize_t result;
-	int sys_errno;
-	int available = 0;
+	ssize_t received;
+	size_t thistime;
+	int err;
 
-	result = async_syscall_result_ssize_t(subreq, &sys_errno);
-	if (result == -1) {
-		async_req_nterror(req, map_nt_error_from_unix(sys_errno));
-		return;
-	}
-	if (result == 0) {
-		async_req_nterror(req, NT_STATUS_END_OF_FILE);
+	received = read_pkt_recv(subreq, state->p, &state->p->msg, &err);
+	TALLOC_FREE(subreq);
+	if (received == -1) {
+		async_req_nterror(req, map_nt_error_from_unix(err));
 		return;
 	}
 
-	state->nread = result;
+	thistime = MIN(received, state->len);
 
-	/*
-	 * We don't look at the ioctl result. We don't really care if there is
-	 * data available, because this is racy anyway.
-	 */
-	ioctl(state->fd, FIONREAD, &available);
-	state->is_data_outstanding = (available > 0);
+	memcpy(state->data, state->p->msg, thistime);
+	state->p->sent = thistime;
+	state->nread = thistime;
+
+	if (state->p->sent < received) {
+		state->is_data_outstanding = true;
+	} else {
+		TALLOC_FREE(state->p->msg);
+		state->is_data_outstanding = false;
+	}
 
 	async_req_done(req);
+	return;
 }
 
 NTSTATUS np_read_recv(struct async_req *req, ssize_t *nread,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list