[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Aug 29 19:48:01 UTC 2024


The branch, master has been updated
       via  e2c8f718cad s4:torture/smb2: better error handling in create.c
       via  3fd40cb8a90 s4:torture/raw: better error handling in streams.c
       via  28fd1ea4a1b s4:torture/smb2: make use of torture_assert_*_equal_goto() in streams.c
       via  e2a9cd1d02a s4:libcli/smb2: let smb2_deltree delete directory streams
       via  b1b1f2ea6b9 s4:libcli: allow smb2_composite_unlink* to truncate the file before close
       via  41df9e1c74d s3:tests: make use of TMPDIR in test_symlink_traversal_*.sh
       via  87f85350cc6 lib/torture: add torture_assert_nttime_equal_goto()
       via  d73c0e0d482 librpc/ndr: remove unused NDR_PUSH_ALLOC_SIZE()
       via  664eb193432 librpc/ndr: avoid alignment allocation in ndr_push_DATA_BLOB()
      from  df103890f9f libndr: Streamline ndr_token_retrieve_cmp_fn

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


- Log -----------------------------------------------------------------
commit e2c8f718cad576bffad66569cd6e86d87f1d9712
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jul 25 11:58:37 2024 +0200

    s4:torture/smb2: better error handling in create.c
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Thu Aug 29 19:47:54 UTC 2024 on atb-devel-224

commit 3fd40cb8a90ec6a08f80d23a4ea3e782b7acff8a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jul 25 11:06:18 2024 +0200

    s4:torture/raw: better error handling in streams.c
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 28fd1ea4a1b6f5aef060b4dbea14680eb16bdad4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Jul 8 09:05:49 2024 +0200

    s4:torture/smb2: make use of torture_assert_*_equal_goto() in streams.c
    
    We should fail immediately...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit e2a9cd1d02a4182085a59df774f85e57c4448b08
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jul 18 16:22:55 2024 +0200

    s4:libcli/smb2: let smb2_deltree delete directory streams
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit b1b1f2ea6b9d506190b28340bff01d46d2a885e8
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Jul 30 16:33:15 2024 +0200

    s4:libcli: allow smb2_composite_unlink* to truncate the file before close
    
    This is needed to delete streams...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 41df9e1c74d2465f86f21204a06a85b71711f313
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 7 16:28:22 2024 +0200

    s3:tests: make use of TMPDIR in test_symlink_traversal_*.sh
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 87f85350cc688352cdda7d74fdc3f0f674b41c6d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Jul 30 13:57:25 2024 +0200

    lib/torture: add torture_assert_nttime_equal_goto()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15656
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit d73c0e0d482355d79ff3c41cadc566f52f7b0f55
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 29 13:27:48 2024 +0200

    librpc/ndr: remove unused NDR_PUSH_ALLOC_SIZE()
    
    Pair-Programmed-With: Volker Lendecke <vl at samba.org>
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 664eb193432e01dae3c26c083f745d16f0fd5c3d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 29 13:26:04 2024 +0200

    librpc/ndr: avoid alignment allocation in ndr_push_DATA_BLOB()
    
    Pair-Programmed-With: Volker Lendecke <vl at samba.org>
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

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

Summary of changes:
 lib/torture/torture.h                              |  9 +++
 librpc/ndr/libndr.h                                |  6 --
 librpc/ndr/ndr_basic.c                             |  9 ++-
 .../script/tests/test_symlink_traversal_smb1.sh    | 12 ++--
 .../tests/test_symlink_traversal_smb1_posix.sh     | 12 ++--
 .../script/tests/test_symlink_traversal_smb2.sh    | 12 ++--
 source4/libcli/raw/interfaces.h                    |  6 ++
 source4/libcli/smb2/util.c                         | 46 +++++++++++++-
 source4/libcli/smb_composite/smb2.c                | 63 +++++++++++++++++++
 source4/torture/raw/streams.c                      | 31 ++-------
 source4/torture/smb2/create.c                      | 61 +++++++-----------
 source4/torture/smb2/streams.c                     | 73 ++++------------------
 12 files changed, 188 insertions(+), 152 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/torture/torture.h b/lib/torture/torture.h
index 2194703d5fc..4ef0d88735b 100644
--- a/lib/torture/torture.h
+++ b/lib/torture/torture.h
@@ -771,6 +771,15 @@ static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
 	}\
 	} while(0)
 
+#define torture_assert_nttime_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
+	do { NTTIME __got = got, __expected = expected; \
+	if (!nt_time_equal(&__got, &__expected)) { \
+		torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_time_string(torture_ctx, __got), nt_time_string(torture_ctx, __expected), cmt); \
+		ret = false; \
+		goto label; \
+	}\
+	} while(0)
+
 #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
 	do {const struct dom_sid *__got = (got), *__expected = (expected); \
 	if (!dom_sid_equal(__got, __expected)) { \
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index 223501ab781..02ef2836c1a 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -515,12 +515,6 @@ enum ndr_compression_alg {
 	if (unlikely(!(s))) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %zu * %s failed: %s\n", (size_t)n, # s, __location__); \
 } while (0)
 
-
-#define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \
-       (s) = talloc_array(ndr, uint8_t, size); \
-       if (unlikely(!(s))) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %zu failed: %s\n", (size_t)size, __location__); \
-} while (0)
-
 #define NDR_PUSH_ALLOC(ndr, s) do { \
        (s) = talloc_ptrtype(ndr, (s)); \
        if (unlikely(!(s))) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %s failed: %s\n", # s, __location__); \
diff --git a/librpc/ndr/ndr_basic.c b/librpc/ndr/ndr_basic.c
index 5fd15730a74..8b4b85b9c81 100644
--- a/librpc/ndr/ndr_basic.c
+++ b/librpc/ndr/ndr_basic.c
@@ -1404,18 +1404,23 @@ _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_
  */
 _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, ndr_flags_type ndr_flags, DATA_BLOB blob)
 {
+	static const uint8_t padding[8] = { 0, };
+
 	if (ndr->flags & LIBNDR_FLAG_REMAINING) {
 		/* nothing to do */
 	} else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
+		blob.data = discard_const_p(uint8_t, padding);
 		if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
 			blob.length = NDR_ALIGN(ndr, 2);
 		} else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
 			blob.length = NDR_ALIGN(ndr, 4);
 		} else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
 			blob.length = NDR_ALIGN(ndr, 8);
+		} else {
+			return ndr_push_error(ndr,
+					      NDR_ERR_LENGTH,
+					      "Invalid align flags");
 		}
-		NDR_PUSH_ALLOC_SIZE(ndr, blob.data, blob.length);
-		data_blob_clear(&blob);
 	} else {
 		NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length));
 	}
diff --git a/source3/script/tests/test_symlink_traversal_smb1.sh b/source3/script/tests/test_symlink_traversal_smb1.sh
index ff38210e95b..331f492c06c 100755
--- a/source3/script/tests/test_symlink_traversal_smb1.sh
+++ b/source3/script/tests/test_symlink_traversal_smb1.sh
@@ -32,15 +32,15 @@ share_test_dir="$LOCAL_PATH"
 #
 # These files/directories will be created.
 #
-file_outside_share="/tmp/symlink_traverse_test_file.$$"
-dir_outside_share="/tmp/symlink_traverse_test_dir.$$"
-file_outside_share_noperms="/tmp/symlink_traverse_test_file_noperm.$$"
-dir_outside_share_noperms="/tmp/symlink_traverse_test_dir_noperm.$$"
+file_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_file.$$"
+dir_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_dir.$$"
+file_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_file_noperm.$$"
+dir_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noperm.$$"
 #
 # These two objects do not exist.
 #
-file_outside_share_noexist="/tmp/symlink_traverse_test_noexist.$$"
-dir_outside_share_noexist="/tmp/symlink_traverse_test_dir_noexist.$$"
+file_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_noexist.$$"
+dir_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noexist.$$"
 
 #
 # Cleanup function.
diff --git a/source3/script/tests/test_symlink_traversal_smb1_posix.sh b/source3/script/tests/test_symlink_traversal_smb1_posix.sh
index 52d6cfb9e3d..93f0ff6f988 100755
--- a/source3/script/tests/test_symlink_traversal_smb1_posix.sh
+++ b/source3/script/tests/test_symlink_traversal_smb1_posix.sh
@@ -32,15 +32,15 @@ share_test_dir="$LOCAL_PATH"
 #
 # These files/directories will be created.
 #
-file_outside_share="/tmp/symlink_traverse_test_file.$$"
-dir_outside_share="/tmp/symlink_traverse_test_dir.$$"
-file_outside_share_noperms="/tmp/symlink_traverse_test_file_noperm.$$"
-dir_outside_share_noperms="/tmp/symlink_traverse_test_dir_noperm.$$"
+file_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_file.$$"
+dir_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_dir.$$"
+file_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_file_noperm.$$"
+dir_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noperm.$$"
 #
 # These two objects do not exist.
 #
-file_outside_share_noexist="/tmp/symlink_traverse_test_noexist.$$"
-dir_outside_share_noexist="/tmp/symlink_traverse_test_dir_noexist.$$"
+file_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_noexist.$$"
+dir_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noexist.$$"
 
 #
 # Cleanup function.
diff --git a/source3/script/tests/test_symlink_traversal_smb2.sh b/source3/script/tests/test_symlink_traversal_smb2.sh
index 38719cc8eae..6688888986b 100755
--- a/source3/script/tests/test_symlink_traversal_smb2.sh
+++ b/source3/script/tests/test_symlink_traversal_smb2.sh
@@ -32,15 +32,15 @@ share_test_dir="$LOCAL_PATH"
 #
 # These files/directories will be created.
 #
-file_outside_share="/tmp/symlink_traverse_test_file.$$"
-dir_outside_share="/tmp/symlink_traverse_test_dir.$$"
-file_outside_share_noperms="/tmp/symlink_traverse_test_file_noperm.$$"
-dir_outside_share_noperms="/tmp/symlink_traverse_test_dir_noperm.$$"
+file_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_file.$$"
+dir_outside_share="${TMPDIR:-/tmp}/symlink_traverse_test_dir.$$"
+file_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_file_noperm.$$"
+dir_outside_share_noperms="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noperm.$$"
 #
 # These two objects do not exist.
 #
-file_outside_share_noexist="/tmp/symlink_traverse_test_noexist.$$"
-dir_outside_share_noexist="/tmp/symlink_traverse_test_dir_noexist.$$"
+file_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_noexist.$$"
+dir_outside_share_noexist="${TMPDIR:-/tmp}/symlink_traverse_test_dir_noexist.$$"
 
 #
 # Cleanup function.
diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h
index 6abc06df77d..397db161f9a 100644
--- a/source4/libcli/raw/interfaces.h
+++ b/source4/libcli/raw/interfaces.h
@@ -139,6 +139,12 @@ union smb_unlink {
 		struct {
 			const char *pattern;
 			uint16_t attrib;
+
+			/*
+			 * only used by
+			 * smb2_composite_unlink*
+			 */
+			bool truncate_if_needed;
 		} in;
 	} unlink;
 };
diff --git a/source4/libcli/smb2/util.c b/source4/libcli/smb2/util.c
index f86a149c646..ef67d33c94b 100644
--- a/source4/libcli/smb2/util.c
+++ b/source4/libcli/smb2/util.c
@@ -183,6 +183,7 @@ int smb2_deltree(struct smb2_tree *tree, const char *dname)
 	TALLOC_CTX *tmp_ctx = talloc_new(tree);
 	struct smb2_find f;
 	struct smb2_create create_parm;
+	union smb_fileinfo finfo;
 	bool did_delete;
 
 	/* it might be a file */
@@ -223,7 +224,50 @@ int smb2_deltree(struct smb2_tree *tree, const char *dname)
 		talloc_free(tmp_ctx);
 		return -1;
 	}
-	
+
+	ZERO_STRUCT(finfo);
+	finfo.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
+	finfo.generic.in.file.handle = create_parm.out.file.handle;
+
+	status = smb2_getinfo_file(tree, tmp_ctx, &finfo);
+	if (NT_STATUS_IS_OK(status)) {
+		/*
+		 * For directories we need to cleanup
+		 * streams manually
+		 */
+		for (i = 0; i < finfo.stream_info.out.num_streams; i++) {
+			const struct stream_struct *s =
+				&finfo.stream_info.out.streams[i];
+			union smb_unlink io;
+			char *spath = NULL;
+
+			if (strequal(s->stream_name.s, "::$DATA")) {
+				/* should not happen for directories */
+				continue;
+			}
+
+			spath = talloc_asprintf(tmp_ctx,
+						"%s%s",
+						dname,
+						s->stream_name.s);
+			if (spath == NULL) {
+				talloc_free(tmp_ctx);
+				return -1;
+			}
+
+			ZERO_STRUCT(io);
+			io.unlink.in.pattern = spath;
+			if (s->alloc_size != 0) {
+				io.unlink.in.truncate_if_needed = true;
+			}
+
+			status = smb2_composite_unlink(tree, &io);
+			TALLOC_FREE(spath);
+			if (NT_STATUS_IS_OK(status)) {
+				total_deleted++;
+			}
+		}
+	}
 
 	do {
 		did_delete = false;
diff --git a/source4/libcli/smb_composite/smb2.c b/source4/libcli/smb_composite/smb2.c
index 0fa51b28579..d2a4a851a76 100644
--- a/source4/libcli/smb_composite/smb2.c
+++ b/source4/libcli/smb_composite/smb2.c
@@ -47,6 +47,38 @@ static void continue_close(struct smb2_request *req)
 	composite_error(ctx, status);	
 }
 
+struct smb2_composite_unlink_state {
+	bool truncate_if_needed;
+	struct smb2_handle handle;
+};
+
+/*
+  continue after the truncate in a composite unlink
+ */
+static void continue_truncate(struct smb2_request *req)
+{
+	struct composite_context *ctx = talloc_get_type(req->async.private_data,
+							struct composite_context);
+	struct smb2_composite_unlink_state *state =
+		talloc_get_type_abort(ctx->private_data,
+		struct smb2_composite_unlink_state);
+	struct smb2_tree *tree = req->tree;
+	struct smb2_close close_parm;
+	NTSTATUS status;
+
+	status = smb2_setinfo_recv(req);
+	if (!NT_STATUS_IS_OK(status)) {
+		/* we ignore errors as we should not leak the handle */
+	}
+
+	ZERO_STRUCT(close_parm);
+	close_parm.in.file.handle = state->handle;
+	close_parm.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+
+	req = smb2_close_send(tree, &close_parm);
+	composite_continue_smb2(ctx, req, continue_close, ctx);
+}
+
 /*
   continue after the create in a composite unlink
  */
@@ -54,6 +86,9 @@ static void continue_unlink(struct smb2_request *req)
 {
 	struct composite_context *ctx = talloc_get_type(req->async.private_data, 
 							struct composite_context);
+	struct smb2_composite_unlink_state *state =
+		talloc_get_type_abort(ctx->private_data,
+		struct smb2_composite_unlink_state);
 	struct smb2_tree *tree = req->tree;
 	struct smb2_create create_parm;
 	struct smb2_close close_parm;
@@ -65,6 +100,23 @@ static void continue_unlink(struct smb2_request *req)
 		return;
 	}
 
+	if (create_parm.out.size != 0 &&
+	    state->truncate_if_needed)
+	{
+		union smb_setfileinfo sinfo;
+
+		state->handle = create_parm.out.file.handle;
+
+		ZERO_STRUCT(sinfo);
+		sinfo.end_of_file_info.level =
+			RAW_SFILEINFO_END_OF_FILE_INFORMATION;
+		sinfo.end_of_file_info.in.file.handle = state->handle;
+		sinfo.end_of_file_info.in.size = 0;
+		req = smb2_setinfo_file_send(tree, &sinfo);
+		composite_continue_smb2(ctx, req, continue_truncate, ctx);
+		return;
+	}
+
 	ZERO_STRUCT(close_parm);
 	close_parm.in.file.handle = create_parm.out.file.handle;
 	
@@ -79,12 +131,20 @@ struct composite_context *smb2_composite_unlink_send(struct smb2_tree *tree,
 						     union smb_unlink *io)
 {
 	struct composite_context *ctx;
+	struct smb2_composite_unlink_state *state = NULL;
 	struct smb2_create create_parm;
 	struct smb2_request *req;
 
 	ctx = composite_create(tree, tree->session->transport->ev);
 	if (ctx == NULL) return NULL;
 
+	state = talloc_zero(ctx, struct smb2_composite_unlink_state);
+	if (composite_nomem(state, ctx)) {
+		return ctx;
+	}
+	ctx->private_data = state;
+	state->truncate_if_needed = io->unlink.in.truncate_if_needed;
+
 	/* check for wildcards - we could support these with a
 	   search, but for now they aren't necessary */
 	if (strpbrk(io->unlink.in.pattern, "*?<>") != NULL) {
@@ -94,6 +154,9 @@ struct composite_context *smb2_composite_unlink_send(struct smb2_tree *tree,
 
 	ZERO_STRUCT(create_parm);
 	create_parm.in.desired_access     = SEC_STD_DELETE;
+	if (state->truncate_if_needed) {
+		create_parm.in.desired_access |= SEC_FILE_WRITE_DATA;
+	}
 	create_parm.in.create_disposition = NTCREATEX_DISP_OPEN;
 	create_parm.in.share_access = 
 		NTCREATEX_SHARE_ACCESS_DELETE|
diff --git a/source4/torture/raw/streams.c b/source4/torture/raw/streams.c
index 0eb5bdd6390..90531499df3 100644
--- a/source4/torture/raw/streams.c
+++ b/source4/torture/raw/streams.c
@@ -42,23 +42,8 @@
 #define CHECK_NTTIME(v, correct) \
 	torture_assert_u64_equal(tctx,v,correct,"CHECK_NTTIME")
 
-#define CHECK_STR(v, correct) do { \
-	bool ok; \
-	if ((v) && !(correct)) { \
-		ok = false; \
-	} else if (!(v) && (correct)) { \
-		ok = false; \
-	} else if (!(v) && !(correct)) { \
-		ok = true; \
-	} else if (strcmp((v), (correct)) == 0) { \
-		ok = true; \
-	} else { \
-		ok = false; \
-	} \
-	torture_assert(tctx,ok,\
-		       talloc_asprintf(tctx, "got '%s', expected '%s'",\
-		       (v)?(v):"NULL", (correct)?(correct):"NULL")); \
-} while (0)
+#define CHECK_STR(v, correct) \
+	torture_assert_str_equal(tctx,v,correct,"CHECK_STR")
 
 /*
   check that a stream has the right contents
@@ -1092,18 +1077,12 @@ done:
         sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
         sfinfo.generic.in.file.fnum = fnum; \
         status = smb_raw_setfileinfo(cli->tree, &sfinfo); \
-        if (!NT_STATUS_EQUAL(status, rightstatus)) { \
-                printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
-                        nt_errstr(status), nt_errstr(rightstatus)); \
-                ret = false; \
-        } \
+        torture_assert_ntstatus_equal_goto(tctx, status, rightstatus, ret, done, #call); \
         finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
         finfo1.generic.in.file.fnum = fnum; \
         status2 = smb_raw_fileinfo(cli->tree, tctx, &finfo1); \
-        if (!NT_STATUS_IS_OK(status2)) { \
-                printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status)); \
-                ret = false; \
-        }} while (0)
+        torture_assert_ntstatus_ok_goto(tctx, status2, ret, done, "ALL_INFO"); \
+} while (0)
 
 /*
   test stream renames
diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c
index 18e76565f80..756256dc4f5 100644
--- a/source4/torture/smb2/create.c
+++ b/source4/torture/smb2/create.c
@@ -114,18 +114,18 @@
 		ret = false; \
 	}} while (0)
 
-#define SET_ATTRIB(sattrib) do { \
+#define SET_ATTRIB(sattrib, expected_status) do { \
 	union smb_setfileinfo sfinfo; \
 	ZERO_STRUCT(sfinfo.basic_info.in); \
 	sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
 	sfinfo.basic_info.in.file.handle = h1; \
 	sfinfo.basic_info.in.attrib = sattrib; \
 	status = smb2_setinfo_file(tree, &sfinfo); \
-	if (!NT_STATUS_IS_OK(status)) { \
-		torture_comment(tctx, \
-		    "(%s) Failed to set attrib 0x%x on %s\n", \
-		       __location__, (unsigned int)(sattrib), fname); \
-	}} while (0)
+	torture_assert_ntstatus_equal(tctx, status, expected_status, \
+		talloc_asprintf(tctx, \
+		"(%s) Failed to set attrib 0x%x on %s\n", \
+		 __location__, (unsigned int)(sattrib), fname)); \
+} while (0)
 
 /*
   test some interesting combinations found by gentest
@@ -759,30 +759,21 @@ static bool test_smb2_open(struct torture_context *tctx,
 		if (open_funcs[i].with_file) {
 			io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
 			status= smb2_create(tree, tctx, &(io.smb2));
-			if (!NT_STATUS_IS_OK(status)) {
-				torture_comment(tctx,
+			torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+				talloc_asprintf(tctx,
 				    "Failed to create file %s status %s %zu\n",
-				    fname, nt_errstr(status), i);
-
-				ret = false;
-				goto done;
-			}
+				    fname, nt_errstr(status), i));
 			smb2_util_close(tree, io.smb2.out.file.handle);
 		}
 		io.smb2.in.create_disposition = open_funcs[i].create_disp;
 		status = smb2_create(tree, tctx, &(io.smb2));
-		if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
-			torture_comment(tctx,
-			    "(%s) incorrect status %s should be %s (i=%zu "
-			    "with_file=%d open_disp=%d)\n",
-			 __location__, nt_errstr(status),
-			nt_errstr(open_funcs[i].correct_status),
-			i, (int)open_funcs[i].with_file,
-			(int)open_funcs[i].create_disp);
-
-			ret = false;
-			goto done;
-		}
+		torture_assert_ntstatus_equal_goto(tctx, status,
+					open_funcs[i].correct_status,
+					ret, done,
+					talloc_asprintf(tctx,
+					"(i=%zu with_file=%d open_disp=%d)\n",
+					i, (int)open_funcs[i].with_file,
+					(int)open_funcs[i].create_disp));
 		if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
 			smb2_util_close(tree, io.smb2.out.file.handle);
 			smb2_util_unlink(tree, fname);
@@ -991,8 +982,7 @@ static bool test_smb2_open_multi(struct torture_context *tctx,
 		if (!torture_smb2_connection(tctx, &(trees[i]))) {
 			torture_comment(tctx,
 				"Could not open %d'th connection\n", i);
-			ret = false;
-			goto done;
+			torture_assert_goto(tctx, false, ret, done, __location__);
 		}
 		trees[i]->session->transport->options.request_timeout = 60;
 	}
@@ -1024,8 +1014,7 @@ static bool test_smb2_open_multi(struct torture_context *tctx,
 		if (requests[i] == NULL) {
 			torture_comment(tctx,
 				"could not send %d'th request\n", i);
-			ret = false;
-			goto done;
+			torture_assert_goto(tctx, false, ret, done, __location__);
 		}
 	}
 
@@ -1064,13 +1053,12 @@ static bool test_smb2_open_multi(struct torture_context *tctx,
 
 		if (tevent_loop_once(tctx->ev) != 0) {
 			torture_comment(tctx, "tevent_loop_once failed\n");
-			ret = false;
-			goto done;
+			torture_assert_goto(tctx, false, ret, done, __location__);
 		}
 	}
 
 	if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
-		ret = false;
+		torture_assert_goto(tctx, false, ret, done, __location__);
 	}
 done:
 	smb2_deltree(tree, fname);
@@ -1143,7 +1131,7 @@ static bool test_smb2_open_for_delete(struct torture_context *tctx,
 	status = smb2_create(tree, tctx, &(io.smb2));
 	CHECK_STATUS(status, NT_STATUS_OK);
 	h1 = io.smb2.out.file.handle;
-	SET_ATTRIB(FILE_ATTRIBUTE_ARCHIVE);
+	SET_ATTRIB(FILE_ATTRIBUTE_ARCHIVE, NT_STATUS_OK);
 	smb2_util_close(tree, h1);
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list