2 Unix SMB/CIFS implementation.
4 test suite for SMB2 write operations
6 Copyright (C) Andrew Tridgell 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "librpc/gen_ndr/security.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 #define FNAME "testmaxwrite.dat"
34 static NTSTATUS
torture_smb2_write(struct torture_context
*tctx
,
35 struct smb2_tree
*tree
,
36 struct smb2_handle handle
)
46 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
52 w
.in
.file
.handle
= handle
;
54 w
.in
.data
= data_blob_talloc(tmp_ctx
, NULL
, len
);
57 w
.in
.data
.data
[i
] = i
% 256;
60 torture_comment(tctx
, "trying to write %d bytes (min=%d max=%d)\n",
63 status
= smb2_write(tree
, &w
);
64 if (!NT_STATUS_IS_OK(status
)) {
65 torture_comment(tctx
, "write failed - %s\n", nt_errstr(status
));
67 status
= smb2_util_close(tree
, handle
);
68 if (!NT_STATUS_IS_OK(status
)) {
70 torture_comment(tctx
, "coping with server disconnect\n");
72 if (!torture_smb2_connection(tctx
, &tree
)) {
73 torture_comment(tctx
, "failed to reconnect\n");
74 return NT_STATUS_NET_WRITE_FAULT
;
77 status
= torture_smb2_createfile(tctx
, tree
, FNAME
, &handle
);
78 if (!NT_STATUS_IS_OK(status
)) {
79 torture_comment(tctx
, "failed to create file handle\n");
90 r
.in
.file
.handle
= handle
;
94 torture_comment(tctx
, "reading %d bytes\n", len
);
96 status
= smb2_read(tree
, tmp_ctx
, &r
);
97 if (!NT_STATUS_IS_OK(status
)) {
98 torture_comment(tctx
, "read failed - %s\n", nt_errstr(status
));
99 } else if (w
.in
.data
.length
!= r
.out
.data
.length
||
100 memcmp(w
.in
.data
.data
, r
.out
.data
.data
, len
) != 0) {
101 torture_comment(tctx
, "read data mismatch\n");
104 talloc_free(tmp_ctx
);
107 torture_comment(tctx
, "converged: len=%d\n", max
);
108 smb2_util_close(tree
, handle
);
109 smb2_util_unlink(tree
, FNAME
);
117 basic testing of SMB2 connection calls
119 bool torture_smb2_maxwrite(struct torture_context
*tctx
)
121 struct smb2_tree
*tree
;
122 struct smb2_handle h1
;
124 if (!torture_smb2_connection(tctx
, &tree
)) {
128 torture_assert_ntstatus_ok(tctx
,
129 torture_smb2_createfile(tctx
, tree
, FNAME
, &h1
),
130 "failed to create file handle");
132 torture_assert_ntstatus_ok(tctx
,
133 torture_smb2_write(tctx
, tree
, h1
),