[SCM] Samba Shared Repository - branch master updated - 8c983af56d6476cfc576beede034b2c1aed59b33

Volker Lendecke vlendec at samba.org
Wed Jan 14 16:09:27 GMT 2009


The branch, master has been updated
       via  8c983af56d6476cfc576beede034b2c1aed59b33 (commit)
       via  e1aeb486e87140a51d0a4f7bf91d144dbeff15c7 (commit)
       via  11e3388083be7a1be7854cab1603f2dc2905032e (commit)
       via  15dd11b31eac52ffe216efc60129980c9fc3f052 (commit)
       via  274f575b2419800ef1a69f303088711eebb73b1a (commit)
       via  583d7913c8a74b9dfe31cf39446f6cddbd077636 (commit)
       via  87f9f0b01a56f58eb7b03a44fed4f56cd94c7ff8 (commit)
      from  990491d187a77cd0347cf7a17e18bb794b7ba793 (commit)

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


- Log -----------------------------------------------------------------
commit 8c983af56d6476cfc576beede034b2c1aed59b33
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jan 14 16:51:43 2009 +0100

    Make rpc_read look like a real read call
    
    It doesn't really need to know about prs_structs

commit e1aeb486e87140a51d0a4f7bf91d144dbeff15c7
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jan 14 16:43:37 2009 +0100

    Make rpc_read() match the control flow normally used in Samba
    
    Replace do { .. } while () with a while () { .. }

commit 11e3388083be7a1be7854cab1603f2dc2905032e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jan 14 16:06:10 2009 +0100

    Simplify rpc_read a bit
    
    rpc_read always reads the whole bytes it was asked to read. So it is not really
    necessary for it to update the current_pdu_offset, for clarity this can better
    be done in the caller.

commit 15dd11b31eac52ffe216efc60129980c9fc3f052
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jan 14 12:58:38 2009 +0100

    Remove an unnecessary size check
    
    rpc_read is only ever called with at most fraglen-RPC_HEADER_SIZE length

commit 274f575b2419800ef1a69f303088711eebb73b1a
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jan 14 12:58:13 2009 +0100

    Check the fragment size the server has sent us

commit 583d7913c8a74b9dfe31cf39446f6cddbd077636
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 13 22:50:43 2009 +0100

    Slightly simplify rpc_read: It should not do the resize

commit 87f9f0b01a56f58eb7b03a44fed4f56cd94c7ff8
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jan 13 22:24:57 2009 +0100

    Always read with offset 0 from a named pipe

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

Summary of changes:
 source3/rpc_client/cli_pipe.c |  132 ++++++++++++++++++++++------------------
 1 files changed, 73 insertions(+), 59 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index c87df09..99bd85a 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -176,15 +176,15 @@ static uint32 get_rpc_call_id(void)
  Read from a RPC named pipe
  ********************************************************************/
 static NTSTATUS rpc_read_np(struct cli_state *cli, const char *pipe_name,
-			    int fnum, char *buf, off_t offset, size_t size,
+			    int fnum, char *buf, size_t size,
 			    ssize_t *pnum_read)
 {
        ssize_t num_read;
 
-       num_read = cli_read(cli, fnum, buf, offset, size);
+       num_read = cli_read(cli, fnum, buf, 0, size);
 
-       DEBUG(5,("rpc_read_np: num_read = %d, read offset: %u, to read: %u\n",
-		(int)num_read, (unsigned int)offset, (unsigned int)size));
+       DEBUG(5,("rpc_read_np: num_read = %d, to read: %u\n", (int)num_read,
+		(unsigned int)size));
 
        /*
 	* A dos error of ERRDOS/ERRmoredata is not an error.
@@ -223,66 +223,65 @@ static NTSTATUS rpc_read_np(struct cli_state *cli, const char *pipe_name,
        return NT_STATUS_OK;
 }
 
+/*
+ * Realloc pdu to have a least "size" bytes
+ */
+
+static bool rpc_grow_buffer(prs_struct *pdu, size_t size)
+{
+	size_t extra_size;
+
+	if (prs_data_size(pdu) >= size) {
+		return true;
+	}
+
+	extra_size = size - prs_data_size(pdu);
+
+	if (!prs_force_grow(pdu, extra_size)) {
+		DEBUG(0, ("rpc_grow_buffer: Failed to grow parse struct by "
+			  "%d bytes.\n", (int)extra_size));
+		return false;
+	}
+
+	DEBUG(5, ("rpc_grow_buffer: grew buffer by %d bytes to %u\n",
+		  (int)extra_size, prs_data_size(pdu)));
+	return true;
+}
+
 
 /*******************************************************************
  Use SMBreadX to get rest of one fragment's worth of rpc data.
- Will expand the current_pdu struct to the correct size.
+ Reads the whole size or give an error message
  ********************************************************************/
 
 static NTSTATUS rpc_read(struct rpc_pipe_client *cli,
-			prs_struct *current_pdu,
-			uint32 data_to_read,
-			uint32 *current_pdu_offset)
+			 char *pdata, size_t size)
 {
-	size_t size = (size_t)cli->max_recv_frag;
-	uint32 stream_offset = 0;
 	ssize_t num_read = 0;
-	char *pdata;
-	ssize_t extra_data_size = ((ssize_t)*current_pdu_offset) + ((ssize_t)data_to_read) - (ssize_t)prs_data_size(current_pdu);
-
-	DEBUG(5,("rpc_read: data_to_read: %u current_pdu offset: %u extra_data_size: %d\n",
-		(unsigned int)data_to_read, (unsigned int)*current_pdu_offset, (int)extra_data_size ));
 
-	/*
-	 * Grow the buffer if needed to accommodate the data to be read.
-	 */
+	DEBUG(5, ("rpc_read: data_to_read: %u\n", (unsigned int)size));
 
-	if (extra_data_size > 0) {
-		if(!prs_force_grow(current_pdu, (uint32)extra_data_size)) {
-			DEBUG(0,("rpc_read: Failed to grow parse struct by %d bytes.\n", (int)extra_data_size ));
-			return NT_STATUS_NO_MEMORY;
-		}
-		DEBUG(5,("rpc_read: grew buffer by %d bytes to %u\n", (int)extra_data_size, prs_data_size(current_pdu) ));
-	}
-
-	pdata = prs_data_p(current_pdu) + *current_pdu_offset;
-
-	do {
+	while (num_read < size) {
+		ssize_t thistime = 0;
 		NTSTATUS status;
 
-		/* read data using SMBreadX */
-		if (size > (size_t)data_to_read) {
-			size = (size_t)data_to_read;
-		}
-
 		switch (cli->transport_type) {
 		case NCACN_NP:
 			status = rpc_read_np(cli->trans.np.cli,
 					     cli->trans.np.pipe_name,
-					     cli->trans.np.fnum, pdata,
-					     (off_t)stream_offset, size,
-					     &num_read);
+					     cli->trans.np.fnum,
+					     pdata + num_read,
+					     size - num_read, &thistime);
 			break;
 		case NCACN_IP_TCP:
 		case NCACN_UNIX_STREAM:
 			status = NT_STATUS_OK;
-			num_read = sys_read(cli->trans.sock.fd, pdata, size);
-			if (num_read == -1) {
+			thistime = sys_read(cli->trans.sock.fd,
+					    pdata + num_read,
+					    size - num_read);
+			if (thistime == -1) {
 				status = map_nt_error_from_unix(errno);
 			}
-			if (num_read == 0) {
-				status = NT_STATUS_END_OF_FILE;
-			}
 			break;
 		default:
 			DEBUG(0, ("unknown transport type %d\n",
@@ -290,17 +289,17 @@ static NTSTATUS rpc_read(struct rpc_pipe_client *cli,
 			return NT_STATUS_INTERNAL_ERROR;
 		}
 
-		data_to_read -= num_read;
-		stream_offset += num_read;
-		pdata += num_read;
+		if (!NT_STATUS_IS_OK(status)) {
+			return status;
+		}
+		if (thistime == 0) {
+			return NT_STATUS_END_OF_FILE;
+		}
 
-	} while (num_read > 0 && data_to_read > 0);
-	/* && err == (0x80000000 | STATUS_BUFFER_OVERFLOW)); */
+		num_read += thistime;
+
+	}
 
-	/*
-	 * Update the current offset into current_pdu by the amount read.
-	 */
-	*current_pdu_offset += stream_offset;
 	return NT_STATUS_OK;
 }
 
@@ -316,11 +315,16 @@ static NTSTATUS cli_pipe_get_current_pdu(struct rpc_pipe_client *cli, RPC_HDR *p
 
 	/* Ensure we have at least RPC_HEADER_LEN worth of data to parse. */
 	if (current_pdu_len < RPC_HEADER_LEN) {
-		/* rpc_read expands the current_pdu struct as neccessary. */
-		ret = rpc_read(cli, current_pdu, RPC_HEADER_LEN - current_pdu_len, &current_pdu_len);
+		if (!rpc_grow_buffer(current_pdu, RPC_HEADER_LEN)) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		ret = rpc_read(cli,
+			       prs_data_p(current_pdu) + current_pdu_len,
+			       RPC_HEADER_LEN - current_pdu_len);
 		if (!NT_STATUS_IS_OK(ret)) {
 			return ret;
 		}
+		current_pdu_len = RPC_HEADER_LEN;
 	}
 
 	/* This next call sets the endian bit correctly in current_pdu. */
@@ -330,19 +334,26 @@ static NTSTATUS cli_pipe_get_current_pdu(struct rpc_pipe_client *cli, RPC_HDR *p
 		return NT_STATUS_BUFFER_TOO_SMALL;
 	}
 
+	if (prhdr->frag_len > cli->max_recv_frag) {
+		DEBUG(0, ("cli_pipe_get_current_pdu: Server sent fraglen %d,"
+			  " we only allow %d\n", (int)prhdr->frag_len,
+			  (int)cli->max_recv_frag));
+		return NT_STATUS_BUFFER_TOO_SMALL;
+	}
+
 	/* Ensure we have frag_len bytes of data. */
 	if (current_pdu_len < prhdr->frag_len) {
-		/* rpc_read expands the current_pdu struct as neccessary. */
-		ret = rpc_read(cli, current_pdu, (uint32)prhdr->frag_len - current_pdu_len, &current_pdu_len);
+		if (!rpc_grow_buffer(current_pdu, prhdr->frag_len)) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		ret = rpc_read(cli,
+			       prs_data_p(current_pdu) + current_pdu_len,
+			       prhdr->frag_len - current_pdu_len);
 		if (!NT_STATUS_IS_OK(ret)) {
 			return ret;
 		}
 	}
 
-	if (current_pdu_len < prhdr->frag_len) {
-		return NT_STATUS_BUFFER_TOO_SMALL;
-	}
-
 	return NT_STATUS_OK;
 }
 
@@ -2923,6 +2934,9 @@ static NTSTATUS rpc_pipe_open_np(struct cli_state *cli,
 	result->srv_name_slash = talloc_asprintf_strupper_m(
 		result, "\\\\%s", result->desthost);
 
+	result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN;
+	result->max_recv_frag = RPC_MAX_PDU_FRAG_LEN;
+
 	if ((result->desthost == NULL) || (result->srv_name_slash == NULL)) {
 		TALLOC_FREE(result);
 		return NT_STATUS_NO_MEMORY;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list