2 Unix SMB/CIFS implementation.
4 test suite for SMB2 oplocks
6 Copyright (C) Stefan Metzmacher 2008
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 CHECK_VAL(v, correct) do { \
30 if ((v) != (correct)) { \
31 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
32 __location__, #v, (int)v, (int)correct); \
36 #define CHECK_STATUS(status, correct) do { \
37 if (!NT_STATUS_EQUAL(status, correct)) { \
38 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
39 nt_errstr(status), nt_errstr(correct)); \
45 struct smb2_handle handle
;
52 static void torture_oplock_break_callback(struct smb2_request
*req
)
58 status
= smb2_break_recv(req
, &break_info
.br
);
59 if (!NT_STATUS_IS_OK(status
)) {
60 break_info
.failures
++;
66 /* a oplock break request handler */
67 static bool torture_oplock_handler(struct smb2_transport
*transport
,
68 const struct smb2_handle
*handle
,
69 uint8_t level
, void *private_data
)
71 struct smb2_tree
*tree
= private_data
;
73 struct smb2_request
*req
;
75 break_info
.handle
= *handle
;
76 break_info
.level
= level
;
80 case SMB2_OPLOCK_LEVEL_II
:
83 case SMB2_OPLOCK_LEVEL_NONE
:
88 break_info
.failures
++;
90 printf("Acking to %s [0x%02X] in oplock handler\n",
93 ZERO_STRUCT(break_info
.br
);
94 break_info
.br
.in
.file
.handle
= *handle
;
95 break_info
.br
.in
.oplock_level
= level
;
96 break_info
.br
.in
.reserved
= 0;
97 break_info
.br
.in
.reserved2
= 0;
99 req
= smb2_break_send(tree
, &break_info
.br
);
100 req
->async
.fn
= torture_oplock_break_callback
;
101 req
->async
.private_data
= NULL
;
106 bool torture_smb2_oplock_batch1(struct torture_context
*tctx
,
107 struct smb2_tree
*tree
)
109 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
110 struct smb2_handle h1
, h2
;
111 struct smb2_create io
;
113 const char *fname
= "oplock.dat";
116 tree
->session
->transport
->oplock
.handler
= torture_oplock_handler
;
117 tree
->session
->transport
->oplock
.private_data
= tree
;
119 smb2_util_unlink(tree
, fname
);
121 ZERO_STRUCT(break_info
);
124 io
.in
.security_flags
= 0x00;
125 io
.in
.oplock_level
= SMB2_OPLOCK_LEVEL_BATCH
;
126 io
.in
.impersonation_level
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
127 io
.in
.create_flags
= 0x00000000;
128 io
.in
.reserved
= 0x00000000;
129 io
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
130 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
131 io
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
132 NTCREATEX_SHARE_ACCESS_WRITE
|
133 NTCREATEX_SHARE_ACCESS_DELETE
;
134 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN_IF
;
135 io
.in
.create_options
= NTCREATEX_OPTIONS_SEQUENTIAL_ONLY
|
136 NTCREATEX_OPTIONS_ASYNC_ALERT
|
137 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
|
141 status
= smb2_create(tree
, mem_ctx
, &io
);
142 CHECK_STATUS(status
, NT_STATUS_OK
);
143 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
144 /*CHECK_VAL(io.out.reserved, 0);*/
145 CHECK_VAL(io
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
146 CHECK_VAL(io
.out
.alloc_size
, 0);
147 CHECK_VAL(io
.out
.size
, 0);
148 CHECK_VAL(io
.out
.file_attr
, FILE_ATTRIBUTE_ARCHIVE
);
149 CHECK_VAL(io
.out
.reserved2
, 0);
150 CHECK_VAL(break_info
.count
, 0);
152 h1
= io
.out
.file
.handle
;
154 ZERO_STRUCT(io
.in
.blobs
);
155 status
= smb2_create(tree
, mem_ctx
, &io
);
156 CHECK_VAL(break_info
.count
, 1);
157 CHECK_VAL(break_info
.failures
, 0);
158 CHECK_VAL(break_info
.level
, SMB2_OPLOCK_LEVEL_II
);
159 CHECK_STATUS(status
, NT_STATUS_OK
);
160 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_II
);
161 /*CHECK_VAL(io.out.reserved, 0);*/
162 CHECK_VAL(io
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
163 CHECK_VAL(io
.out
.alloc_size
, 0);
164 CHECK_VAL(io
.out
.size
, 0);
165 CHECK_VAL(io
.out
.file_attr
, FILE_ATTRIBUTE_ARCHIVE
);
166 CHECK_VAL(io
.out
.reserved2
, 0);
168 h2
= io
.out
.file
.handle
;
171 talloc_free(mem_ctx
);
173 smb2_util_close(tree
, h1
);
174 smb2_util_close(tree
, h2
);
175 smb2_util_unlink(tree
, fname
);