[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Mar 27 12:32:04 UTC 2019


The branch, master has been updated
       via  3e1d8ab1255 libsmb: Change cli_posix_readlink to return talloc'ed target
       via  3478e9d124f libsmb: Don't pass "cli" to cli_posix_readlink_recv
       via  c7fae52ff09 libsmb: Rename "readlink_state" to "cli_posix_readlink_state"
       via  f9a6992e802 libsmb: Fix valgrind errors in cli_smb2_get_reparse_point
      from  ac487bf4d04 lib: Make fd_load work for non-regular files

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


- Log -----------------------------------------------------------------
commit 3e1d8ab1255f1797a1803494b6333dc7990e0795
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Mar 26 09:48:16 2019 +0100

    libsmb: Change cli_posix_readlink to return talloc'ed target
    
    This is a deviation from the Posix readlink function that from my
    point of view makes this function easier to use. In Posix, probably
    the assumption is that readlink is cheap, so someone under memory
    constraints could just start with a small buffer and incrementally
    increase the buffer size. For us, it's a network round-trip, and we
    have the luxury of [mt]alloc, which the syscall kernel interface does
    not have.
    
    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): Wed Mar 27 12:31:37 UTC 2019 on sn-devel-144

commit 3478e9d124f95344d67f1794e92658fa253b48fd
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Mar 25 12:32:07 2019 +0100

    libsmb: Don't pass "cli" to cli_posix_readlink_recv
    
    From my point of view the option to change "cli" between
    cli_posix_readlink_send and _recv is not necessary.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c7fae52ff09fca90e14231523fd3ec8ea6bdec55
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Mar 25 12:26:37 2019 +0100

    libsmb: Rename "readlink_state" to "cli_posix_readlink_state"
    
    This is more in line with most other users of tevent_req: The state is
    called fully after the routines it acts as a state repository for.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f9a6992e8027c119e7cf0426b46adb301083a7a5
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Mar 26 10:56:27 2019 +0100

    libsmb: Fix valgrind errors in cli_smb2_get_reparse_point
    
    Both tevent_req_nterror and tevent_req_is_nterror invalidate
    "state". Pull the variables out of "state" before calling those two
    functions.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 source3/client/client.c        |   6 ++-
 source3/libsmb/cli_smb2_fnum.c |   6 ++-
 source3/libsmb/clifile.c       | 106 +++++++++++++++++++++--------------------
 source3/libsmb/proto.h         |  14 +++---
 source3/torture/torture.c      |   8 ++--
 5 files changed, 74 insertions(+), 66 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/client.c b/source3/client/client.c
index 366368630cb..a69ab5daa76 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -3487,7 +3487,7 @@ static int cmd_readlink(void)
 	char *name= NULL;
 	char *buf = NULL;
 	char *targetname = NULL;
-	char linkname[PATH_MAX+1];
+	char *linkname = NULL;
 	struct cli_state *targetcli;
         NTSTATUS status;
 
@@ -3519,7 +3519,7 @@ static int cmd_readlink(void)
 		return 1;
 	}
 
-	status = cli_posix_readlink(targetcli, name, linkname, PATH_MAX+1);
+	status = cli_posix_readlink(targetcli, name, talloc_tos(), &linkname);
 	if (!NT_STATUS_IS_OK(status)) {
 		d_printf("%s readlink on file %s\n",
 			 nt_errstr(status), name);
@@ -3528,6 +3528,8 @@ static int cmd_readlink(void)
 
 	d_printf("%s -> %s\n", name, linkname);
 
+	TALLOC_FREE(linkname);
+
 	return 0;
 }
 
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 44786ca5912..33bc31592a4 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -5182,6 +5182,7 @@ static void cli_smb2_get_reparse_point_fnum_done(struct tevent_req *subreq)
 		subreq, struct tevent_req);
 	struct cli_smb2_get_reparse_point_fnum_state *state = tevent_req_data(
 		req, struct cli_smb2_get_reparse_point_fnum_state);
+	struct cli_state *cli = state->cli;
 	NTSTATUS status;
 
 	status = smb2cli_ioctl_recv(subreq, state,
@@ -5189,7 +5190,7 @@ static void cli_smb2_get_reparse_point_fnum_done(struct tevent_req *subreq)
 				&state->output_buffer);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
-		state->cli->raw_status = status;
+		cli->raw_status = status;
 		return;
 	}
 	tevent_req_done(req);
@@ -5203,8 +5204,9 @@ NTSTATUS cli_smb2_get_reparse_point_fnum_recv(struct tevent_req *req,
 		req, struct cli_smb2_get_reparse_point_fnum_state);
 
 	if (tevent_req_is_nterror(req, &state->cli->raw_status)) {
+		NTSTATUS status = state->cli->raw_status;
 		tevent_req_received(req);
-		return state->cli->raw_status;
+		return status;
 	}
 	*output = data_blob_dup_talloc(mem_ctx, state->output_buffer);
 	if (output->data == NULL) {
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index f2bfdcce23d..dec0dd01609 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -299,9 +299,9 @@ NTSTATUS cli_posix_symlink(struct cli_state *cli,
  Read a POSIX symlink.
 ****************************************************************************/
 
-struct readlink_state {
-	uint8_t *data;
-	uint32_t num_data;
+struct cli_posix_readlink_state {
+	struct cli_state *cli;
+	char *converted;
 };
 
 static void cli_posix_readlink_done(struct tevent_req *subreq);
@@ -309,28 +309,26 @@ static void cli_posix_readlink_done(struct tevent_req *subreq);
 struct tevent_req *cli_posix_readlink_send(TALLOC_CTX *mem_ctx,
 					struct tevent_context *ev,
 					struct cli_state *cli,
-					const char *fname,
-					size_t len)
+					const char *fname)
 {
 	struct tevent_req *req = NULL, *subreq = NULL;
-	struct readlink_state *state = NULL;
-	uint32_t maxbytelen = (uint32_t)(smbXcli_conn_use_unicode(cli->conn) ? len*3 : len);
+	struct cli_posix_readlink_state *state = NULL;
 
-	req = tevent_req_create(mem_ctx, &state, struct readlink_state);
+	req = tevent_req_create(
+		mem_ctx, &state, struct cli_posix_readlink_state);
 	if (req == NULL) {
 		return NULL;
 	}
+	state->cli = cli;
 
-	/*
-	 * Len is in bytes, we need it in UCS2 units.
-	 */
-	if ((2*len < len) || (maxbytelen < len)) {
-		tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
-		return tevent_req_post(req, ev);
-	}
-
-	subreq = cli_qpathinfo_send(state, ev, cli, fname,
-				    SMB_QUERY_FILE_UNIX_LINK, 1, maxbytelen);
+	subreq = cli_qpathinfo_send(
+		state,
+		ev,
+		cli,
+		fname,
+		SMB_QUERY_FILE_UNIX_LINK,
+		1,
+		UINT16_MAX);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
@@ -342,12 +340,16 @@ static void cli_posix_readlink_done(struct tevent_req *subreq)
 {
 	struct tevent_req *req = tevent_req_callback_data(
 		subreq, struct tevent_req);
-	struct readlink_state *state = tevent_req_data(
-		req, struct readlink_state);
+	struct cli_posix_readlink_state *state = tevent_req_data(
+		req, struct cli_posix_readlink_state);
 	NTSTATUS status;
+	uint8_t *data = NULL;
+	uint32_t num_data;
+	charset_t charset;
+	size_t converted_size;
+	bool ok;
 
-	status = cli_qpathinfo_recv(subreq, state, &state->data,
-				    &state->num_data);
+	status = cli_qpathinfo_recv(subreq, state, &data, &num_data);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
 		return;
@@ -355,45 +357,49 @@ static void cli_posix_readlink_done(struct tevent_req *subreq)
 	/*
 	 * num_data is > 1, we've given 1 as minimum to cli_qpathinfo_send
 	 */
-	if (state->data[state->num_data-1] != '\0') {
+	if (data[num_data-1] != '\0') {
 		tevent_req_nterror(req, NT_STATUS_DATA_ERROR);
 		return;
 	}
+
+	charset = smbXcli_conn_use_unicode(state->cli->conn) ?
+		CH_UTF16LE : CH_DOS;
+
+	/* The returned data is a pushed string, not raw data. */
+	ok = convert_string_talloc(
+		state,
+		charset,
+		CH_UNIX,
+		data,
+		num_data,
+		&state->converted,
+		&converted_size);
+	if (!ok) {
+		tevent_req_oom(req);
+		return;
+	}
 	tevent_req_done(req);
 }
 
-NTSTATUS cli_posix_readlink_recv(struct tevent_req *req, struct cli_state *cli,
-				char *retpath, size_t len)
+NTSTATUS cli_posix_readlink_recv(
+	struct tevent_req *req, TALLOC_CTX *mem_ctx, char **target)
 {
+	struct cli_posix_readlink_state *state = tevent_req_data(
+		req, struct cli_posix_readlink_state);
 	NTSTATUS status;
-	char *converted = NULL;
-	size_t converted_size = 0;
-	struct readlink_state *state = tevent_req_data(req, struct readlink_state);
 
 	if (tevent_req_is_nterror(req, &status)) {
 		return status;
 	}
-	/* The returned data is a pushed string, not raw data. */
-	if (!convert_string_talloc(state,
-				smbXcli_conn_use_unicode(cli->conn) ? CH_UTF16LE : CH_DOS, 
-				CH_UNIX,
-				state->data,
-				state->num_data,
-				&converted,
-				&converted_size)) {
-		return NT_STATUS_NO_MEMORY;
-	}
-
-	len = MIN(len,converted_size);
-	if (len == 0) {
-		return NT_STATUS_DATA_ERROR;
-	}
-	memcpy(retpath, converted, len);
+	*target = talloc_move(mem_ctx, &state->converted);
 	return NT_STATUS_OK;
 }
 
-NTSTATUS cli_posix_readlink(struct cli_state *cli, const char *fname,
-				char *linkpath, size_t len)
+NTSTATUS cli_posix_readlink(
+	struct cli_state *cli,
+	const char *fname,
+	TALLOC_CTX *mem_ctx,
+	char **target)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
 	struct tevent_context *ev = NULL;
@@ -414,11 +420,7 @@ NTSTATUS cli_posix_readlink(struct cli_state *cli, const char *fname,
 		goto fail;
 	}
 
-	req = cli_posix_readlink_send(frame,
-				ev,
-				cli,
-				fname,
-				len);
+	req = cli_posix_readlink_send(frame, ev, cli, fname);
 	if (req == NULL) {
 		status = NT_STATUS_NO_MEMORY;
 		goto fail;
@@ -428,7 +430,7 @@ NTSTATUS cli_posix_readlink(struct cli_state *cli, const char *fname,
 		goto fail;
 	}
 
-	status = cli_posix_readlink_recv(req, cli, linkpath, len);
+	status = cli_posix_readlink_recv(req, mem_ctx, target);
 
  fail:
 	TALLOC_FREE(frame);
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index 4b9cfbea96e..c811d07905f 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -265,12 +265,14 @@ NTSTATUS cli_posix_symlink(struct cli_state *cli,
 struct tevent_req *cli_posix_readlink_send(TALLOC_CTX *mem_ctx,
 					struct tevent_context *ev,
 					struct cli_state *cli,
-					const char *fname,
-					size_t len);
-NTSTATUS cli_posix_readlink_recv(struct tevent_req *req, struct cli_state *cli,
-				char *retpath, size_t len);
-NTSTATUS cli_posix_readlink(struct cli_state *cli, const char *fname,
-			char *linkpath, size_t len);
+					const char *fname);
+NTSTATUS cli_posix_readlink_recv(
+	struct tevent_req *req, TALLOC_CTX *mem_ctx, char **target);
+NTSTATUS cli_posix_readlink(
+	struct cli_state *cli,
+	const char *fname,
+	TALLOC_CTX *mem_ctx,
+	char **target);
 struct tevent_req *cli_posix_hardlink_send(TALLOC_CTX *mem_ctx,
 					struct tevent_context *ev,
 					struct cli_state *cli,
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index c7b3bf28041..219ac4a370c 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -6228,7 +6228,7 @@ static bool run_simple_posix_open_test(int dummy)
 	const char *sname = "posix:symlink";
 	const char *dname = "posix:dir";
 	char buf[10];
-	char namebuf[11];
+	char *target = NULL;
 	uint16_t fnum1 = (uint16_t)-1;
 	SMB_STRUCT_STAT sbuf;
 	bool correct = false;
@@ -6515,15 +6515,15 @@ static bool run_simple_posix_open_test(int dummy)
 		}
 	}
 
-	status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
+	status = cli_posix_readlink(cli1, sname, talloc_tos(), &target);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
 		goto out;
 	}
 
-	if (strcmp(namebuf, fname) != 0) {
+	if (strcmp(target, fname) != 0) {
 		printf("POSIX readlink on %s failed to match name %s (read %s)\n",
-			sname, fname, namebuf);
+			sname, fname, target);
 		goto out;
 	}
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list