[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Apr 5 01:01:02 UTC 2019


The branch, master has been updated
       via  60e31c5556d rpc: Convert npa_tstream.c to use tstream_u32_read_send
       via  05c358759ca rpc: Add tstream_u32_read
      from  15afc4fb18f s3-messages: add mallinfo() information to pool-usage report

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


- Log -----------------------------------------------------------------
commit 60e31c5556d6c409ff31a68444bebfb77f4a1869
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 1 15:23:11 2019 +0200

    rpc: Convert npa_tstream.c to use tstream_u32_read_send
    
    This avoids a bit of code duplication. Overall the last two commits
    add a few lines, but that also contains the header file and another GPL
    header for tstream_u32_read.c.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Apr  5 01:00:48 UTC 2019 on sn-devel-144

commit 05c358759ca86a585c98edec4b80ee6589525a28
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 21 19:41:28 2019 +0100

    rpc: Add tstream_u32_read
    
    In npa_tstream.c we have two next_vector functions reading a big
    endian uin32_t length and then the blob described by the length. This
    factors that next_vector out into a central routine.
    
    Why? I'll add another NPA protocol in the future, and this would add
    yet another two copies of that next_vector code
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 libcli/named_pipe_auth/npa_tstream.c               | 229 ++++-----------------
 libcli/named_pipe_auth/tstream_u32_read.c          | 159 ++++++++++++++
 .../tstream_u32_read.h}                            |  21 +-
 libcli/named_pipe_auth/wscript_build               |   2 +-
 4 files changed, 215 insertions(+), 196 deletions(-)
 create mode 100644 libcli/named_pipe_auth/tstream_u32_read.c
 copy libcli/{smb/smb2_lock.h => named_pipe_auth/tstream_u32_read.h} (69%)


Changeset truncated at 500 lines:

diff --git a/libcli/named_pipe_auth/npa_tstream.c b/libcli/named_pipe_auth/npa_tstream.c
index 3ba1c2cbf34..8fc03371a50 100644
--- a/libcli/named_pipe_auth/npa_tstream.c
+++ b/libcli/named_pipe_auth/npa_tstream.c
@@ -24,6 +24,7 @@
 #include "../lib/tsocket/tsocket_internal.h"
 #include "../librpc/gen_ndr/ndr_named_pipe_auth.h"
 #include "../libcli/named_pipe_auth/npa_tstream.h"
+#include "../libcli/named_pipe_auth/tstream_u32_read.h"
 #include "../libcli/smb/smb_constants.h"
 
 static const struct tstream_context_ops tstream_npa_ops;
@@ -51,7 +52,6 @@ struct tstream_npa_connect_state {
 	struct iovec auth_req_iov;
 
 	struct named_pipe_auth_rep auth_rep;
-	DATA_BLOB auth_rep_blob;
 };
 
 static void tstream_npa_connect_unix_done(struct tevent_req *subreq);
@@ -210,11 +210,6 @@ static void tstream_npa_connect_unix_done(struct tevent_req *subreq)
 	tevent_req_set_callback(subreq, tstream_npa_connect_writev_done, req);
 }
 
-static int tstream_npa_connect_next_vector(struct tstream_context *unix_stream,
-					   void *private_data,
-					   TALLOC_CTX *mem_ctx,
-					   struct iovec **_vector,
-					   size_t *_count);
 static void tstream_npa_connect_readv_done(struct tevent_req *subreq);
 
 static void tstream_npa_connect_writev_done(struct tevent_req *subreq)
@@ -235,81 +230,11 @@ static void tstream_npa_connect_writev_done(struct tevent_req *subreq)
 		return;
 	}
 
-	state->auth_rep_blob = data_blob_const(NULL, 0);
-
-	subreq = tstream_readv_pdu_send(state, state->caller.ev,
-					state->unix_stream,
-					tstream_npa_connect_next_vector,
-					state);
-	if (tevent_req_nomem(subreq, req)) {
-		return;
-	}
+	subreq = tstream_u32_read_send(
+		state, state->caller.ev, 0x00FFFFFF, state->unix_stream);
 	tevent_req_set_callback(subreq, tstream_npa_connect_readv_done, req);
 }
 
-static int tstream_npa_connect_next_vector(struct tstream_context *unix_stream,
-					   void *private_data,
-					   TALLOC_CTX *mem_ctx,
-					   struct iovec **_vector,
-					   size_t *_count)
-{
-	struct tstream_npa_connect_state *state = talloc_get_type_abort(private_data,
-					struct tstream_npa_connect_state);
-	struct iovec *vector;
-	size_t count;
-	off_t ofs = 0;
-
-	if (state->auth_rep_blob.length == 0) {
-		state->auth_rep_blob = data_blob_talloc(state, NULL, 4);
-		if (!state->auth_rep_blob.data) {
-			return -1;
-		}
-	} else if (state->auth_rep_blob.length == 4) {
-		uint32_t msg_len;
-
-		ofs = 4;
-
-		msg_len = RIVAL(state->auth_rep_blob.data, 0);
-
-		if (msg_len > 0x00FFFFFF) {
-			errno = EMSGSIZE;
-			return -1;
-		}
-
-		if (msg_len == 0) {
-			errno = EMSGSIZE;
-			return -1;
-		}
-
-		msg_len += ofs;
-
-		state->auth_rep_blob.data = talloc_realloc(state,
-						state->auth_rep_blob.data,
-						uint8_t, msg_len);
-		if (!state->auth_rep_blob.data) {
-			return -1;
-		}
-		state->auth_rep_blob.length = msg_len;
-	} else {
-		*_vector = NULL;
-		*_count = 0;
-		return 0;
-	}
-
-	/* we need to get a message header */
-	vector = talloc_array(mem_ctx, struct iovec, 1);
-	if (!vector) {
-		return -1;
-	}
-	vector[0].iov_base = (char *) (state->auth_rep_blob.data + ofs);
-	vector[0].iov_len = state->auth_rep_blob.length - ofs;
-	count = 1;
-
-	*_vector = vector;
-	*_count = count;
-	return 0;
-}
-
 static void tstream_npa_connect_readv_done(struct tevent_req *subreq)
 {
 	struct tevent_req *req =
@@ -318,23 +243,23 @@ static void tstream_npa_connect_readv_done(struct tevent_req *subreq)
 	struct tstream_npa_connect_state *state =
 		tevent_req_data(req,
 		struct tstream_npa_connect_state);
-	int ret;
-	int sys_errno;
+	DATA_BLOB in;
+	int err;
 	enum ndr_err_code ndr_err;
 
-	ret = tstream_readv_pdu_recv(subreq, &sys_errno);
+	err = tstream_u32_read_recv(subreq, state, &in.data, &in.length);
 	TALLOC_FREE(subreq);
-	if (ret == -1) {
-		tevent_req_error(req, sys_errno);
+	if (err != 0) {
+		tevent_req_error(req, err);
 		return;
 	}
 
-	DEBUG(10,("name_pipe_auth_rep(client)[%u]\n",
-		 (uint32_t)state->auth_rep_blob.length));
-	dump_data(11, state->auth_rep_blob.data, state->auth_rep_blob.length);
+	DBG_DEBUG("name_pipe_auth_rep(client)[%zu]\n", in.length);
+	dump_data(11, in.data, in.length);
 
-	ndr_err = ndr_pull_struct_blob(
-		&state->auth_rep_blob, state,
+	ndr_err = ndr_pull_struct_blob_all(
+		&in,
+		state,
 		&state->auth_rep,
 		(ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_rep);
 
@@ -1086,11 +1011,6 @@ struct tstream_npa_accept_state {
 	struct auth_session_info_transport *session_info;
 };
 
-static int tstream_npa_accept_next_vector(struct tstream_context *unix_stream,
-					  void *private_data,
-					  TALLOC_CTX *mem_ctx,
-					  struct iovec **_vector,
-					  size_t *_count);
 static void tstream_npa_accept_existing_reply(struct tevent_req *subreq);
 static void tstream_npa_accept_existing_done(struct tevent_req *subreq);
 
@@ -1126,13 +1046,7 @@ struct tevent_req *tstream_npa_accept_existing_send(TALLOC_CTX *mem_ctx,
 	state->device_state = device_state;
 	state->alloc_size = allocation_size;
 
-	/*
-	 * The named pipe pdu's have the length as 8 byte (initial_read_size),
-	 * named_pipe_full_request provides the pdu length then.
-	 */
-	subreq = tstream_readv_pdu_send(state, ev, plain,
-					tstream_npa_accept_next_vector,
-					state);
+	subreq = tstream_u32_read_send(state, ev, 0x00FFFFFF, plain);
 	if (tevent_req_nomem(subreq, req)) {
 		goto post;
 	}
@@ -1147,82 +1061,6 @@ post:
 	return req;
 }
 
-static int tstream_npa_accept_next_vector(struct tstream_context *unix_stream,
-					  void *private_data,
-					  TALLOC_CTX *mem_ctx,
-					  struct iovec **_vector,
-					  size_t *_count)
-{
-	struct tstream_npa_accept_state *state =
-		talloc_get_type_abort(private_data,
-					struct tstream_npa_accept_state);
-	struct iovec *vector;
-	size_t count;
-	off_t ofs = 0;
-
-	if (state->npa_blob.length == 0) {
-		state->npa_blob = data_blob_talloc(state, NULL, 4);
-		if (!state->npa_blob.data) {
-			return -1;
-		}
-	} else if (state->npa_blob.length == 4) {
-		uint32_t msg_len;
-
-		ofs = 4;
-
-		msg_len = RIVAL(state->npa_blob.data, 0);
-
-		if (msg_len > 0x00FFFFFF) {
-			errno = EMSGSIZE;
-			return -1;
-		}
-
-		if (msg_len == 0) {
-			errno = EMSGSIZE;
-			return -1;
-		}
-
-		msg_len += ofs;
-
-		state->npa_blob.data = talloc_realloc(state,
-						      state->npa_blob.data,
-						      uint8_t, msg_len);
-		if (!state->npa_blob.data) {
-			return -1;
-		}
-		state->npa_blob.length = msg_len;
-	} else {
-		if (memcmp(&state->npa_blob.data[4],
-			   NAMED_PIPE_AUTH_MAGIC, 4) != 0) {
-			DEBUG(0, ("Wrong protocol\n"));
-#if defined(EPROTONOSUPPORT)
-			errno = EPROTONOSUPPORT;
-#elif defined(EPROTO)
-			errno = EPROTO;
-#else
-			errno = EINVAL;
-#endif
-			return -1;
-		}
-		*_vector = NULL;
-		*_count = 0;
-		return 0;
-	}
-
-	/* we need to get a message header */
-	vector = talloc_array(mem_ctx, struct iovec, 1);
-	if (!vector) {
-		return -1;
-	}
-	vector[0].iov_base = (char *) (state->npa_blob.data + ofs);
-	vector[0].iov_len = state->npa_blob.length - ofs;
-	count = 1;
-
-	*_vector = vector;
-	*_count = count;
-	return 0;
-}
-
 static void tstream_npa_accept_existing_reply(struct tevent_req *subreq)
 {
 	struct tevent_req *req =
@@ -1233,20 +1071,35 @@ static void tstream_npa_accept_existing_reply(struct tevent_req *subreq)
 	struct named_pipe_auth_rep pipe_reply;
 	struct named_pipe_auth_req_info4 i4;
 	enum ndr_err_code ndr_err;
-	DATA_BLOB out;
-	int sys_errno;
+	DATA_BLOB in, out;
+	int err;
 	int ret;
 
-	ret = tstream_readv_pdu_recv(subreq, &sys_errno);
-	TALLOC_FREE(subreq);
-	if (ret == -1) {
-		tevent_req_error(req, sys_errno);
+	err = tstream_u32_read_recv(subreq, state, &in.data, &in.length);
+	if (err != 0) {
+		tevent_req_error(req, err);
+		return;
+	}
+	if (in.length < 8) {
+		tevent_req_error(req, EMSGSIZE);
+		return;
+	}
+
+	if (memcmp(&in.data[4], NAMED_PIPE_AUTH_MAGIC, 4) != 0) {
+		DBG_ERR("Wrong protocol\n");
+#if defined(EPROTONOSUPPORT)
+		err = EPROTONOSUPPORT;
+#elif defined(EPROTO)
+		err = EPROTO;
+#else
+		err = EINVAL;
+#endif
+		tevent_req_error(req, err);
 		return;
 	}
 
-	DEBUG(10, ("Received packet of length %lu\n",
-		   (long)state->npa_blob.length));
-	dump_data(11, state->npa_blob.data, state->npa_blob.length);
+	DBG_DEBUG("Received packet of length %zu\n", in.length);
+	dump_data(11, in.data, in.length);
 
 	ZERO_STRUCT(pipe_reply);
 	pipe_reply.level = 0;
@@ -1263,8 +1116,10 @@ static void tstream_npa_accept_existing_reply(struct tevent_req *subreq)
 
 	/* parse the passed credentials */
 	ndr_err = ndr_pull_struct_blob_all(
-			&state->npa_blob, pipe_request, pipe_request,
-			(ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_req);
+		&in,
+		pipe_request,
+		pipe_request,
+		(ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_req);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
 		pipe_reply.status = ndr_map_error2ntstatus(ndr_err);
 		DEBUG(2, ("Could not unmarshall named_pipe_auth_req: %s\n",
diff --git a/libcli/named_pipe_auth/tstream_u32_read.c b/libcli/named_pipe_auth/tstream_u32_read.c
new file mode 100644
index 00000000000..c8e95ef6b99
--- /dev/null
+++ b/libcli/named_pipe_auth/tstream_u32_read.c
@@ -0,0 +1,159 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Copyright (C) Volker Lendecke 2019
+ *
+ * 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/>.
+ */
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "tstream_u32_read.h"
+#include "lib/util/byteorder.h"
+#include "lib/util/tevent_unix.h"
+
+struct tstream_u32_read_state {
+	size_t max_msglen;
+	size_t buflen;
+	uint8_t *buf;
+};
+
+static int tstream_u32_read_next_vector(struct tstream_context *stream,
+					void *private_data,
+					TALLOC_CTX *mem_ctx,
+					struct iovec **_vector,
+					size_t *_count);
+static void tstream_u32_read_done(struct tevent_req *subreq);
+
+struct tevent_req *tstream_u32_read_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	uint32_t max_msglen,
+	struct tstream_context *stream)
+{
+	struct tevent_req *req = NULL, *subreq = NULL;
+	struct tstream_u32_read_state *state = NULL;
+
+	req = tevent_req_create(
+		mem_ctx, &state, struct tstream_u32_read_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	state->max_msglen = max_msglen;
+
+	subreq = tstream_readv_pdu_send(
+		state,
+		ev,
+		stream,
+		tstream_u32_read_next_vector,
+		state);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, tstream_u32_read_done, req);
+	return req;
+}
+
+static int tstream_u32_read_next_vector(struct tstream_context *stream,
+					void *private_data,
+					TALLOC_CTX *mem_ctx,
+					struct iovec **_vector,
+					size_t *_count)
+{
+	struct tstream_u32_read_state *state = talloc_get_type_abort(
+		private_data, struct tstream_u32_read_state);
+	size_t buflen = talloc_get_size(state->buf);
+	struct iovec *vector;
+	uint32_t msg_len;
+	size_t ofs = 0;
+	size_t count;
+
+	if (buflen == 0) {
+		msg_len = 4;
+		state->buf = talloc_array(state, uint8_t, msg_len);
+		if (state->buf == NULL) {
+			return -1;
+		}
+	} else if (buflen == 4) {
+
+		ofs = 4;
+
+		msg_len = RIVAL(state->buf, 0);
+		if ((msg_len == 0) || (msg_len > state->max_msglen)) {
+			errno = EMSGSIZE;
+			return -1;
+		}
+		msg_len += ofs;
+		if (msg_len < ofs) {
+			errno = EMSGSIZE;
+			return -1;
+		}
+
+		state->buf = talloc_realloc(
+			state, state->buf, uint8_t, msg_len);
+		if (state->buf == NULL) {
+			return -1;
+		}
+	} else {
+		*_vector = NULL;
+		*_count = 0;
+		return 0;
+	}
+
+	vector = talloc(mem_ctx, struct iovec);
+	if (vector == NULL) {
+		return -1;
+	}
+	*vector = (struct iovec) {
+		.iov_base = state->buf + ofs, .iov_len = msg_len - ofs,
+	};
+	count = 1;
+
+	*_vector = vector;
+	*_count = count;
+	return 0;
+}
+
+static void tstream_u32_read_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	int ret, err;
+
+	ret = tstream_readv_pdu_recv(subreq, &err);
+	TALLOC_FREE(subreq);
+	if (ret == -1) {
+		tevent_req_error(req, err);
+		return;
+	}
+	tevent_req_done(req);
+}
+
+int tstream_u32_read_recv(
+	struct tevent_req *req,
+	TALLOC_CTX *mem_ctx,
+	uint8_t **buf,
+	size_t *buflen)
+{
+	struct tstream_u32_read_state *state = tevent_req_data(
+		req, struct tstream_u32_read_state);
+	int err;
+
+	if (tevent_req_is_unix_error(req, &err)) {
+		return err;
+	}
+	*buflen = talloc_get_size(state->buf);
+	*buf = talloc_move(mem_ctx, &state->buf);
+	return 0;
+}
diff --git a/libcli/smb/smb2_lock.h b/libcli/named_pipe_auth/tstream_u32_read.h
similarity index 69%
copy from libcli/smb/smb2_lock.h
copy to libcli/named_pipe_auth/tstream_u32_read.h
index f0e05355232..1356ff03631 100644
--- a/libcli/smb/smb2_lock.h
+++ b/libcli/named_pipe_auth/tstream_u32_read.h
@@ -17,16 +17,21 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIBCLI_SMB_SMB2_LOCK_H__
-#define __LIBCLI_SMB_SMB2_LOCK_H__
+#ifndef TSTREAM_U32_READ_H
+#define TSTREAM_U32_READ_H
 
 #include "replace.h"


-- 
Samba Shared Repository



More information about the samba-cvs mailing list