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"
28 #include "param/param.h"
30 #define CHECK_VAL(v, correct) do { \
31 if ((v) != (correct)) { \
32 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
33 __location__, #v, (int)v, (int)correct); \
37 #define CHECK_STATUS(status, correct) do { \
38 if (!NT_STATUS_EQUAL(status, correct)) { \
39 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
40 nt_errstr(status), nt_errstr(correct)); \
46 struct smb2_handle handle;
53 static void torture_oplock_break_callback(struct smb2_request *req)
59 status = smb2_break_recv(req, &break_info.br);
60 if (!NT_STATUS_IS_OK(status)) {
61 break_info.failures++;
67 /* a oplock break request handler */
68 static bool torture_oplock_handler(struct smb2_transport *transport,
69 const struct smb2_handle *handle,
70 uint8_t level, void *private_data)
72 struct smb2_tree *tree = private_data;
74 struct smb2_request *req;
76 break_info.handle = *handle;
77 break_info.level = level;
81 case SMB2_OPLOCK_LEVEL_II:
84 case SMB2_OPLOCK_LEVEL_NONE:
89 break_info.failures++;
91 printf("Acking to %s [0x%02X] in oplock handler\n",
94 ZERO_STRUCT(break_info.br);
95 break_info.br.in.file.handle = *handle;
96 break_info.br.in.oplock_level = level;
97 break_info.br.in.reserved = 0;
98 break_info.br.in.reserved2 = 0;
100 req = smb2_break_send(tree, &break_info.br);
101 req->async.fn = torture_oplock_break_callback;
102 req->async.private_data = NULL;
107 bool torture_smb2_oplock_batch1(struct torture_context *tctx,
108 struct smb2_tree *tree)
110 TALLOC_CTX *mem_ctx = talloc_new(tctx);
111 struct smb2_handle h1, h2;
112 struct smb2_create io;
114 const char *fname = "oplock.dat";
117 tree->session->transport->oplock.handler = torture_oplock_handler;
118 tree->session->transport->oplock.private_data = tree;
120 smb2_util_unlink(tree, fname);
122 ZERO_STRUCT(break_info);
125 io.in.security_flags = 0x00;
126 io.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH;
127 io.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
128 io.in.create_flags = 0x00000000;
129 io.in.reserved = 0x00000000;
130 io.in.desired_access = SEC_RIGHTS_FILE_ALL;
131 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
132 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
133 NTCREATEX_SHARE_ACCESS_WRITE |
134 NTCREATEX_SHARE_ACCESS_DELETE;
135 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
136 io.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
137 NTCREATEX_OPTIONS_ASYNC_ALERT |
138 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
142 status = smb2_create(tree, mem_ctx, &io);
143 CHECK_STATUS(status, NT_STATUS_OK);
144 CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
145 /*CHECK_VAL(io.out.reserved, 0);*/
146 CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_CREATED);
147 CHECK_VAL(io.out.alloc_size, 0);
148 CHECK_VAL(io.out.size, 0);
149 CHECK_VAL(io.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
150 CHECK_VAL(io.out.reserved2, 0);
151 CHECK_VAL(break_info.count, 0);
153 h1 = io.out.file.handle;
155 ZERO_STRUCT(io.in.blobs);
156 status = smb2_create(tree, mem_ctx, &io);
157 CHECK_VAL(break_info.count, 1);
158 CHECK_VAL(break_info.failures, 0);
159 CHECK_VAL(break_info.level, SMB2_OPLOCK_LEVEL_II);
160 CHECK_STATUS(status, NT_STATUS_OK);
161 CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_II);
162 /*CHECK_VAL(io.out.reserved, 0);*/
163 CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_EXISTED);
164 CHECK_VAL(io.out.alloc_size, 0);
165 CHECK_VAL(io.out.size, 0);
166 CHECK_VAL(io.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
167 CHECK_VAL(io.out.reserved2, 0);
169 h2 = io.out.file.handle;
172 talloc_free(mem_ctx);
174 smb2_util_close(tree, h1);
175 smb2_util_close(tree, h2);
176 smb2_util_unlink(tree, fname);