Debian Codegraph @

source4/torture/smb2/notify.c

raw
1 /*
2 Unix SMB/CIFS implementation.
3
4 SMB2 notify test suite
5
6 Copyright (C) Stefan Metzmacher 2006
7 Copyright (C) Andrew Tridgell 2009
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "../libcli/smb/smbXcli_base.h"
27
28 #include "torture/torture.h"
29 #include "torture/smb2/proto.h"
30 #include "librpc/gen_ndr/ndr_security.h"
31 #include "libcli/security/security.h"
32 #include "torture/util.h"
33
34 #include "system/filesys.h"
35 #include "auth/credentials/credentials.h"
36 #include "lib/cmdline/cmdline.h"
37 #include "librpc/gen_ndr/security.h"
38
39 #include "lib/events/events.h"
40
41 #include "libcli/raw/libcliraw.h"
42 #include "libcli/raw/raw_proto.h"
43 #include "libcli/libcli.h"
44
45 #define CHECK_STATUS(status, correct) do { \
46 if (!NT_STATUS_EQUAL(status, correct)) { \
47 torture_result(torture, TORTURE_FAIL, \
48 "(%s) Incorrect status %s - should be %s\n", \
49 __location__, nt_errstr(status), nt_errstr(correct)); \
50 ret = false; \
51 goto done; \
52 }} while (0)
53
54 #define CHECK_VAL(v, correct) do { \
55 if ((v) != (correct)) { \
56 torture_result(torture, TORTURE_FAIL, \
57 "(%s) wrong value for %s 0x%x should be 0x%x\n", \
58 __location__, #v, (int)v, (int)correct); \
59 ret = false; \
60 goto done; \
61 }} while (0)
62
63 #define CHECK_WIRE_STR(field, value) do { \
64 if (!field.s || strcmp(field.s, value)) { \
65 torture_result(torture, TORTURE_FAIL, \
66 "(%s) %s [%s] != %s\n", __location__, #field, \
67 field.s, value); \
68 ret = false; \
69 goto done; \
70 }} while (0)
71
72 #define WAIT_FOR_ASYNC_RESPONSE(req) \
73 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) { \
74 if (tevent_loop_once(torture->ev) != 0) { \
75 break; \
76 } \
77 }
78
79 #define BASEDIR "test_notify"
80 #define FNAME "smb2-notify01.dat"
81
82 static bool test_valid_request(struct torture_context *torture,
83 struct smb2_tree *tree)
84 {
85 bool ret = true;
86 NTSTATUS status;
87 struct smb2_handle dh;
88 struct smb2_notify n;
89 struct smb2_request *req;
90 uint32_t max_buffer_size;
91
92 torture_comment(torture, "TESTING VALIDITY OF CHANGE NOTIFY REQUEST\n");
93
94 smb2_transport_credits_ask_num(tree->session->transport, 256);
95
96 smb2_util_unlink(tree, FNAME);
97
98 status = smb2_util_roothandle(tree, &dh);
99 CHECK_STATUS(status, NT_STATUS_OK);
100
101 max_buffer_size =
102 smb2cli_conn_max_trans_size(tree->session->transport->conn);
103
104 n.in.recursive = 0x0000;
105 n.in.buffer_size = max_buffer_size;
106 n.in.file.handle = dh;
107 n.in.completion_filter = FILE_NOTIFY_CHANGE_ALL;
108 n.in.unknown = 0x00000000;
109 req = smb2_notify_send(tree, &n);
110
111 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
112 if (tevent_loop_once(torture->ev) != 0) {
113 break;
114 }
115 }
116
117 status = torture_setup_simple_file(torture, tree, FNAME);
118 CHECK_STATUS(status, NT_STATUS_OK);
119
120 status = smb2_notify_recv(req, torture, &n);
121 CHECK_STATUS(status, NT_STATUS_OK);
122 CHECK_VAL(n.out.num_changes, 1);
123 CHECK_VAL(n.out.changes[0].action, NOTIFY_ACTION_ADDED);
124 CHECK_WIRE_STR(n.out.changes[0].name, FNAME);
125
126 /*
127 * if the change response doesn't fit in the buffer
128 * NOTIFY_ENUM_DIR is returned.
129 */
130 n.in.buffer_size = 0x00000000;
131 req = smb2_notify_send(tree, &n);
132
133 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
134 if (tevent_loop_once(torture->ev) != 0) {
135 break;
136 }
137 }
138
139 status = torture_setup_simple_file(torture, tree, FNAME);
140 CHECK_STATUS(status, NT_STATUS_OK);
141
142 status = smb2_notify_recv(req, torture, &n);
143 CHECK_STATUS(status, NT_STATUS_NOTIFY_ENUM_DIR);
144
145 /*
146 * if the change response fits in the buffer we get
147 * NT_STATUS_OK again
148 */
149 n.in.buffer_size = max_buffer_size;
150 req = smb2_notify_send(tree, &n);
151
152 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
153 if (tevent_loop_once(torture->ev) != 0) {
154 break;
155 }
156 }
157
158 status = torture_setup_simple_file(torture, tree, FNAME);
159 CHECK_STATUS(status, NT_STATUS_OK);
160
161 status = smb2_notify_recv(req, torture, &n);
162 CHECK_STATUS(status, NT_STATUS_OK);
163 CHECK_VAL(n.out.num_changes, 3);
164 CHECK_VAL(n.out.changes[0].action, NOTIFY_ACTION_REMOVED);
165 CHECK_WIRE_STR(n.out.changes[0].name, FNAME);
166 CHECK_VAL(n.out.changes[1].action, NOTIFY_ACTION_ADDED);
167 CHECK_WIRE_STR(n.out.changes[1].name, FNAME);
168 CHECK_VAL(n.out.changes[2].action, NOTIFY_ACTION_MODIFIED);
169 CHECK_WIRE_STR(n.out.changes[2].name, FNAME);
170
171 /* if the first notify returns NOTIFY_ENUM_DIR, all do */
172 status = smb2_util_close(tree, dh);
173 CHECK_STATUS(status, NT_STATUS_OK);
174 status = smb2_util_roothandle(tree, &dh);
175 CHECK_STATUS(status, NT_STATUS_OK);
176
177 n.in.recursive = 0x0000;
178 n.in.buffer_size = 0x00000001;
179 n.in.file.handle = dh;
180 n.in.completion_filter = FILE_NOTIFY_CHANGE_ALL;
181 n.in.unknown = 0x00000000;
182 req = smb2_notify_send(tree, &n);
183
184 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
185 if (tevent_loop_once(torture->ev) != 0) {
186 break;
187 }
188 }
189
190 status = torture_setup_simple_file(torture, tree, FNAME);
191 CHECK_STATUS(status, NT_STATUS_OK);
192
193 status = smb2_notify_recv(req, torture, &n);
194 CHECK_STATUS(status, NT_STATUS_NOTIFY_ENUM_DIR);
195
196 n.in.buffer_size = max_buffer_size;
197 req = smb2_notify_send(tree, &n);
198 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
199 if (tevent_loop_once(torture->ev) != 0) {
200 break;
201 }
202 }
203
204 status = torture_setup_simple_file(torture, tree, FNAME);
205 CHECK_STATUS(status, NT_STATUS_OK);
206
207 status = smb2_notify_recv(req, torture, &n);
208 CHECK_STATUS(status, NT_STATUS_NOTIFY_ENUM_DIR);
209
210 /* if the buffer size is too large, we get invalid parameter */
211 n.in.recursive = 0x0000;
212 n.in.buffer_size = max_buffer_size + 1;
213 n.in.file.handle = dh;
214 n.in.completion_filter = FILE_NOTIFY_CHANGE_ALL;
215 n.in.unknown = 0x00000000;
216 req = smb2_notify_send(tree, &n);
217 status = smb2_notify_recv(req, torture, &n);
218 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
219
220 done:
221 return ret;
222 }
223
224 /*
225 basic testing of change notify on directories
226 */
227
228 #define BASEDIR_DIR BASEDIR "_DIR"
229
230 static bool torture_smb2_notify_dir(struct torture_context *torture,
231 struct smb2_tree *tree1,
232 struct smb2_tree *tree2)
233 {
234 bool ret = true;
235 NTSTATUS status;
236 union smb_notify notify;
237 union smb_open io;
238 union smb_close cl;
239 int i, count;
240 struct smb2_handle h1 = {{0}};
241 struct smb2_handle h2 = {{0}};
242 struct smb2_request *req, *req2;
243 const char *fname = BASEDIR_DIR "\\subdir-name";
244 extern int torture_numops;
245
246 torture_comment(torture, "TESTING CHANGE NOTIFY ON DIRECTORIES\n");
247
248 smb2_deltree(tree1, BASEDIR_DIR);
249 smb2_util_rmdir(tree1, BASEDIR_DIR);
250 /*
251 get a handle on the directory
252 */
253 ZERO_STRUCT(io.smb2);
254 io.generic.level = RAW_OPEN_SMB2;
255 io.smb2.in.create_flags = 0;
256 io.smb2.in.desired_access = SEC_FILE_ALL;
257 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
258 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
259 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
260 NTCREATEX_SHARE_ACCESS_WRITE;
261 io.smb2.in.alloc_size = 0;
262 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
263 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
264 io.smb2.in.security_flags = 0;
265 io.smb2.in.fname = BASEDIR_DIR;
266
267 status = smb2_create(tree1, torture, &(io.smb2));
268 CHECK_STATUS(status, NT_STATUS_OK);
269 h1 = io.smb2.out.file.handle;
270
271 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
272 io.smb2.in.desired_access = SEC_RIGHTS_FILE_READ;
273 status = smb2_create(tree1, torture, &(io.smb2));
274 CHECK_STATUS(status, NT_STATUS_OK);
275 h2 = io.smb2.out.file.handle;
276
277 /* ask for a change notify,
278 on file or directory name changes */
279 ZERO_STRUCT(notify.smb2);
280 notify.smb2.level = RAW_NOTIFY_SMB2;
281 notify.smb2.in.buffer_size = 1000;
282 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
283 notify.smb2.in.file.handle = h1;
284 notify.smb2.in.recursive = true;
285
286 torture_comment(torture, "Testing notify cancel\n");
287
288 req = smb2_notify_send(tree1, &(notify.smb2));
289 smb2_cancel(req);
290 status = smb2_notify_recv(req, torture, &(notify.smb2));
291 CHECK_STATUS(status, NT_STATUS_CANCELLED);
292
293 torture_comment(torture, "Testing notify mkdir\n");
294
295 req = smb2_notify_send(tree1, &(notify.smb2));
296 smb2_util_mkdir(tree2, fname);
297
298 status = smb2_notify_recv(req, torture, &(notify.smb2));
299 CHECK_STATUS(status, NT_STATUS_OK);
300
301 CHECK_VAL(notify.smb2.out.num_changes, 1);
302 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
303 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
304
305 torture_comment(torture, "Testing notify rmdir\n");
306
307 req = smb2_notify_send(tree1, &(notify.smb2));
308 smb2_util_rmdir(tree2, fname);
309
310 status = smb2_notify_recv(req, torture, &(notify.smb2));
311 CHECK_STATUS(status, NT_STATUS_OK);
312 CHECK_VAL(notify.smb2.out.num_changes, 1);
313 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
314 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
315
316 torture_comment(torture,
317 "Testing notify mkdir - rmdir - mkdir - rmdir\n");
318
319 smb2_util_mkdir(tree2, fname);
320 smb2_util_rmdir(tree2, fname);
321 smb2_util_mkdir(tree2, fname);
322 smb2_util_rmdir(tree2, fname);
323 smb_msleep(200);
324 req = smb2_notify_send(tree1, &(notify.smb2));
325 status = smb2_notify_recv(req, torture, &(notify.smb2));
326 CHECK_STATUS(status, NT_STATUS_OK);
327 CHECK_VAL(notify.smb2.out.num_changes, 4);
328 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
329 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
330 CHECK_VAL(notify.smb2.out.changes[1].action, NOTIFY_ACTION_REMOVED);
331 CHECK_WIRE_STR(notify.smb2.out.changes[1].name, "subdir-name");
332 CHECK_VAL(notify.smb2.out.changes[2].action, NOTIFY_ACTION_ADDED);
333 CHECK_WIRE_STR(notify.smb2.out.changes[2].name, "subdir-name");
334 CHECK_VAL(notify.smb2.out.changes[3].action, NOTIFY_ACTION_REMOVED);
335 CHECK_WIRE_STR(notify.smb2.out.changes[3].name, "subdir-name");
336
337 count = torture_numops;
338 torture_comment(torture,
339 "Testing buffered notify on create of %d files\n", count);
340 for (i=0;i<count;i++) {
341 struct smb2_handle h12;
342 char *fname2 = talloc_asprintf(torture,
343 BASEDIR_DIR "\\test%d.txt",
344 i);
345
346 ZERO_STRUCT(io.smb2);
347 io.generic.level = RAW_OPEN_SMB2;
348 io.smb2.in.create_flags = 0;
349 io.smb2.in.desired_access = SEC_FILE_ALL;
350 io.smb2.in.create_options =
351 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
352 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
353 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
354 NTCREATEX_SHARE_ACCESS_WRITE;
355 io.smb2.in.alloc_size = 0;
356 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
357 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
358 io.smb2.in.security_flags = 0;
359 io.smb2.in.fname = fname2;
360
361 status = smb2_create(tree1, torture, &(io.smb2));
362 if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
363 torture_comment(torture, "Failed to create %s \n",
364 fname);
365 ret = false;
366 goto done;
367 }
368 h12 = io.smb2.out.file.handle;
369 talloc_free(fname2);
370 smb2_util_close(tree1, h12);
371 }
372
373 /* (1st notify) setup a new notify on a different directory handle.
374 This new notify won't see the events above. */
375 notify.smb2.in.file.handle = h2;
376 req2 = smb2_notify_send(tree1, &(notify.smb2));
377
378 /* (2nd notify) whereas this notify will see the above buffered events,
379 and it directly returns the buffered events */
380 notify.smb2.in.file.handle = h1;
381 req = smb2_notify_send(tree1, &(notify.smb2));
382
383 status = smb2_util_unlink(tree1, BASEDIR_DIR "\\nonexistent.txt");
384 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
385
386 /* (1st unlink) as the 2nd notify directly returns,
387 this unlink is only seen by the 1st notify and
388 the 3rd notify (later) */
389 torture_comment(torture,
390 "Testing notify on unlink for the first file\n");
391 status = smb2_util_unlink(tree2, BASEDIR_DIR "\\test0.txt");
392 CHECK_STATUS(status, NT_STATUS_OK);
393
394 /* receive the reply from the 2nd notify */
395 status = smb2_notify_recv(req, torture, &(notify.smb2));
396 CHECK_STATUS(status, NT_STATUS_OK);
397
398 CHECK_VAL(notify.smb2.out.num_changes, count);
399 for (i=1;i<count;i++) {
400 CHECK_VAL(notify.smb2.out.changes[i].action,
401 NOTIFY_ACTION_ADDED);
402 }
403 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "test0.txt");
404
405 torture_comment(torture, "and now from the 1st notify\n");
406 status = smb2_notify_recv(req2, torture, &(notify.smb2));
407 CHECK_STATUS(status, NT_STATUS_OK);
408 CHECK_VAL(notify.smb2.out.num_changes, 1);
409 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
410 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "test0.txt");
411
412 torture_comment(torture,
413 "(3rd notify) this notify will only see the 1st unlink\n");
414 req = smb2_notify_send(tree1, &(notify.smb2));
415
416 status = smb2_util_unlink(tree1, BASEDIR_DIR "\\nonexistent.txt");
417 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
418
419 for (i=1;i<count;i++) {
420 char *fname2 = talloc_asprintf(torture,
421 BASEDIR_DIR "\\test%d.txt", i);
422 status = smb2_util_unlink(tree2, fname2);
423 CHECK_STATUS(status, NT_STATUS_OK);
424 talloc_free(fname2);
425 }
426
427 /* receive the 3rd notify */
428 status = smb2_notify_recv(req, torture, &(notify.smb2));
429 CHECK_STATUS(status, NT_STATUS_OK);
430 CHECK_VAL(notify.smb2.out.num_changes, 1);
431 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
432 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "test0.txt");
433
434 /* and we now see the rest of the unlink calls on both
435 * directory handles */
436 notify.smb2.in.file.handle = h1;
437 sleep(3);
438 req = smb2_notify_send(tree1, &(notify.smb2));
439 status = smb2_notify_recv(req, torture, &(notify.smb2));
440 CHECK_STATUS(status, NT_STATUS_OK);
441 CHECK_VAL(notify.smb2.out.num_changes, count-1);
442 for (i=0;i<notify.smb2.out.num_changes;i++) {
443 CHECK_VAL(notify.smb2.out.changes[i].action,
444 NOTIFY_ACTION_REMOVED);
445 }
446 notify.smb2.in.file.handle = h2;
447 req = smb2_notify_send(tree1, &(notify.smb2));
448 status = smb2_notify_recv(req, torture, &(notify.smb2));
449 CHECK_STATUS(status, NT_STATUS_OK);
450 CHECK_VAL(notify.smb2.out.num_changes, count-1);
451 for (i=0;i<notify.smb2.out.num_changes;i++) {
452 CHECK_VAL(notify.smb2.out.changes[i].action,
453 NOTIFY_ACTION_REMOVED);
454 }
455
456 torture_comment(torture,
457 "Testing if a close() on the dir handle triggers the notify reply\n");
458
459 notify.smb2.in.file.handle = h1;
460 req = smb2_notify_send(tree1, &(notify.smb2));
461
462 ZERO_STRUCT(cl.smb2);
463 cl.smb2.level = RAW_CLOSE_SMB2;
464 cl.smb2.in.file.handle = h1;
465 status = smb2_close(tree1, &(cl.smb2));
466 CHECK_STATUS(status, NT_STATUS_OK);
467
468 status = smb2_notify_recv(req, torture, &(notify.smb2));
469 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
470 CHECK_VAL(notify.smb2.out.num_changes, 9);
471
472 done:
473 smb2_util_close(tree1, h1);
474 smb2_util_close(tree1, h2);
475 smb2_deltree(tree1, BASEDIR_DIR);
476 return ret;
477 }
478
479 static struct smb2_handle custom_smb2_create(struct smb2_tree *tree,
480 struct torture_context *torture,
481 struct smb2_create *smb2)
482 {
483 struct smb2_handle h1;
484 bool ret = true;
485 NTSTATUS status;
486 smb2_deltree(tree, smb2->in.fname);
487 status = smb2_create(tree, torture, smb2);
488 CHECK_STATUS(status, NT_STATUS_OK);
489 h1 = smb2->out.file.handle;
490 done:
491 if (!ret) {
492 h1 = (struct smb2_handle) {
493 .data = { 0 , 0},
494 };
495 }
496 return h1;
497 }
498
499 /*
500 testing of recursive change notify
501 */
502
503 #define BASEDIR_REC BASEDIR "_REC"
504
505 static bool torture_smb2_notify_recursive(struct torture_context *torture,
506 struct smb2_tree *tree1,
507 struct smb2_tree *tree2)
508 {
509 bool ret = true;
510 NTSTATUS status;
511 union smb_notify notify;
512 union smb_open io, io1;
513 union smb_setfileinfo sinfo;
514 struct smb2_handle h1;
515 struct smb2_request *req1, *req2;
516
517 smb2_deltree(tree1, BASEDIR_REC);
518 smb2_util_rmdir(tree1, BASEDIR_REC);
519
520 torture_comment(torture, "TESTING CHANGE NOTIFY WITH RECURSION\n");
521
522 /*
523 get a handle on the directory
524 */
525 ZERO_STRUCT(io.smb2);
526 io.generic.level = RAW_OPEN_SMB2;
527 io.smb2.in.create_flags = 0;
528 io.smb2.in.desired_access = SEC_FILE_ALL;
529 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
530 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
531 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
532 NTCREATEX_SHARE_ACCESS_WRITE;
533 io.smb2.in.alloc_size = 0;
534 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
535 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
536 io.smb2.in.security_flags = 0;
537 io.smb2.in.fname = BASEDIR_REC;
538
539 status = smb2_create(tree1, torture, &(io.smb2));
540 CHECK_STATUS(status, NT_STATUS_OK);
541 h1 = io.smb2.out.file.handle;
542
543 /* ask for a change notify, on file or directory name
544 changes. Setup both with and without recursion */
545 ZERO_STRUCT(notify.smb2);
546 notify.smb2.level = RAW_NOTIFY_SMB2;
547 notify.smb2.in.buffer_size = 1000;
548 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME |
549 FILE_NOTIFY_CHANGE_ATTRIBUTES |
550 FILE_NOTIFY_CHANGE_CREATION;
551 notify.smb2.in.file.handle = h1;
552
553 notify.smb2.in.recursive = true;
554 req1 = smb2_notify_send(tree1, &(notify.smb2));
555 smb2_cancel(req1);
556 status = smb2_notify_recv(req1, torture, &(notify.smb2));
557 CHECK_STATUS(status, NT_STATUS_CANCELLED);
558
559 notify.smb2.in.recursive = false;
560 req2 = smb2_notify_send(tree1, &(notify.smb2));
561 smb2_cancel(req2);
562 status = smb2_notify_recv(req2, torture, &(notify.smb2));
563 CHECK_STATUS(status, NT_STATUS_CANCELLED);
564
565 ZERO_STRUCT(io1.smb2);
566 io1.generic.level = RAW_OPEN_SMB2;
567 io1.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
568 io1.smb2.in.desired_access = SEC_RIGHTS_FILE_READ |
569 SEC_RIGHTS_FILE_WRITE|
570 SEC_RIGHTS_FILE_ALL;
571 io1.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
572 io1.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
573 io1.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
574 NTCREATEX_SHARE_ACCESS_WRITE |
575 NTCREATEX_SHARE_ACCESS_DELETE;
576 io1.smb2.in.alloc_size = 0;
577 io1.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
578 io1.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
579 io1.smb2.in.security_flags = 0;
580 io1.smb2.in.fname = BASEDIR_REC "\\subdir-name";
581 status = smb2_create(tree2, torture, &(io1.smb2));
582 CHECK_STATUS(status, NT_STATUS_OK);
583 smb2_util_close(tree2, io1.smb2.out.file.handle);
584
585 io1.smb2.in.fname = BASEDIR_REC "\\subdir-name\\subname1";
586 status = smb2_create(tree2, torture, &(io1.smb2));
587 CHECK_STATUS(status, NT_STATUS_OK);
588 ZERO_STRUCT(sinfo);
589 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
590 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
591 sinfo.rename_information.in.overwrite = 0;
592 sinfo.rename_information.in.root_fid = 0;
593 sinfo.rename_information.in.new_name =
594 BASEDIR_REC "\\subdir-name\\subname1-r";
595 status = smb2_setinfo_file(tree2, &sinfo);
596 CHECK_STATUS(status, NT_STATUS_OK);
597
598 io1.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
599 io1.smb2.in.fname = BASEDIR_REC "\\subdir-name\\subname2";
600 status = smb2_create(tree2, torture, &(io1.smb2));
601 CHECK_STATUS(status, NT_STATUS_OK);
602 ZERO_STRUCT(sinfo);
603 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
604 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
605 sinfo.rename_information.in.overwrite = true;
606 sinfo.rename_information.in.root_fid = 0;
607 sinfo.rename_information.in.new_name = BASEDIR_REC "\\subname2-r";
608 status = smb2_setinfo_file(tree2, &sinfo);
609 CHECK_STATUS(status, NT_STATUS_OK);
610
611 io1.smb2.in.fname = BASEDIR_REC "\\subname2-r";
612 io1.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
613 status = smb2_create(tree2, torture, &(io1.smb2));
614 CHECK_STATUS(status, NT_STATUS_OK);
615 ZERO_STRUCT(sinfo);
616 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
617 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
618 sinfo.rename_information.in.overwrite = true;
619 sinfo.rename_information.in.root_fid = 0;
620 sinfo.rename_information.in.new_name = BASEDIR_REC "\\subname3-r";
621 status = smb2_setinfo_file(tree2, &sinfo);
622 CHECK_STATUS(status, NT_STATUS_OK);
623
624 notify.smb2.in.completion_filter = 0;
625 notify.smb2.in.recursive = true;
626 smb_msleep(200);
627 req1 = smb2_notify_send(tree1, &(notify.smb2));
628
629 status = smb2_util_rmdir(tree2,
630 BASEDIR_REC "\\subdir-name\\subname1-r");
631 CHECK_STATUS(status, NT_STATUS_OK);
632 status = smb2_util_rmdir(tree2,
633 BASEDIR_REC "\\subdir-name");
634 CHECK_STATUS(status, NT_STATUS_OK);
635 status = smb2_util_unlink(tree2, BASEDIR_REC "\\subname3-r");
636 CHECK_STATUS(status, NT_STATUS_OK);
637
638 notify.smb2.in.recursive = false;
639 req2 = smb2_notify_send(tree1, &(notify.smb2));
640
641 status = smb2_notify_recv(req1, torture, &(notify.smb2));
642 CHECK_STATUS(status, NT_STATUS_OK);
643
644 CHECK_VAL(notify.smb2.out.num_changes, 9);
645 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
646 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
647 CHECK_VAL(notify.smb2.out.changes[1].action, NOTIFY_ACTION_ADDED);
648 CHECK_WIRE_STR(notify.smb2.out.changes[1].name, "subdir-name\\subname1");
649 CHECK_VAL(notify.smb2.out.changes[2].action, NOTIFY_ACTION_OLD_NAME);
650 CHECK_WIRE_STR(notify.smb2.out.changes[2].name, "subdir-name\\subname1");
651 CHECK_VAL(notify.smb2.out.changes[3].action, NOTIFY_ACTION_NEW_NAME);
652 CHECK_WIRE_STR(notify.smb2.out.changes[3].name, "subdir-name\\subname1-r");
653 CHECK_VAL(notify.smb2.out.changes[4].action, NOTIFY_ACTION_ADDED);
654 CHECK_WIRE_STR(notify.smb2.out.changes[4].name, "subdir-name\\subname2");
655 CHECK_VAL(notify.smb2.out.changes[5].action, NOTIFY_ACTION_REMOVED);
656 CHECK_WIRE_STR(notify.smb2.out.changes[5].name, "subdir-name\\subname2");
657 CHECK_VAL(notify.smb2.out.changes[6].action, NOTIFY_ACTION_ADDED);
658 CHECK_WIRE_STR(notify.smb2.out.changes[6].name, "subname2-r");
659 CHECK_VAL(notify.smb2.out.changes[7].action, NOTIFY_ACTION_OLD_NAME);
660 CHECK_WIRE_STR(notify.smb2.out.changes[7].name, "subname2-r");
661 CHECK_VAL(notify.smb2.out.changes[8].action, NOTIFY_ACTION_NEW_NAME);
662 CHECK_WIRE_STR(notify.smb2.out.changes[8].name, "subname3-r");
663
664 done:
665 smb2_deltree(tree1, BASEDIR_REC);
666 return ret;
667 }
668
669 /*
670 testing of change notify mask change
671 */
672
673 #define BASEDIR_MC BASEDIR "_MC"
674
675 static bool torture_smb2_notify_mask_change(struct torture_context *torture,
676 struct smb2_tree *tree1,
677 struct smb2_tree *tree2)
678 {
679 bool ret = true;
680 NTSTATUS status;
681 union smb_notify notify;
682 union smb_open io, io1;
683 struct smb2_handle h1;
684 struct smb2_request *req1, *req2;
685 union smb_setfileinfo sinfo;
686
687 smb2_deltree(tree1, BASEDIR_MC);
688 smb2_util_rmdir(tree1, BASEDIR_MC);
689
690 torture_comment(torture, "TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
691
692 /*
693 get a handle on the directory
694 */
695 ZERO_STRUCT(io.smb2);
696 io.generic.level = RAW_OPEN_SMB2;
697 io.smb2.in.create_flags = 0;
698 io.smb2.in.desired_access = SEC_FILE_ALL;
699 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
700 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
701 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
702 NTCREATEX_SHARE_ACCESS_WRITE;
703 io.smb2.in.alloc_size = 0;
704 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
705 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
706 io.smb2.in.security_flags = 0;
707 io.smb2.in.fname = BASEDIR_MC;
708
709 status = smb2_create(tree1, torture, &(io.smb2));
710 CHECK_STATUS(status, NT_STATUS_OK);
711 h1 = io.smb2.out.file.handle;
712
713 /* ask for a change notify, on file or directory name
714 changes. Setup both with and without recursion */
715 ZERO_STRUCT(notify.smb2);
716 notify.smb2.level = RAW_NOTIFY_SMB2;
717 notify.smb2.in.buffer_size = 1000;
718 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
719 notify.smb2.in.file.handle = h1;
720
721 notify.smb2.in.recursive = true;
722 req1 = smb2_notify_send(tree1, &(notify.smb2));
723
724 smb2_cancel(req1);
725 status = smb2_notify_recv(req1, torture, &(notify.smb2));
726 CHECK_STATUS(status, NT_STATUS_CANCELLED);
727
728
729 notify.smb2.in.recursive = false;
730 req2 = smb2_notify_send(tree1, &(notify.smb2));
731
732 smb2_cancel(req2);
733 status = smb2_notify_recv(req2, torture, &(notify.smb2));
734 CHECK_STATUS(status, NT_STATUS_CANCELLED);
735
736 notify.smb2.in.recursive = true;
737 req1 = smb2_notify_send(tree1, &(notify.smb2));
738
739 /* Set to hidden then back again. */
740 ZERO_STRUCT(io1.smb2);
741 io1.generic.level = RAW_OPEN_SMB2;
742 io1.smb2.in.create_flags = 0;
743 io1.smb2.in.desired_access = SEC_RIGHTS_FILE_READ |
744 SEC_RIGHTS_FILE_WRITE|
745 SEC_RIGHTS_FILE_ALL;
746 io1.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
747 io1.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
748 NTCREATEX_SHARE_ACCESS_WRITE |
749 NTCREATEX_SHARE_ACCESS_DELETE;
750 io1.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
751 io1.smb2.in.security_flags = 0;
752 io1.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
753 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
754 io1.smb2.in.fname = BASEDIR_MC "\\tname1";
755
756 smb2_util_close(tree1,
757 custom_smb2_create(tree1, torture, &(io1.smb2)));
758 status = smb2_util_setatr(tree1, BASEDIR_MC "\\tname1",
759 FILE_ATTRIBUTE_HIDDEN);
760 CHECK_STATUS(status, NT_STATUS_OK);
761 smb2_util_unlink(tree1, BASEDIR_MC "\\tname1");
762
763 status = smb2_notify_recv(req1, torture, &(notify.smb2));
764 CHECK_STATUS(status, NT_STATUS_OK);
765
766 CHECK_VAL(notify.smb2.out.num_changes, 1);
767 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
768 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "tname1");
769
770 /* Now try and change the mask to include other events.
771 * This should not work - once the mask is set on a directory
772 * h1 it seems to be fixed until the fnum is closed. */
773
774 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME |
775 FILE_NOTIFY_CHANGE_ATTRIBUTES |
776 FILE_NOTIFY_CHANGE_CREATION;
777 notify.smb2.in.recursive = true;
778 req1 = smb2_notify_send(tree1, &(notify.smb2));
779
780 notify.smb2.in.recursive = false;
781 req2 = smb2_notify_send(tree1, &(notify.smb2));
782
783 io1.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
784 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
785 io1.smb2.in.fname = BASEDIR_MC "\\subdir-name";
786 status = smb2_create(tree2, torture, &(io1.smb2));
787 CHECK_STATUS(status, NT_STATUS_OK);
788 smb2_util_close(tree2, io1.smb2.out.file.handle);
789
790 ZERO_STRUCT(sinfo);
791 io1.smb2.in.fname = BASEDIR_MC "\\subdir-name\\subname1";
792 io1.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
793 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
794 status = smb2_create(tree2, torture, &(io1.smb2));
795 CHECK_STATUS(status, NT_STATUS_OK);
796 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
797 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
798 sinfo.rename_information.in.overwrite = true;
799 sinfo.rename_information.in.root_fid = 0;
800 sinfo.rename_information.in.new_name =
801 BASEDIR_MC "\\subdir-name\\subname1-r";
802 status = smb2_setinfo_file(tree2, &sinfo);
803 CHECK_STATUS(status, NT_STATUS_OK);
804
805 io1.smb2.in.fname = BASEDIR_MC "\\subdir-name\\subname2";
806 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
807 io1.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
808 status = smb2_create(tree2, torture, &(io1.smb2));
809 CHECK_STATUS(status, NT_STATUS_OK);
810 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
811 sinfo.rename_information.in.new_name = BASEDIR_MC "\\subname2-r";
812 status = smb2_setinfo_file(tree2, &sinfo);
813 CHECK_STATUS(status, NT_STATUS_OK);
814 smb2_util_close(tree2, io1.smb2.out.file.handle);
815
816 io1.smb2.in.fname = BASEDIR_MC "\\subname2-r";
817 io1.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
818 status = smb2_create(tree2, torture, &(io1.smb2));
819 CHECK_STATUS(status, NT_STATUS_OK);
820 sinfo.rename_information.in.file.handle = io1.smb2.out.file.handle;
821 sinfo.rename_information.in.new_name = BASEDIR_MC "\\subname3-r";
822 status = smb2_setinfo_file(tree2, &sinfo);
823 CHECK_STATUS(status, NT_STATUS_OK);
824 smb2_util_close(tree2, io1.smb2.out.file.handle);
825
826 status = smb2_util_rmdir(tree2, BASEDIR_MC "\\subdir-name\\subname1-r");
827 CHECK_STATUS(status, NT_STATUS_OK);
828 status = smb2_util_rmdir(tree2, BASEDIR_MC "\\subdir-name");
829 CHECK_STATUS(status, NT_STATUS_OK);
830 status = smb2_util_unlink(tree2, BASEDIR_MC "\\subname3-r");
831 CHECK_STATUS(status, NT_STATUS_OK);
832
833 status = smb2_notify_recv(req1, torture, &(notify.smb2));
834 CHECK_STATUS(status, NT_STATUS_OK);
835
836 CHECK_VAL(notify.smb2.out.num_changes, 1);
837 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
838 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subname2-r");
839
840 status = smb2_notify_recv(req2, torture, &(notify.smb2));
841 CHECK_STATUS(status, NT_STATUS_OK);
842
843 CHECK_VAL(notify.smb2.out.num_changes, 1);
844 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
845 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subname3-r");
846
847 if (!ret) {
848 goto done;
849 }
850
851 done:
852 smb2_deltree(tree1, BASEDIR_MC);
853 return ret;
854 }
855
856 /*
857 testing of mask bits for change notify
858 */
859
860 #define BASEDIR_MSK BASEDIR "_MSK"
861
862 static bool torture_smb2_notify_mask(struct torture_context *torture,
863 struct smb2_tree *tree1,
864 struct smb2_tree *tree2)
865 {
866 bool ret = true;
867 NTSTATUS status;
868 union smb_notify notify;
869 union smb_open io, io1;
870 struct smb2_handle h1, h2;
871 int i;
872 char c = 1;
873 union smb_setfileinfo sinfo;
874
875 smb2_deltree(tree1, BASEDIR_MSK);
876 smb2_util_rmdir(tree1, BASEDIR_MSK);
877
878 torture_comment(torture, "TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
879
880
881 ZERO_STRUCT(h1);
882 ZERO_STRUCT(h2);
883 /*
884 get a handle on the directory
885 */
886 ZERO_STRUCT(io.smb2);
887 io.generic.level = RAW_OPEN_SMB2;
888 io.smb2.in.create_flags = 0;
889 io.smb2.in.desired_access = SEC_FILE_ALL;
890 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
891 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
892 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
893 NTCREATEX_SHARE_ACCESS_WRITE;
894 io.smb2.in.alloc_size = 0;
895 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
896 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
897 io.smb2.in.security_flags = 0;
898 io.smb2.in.fname = BASEDIR_MSK;
899
900 ZERO_STRUCT(notify.smb2);
901 notify.smb2.level = RAW_NOTIFY_SMB2;
902 notify.smb2.in.buffer_size = 1000;
903 notify.smb2.in.recursive = true;
904
905 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, \
906 expected, nchanges) \
907 do { \
908 do { for (i=0;i<32;i++) { \
909 struct smb2_request *req; \
910 status = smb2_create(tree1, torture, &(io.smb2)); \
911 CHECK_STATUS(status, NT_STATUS_OK); \
912 h1 = io.smb2.out.file.handle; \
913 setup \
914 notify.smb2.in.file.handle = h1; \
915 notify.smb2.in.completion_filter = ((uint32_t)1<<i); \
916 /* cancel initial requests so the buffer is setup */ \
917 req = smb2_notify_send(tree1, &(notify.smb2)); \
918 smb2_cancel(req); \
919 status = smb2_notify_recv(req, torture, &(notify.smb2)); \
920 CHECK_STATUS(status, NT_STATUS_CANCELLED); \
921 /* send the change notify request */ \
922 req = smb2_notify_send(tree1, &(notify.smb2)); \
923 op \
924 smb_msleep(200); smb2_cancel(req); \
925 status = smb2_notify_recv(req, torture, &(notify.smb2)); \
926 cleanup \
927 smb2_util_close(tree1, h1); \
928 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
929 CHECK_STATUS(status, NT_STATUS_OK); \
930 /* special case to cope with file rename behaviour */ \
931 if (nchanges == 2 && notify.smb2.out.num_changes == 1 && \
932 notify.smb2.out.changes[0].action == \
933 NOTIFY_ACTION_MODIFIED && \
934 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
935 Action == NOTIFY_ACTION_OLD_NAME) { \
936 torture_comment(torture, \
937 "(rename file special handling OK)\n"); \
938 } else if (nchanges != notify.smb2.out.num_changes) { \
939 torture_result(torture, TORTURE_FAIL, \
940 "ERROR: nchanges=%d expected=%d "\
941 "action=%d filter=0x%08x\n", \
942 notify.smb2.out.num_changes, \
943 nchanges, \
944 notify.smb2.out.changes[0].action, \
945 notify.smb2.in.completion_filter); \
946 ret = false; \
947 goto done; \
948 } else if (notify.smb2.out.changes[0].action != Action) { \
949 torture_result(torture, TORTURE_FAIL, \
950 "ERROR: nchanges=%d action=%d " \
951 "expectedAction=%d filter=0x%08x\n", \
952 notify.smb2.out.num_changes, \
953 notify.smb2.out.changes[0].action, \
954 Action, \
955 notify.smb2.in.completion_filter); \
956 ret = false; \
957 goto done; \
958 } else if (strcmp(notify.smb2.out.changes[0].name.s, \
959 "tname1") != 0) { \
960 torture_result(torture, TORTURE_FAIL, \
961 "ERROR: nchanges=%d action=%d " \
962 "filter=0x%08x name=%s\n", \
963 notify.smb2.out.num_changes, \
964 notify.smb2.out.changes[0].action, \
965 notify.smb2.in.completion_filter, \
966 notify.smb2.out.changes[0].name.s); \
967 ret = false; \
968 goto done; \
969 } \
970 } \
971 } while (0); \
972 } while (0);
973
974 torture_comment(torture, "Testing mkdir\n");
975 NOTIFY_MASK_TEST("Testing mkdir",;,
976 smb2_util_mkdir(tree2, BASEDIR_MSK "\\tname1");,
977 smb2_util_rmdir(tree2, BASEDIR_MSK "\\tname1");,
978 NOTIFY_ACTION_ADDED,
979 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
980
981 torture_comment(torture, "Testing create file\n");
982 ZERO_STRUCT(io1.smb2);
983 io1.generic.level = RAW_OPEN_SMB2;
984 io1.smb2.in.create_flags = 0;
985 io1.smb2.in.desired_access = SEC_FILE_ALL;
986 io1.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
987 io1.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
988 NTCREATEX_SHARE_ACCESS_WRITE;
989 io1.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
990 io1.smb2.in.security_flags = 0;
991 io1.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
992 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
993 io1.smb2.in.fname = BASEDIR_MSK "\\tname1";
994
995 NOTIFY_MASK_TEST("Testing create file",;,
996 smb2_util_close(tree2, custom_smb2_create(tree2,
997 torture, &(io1.smb2)));,
998 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1");,
999 NOTIFY_ACTION_ADDED,
1000 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
1001
1002 torture_comment(torture, "Testing unlink\n");
1003 NOTIFY_MASK_TEST("Testing unlink",
1004 smb2_util_close(tree2, custom_smb2_create(tree2,
1005 torture, &(io1.smb2)));,
1006 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1");,
1007 ;,
1008 NOTIFY_ACTION_REMOVED,
1009 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
1010
1011 torture_comment(torture, "Testing rmdir\n");
1012 NOTIFY_MASK_TEST("Testing rmdir",
1013 smb2_util_mkdir(tree2, BASEDIR_MSK "\\tname1");,
1014 smb2_util_rmdir(tree2, BASEDIR_MSK "\\tname1");,
1015 ;,
1016 NOTIFY_ACTION_REMOVED,
1017 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
1018
1019 torture_comment(torture, "Testing rename file\n");
1020 ZERO_STRUCT(sinfo);
1021 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
1022 sinfo.rename_information.in.overwrite = true;
1023 sinfo.rename_information.in.root_fid = 0;
1024 sinfo.rename_information.in.new_name = BASEDIR_MSK "\\tname2";
1025 NOTIFY_MASK_TEST("Testing rename file",
1026 torture_smb2_testfile(tree2, BASEDIR_MSK "\\tname1", &h2);,
1027 (sinfo.rename_information.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1028 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname2");,
1029 NOTIFY_ACTION_OLD_NAME,
1030 FILE_NOTIFY_CHANGE_FILE_NAME, 2);
1031
1032 torture_comment(torture, "Testing rename dir\n");
1033 ZERO_STRUCT(sinfo);
1034 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
1035 sinfo.rename_information.in.overwrite = true;
1036 sinfo.rename_information.in.root_fid = 0;
1037 sinfo.rename_information.in.new_name = BASEDIR_MSK "\\tname2";
1038 NOTIFY_MASK_TEST("Testing rename dir",
1039 torture_smb2_testdir(tree2, BASEDIR_MSK "\\tname1", &h2);,
1040 (sinfo.rename_information.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1041 (smb2_util_close(tree2, h2), smb2_util_rmdir(tree2, BASEDIR_MSK "\\tname2"));,
1042 NOTIFY_ACTION_OLD_NAME,
1043 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
1044
1045 torture_comment(torture, "Testing set path attribute\n");
1046 NOTIFY_MASK_TEST("Testing set path attribute",
1047 torture_setup_simple_file(torture, tree2, BASEDIR_MSK "\\tname1");,
1048 smb2_util_setatr(tree2, BASEDIR_MSK "\\tname1",
1049 FILE_ATTRIBUTE_HIDDEN);,
1050 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1");,
1051 NOTIFY_ACTION_MODIFIED,
1052 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
1053
1054 torture_comment(torture, "Testing set path write time\n");
1055 ZERO_STRUCT(sinfo);
1056 sinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
1057 sinfo.basic_info.in.write_time = 1000;
1058 NOTIFY_MASK_TEST("Testing set path write time",
1059 torture_setup_simple_file(torture, tree2, BASEDIR_MSK "\\tname1");,
1060 (sinfo.generic.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1061 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1");,
1062 NOTIFY_ACTION_MODIFIED,
1063 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
1064
1065 if (torture_setting_bool(torture, "samba3", false)) {
1066 torture_comment(torture,
1067 "Samba3 does not yet support create times "
1068 "everywhere\n");
1069 }
1070 else {
1071 ZERO_STRUCT(sinfo);
1072 sinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
1073 sinfo.basic_info.in.create_time = 0;
1074 torture_comment(torture, "Testing set file create time\n");
1075 NOTIFY_MASK_TEST("Testing set file create time",
1076 smb2_create_complex_file(torture, tree2,
1077 BASEDIR_MSK "\\tname1", &h2);,
1078 (sinfo.generic.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1079 (smb2_util_close(tree2, h2),
1080 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1"));,
1081 NOTIFY_ACTION_MODIFIED,
1082 FILE_NOTIFY_CHANGE_CREATION, 1);
1083 }
1084
1085 ZERO_STRUCT(sinfo);
1086 sinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
1087 sinfo.basic_info.in.access_time = 0;
1088 torture_comment(torture, "Testing set file access time\n");
1089 NOTIFY_MASK_TEST("Testing set file access time",
1090 smb2_create_complex_file(torture,
1091 tree2,
1092 BASEDIR_MSK "\\tname1",
1093 &h2);,
1094 (sinfo.generic.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1095 (smb2_util_close(tree2, h2),
1096 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1"));,
1097 NOTIFY_ACTION_MODIFIED,
1098 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
1099
1100 ZERO_STRUCT(sinfo);
1101 sinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
1102 sinfo.basic_info.in.change_time = 0;
1103 torture_comment(torture, "Testing set file change time\n");
1104 NOTIFY_MASK_TEST("Testing set file change time",
1105 smb2_create_complex_file(torture,
1106 tree2,
1107 BASEDIR_MSK "\\tname1",
1108 &h2);,
1109 (sinfo.generic.in.file.handle = h2, smb2_setinfo_file(tree2, &sinfo));,
1110 (smb2_util_close(tree2, h2),
1111 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1"));,
1112 NOTIFY_ACTION_MODIFIED,
1113 0, 1);
1114
1115
1116 torture_comment(torture, "Testing write\n");
1117 NOTIFY_MASK_TEST("Testing write",
1118 smb2_create_complex_file(torture,
1119 tree2,
1120 BASEDIR_MSK "\\tname1",
1121 &h2);,
1122 smb2_util_write(tree2, h2, &c, 10000, 1);,
1123 (smb2_util_close(tree2, h2),
1124 smb2_util_unlink(tree2, BASEDIR_MSK "\\tname1"));,
1125 NOTIFY_ACTION_MODIFIED,
1126 0, 1);
1127
1128 done:
1129 smb2_deltree(tree1, BASEDIR_MSK);
1130 return ret;
1131 }
1132
1133 #define BASEDIR_FL BASEDIR "_FL"
1134 /*
1135 basic testing of change notify on files
1136 */
1137 static bool torture_smb2_notify_file(struct torture_context *torture,
1138 struct smb2_tree *tree)
1139 {
1140 NTSTATUS status;
1141 bool ret = true;
1142 union smb_open io;
1143 union smb_close cl;
1144 union smb_notify notify;
1145 struct smb2_request *req;
1146 struct smb2_handle h1;
1147 const char *fname = BASEDIR_FL "\\file.txt";
1148
1149 smb2_deltree(tree, BASEDIR_FL);
1150 smb2_util_rmdir(tree, BASEDIR_FL);
1151
1152 torture_comment(torture, "TESTING CHANGE NOTIFY ON FILES\n");
1153 status = torture_smb2_testdir(tree, BASEDIR_FL, &h1);
1154 CHECK_STATUS(status, NT_STATUS_OK);
1155
1156 ZERO_STRUCT(io.smb2);
1157 io.generic.level = RAW_OPEN_SMB2;
1158 io.smb2.in.create_flags = 0;
1159 io.smb2.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
1160 io.smb2.in.create_options = 0;
1161 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1162 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1163 NTCREATEX_SHARE_ACCESS_WRITE;
1164 io.smb2.in.alloc_size = 0;
1165 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1166 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1167 io.smb2.in.security_flags = 0;
1168 io.smb2.in.fname = fname;
1169 status = smb2_create(tree, torture, &(io.smb2));
1170 CHECK_STATUS(status, NT_STATUS_OK);
1171 h1 = io.smb2.out.file.handle;
1172
1173 /* ask for a change notify,
1174 on file or directory name changes */
1175 ZERO_STRUCT(notify.smb2);
1176 notify.smb2.level = RAW_NOTIFY_SMB2;
1177 notify.smb2.in.file.handle = h1;
1178 notify.smb2.in.buffer_size = 1000;
1179 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
1180 notify.smb2.in.recursive = false;
1181
1182 torture_comment(torture,
1183 "Testing if notifies on file handles are invalid (should be)\n");
1184
1185 req = smb2_notify_send(tree, &(notify.smb2));
1186 status = smb2_notify_recv(req, torture, &(notify.smb2));
1187 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
1188
1189 ZERO_STRUCT(cl.smb2);
1190 cl.close.level = RAW_CLOSE_SMB2;
1191 cl.close.in.file.handle = h1;
1192 status = smb2_close(tree, &(cl.smb2));
1193 CHECK_STATUS(status, NT_STATUS_OK);
1194
1195 status = smb2_util_unlink(tree, fname);
1196 CHECK_STATUS(status, NT_STATUS_OK);
1197
1198 done:
1199 smb2_deltree(tree, BASEDIR_FL);
1200 return ret;
1201 }
1202 /*
1203 basic testing of change notifies followed by a tdis
1204 */
1205
1206 #define BASEDIR_TD BASEDIR "_TD"
1207
1208 static bool torture_smb2_notify_tree_disconnect(
1209 struct torture_context *torture,
1210 struct smb2_tree *tree)
1211 {
1212 bool ret = true;
1213 NTSTATUS status;
1214 union smb_notify notify;
1215 union smb_open io;
1216 struct smb2_handle h1;
1217 struct smb2_request *req;
1218
1219 smb2_deltree(tree, BASEDIR_TD);
1220 smb2_util_rmdir(tree, BASEDIR_TD);
1221
1222 torture_comment(torture, "TESTING CHANGE NOTIFY+CANCEL FOLLOWED BY "
1223 "TREE-DISCONNECT\n");
1224
1225 /*
1226 get a handle on the directory
1227 */
1228 ZERO_STRUCT(io.smb2);
1229 io.generic.level = RAW_OPEN_SMB2;
1230 io.smb2.in.create_flags = 0;
1231 io.smb2.in.desired_access = SEC_FILE_ALL;
1232 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1233 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1234 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1235 NTCREATEX_SHARE_ACCESS_WRITE;
1236 io.smb2.in.alloc_size = 0;
1237 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1238 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1239 io.smb2.in.security_flags = 0;
1240 io.smb2.in.fname = BASEDIR_TD;
1241
1242 status = smb2_create(tree, torture, &(io.smb2));
1243 CHECK_STATUS(status, NT_STATUS_OK);
1244 h1 = io.smb2.out.file.handle;
1245
1246 /* ask for a change notify,
1247 on file or directory name changes */
1248 ZERO_STRUCT(notify.smb2);
1249 notify.smb2.level = RAW_NOTIFY_SMB2;
1250 notify.smb2.in.buffer_size = 1000;
1251 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1252 notify.smb2.in.file.handle = h1;
1253 notify.smb2.in.recursive = true;
1254
1255 req = smb2_notify_send(tree, &(notify.smb2));
1256 smb2_cancel(req);
1257 status = smb2_notify_recv(req, torture, &(notify.smb2));
1258
1259 status = smb2_tdis(tree);
1260 CHECK_STATUS(status, NT_STATUS_OK);
1261
1262 req = smb2_notify_send(tree, &(notify.smb2));
1263
1264 smb2_notify_recv(req, torture, &(notify.smb2));
1265 CHECK_STATUS(status, NT_STATUS_OK);
1266 CHECK_VAL(notify.smb2.out.num_changes, 0);
1267
1268 done:
1269 smb2_deltree(tree, BASEDIR_TD);
1270 return ret;
1271 }
1272
1273 /*
1274 testing of change notifies followed by a tdis - no cancel
1275 */
1276
1277 #define BASEDIR_NTDIS BASEDIR "_NTDIS"
1278
1279 static bool torture_smb2_notify_tree_disconnect_1(
1280 struct torture_context *torture,
1281 struct smb2_tree *tree)
1282 {
1283 bool ret = true;
1284 NTSTATUS status;
1285 union smb_notify notify;
1286 union smb_open io;
1287 struct smb2_handle h1;
1288 struct smb2_request *req;
1289
1290 smb2_deltree(tree, BASEDIR_NTDIS);
1291 smb2_util_rmdir(tree, BASEDIR_NTDIS);
1292
1293 torture_comment(torture, "TESTING CHANGE NOTIFY ASYNC FOLLOWED BY "
1294 "TREE-DISCONNECT\n");
1295
1296 /*
1297 get a handle on the directory
1298 */
1299 ZERO_STRUCT(io.smb2);
1300 io.generic.level = RAW_OPEN_SMB2;
1301 io.smb2.in.create_flags = 0;
1302 io.smb2.in.desired_access = SEC_FILE_ALL;
1303 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1304 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1305 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1306 NTCREATEX_SHARE_ACCESS_WRITE;
1307 io.smb2.in.alloc_size = 0;
1308 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1309 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1310 io.smb2.in.security_flags = 0;
1311 io.smb2.in.fname = BASEDIR_NTDIS;
1312
1313 status = smb2_create(tree, torture, &(io.smb2));
1314 CHECK_STATUS(status, NT_STATUS_OK);
1315 h1 = io.smb2.out.file.handle;
1316
1317 /* ask for a change notify,
1318 on file or directory name changes */
1319 ZERO_STRUCT(notify.smb2);
1320 notify.smb2.level = RAW_NOTIFY_SMB2;
1321 notify.smb2.in.buffer_size = 1000;
1322 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1323 notify.smb2.in.file.handle = h1;
1324 notify.smb2.in.recursive = true;
1325
1326 req = smb2_notify_send(tree, &(notify.smb2));
1327 WAIT_FOR_ASYNC_RESPONSE(req);
1328
1329 status = smb2_tdis(tree);
1330 CHECK_STATUS(status, NT_STATUS_OK);
1331
1332 status = smb2_notify_recv(req, torture, &(notify.smb2));
1333 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
1334 CHECK_VAL(notify.smb2.out.num_changes, 0);
1335
1336 done:
1337 smb2_deltree(tree, BASEDIR_NTDIS);
1338 return ret;
1339 }
1340
1341 /*
1342 basic testing of change notifies followed by a close
1343 */
1344
1345 #define BASEDIR_CNC BASEDIR "_CNC"
1346
1347 static bool torture_smb2_notify_close(struct torture_context *torture,
1348 struct smb2_tree *tree1)
1349 {
1350 bool ret = true;
1351 NTSTATUS status;
1352 union smb_notify notify;
1353 union smb_open io;
1354 struct smb2_handle h1;
1355 struct smb2_request *req;
1356
1357 smb2_deltree(tree1, BASEDIR_CNC);
1358 smb2_util_rmdir(tree1, BASEDIR_CNC);
1359
1360 torture_comment(torture, "TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1361
1362 /*
1363 get a handle on the directory
1364 */
1365 ZERO_STRUCT(io.smb2);
1366 io.generic.level = RAW_OPEN_SMB2;
1367 io.smb2.in.create_flags = 0;
1368 io.smb2.in.desired_access = SEC_FILE_ALL;
1369 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1370 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1371 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1372 NTCREATEX_SHARE_ACCESS_WRITE;
1373 io.smb2.in.alloc_size = 0;
1374 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1375 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1376 io.smb2.in.security_flags = 0;
1377 io.smb2.in.fname = BASEDIR_CNC;
1378
1379 status = smb2_create(tree1, torture, &(io.smb2));
1380 CHECK_STATUS(status, NT_STATUS_OK);
1381
1382 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1383 status = smb2_create(tree1, torture, &(io.smb2));
1384 CHECK_STATUS(status, NT_STATUS_OK);
1385 h1 = io.smb2.out.file.handle;
1386
1387 /* ask for a change notify,
1388 on file or directory name changes */
1389 ZERO_STRUCT(notify.smb2);
1390 notify.smb2.level = RAW_NOTIFY_SMB2;
1391 notify.smb2.in.buffer_size = 1000;
1392 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1393 notify.smb2.in.file.handle = h1;
1394 notify.smb2.in.recursive = true;
1395
1396 req = smb2_notify_send(tree1, &(notify.smb2));
1397
1398 WAIT_FOR_ASYNC_RESPONSE(req);
1399
1400 status = smb2_util_close(tree1, h1);
1401 CHECK_STATUS(status, NT_STATUS_OK);
1402
1403 status = smb2_notify_recv(req, torture, &(notify.smb2));
1404 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
1405 CHECK_VAL(notify.smb2.out.num_changes, 0);
1406
1407 done:
1408 smb2_deltree(tree1, BASEDIR_CNC);
1409 return ret;
1410 }
1411
1412 /*
1413 basic testing of change notifies followed by a ulogoff
1414 */
1415
1416 #define BASEDIR_NUL BASEDIR "_NUL"
1417 static bool torture_smb2_notify_ulogoff(struct torture_context *torture,
1418 struct smb2_tree *tree1)
1419 {
1420 bool ret = true;
1421 NTSTATUS status;
1422 union smb_notify notify;
1423 union smb_open io;
1424 struct smb2_handle h1;
1425 struct smb2_request *req;
1426
1427 smb2_deltree(tree1, BASEDIR_NUL);
1428 smb2_util_rmdir(tree1, BASEDIR_NUL);
1429
1430 torture_comment(torture, "TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1431
1432 /*
1433 get a handle on the directory
1434 */
1435 ZERO_STRUCT(io.smb2);
1436 io.generic.level = RAW_OPEN_SMB2;
1437 io.smb2.in.create_flags = 0;
1438 io.smb2.in.desired_access = SEC_FILE_ALL;
1439 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1440 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1441 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1442 NTCREATEX_SHARE_ACCESS_WRITE;
1443 io.smb2.in.alloc_size = 0;
1444 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1445 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1446 io.smb2.in.security_flags = 0;
1447 io.smb2.in.fname = BASEDIR_NUL;
1448
1449 status = smb2_create(tree1, torture, &(io.smb2));
1450 CHECK_STATUS(status, NT_STATUS_OK);
1451
1452 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1453 status = smb2_create(tree1, torture, &(io.smb2));
1454 CHECK_STATUS(status, NT_STATUS_OK);
1455 h1 = io.smb2.out.file.handle;
1456
1457 /* ask for a change notify,
1458 on file or directory name changes */
1459 ZERO_STRUCT(notify.smb2);
1460 notify.smb2.level = RAW_NOTIFY_SMB2;
1461 notify.smb2.in.buffer_size = 1000;
1462 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1463 notify.smb2.in.file.handle = h1;
1464 notify.smb2.in.recursive = true;
1465
1466 req = smb2_notify_send(tree1, &(notify.smb2));
1467
1468 WAIT_FOR_ASYNC_RESPONSE(req);
1469
1470 status = smb2_logoff(tree1->session);
1471 CHECK_STATUS(status, NT_STATUS_OK);
1472
1473 status = smb2_notify_recv(req, torture, &(notify.smb2));
1474 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
1475 CHECK_VAL(notify.smb2.out.num_changes, 0);
1476
1477 done:
1478 smb2_deltree(tree1, BASEDIR_NUL);
1479 return ret;
1480 }
1481
1482 /*
1483 basic testing of change notifies followed by a session reconnect
1484 */
1485
1486 #define BASEDIR_NSR BASEDIR "_NSR"
1487
1488 static bool torture_smb2_notify_session_reconnect(struct torture_context *torture,
1489 struct smb2_tree *tree1)
1490 {
1491 bool ret = true;
1492 NTSTATUS status;
1493 union smb_notify notify;
1494 union smb_open io;
1495 struct smb2_handle h1;
1496 struct smb2_request *req;
1497 uint64_t previous_session_id = 0;
1498 struct smb2_session *session2 = NULL;
1499
1500 smb2_deltree(tree1, BASEDIR_NSR);
1501 smb2_util_rmdir(tree1, BASEDIR_NSR);
1502
1503 torture_comment(torture, "TESTING CHANGE NOTIFY FOLLOWED BY SESSION RECONNECT\n");
1504
1505 /*
1506 get a handle on the directory
1507 */
1508 ZERO_STRUCT(io.smb2);
1509 io.generic.level = RAW_OPEN_SMB2;
1510 io.smb2.in.create_flags = 0;
1511 io.smb2.in.desired_access = SEC_FILE_ALL;
1512 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1513 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1514 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1515 NTCREATEX_SHARE_ACCESS_WRITE;
1516 io.smb2.in.alloc_size = 0;
1517 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1518 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1519 io.smb2.in.security_flags = 0;
1520 io.smb2.in.fname = BASEDIR_NSR;
1521
1522 status = smb2_create(tree1, torture, &(io.smb2));
1523 CHECK_STATUS(status, NT_STATUS_OK);
1524
1525 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1526 status = smb2_create(tree1, torture, &(io.smb2));
1527 CHECK_STATUS(status, NT_STATUS_OK);
1528 h1 = io.smb2.out.file.handle;
1529
1530 /* ask for a change notify,
1531 on file or directory name changes */
1532 ZERO_STRUCT(notify.smb2);
1533 notify.smb2.level = RAW_NOTIFY_SMB2;
1534 notify.smb2.in.buffer_size = 1000;
1535 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1536 notify.smb2.in.file.handle = h1;
1537 notify.smb2.in.recursive = true;
1538
1539 req = smb2_notify_send(tree1, &(notify.smb2));
1540
1541 WAIT_FOR_ASYNC_RESPONSE(req);
1542
1543 previous_session_id = smb2cli_session_current_id(tree1->session->smbXcli);
1544 torture_assert(torture, torture_smb2_session_setup(torture,
1545 tree1->session->transport,
1546 previous_session_id,
1547 torture, &session2),
1548 "session setup with previous_session_id failed");
1549
1550 status = smb2_notify_recv(req, torture, &(notify.smb2));
1551 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
1552 CHECK_VAL(notify.smb2.out.num_changes, 0);
1553
1554 status = smb2_logoff(tree1->session);
1555 CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
1556
1557 status = smb2_logoff(session2);
1558 CHECK_STATUS(status, NT_STATUS_OK);
1559 done:
1560 smb2_deltree(tree1, BASEDIR_NSR);
1561 return ret;
1562 }
1563
1564 /*
1565 basic testing of change notifies followed by an invalid reauth
1566 */
1567
1568 #define BASEDIR_IR BASEDIR "_IR"
1569
1570 static bool torture_smb2_notify_invalid_reauth(struct torture_context *torture,
1571 struct smb2_tree *tree1,
1572 struct smb2_tree *tree2)
1573 {
1574 bool ret = true;
1575 NTSTATUS status;
1576 union smb_notify notify;
1577 union smb_open io;
1578 struct smb2_handle h1;
1579 struct smb2_request *req;
1580 struct cli_credentials *invalid_creds;
1581
1582 smb2_deltree(tree2, BASEDIR_IR);
1583 smb2_util_rmdir(tree2, BASEDIR_IR);
1584
1585 torture_comment(torture, "TESTING CHANGE NOTIFY FOLLOWED BY invalid REAUTH\n");
1586
1587 /*
1588 get a handle on the directory
1589 */
1590 ZERO_STRUCT(io.smb2);
1591 io.generic.level = RAW_OPEN_SMB2;
1592 io.smb2.in.create_flags = 0;
1593 io.smb2.in.desired_access = SEC_FILE_ALL;
1594 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1595 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1596 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1597 NTCREATEX_SHARE_ACCESS_WRITE;
1598 io.smb2.in.alloc_size = 0;
1599 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1600 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1601 io.smb2.in.security_flags = 0;
1602 io.smb2.in.fname = BASEDIR_IR;
1603
1604 status = smb2_create(tree1, torture, &(io.smb2));
1605 CHECK_STATUS(status, NT_STATUS_OK);
1606
1607 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
1608 status = smb2_create(tree1, torture, &(io.smb2));
1609 CHECK_STATUS(status, NT_STATUS_OK);
1610 h1 = io.smb2.out.file.handle;
1611
1612 /* ask for a change notify,
1613 on file or directory name changes */
1614 ZERO_STRUCT(notify.smb2);
1615 notify.smb2.level = RAW_NOTIFY_SMB2;
1616 notify.smb2.in.buffer_size = 1000;
1617 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1618 notify.smb2.in.file.handle = h1;
1619 notify.smb2.in.recursive = true;
1620
1621 req = smb2_notify_send(tree1, &(notify.smb2));
1622
1623 WAIT_FOR_ASYNC_RESPONSE(req);
1624
1625 invalid_creds = cli_credentials_init(torture);
1626 torture_assert(torture, (invalid_creds != NULL), "talloc error");
1627 cli_credentials_set_username(invalid_creds, "__none__invalid__none__", CRED_SPECIFIED);
1628 cli_credentials_set_domain(invalid_creds, "__none__invalid__none__", CRED_SPECIFIED);
1629 cli_credentials_set_password(invalid_creds, "__none__invalid__none__", CRED_SPECIFIED);
1630 cli_credentials_set_realm(invalid_creds, NULL, CRED_SPECIFIED);
1631 cli_credentials_set_workstation(invalid_creds, "", CRED_UNINITIALISED);
1632
1633 status = smb2_session_setup_spnego(tree1->session,
1634 invalid_creds,
1635 0 /* previous_session_id */);
1636 CHECK_STATUS(status, NT_STATUS_LOGON_FAILURE);
1637
1638 status = smb2_notify_recv(req, torture, &(notify.smb2));
1639 CHECK_STATUS(status, NT_STATUS_NOTIFY_CLEANUP);
1640 CHECK_VAL(notify.smb2.out.num_changes, 0);
1641
1642 /*
1643 * Demonstrate that the session is no longer valid.
1644 */
1645 status = smb2_create(tree1, torture, &(io.smb2));
1646 CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
1647 done:
1648 smb2_deltree(tree2, BASEDIR_IR);
1649 return ret;
1650 }
1651
1652 static void tcp_dis_handler(struct smb2_transport *t, void *p)
1653 {
1654 struct smb2_tree *tree = (struct smb2_tree *)p;
1655 smb2_transport_dead(tree->session->transport,
1656 NT_STATUS_LOCAL_DISCONNECT);
1657 t = NULL;
1658 tree = NULL;
1659 }
1660
1661 /*
1662 basic testing of change notifies followed by tcp disconnect
1663 */
1664
1665 #define BASEDIR_NTCPD BASEDIR "_NTCPD"
1666
1667 static bool torture_smb2_notify_tcp_disconnect(
1668 struct torture_context *torture,
1669 struct smb2_tree *tree)
1670 {
1671 bool ret = true;
1672 NTSTATUS status;
1673 union smb_notify notify;
1674 union smb_open io;
1675 struct smb2_handle h1;
1676 struct smb2_request *req;
1677
1678 smb2_deltree(tree, BASEDIR_NTCPD);
1679 smb2_util_rmdir(tree, BASEDIR_NTCPD);
1680
1681 torture_comment(torture,
1682 "TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1683
1684 /*
1685 get a handle on the directory
1686 */
1687 ZERO_STRUCT(io.smb2);
1688 io.generic.level = RAW_OPEN_SMB2;
1689 io.smb2.in.create_flags = 0;
1690 io.smb2.in.desired_access = SEC_FILE_ALL;
1691 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1692 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1693 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1694 NTCREATEX_SHARE_ACCESS_WRITE;
1695 io.smb2.in.alloc_size = 0;
1696 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
1697 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1698 io.smb2.in.security_flags = 0;
1699 io.smb2.in.fname = BASEDIR_NTCPD;
1700
1701 status = smb2_create(tree, torture, &(io.smb2));
1702 CHECK_STATUS(status, NT_STATUS_OK);
1703 h1 = io.smb2.out.file.handle;
1704
1705 /* ask for a change notify,
1706 on file or directory name changes */
1707 ZERO_STRUCT(notify.smb2);
1708 notify.smb2.level = RAW_NOTIFY_SMB2;
1709 notify.smb2.in.buffer_size = 1000;
1710 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1711 notify.smb2.in.file.handle = h1;
1712 notify.smb2.in.recursive = true;
1713
1714 req = smb2_notify_send(tree, &(notify.smb2));
1715 smb2_cancel(req);
1716 status = smb2_notify_recv(req, torture, &(notify.smb2));
1717 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1718
1719 notify.smb2.in.recursive = true;
1720 req = smb2_notify_send(tree, &(notify.smb2));
1721 smb2_transport_idle_handler(tree->session->transport,
1722 tcp_dis_handler, 250000, tree);
1723 tree = NULL;
1724 status = smb2_notify_recv(req, torture, &(notify.smb2));
1725 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
1726
1727 done:
1728 return ret;
1729 }
1730
1731 /*
1732 test setting up two change notify requests on one handle
1733 */
1734
1735 #define BASEDIR_NDOH BASEDIR "_NDOH"
1736
1737 static bool torture_smb2_notify_double(struct torture_context *torture,
1738 struct smb2_tree *tree1,
1739 struct smb2_tree *tree2)
1740 {
1741 bool ret = true;
1742 NTSTATUS status;
1743 union smb_notify notify;
1744 union smb_open io;
1745 struct smb2_handle h1;
1746 struct smb2_request *req1, *req2;
1747
1748 smb2_deltree(tree1, BASEDIR_NDOH);
1749 smb2_util_rmdir(tree1, BASEDIR_NDOH);
1750
1751 torture_comment(torture,
1752 "TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1753
1754 /*
1755 get a handle on the directory
1756 */
1757 ZERO_STRUCT(io.smb2);
1758 io.generic.level = RAW_OPEN_SMB2;
1759 io.smb2.in.create_flags = 0;
1760 io.smb2.in.desired_access = SEC_RIGHTS_FILE_READ|
1761 SEC_RIGHTS_FILE_WRITE|
1762 SEC_RIGHTS_FILE_ALL;
1763 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1764 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1765 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1766 NTCREATEX_SHARE_ACCESS_WRITE;
1767 io.smb2.in.alloc_size = 0;
1768 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
1769 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1770 io.smb2.in.security_flags = 0;
1771 io.smb2.in.fname = BASEDIR_NDOH;
1772
1773 status = smb2_create(tree1, torture, &(io.smb2));
1774 CHECK_STATUS(status, NT_STATUS_OK);
1775 h1 = io.smb2.out.file.handle;
1776
1777 /* ask for a change notify,
1778 on file or directory name changes */
1779 ZERO_STRUCT(notify.smb2);
1780 notify.smb2.level = RAW_NOTIFY_SMB2;
1781 notify.smb2.in.buffer_size = 1000;
1782 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1783 notify.smb2.in.file.handle = h1;
1784 notify.smb2.in.recursive = true;
1785
1786 req1 = smb2_notify_send(tree1, &(notify.smb2));
1787 smb2_cancel(req1);
1788 status = smb2_notify_recv(req1, torture, &(notify.smb2));
1789 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1790
1791 req2 = smb2_notify_send(tree1, &(notify.smb2));
1792 smb2_cancel(req2);
1793 status = smb2_notify_recv(req2, torture, &(notify.smb2));
1794 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1795
1796 smb2_util_mkdir(tree2, BASEDIR_NDOH "\\subdir-name");
1797 req1 = smb2_notify_send(tree1, &(notify.smb2));
1798 req2 = smb2_notify_send(tree1, &(notify.smb2));
1799
1800 status = smb2_notify_recv(req1, torture, &(notify.smb2));
1801 CHECK_STATUS(status, NT_STATUS_OK);
1802 CHECK_VAL(notify.smb2.out.num_changes, 1);
1803 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
1804
1805 smb2_util_mkdir(tree2, BASEDIR_NDOH "\\subdir-name2");
1806
1807 status = smb2_notify_recv(req2, torture, &(notify.smb2));
1808 CHECK_STATUS(status, NT_STATUS_OK);
1809 CHECK_VAL(notify.smb2.out.num_changes, 1);
1810 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name2");
1811
1812 done:
1813 smb2_deltree(tree1, BASEDIR_NDOH);
1814 return ret;
1815 }
1816
1817
1818 /*
1819 test multiple change notifies at different depths and with/without recursion
1820 */
1821
1822 #define BASEDIR_TREE BASEDIR "_TREE"
1823
1824 static bool torture_smb2_notify_tree(struct torture_context *torture,
1825 struct smb2_tree *tree)
1826 {
1827 bool ret = true;
1828 union smb_notify notify;
1829 union smb_open io;
1830 struct smb2_request *req;
1831 struct timeval tv;
1832 struct {
1833 const char *path;
1834 bool recursive;
1835 uint32_t filter;
1836 int expected;
1837 struct smb2_handle h1;
1838 int counted;
1839 } dirs[] = {
1840 {
1841 .path = BASEDIR_TREE "\\abc",
1842 .recursive = true,
1843 .filter = FILE_NOTIFY_CHANGE_NAME,
1844 .expected = 30,
1845 },
1846 {
1847 .path = BASEDIR_TREE "\\zqy",
1848 .recursive = true,
1849 .filter = FILE_NOTIFY_CHANGE_NAME,
1850 .expected = 8,
1851 },
1852 {
1853 .path = BASEDIR_TREE "\\atsy",
1854 .recursive = true,
1855 .filter = FILE_NOTIFY_CHANGE_NAME,
1856 .expected = 4,
1857 },
1858 {
1859 .path = BASEDIR_TREE "\\abc\\foo",
1860 .recursive = true,
1861 .filter = FILE_NOTIFY_CHANGE_NAME,
1862 .expected = 2,
1863 },
1864 {
1865 .path = BASEDIR_TREE "\\abc\\blah",
1866 .recursive = true,
1867 .filter = FILE_NOTIFY_CHANGE_NAME,
1868 .expected = 13,
1869 },
1870 {
1871 .path = BASEDIR_TREE "\\abc\\blah",
1872 .recursive = false,
1873 .filter = FILE_NOTIFY_CHANGE_NAME,
1874 .expected = 7,
1875 },
1876 {
1877 .path = BASEDIR_TREE "\\abc\\blah\\a",
1878 .recursive = true,
1879 .filter = FILE_NOTIFY_CHANGE_NAME,
1880 .expected = 2,
1881 },
1882 {
1883 .path = BASEDIR_TREE "\\abc\\blah\\b",
1884 .recursive = true,
1885 .filter = FILE_NOTIFY_CHANGE_NAME,
1886 .expected = 2,
1887 },
1888 {
1889 .path = BASEDIR_TREE "\\abc\\blah\\c",
1890 .recursive = true,
1891 .filter = FILE_NOTIFY_CHANGE_NAME,
1892 .expected = 2,
1893 },
1894 {
1895 .path = BASEDIR_TREE "\\abc\\fooblah",
1896 .recursive = true,
1897 .filter = FILE_NOTIFY_CHANGE_NAME,
1898 .expected = 2,
1899 },
1900 {
1901 .path = BASEDIR_TREE "\\zqy\\xx",
1902 .recursive = true,
1903 .filter = FILE_NOTIFY_CHANGE_NAME,
1904 .expected = 2,
1905 },
1906 {
1907 .path = BASEDIR_TREE "\\zqy\\yyy",
1908 .recursive = true,
1909 .filter = FILE_NOTIFY_CHANGE_NAME,
1910 .expected = 2,
1911 },
1912 {
1913 .path = BASEDIR_TREE "\\zqy\\..",
1914 .recursive = true,
1915 .filter = FILE_NOTIFY_CHANGE_NAME,
1916 .expected = 40,
1917 },
1918 {
1919 .path = BASEDIR_TREE,
1920 .recursive = true,
1921 .filter = FILE_NOTIFY_CHANGE_NAME,
1922 .expected = 40,
1923 },
1924 {
1925 .path = BASEDIR_TREE,
1926 .recursive = false,
1927 .filter = FILE_NOTIFY_CHANGE_NAME,
1928 .expected = 6,
1929 },
1930 {
1931 .path = BASEDIR_TREE "\\atsy",
1932 .recursive = false,
1933 .filter = FILE_NOTIFY_CHANGE_NAME,
1934 .expected = 4,
1935 },
1936 {
1937 .path = BASEDIR_TREE "\\abc",
1938 .recursive = true,
1939 .filter = FILE_NOTIFY_CHANGE_NAME,
1940 .expected = 24,
1941 },
1942 {
1943 .path = BASEDIR_TREE "\\abc",
1944 .recursive = false,
1945 .filter = FILE_NOTIFY_CHANGE_FILE_NAME,
1946 .expected = 0,
1947 },
1948 {
1949 .path = BASEDIR_TREE "\\abc",
1950 .recursive = true,
1951 .filter = FILE_NOTIFY_CHANGE_FILE_NAME,
1952 .expected = 0,
1953 },
1954 {
1955 .path = BASEDIR_TREE "\\abc",
1956 .recursive = true,
1957 .filter = FILE_NOTIFY_CHANGE_NAME,
1958 .expected = 24,
1959 },
1960 };
1961 int i;
1962 NTSTATUS status;
1963 bool all_done = false;
1964
1965 smb2_deltree(tree, BASEDIR_TREE);
1966 smb2_util_rmdir(tree, BASEDIR_TREE);
1967
1968 torture_comment(torture, "TESTING NOTIFY FOR DIFFERENT DEPTHS\n");
1969
1970 ZERO_STRUCT(io.smb2);
1971 io.generic.level = RAW_OPEN_SMB2;
1972 io.smb2.in.create_flags = 0;
1973 io.smb2.in.desired_access = SEC_FILE_ALL;
1974 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1975 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
1976 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1977 NTCREATEX_SHARE_ACCESS_WRITE;
1978 io.smb2.in.alloc_size = 0;
1979 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
1980 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
1981 io.smb2.in.security_flags = 0;
1982 io.smb2.in.fname = BASEDIR_TREE;
1983 status = smb2_create(tree, torture, &(io.smb2));
1984 CHECK_STATUS(status, NT_STATUS_OK);
1985
1986 ZERO_STRUCT(notify.smb2);
1987 notify.smb2.level = RAW_NOTIFY_SMB2;
1988 notify.smb2.in.buffer_size = 20000;
1989
1990 /*
1991 setup the directory tree, and the notify buffer on each directory
1992 */
1993 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1994 io.smb2.in.fname = dirs[i].path;
1995 status = smb2_create(tree, torture, &(io.smb2));
1996 CHECK_STATUS(status, NT_STATUS_OK);
1997 dirs[i].h1 = io.smb2.out.file.handle;
1998
1999 notify.smb2.in.completion_filter = dirs[i].filter;
2000 notify.smb2.in.file.handle = dirs[i].h1;
2001 notify.smb2.in.recursive = dirs[i].recursive;
2002 req = smb2_notify_send(tree, &(notify.smb2));
2003 smb2_cancel(req);
2004 status = smb2_notify_recv(req, torture, &(notify.smb2));
2005 CHECK_STATUS(status, NT_STATUS_CANCELLED);
2006 }
2007
2008 /* trigger 2 events in each dir */
2009 for (i=0;i<ARRAY_SIZE(dirs);i++) {
2010 char *path = talloc_asprintf(torture, "%s\\test.dir",
2011 dirs[i].path);
2012 smb2_util_mkdir(tree, path);
2013 smb2_util_rmdir(tree, path);
2014 talloc_free(path);
2015 }
2016
2017 /* give a bit of time for the events to propagate */
2018 tv = timeval_current();
2019
2020 do {
2021 /* count events that have happened in each dir */
2022 for (i=0;i<ARRAY_SIZE(dirs);i++) {
2023 notify.smb2.in.completion_filter = dirs[i].filter;
2024 notify.smb2.in.file.handle = dirs[i].h1;
2025 notify.smb2.in.recursive = dirs[i].recursive;
2026 req = smb2_notify_send(tree, &(notify.smb2));
2027 smb2_cancel(req);
2028 notify.smb2.out.num_changes = 0;
2029 status = smb2_notify_recv(req, torture,
2030 &(notify.smb2));
2031 dirs[i].counted += notify.smb2.out.num_changes;
2032 }
2033
2034 all_done = true;
2035
2036 for (i=0;i<ARRAY_SIZE(dirs);i++) {
2037 if (dirs[i].counted != dirs[i].expected) {
2038 all_done = false;
2039 }
2040 }
2041 } while (!all_done && timeval_elapsed(&tv) < 20);
2042
2043 torture_comment(torture, "took %.4f seconds to propagate all events\n",
2044 timeval_elapsed(&tv));
2045
2046 for (i=0;i<ARRAY_SIZE(dirs);i++) {
2047 if (dirs[i].counted != dirs[i].expected) {
2048 torture_comment(torture,
2049 "ERROR: i=%d expected %d got %d for '%s'\n",
2050 i, dirs[i].expected, dirs[i].counted,
2051 dirs[i].path);
2052 ret = false;
2053 }
2054 }
2055
2056 /*
2057 run from the back, closing and deleting
2058 */
2059 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
2060 smb2_util_close(tree, dirs[i].h1);
2061 smb2_util_rmdir(tree, dirs[i].path);
2062 }
2063
2064 done:
2065 smb2_deltree(tree, BASEDIR_TREE);
2066 smb2_util_rmdir(tree, BASEDIR_TREE);
2067 return ret;
2068 }
2069
2070 /*
2071 Test response when cached server events exceed single NT NOTFIY response
2072 packet size.
2073 */
2074
2075 #define BASEDIR_OVF BASEDIR "_OVF"
2076
2077 static bool torture_smb2_notify_overflow(struct torture_context *torture,
2078 struct smb2_tree *tree)
2079 {
2080 bool ret = true;
2081 NTSTATUS status;
2082 union smb_notify notify;
2083 union smb_open io;
2084 struct smb2_handle h1, h2;
2085 int count = 100;
2086 struct smb2_request *req1;
2087 int i;
2088
2089 smb2_deltree(tree, BASEDIR_OVF);
2090 smb2_util_rmdir(tree, BASEDIR_OVF);
2091
2092 torture_comment(torture, "TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
2093
2094 /* get a handle on the directory */
2095 ZERO_STRUCT(io.smb2);
2096 io.generic.level = RAW_OPEN_SMB2;
2097 io.smb2.in.create_flags = 0;
2098 io.smb2.in.desired_access = SEC_FILE_ALL;
2099 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2100 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2101 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2102 NTCREATEX_SHARE_ACCESS_WRITE;
2103 io.smb2.in.alloc_size = 0;
2104 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
2105 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2106 io.smb2.in.security_flags = 0;
2107 io.smb2.in.fname = BASEDIR_OVF;
2108
2109 status = smb2_create(tree, torture, &(io.smb2));
2110 CHECK_STATUS(status, NT_STATUS_OK);
2111 h1 = io.smb2.out.file.handle;
2112
2113 /* ask for a change notify, on name changes. */
2114 ZERO_STRUCT(notify.smb2);
2115 notify.smb2.level = RAW_NOTIFY_NTTRANS;
2116 notify.smb2.in.buffer_size = 1000;
2117 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2118 notify.smb2.in.file.handle = h1;
2119
2120 notify.smb2.in.recursive = true;
2121 req1 = smb2_notify_send(tree, &(notify.smb2));
2122
2123 /* cancel initial requests so the buffer is setup */
2124 smb2_cancel(req1);
2125 status = smb2_notify_recv(req1, torture, &(notify.smb2));
2126 CHECK_STATUS(status, NT_STATUS_CANCELLED);
2127
2128 /* open a lot of files, filling up the server side notify buffer */
2129 torture_comment(torture,
2130 "Testing overflowed buffer notify on create of %d files\n",
2131 count);
2132
2133 for (i=0;i<count;i++) {
2134 char *fname = talloc_asprintf(torture,
2135 BASEDIR_OVF "\\test%d.txt", i);
2136 union smb_open io1;
2137 ZERO_STRUCT(io1.smb2);
2138 io1.generic.level = RAW_OPEN_SMB2;
2139 io1.smb2.in.create_flags = 0;
2140 io1.smb2.in.desired_access = SEC_FILE_ALL;
2141 io1.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2142 io1.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2143 io1.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2144 NTCREATEX_SHARE_ACCESS_WRITE;
2145 io1.smb2.in.alloc_size = 0;
2146 io1.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
2147 io1.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2148 io1.smb2.in.security_flags = 0;
2149 io1.smb2.in.fname = fname;
2150
2151 h2 = custom_smb2_create(tree, torture, &(io1.smb2));
2152 talloc_free(fname);
2153 smb2_util_close(tree, h2);
2154 }
2155
2156 req1 = smb2_notify_send(tree, &(notify.smb2));
2157 status = smb2_notify_recv(req1, torture, &(notify.smb2));
2158 CHECK_STATUS(status, NT_STATUS_NOTIFY_ENUM_DIR);
2159 CHECK_VAL(notify.smb2.out.num_changes, 0);
2160
2161 done:
2162 smb2_deltree(tree, BASEDIR_OVF);
2163 return ret;
2164 }
2165
2166 /*
2167 Test if notifications are returned for changes to the base directory.
2168 They shouldn't be.
2169 */
2170
2171 #define BASEDIR_BAS BASEDIR "_BAS"
2172
2173 static bool torture_smb2_notify_basedir(struct torture_context *torture,
2174 struct smb2_tree *tree1,
2175 struct smb2_tree *tree2)
2176 {
2177 bool ret = true;
2178 NTSTATUS status;
2179 union smb_notify notify;
2180 union smb_open io;
2181 struct smb2_handle h1;
2182 struct smb2_request *req1;
2183
2184 smb2_deltree(tree1, BASEDIR_BAS);
2185 smb2_util_rmdir(tree1, BASEDIR_BAS);
2186
2187 torture_comment(torture, "TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
2188
2189 /* get a handle on the directory */
2190 ZERO_STRUCT(io.smb2);
2191 io.generic.level = RAW_OPEN_SMB2;
2192 io.smb2.in.create_flags = 0;
2193 io.smb2.in.desired_access = SEC_FILE_ALL;
2194 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2195 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2196 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2197 NTCREATEX_SHARE_ACCESS_WRITE;
2198 io.smb2.in.alloc_size = 0;
2199 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
2200 io.smb2.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
2201 io.smb2.in.security_flags = 0;
2202 io.smb2.in.fname = BASEDIR_BAS;
2203
2204 status = smb2_create(tree1, torture, &(io.smb2));
2205 CHECK_STATUS(status, NT_STATUS_OK);
2206 h1 = io.smb2.out.file.handle;
2207
2208 /* create a test file that will also be modified */
2209 io.smb2.in.fname = BASEDIR_BAS "\\tname1";
2210 io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
2211 status = smb2_create(tree2, torture, &(io.smb2));
2212 CHECK_STATUS(status,NT_STATUS_OK);
2213 smb2_util_close(tree2, io.smb2.out.file.handle);
2214
2215 /* ask for a change notify, on attribute changes. */
2216 ZERO_STRUCT(notify.smb2);
2217 notify.smb2.level = RAW_NOTIFY_SMB2;
2218 notify.smb2.in.buffer_size = 1000;
2219 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
2220 notify.smb2.in.file.handle = h1;
2221 notify.smb2.in.recursive = true;
2222
2223 req1 = smb2_notify_send(tree1, &(notify.smb2));
2224
2225 /* set attribute on the base dir */
2226 smb2_util_setatr(tree2, BASEDIR_BAS, FILE_ATTRIBUTE_HIDDEN);
2227
2228 /* set attribute on a file to assure we receive a notification */
2229 smb2_util_setatr(tree2, BASEDIR_BAS "\\tname1", FILE_ATTRIBUTE_HIDDEN);
2230 smb_msleep(200);
2231
2232 /* check how many responses were given, expect only 1 for the file */
2233 status = smb2_notify_recv(req1, torture, &(notify.smb2));
2234 CHECK_STATUS(status, NT_STATUS_OK);
2235 CHECK_VAL(notify.smb2.out.num_changes, 1);
2236 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
2237 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "tname1");
2238
2239 done:
2240 smb2_deltree(tree1, BASEDIR_BAS);
2241 return ret;
2242 }
2243
2244 /*
2245 very simple change notify test
2246 */
2247
2248 #define BASEDIR_TCON BASEDIR "_TCON"
2249
2250 static bool torture_smb2_notify_tcon(struct torture_context *torture,
2251 struct smb2_tree *tree)
2252 {
2253 bool ret = true;
2254 NTSTATUS status;
2255 union smb_notify notify;
2256 union smb_open io;
2257 struct smb2_handle h1 = {{0}};
2258 struct smb2_request *req = NULL;
2259 struct smb2_tree *tree1 = NULL;
2260 const char *fname = BASEDIR_TCON "\\subdir-name";
2261
2262 smb2_deltree(tree, BASEDIR_TCON);
2263 smb2_util_rmdir(tree, BASEDIR_TCON);
2264
2265 torture_comment(torture, "TESTING SIMPLE CHANGE NOTIFY\n");
2266
2267 /*
2268 get a handle on the directory
2269 */
2270
2271 ZERO_STRUCT(io.smb2);
2272 io.generic.level = RAW_OPEN_SMB2;
2273 io.smb2.in.create_flags = 0;
2274 io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
2275 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2276 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL |
2277 FILE_ATTRIBUTE_DIRECTORY;
2278 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2279 NTCREATEX_SHARE_ACCESS_WRITE;
2280 io.smb2.in.alloc_size = 0;
2281 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
2282 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2283 io.smb2.in.security_flags = 0;
2284 io.smb2.in.fname = BASEDIR_TCON;
2285
2286 status = smb2_create(tree, torture, &(io.smb2));
2287 CHECK_STATUS(status, NT_STATUS_OK);
2288 h1 = io.smb2.out.file.handle;
2289
2290 /* ask for a change notify,
2291 on file or directory name changes */
2292 ZERO_STRUCT(notify.smb2);
2293 notify.smb2.level = RAW_NOTIFY_SMB2;
2294 notify.smb2.in.buffer_size = 1000;
2295 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2296 notify.smb2.in.file.handle = h1;
2297 notify.smb2.in.recursive = true;
2298
2299 torture_comment(torture, "Testing notify mkdir\n");
2300 req = smb2_notify_send(tree, &(notify.smb2));
2301 smb2_cancel(req);
2302 status = smb2_notify_recv(req, torture, &(notify.smb2));
2303 CHECK_STATUS(status, NT_STATUS_CANCELLED);
2304
2305 notify.smb2.in.recursive = true;
2306 req = smb2_notify_send(tree, &(notify.smb2));
2307 status = smb2_util_mkdir(tree, fname);
2308 CHECK_STATUS(status, NT_STATUS_OK);
2309
2310 status = smb2_notify_recv(req, torture, &(notify.smb2));
2311 CHECK_STATUS(status, NT_STATUS_OK);
2312
2313 CHECK_VAL(notify.smb2.out.num_changes, 1);
2314 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
2315 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2316
2317 torture_comment(torture, "Testing notify rmdir\n");
2318 req = smb2_notify_send(tree, &(notify.smb2));
2319 status = smb2_util_rmdir(tree, fname);
2320 CHECK_STATUS(status, NT_STATUS_OK);
2321
2322 status = smb2_notify_recv(req, torture, &(notify.smb2));
2323 CHECK_STATUS(status, NT_STATUS_OK);
2324 CHECK_VAL(notify.smb2.out.num_changes, 1);
2325 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
2326 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2327
2328 torture_comment(torture, "SIMPLE CHANGE NOTIFY OK\n");
2329
2330 torture_comment(torture, "TESTING WITH SECONDARY TCON\n");
2331 if (!torture_smb2_tree_connect(torture, tree->session, tree, &tree1)) {
2332 torture_warning(torture, "couldn't reconnect to share, bailing\n");
2333 ret = false;
2334 goto done;
2335 }
2336
2337 torture_comment(torture, "tid1=%d tid2=%d\n",
2338 smb2cli_tcon_current_id(tree->smbXcli),
2339 smb2cli_tcon_current_id(tree1->smbXcli));
2340
2341 torture_comment(torture, "Testing notify mkdir\n");
2342 req = smb2_notify_send(tree, &(notify.smb2));
2343 smb2_util_mkdir(tree1, fname);
2344
2345 status = smb2_notify_recv(req, torture, &(notify.smb2));
2346 CHECK_STATUS(status, NT_STATUS_OK);
2347
2348 CHECK_VAL(notify.smb2.out.num_changes, 1);
2349 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
2350 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2351
2352 torture_comment(torture, "Testing notify rmdir\n");
2353 req = smb2_notify_send(tree, &(notify.smb2));
2354 smb2_util_rmdir(tree, fname);
2355
2356 status = smb2_notify_recv(req, torture, &(notify.smb2));
2357 CHECK_STATUS(status, NT_STATUS_OK);
2358 CHECK_VAL(notify.smb2.out.num_changes, 1);
2359 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
2360 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2361
2362 torture_comment(torture, "CHANGE NOTIFY WITH TCON OK\n");
2363
2364 torture_comment(torture, "Disconnecting secondary tree\n");
2365 status = smb2_tdis(tree1);
2366 CHECK_STATUS(status, NT_STATUS_OK);
2367 talloc_free(tree1);
2368
2369 torture_comment(torture, "Testing notify mkdir\n");
2370 req = smb2_notify_send(tree, &(notify.smb2));
2371 smb2_util_mkdir(tree, fname);
2372
2373 status = smb2_notify_recv(req, torture, &(notify.smb2));
2374 CHECK_STATUS(status, NT_STATUS_OK);
2375
2376 CHECK_VAL(notify.smb2.out.num_changes, 1);
2377 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_ADDED);
2378 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2379
2380 torture_comment(torture, "Testing notify rmdir\n");
2381 req = smb2_notify_send(tree, &(notify.smb2));
2382 smb2_util_rmdir(tree, fname);
2383
2384 status = smb2_notify_recv(req, torture, &(notify.smb2));
2385 CHECK_STATUS(status, NT_STATUS_OK);
2386 CHECK_VAL(notify.smb2.out.num_changes, 1);
2387 CHECK_VAL(notify.smb2.out.changes[0].action, NOTIFY_ACTION_REMOVED);
2388 CHECK_WIRE_STR(notify.smb2.out.changes[0].name, "subdir-name");
2389
2390 torture_comment(torture, "CHANGE NOTIFY WITH TDIS OK\n");
2391 done:
2392 smb2_util_close(tree, h1);
2393 smb2_deltree(tree, BASEDIR_TCON);
2394
2395 return ret;
2396 }
2397
2398 #define BASEDIR_RMD BASEDIR "_RMD"
2399
2400 static bool torture_smb2_notify_rmdir(struct torture_context *torture,
2401 struct smb2_tree *tree1,
2402 struct smb2_tree *tree2,
2403 bool initial_delete_on_close)
2404 {
2405 bool ret = true;
2406 NTSTATUS status;
2407 union smb_notify notify = {};
2408 union smb_setfileinfo sfinfo = {};
2409 union smb_open io = {};
2410 struct smb2_handle h = {};
2411 struct smb2_request *req;
2412
2413 torture_comment(torture, "TESTING NOTIFY CANCEL FOR DELETED DIR\n");
2414
2415 smb2_deltree(tree1, BASEDIR_RMD);
2416 smb2_util_rmdir(tree1, BASEDIR_RMD);
2417
2418 ZERO_STRUCT(io.smb2);
2419 io.generic.level = RAW_OPEN_SMB2;
2420 io.smb2.in.create_flags = 0;
2421 io.smb2.in.desired_access = SEC_FILE_ALL;
2422 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2423 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2424 io.smb2.in.share_access =
2425 NTCREATEX_SHARE_ACCESS_READ |
2426 NTCREATEX_SHARE_ACCESS_WRITE |
2427 NTCREATEX_SHARE_ACCESS_DELETE ;
2428 io.smb2.in.alloc_size = 0;
2429 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
2430 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2431 io.smb2.in.security_flags = 0;
2432 io.smb2.in.fname = BASEDIR_RMD;
2433
2434 status = smb2_create(tree1, torture, &(io.smb2));
2435 CHECK_STATUS(status, NT_STATUS_OK);
2436 h = io.smb2.out.file.handle;
2437
2438 ZERO_STRUCT(notify.smb2);
2439 notify.smb2.level = RAW_NOTIFY_SMB2;
2440 notify.smb2.in.buffer_size = 1000;
2441 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2442 notify.smb2.in.file.handle = h;
2443 notify.smb2.in.recursive = false;
2444
2445 io.smb2.in.desired_access |= SEC_STD_DELETE;
2446 io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
2447 req = smb2_notify_send(tree1, &(notify.smb2));
2448
2449 if (initial_delete_on_close) {
2450 status = smb2_util_rmdir(tree2, BASEDIR_RMD);
2451 CHECK_STATUS(status, NT_STATUS_OK);
2452 } else {
2453 status = smb2_create(tree2, torture, &(io.smb2));
2454 CHECK_STATUS(status, NT_STATUS_OK);
2455
2456 sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
2457 sfinfo.generic.in.file.handle = io.smb2.out.file.handle;
2458 sfinfo.disposition_info.in.delete_on_close = 1;
2459 status = smb2_setinfo_file(tree2, &sfinfo);
2460 CHECK_STATUS(status, NT_STATUS_OK);
2461
2462 smb2_util_close(tree2, io.smb2.out.file.handle);
2463 }
2464
2465 status = smb2_notify_recv(req, torture, &(notify.smb2));
2466 CHECK_STATUS(status, NT_STATUS_DELETE_PENDING);
2467
2468 done:
2469
2470 smb2_util_close(tree1, h);
2471 smb2_deltree(tree1, BASEDIR_RMD);
2472
2473 return ret;
2474 }
2475
2476 static bool torture_smb2_notify_rmdir1(struct torture_context *torture,
2477 struct smb2_tree *tree)
2478 {
2479 return torture_smb2_notify_rmdir(torture, tree, tree, false);
2480 }
2481
2482 static bool torture_smb2_notify_rmdir2(struct torture_context *torture,
2483 struct smb2_tree *tree)
2484 {
2485 return torture_smb2_notify_rmdir(torture, tree, tree, true);
2486 }
2487
2488 static bool torture_smb2_notify_rmdir3(struct torture_context *torture,
2489 struct smb2_tree *tree1,
2490 struct smb2_tree *tree2)
2491 {
2492 return torture_smb2_notify_rmdir(torture, tree1, tree2, false);
2493 }
2494
2495 static bool torture_smb2_notify_rmdir4(struct torture_context *torture,
2496 struct smb2_tree *tree1,
2497 struct smb2_tree *tree2)
2498 {
2499 return torture_smb2_notify_rmdir(torture, tree1, tree2, true);
2500 }
2501
2502 static void notify_timeout(struct tevent_context *ev,
2503 struct tevent_timer *te,
2504 struct timeval current_time,
2505 void *private_data)
2506 {
2507 struct smb2_request *req = talloc_get_type_abort(
2508 private_data, struct smb2_request);
2509
2510 smb2_cancel(req);
2511 }
2512
2513 #define BASEDIR_INR BASEDIR "_INR"
2514
2515 static bool torture_smb2_inotify_rename(struct torture_context *torture,
2516 struct smb2_tree *tree1,
2517 struct smb2_tree *tree2)
2518 {
2519 NTSTATUS status;
2520 struct smb2_notify notify;
2521 struct notify_changes change1 = {0};
2522 struct notify_changes change2 = {0};
2523 struct smb2_create create;
2524 union smb_setfileinfo sinfo;
2525 struct smb2_handle h1 = {{0}};
2526 struct smb2_handle h2 = {{0}};
2527 struct smb2_request *req;
2528 struct tevent_timer *te = NULL;
2529 bool ok = false;
2530
2531 smb2_deltree(tree1, BASEDIR_INR);
2532
2533 torture_comment(torture, "Testing change notify of a rename with inotify\n");
2534
2535 status = torture_smb2_testdir_access(
2536 tree1,
2537 BASEDIR_INR,
2538 &h1,
2539 SEC_RIGHTS_DIR_ALL & ~SEC_STD_DELETE);
2540 torture_assert_ntstatus_ok_goto(torture, status, ok, done, "torture_smb2_testdir failed");
2541
2542 ZERO_STRUCT(create);
2543 create.in.desired_access = SEC_RIGHTS_FILE_READ |
2544 SEC_RIGHTS_FILE_WRITE|
2545 SEC_RIGHTS_FILE_ALL;
2546 create.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2547 create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2548 create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2549 NTCREATEX_SHARE_ACCESS_WRITE |
2550 NTCREATEX_SHARE_ACCESS_DELETE;
2551 create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
2552 create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2553 create.in.fname = BASEDIR_INR "\\subdir-name";
2554
2555 status = smb2_create(tree2, torture, &create);
2556 torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_create failed\n");
2557 h2 = create.out.file.handle;
2558
2559 ZERO_STRUCT(notify);
2560 notify.level = RAW_NOTIFY_SMB2;
2561 notify.in.buffer_size = 4096;
2562 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2563 notify.in.file.handle = h1;
2564 notify.in.recursive = true;
2565 req = smb2_notify_send(tree1, &notify);
2566 torture_assert_not_null_goto(torture, req, ok, done, "smb2_notify_send failed\n");
2567
2568 while (!NT_STATUS_EQUAL(req->status, NT_STATUS_PENDING)) {
2569 if (tevent_loop_once(torture->ev) != 0) {
2570 goto done;
2571 }
2572 }
2573
2574 ZERO_STRUCT(sinfo);
2575 sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
2576 sinfo.rename_information.in.file.handle = h2;
2577 sinfo.rename_information.in.new_name = BASEDIR_INR "\\subdir-name-r";
2578
2579 status = smb2_setinfo_file(tree2, &sinfo);
2580 torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_setinfo_file failed\n");
2581
2582 smb2_util_close(tree2, h2);
2583
2584 te = tevent_add_timer(torture->ev,
2585 tree1,
2586 tevent_timeval_current_ofs(1, 0),
2587 notify_timeout,
2588 req);
2589 torture_assert_not_null_goto(torture, te, ok, done, "tevent_add_timer failed\n");
2590
2591 status = smb2_notify_recv(req, torture, &notify);
2592 torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_notify_recv failed\n");
2593
2594 torture_assert_goto(torture, notify.out.num_changes == 1 || notify.out.num_changes == 2,
2595 ok, done, "bad notify\n");
2596
2597 change1 = notify.out.changes[0];
2598 if (notify.out.num_changes == 2) {
2599 change2 = notify.out.changes[1];
2600 } else {
2601 /*
2602 * We may only get one event at a time, so check for the
2603 * matching second event for the oldname/newname or
2604 * removed/added pair.
2605 */
2606 ZERO_STRUCT(notify);
2607 notify.level = RAW_NOTIFY_SMB2;
2608 notify.in.buffer_size = 4096;
2609 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2610 notify.in.file.handle = h1;
2611 notify.in.recursive = true;
2612 req = smb2_notify_send(tree1, &notify);
2613 torture_assert_not_null_goto(torture, req, ok, done, "smb2_notify_send failed\n");
2614
2615 status = smb2_notify_recv(req, torture, &notify);
2616 torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_notify_recv failed\n");
2617
2618 torture_assert_goto(torture, notify.out.num_changes == 1, ok, done,
2619 "bad notify\n");
2620
2621 change2 = notify.out.changes[0];
2622 }
2623
2624 if ((change1.action != NOTIFY_ACTION_OLD_NAME) &&
2625 (change1.action != NOTIFY_ACTION_REMOVED))
2626 {
2627 torture_fail_goto(torture, done, "bad change notification\n");
2628 }
2629 torture_assert_str_equal_goto(torture, change1.name.s, "subdir-name",
2630 ok, done, "bad change notification\n");
2631
2632 if ((change2.action != NOTIFY_ACTION_NEW_NAME) &&
2633 (change2.action != NOTIFY_ACTION_ADDED))
2634 {
2635 torture_fail_goto(torture, done, "bad change notification\n");
2636 }
2637 torture_assert_str_equal_goto(torture, change2.name.s, "subdir-name-r",
2638 ok, done, "bad change notification\n");
2639
2640 ok = true;
2641 done:
2642 if (!smb2_util_handle_empty(h1)) {
2643 smb2_util_close(tree1, h1);
2644 }
2645 if (!smb2_util_handle_empty(h2)) {
2646 smb2_util_close(tree2, h2);
2647 }
2648
2649 smb2_deltree(tree1, BASEDIR_INR);
2650 return ok;
2651 }
2652
2653 /*
2654 Test asking for a change notify on a handle without permissions.
2655 */
2656
2657 #define BASEDIR_HPERM BASEDIR "_HPERM"
2658
2659 static bool torture_smb2_notify_handle_permissions(
2660 struct torture_context *torture,
2661 struct smb2_tree *tree)
2662 {
2663 bool ret = true;
2664 NTSTATUS status;
2665 union smb_notify notify;
2666 union smb_open io;
2667 struct smb2_handle h1 = {{0}};
2668 struct smb2_request *req;
2669
2670 smb2_deltree(tree, BASEDIR_HPERM);
2671 smb2_util_rmdir(tree, BASEDIR_HPERM);
2672
2673 torture_comment(torture,
2674 "TESTING CHANGE NOTIFY "
2675 "ON A HANDLE WITHOUT PERMISSIONS\n");
2676
2677 /*
2678 get a handle on the directory
2679 */
2680 ZERO_STRUCT(io.smb2);
2681 io.generic.level = RAW_OPEN_SMB2;
2682 io.smb2.in.create_flags = 0;
2683 io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE;
2684 io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2685 io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2686 io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2687 NTCREATEX_SHARE_ACCESS_WRITE;
2688 io.smb2.in.alloc_size = 0;
2689 io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
2690 io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2691 io.smb2.in.security_flags = 0;
2692 io.smb2.in.fname = BASEDIR_HPERM;
2693
2694 status = smb2_create(tree, torture, &io.smb2);
2695 CHECK_STATUS(status, NT_STATUS_OK);
2696 h1 = io.smb2.out.file.handle;
2697
2698 /* ask for a change notify,
2699 on file or directory name changes */
2700 ZERO_STRUCT(notify.smb2);
2701 notify.smb2.level = RAW_NOTIFY_SMB2;
2702 notify.smb2.in.buffer_size = 1000;
2703 notify.smb2.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
2704 notify.smb2.in.file.handle = h1;
2705 notify.smb2.in.recursive = true;
2706
2707 req = smb2_notify_send(tree, &notify.smb2);
2708 torture_assert_goto(torture,
2709 req != NULL,
2710 ret,
2711 done,
2712 "smb2_notify_send failed\n");
2713
2714 /*
2715 * Cancel it, we don't really want to wait.
2716 */
2717 smb2_cancel(req);
2718 status = smb2_notify_recv(req, torture, &notify.smb2);
2719 /* Handle h1 doesn't have permissions for ChangeNotify. */
2720 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
2721
2722 done:
2723 if (!smb2_util_handle_empty(h1)) {
2724 smb2_util_close(tree, h1);
2725 }
2726 smb2_deltree(tree, BASEDIR_HPERM);
2727 return ret;
2728 }
2729
2730 static bool torture_smb2_notify_acl_args(struct torture_context *torture,
2731 struct smb2_tree *tree,
2732 bool copy_sd_only,
2733 uint32_t completion_filter)
2734 {
2735 NTSTATUS status;
2736 struct smb2_create io;
2737 const char *name = "sec_notify.txt";
2738 bool ret = true;
2739 struct smb2_handle handle = {{0}};
2740 struct smb2_handle dir_handle = {{0}};
2741 union smb_fileinfo q;
2742 union smb_setfileinfo set;
2743 struct security_descriptor *sd;
2744 struct smb2_notify notify;
2745 struct smb2_request *req;
2746 struct dom_sid *test_sid;
2747 struct security_ace ace;
2748 struct tevent_timer *te = NULL;
2749
2750 /* one secdesc update generates one notify, regardless of:
2751 * mask (FILE_NOTIFY_CHANGE_SECURITY or FILE_NOTIFY_CHANGE_ALL)
2752 * actual modification of sd (copied sd or added one ace)
2753 */
2754
2755 if (!smb2_util_setup_dir(torture, tree, BASEDIR))
2756 return false;
2757
2758 torture_comment(torture, "Testing security notifications with completion_filter: 0x%08x\n", completion_filter);
2759
2760 /*
2761 get a handle on the directory
2762 */
2763 ZERO_STRUCT(io);
2764 io.level = RAW_OPEN_SMB2;
2765 io.in.create_flags = 0;
2766 io.in.desired_access = SEC_FILE_ALL;
2767 io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2768 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2769 io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
2770 NTCREATEX_SHARE_ACCESS_WRITE;
2771 io.in.alloc_size = 0;
2772 io.in.create_disposition = NTCREATEX_DISP_OPEN;
2773 io.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
2774 io.in.security_flags = 0;
2775 io.in.fname = BASEDIR;
2776
2777 status = smb2_create(tree, torture, &io);
2778 CHECK_STATUS(status, NT_STATUS_OK);
2779 dir_handle = io.out.file.handle;
2780
2781 /*
2782 get a handle on the file
2783 */
2784 ZERO_STRUCT(io);
2785 io.level = RAW_OPEN_SMB2;
2786 io.in.create_flags = 0;
2787 io.in.desired_access = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC | SEC_STD_WRITE_OWNER;
2788 io.in.create_options = 0;
2789 io.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
2790 io.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE |
2791 NTCREATEX_SHARE_ACCESS_READ |
2792 NTCREATEX_SHARE_ACCESS_WRITE;
2793 io.in.alloc_size = 0;
2794 io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
2795 io.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS;
2796 io.in.security_flags = 0;
2797 io.in.fname = talloc_asprintf(torture, "%s\\%s", BASEDIR, name);
2798
2799 status = smb2_create(tree, torture, &io);
2800 CHECK_STATUS(status, NT_STATUS_OK);
2801 handle = io.out.file.handle;
2802
2803 /* get the original sd */
2804 q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
2805 q.query_secdesc.in.file.handle = handle;
2806 q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
2807 status = smb2_getinfo_file(tree, torture, &q);
2808 CHECK_STATUS(status, NT_STATUS_OK);
2809
2810 sd = q.query_secdesc.out.sd;
2811
2812 /* setup notify_send */
2813
2814 ZERO_STRUCT(notify);
2815 notify.level = RAW_NOTIFY_SMB2;
2816 notify.in.buffer_size = 1024;
2817 notify.in.completion_filter = completion_filter;
2818 notify.in.file.handle = dir_handle;
2819 notify.in.recursive = true;
2820
2821 req = smb2_notify_send(tree, &notify);
2822 torture_assert_not_null_goto(torture, req, ret, done, "smb2_notify_send failed\n");
2823
2824 while (!req->cancel.can_cancel && req->state <= SMB2_REQUEST_RECV) {
2825 if (tevent_loop_once(torture->ev) != 0) {
2826 break;
2827 }
2828 }
2829
2830 /* add new ACE */
2831 if (!copy_sd_only) {
2832 test_sid = dom_sid_parse_talloc(torture, SID_NT_AUTHENTICATED_USERS);
2833 ZERO_STRUCT(ace);
2834 ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
2835 ace.flags = 0;
2836 ace.access_mask = SEC_STD_ALL;
2837 ace.trustee = *test_sid;
2838 status = security_descriptor_dacl_add(sd, &ace);
2839 CHECK_STATUS(status, NT_STATUS_OK);
2840 }
2841
2842 set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
2843 set.set_secdesc.in.file.handle = handle;
2844 set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
2845 set.set_secdesc.in.sd = sd;
2846 status = smb2_setinfo_file(tree, &set);
2847 CHECK_STATUS(status, NT_STATUS_OK);
2848
2849 if (!smb2_util_handle_empty(handle)) {
2850 smb2_util_close(tree, handle);
2851 }
2852
2853 /* setup smb2_notify_receive */
2854
2855 /* setup timer so we can cancel after 5 seconds */
2856 te = tevent_add_timer(torture->ev,
2857 tree,
2858 tevent_timeval_current_ofs(5, 0),
2859 notify_timeout,
2860 req);
2861 torture_assert_not_null_goto(torture, te, ret, done, "tevent_add_timer failed\n");
2862
2863 status = smb2_notify_recv(req, torture, &notify);
2864 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
2865 "smb2_notify_recv failed\n");
2866
2867 /* check reply */
2868 CHECK_VAL(notify.out.num_changes, 1);
2869 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
2870 CHECK_WIRE_STR(notify.out.changes[0].name, name);
2871
2872 done:
2873 if (!smb2_util_handle_empty(dir_handle)) {
2874 smb2_util_close(tree, dir_handle);
2875 }
2876 if (!smb2_util_handle_empty(handle)) {
2877 smb2_util_close(tree, handle);
2878 }
2879 smb2_deltree(tree, BASEDIR);
2880 return ret;
2881 }
2882
2883 static bool torture_smb2_notify_acl(struct torture_context *torture,
2884 struct smb2_tree *tree)
2885 {
2886 struct {
2887 bool copy_sd_only;
2888 uint32_t completion_filter;
2889 } tests[] = {
2890 {
2891 .copy_sd_only = true,
2892 .completion_filter = FILE_NOTIFY_CHANGE_SECURITY,
2893 },{
2894 .copy_sd_only = false,
2895 .completion_filter = FILE_NOTIFY_CHANGE_SECURITY,
2896 },{
2897 .copy_sd_only = true,
2898 .completion_filter = FILE_NOTIFY_CHANGE_ALL,
2899 },{
2900 .copy_sd_only = false,
2901 .completion_filter = FILE_NOTIFY_CHANGE_ALL,
2902 }
2903 };
2904 int i;
2905
2906 for (i=0; i < ARRAY_SIZE(tests); i++) {
2907 bool ok;
2908
2909 ok = torture_smb2_notify_acl_args(torture, tree,
2910 tests[i].copy_sd_only,
2911 tests[i].completion_filter);
2912 if (!ok) {
2913 return false;
2914 }
2915 }
2916
2917 return true;
2918 }
2919
2920 /*
2921 basic testing of SMB2 change notify
2922 */
2923 struct torture_suite *torture_smb2_notify_init(TALLOC_CTX *ctx)
2924 {
2925 struct torture_suite *suite = torture_suite_create(ctx, "notify");
2926
2927 torture_suite_add_1smb2_test(suite, "valid-req", test_valid_request);
2928 torture_suite_add_1smb2_test(suite, "tcon", torture_smb2_notify_tcon);
2929 torture_suite_add_2smb2_test(suite, "dir", torture_smb2_notify_dir);
2930 torture_suite_add_2smb2_test(suite, "mask", torture_smb2_notify_mask);
2931 torture_suite_add_1smb2_test(suite, "tdis", torture_smb2_notify_tree_disconnect);
2932 torture_suite_add_1smb2_test(suite, "tdis1", torture_smb2_notify_tree_disconnect_1);
2933 torture_suite_add_2smb2_test(suite, "mask-change", torture_smb2_notify_mask_change);
2934 torture_suite_add_1smb2_test(suite, "close", torture_smb2_notify_close);
2935 torture_suite_add_1smb2_test(suite, "logoff", torture_smb2_notify_ulogoff);
2936 torture_suite_add_1smb2_test(suite, "session-reconnect", torture_smb2_notify_session_reconnect);
2937 torture_suite_add_2smb2_test(suite, "invalid-reauth", torture_smb2_notify_invalid_reauth);
2938 torture_suite_add_1smb2_test(suite, "tree", torture_smb2_notify_tree);
2939 torture_suite_add_2smb2_test(suite, "basedir", torture_smb2_notify_basedir);
2940 torture_suite_add_2smb2_test(suite, "double", torture_smb2_notify_double);
2941 torture_suite_add_1smb2_test(suite, "file", torture_smb2_notify_file);
2942 torture_suite_add_1smb2_test(suite, "tcp", torture_smb2_notify_tcp_disconnect);
2943 torture_suite_add_2smb2_test(suite, "rec", torture_smb2_notify_recursive);
2944 torture_suite_add_1smb2_test(suite, "overflow", torture_smb2_notify_overflow);
2945 torture_suite_add_1smb2_test(suite, "rmdir1",
2946 torture_smb2_notify_rmdir1);
2947 torture_suite_add_1smb2_test(suite, "rmdir2",
2948 torture_smb2_notify_rmdir2);
2949 torture_suite_add_2smb2_test(suite, "rmdir3",
2950 torture_smb2_notify_rmdir3);
2951 torture_suite_add_2smb2_test(suite, "rmdir4",
2952 torture_smb2_notify_rmdir4);
2953 torture_suite_add_1smb2_test(suite,
2954 "handle-permissions",
2955 torture_smb2_notify_handle_permissions);
2956 torture_suite_add_1smb2_test(suite, "security",
2957 torture_smb2_notify_acl);
2958
2959 suite->description = talloc_strdup(suite, "SMB2-NOTIFY tests");
2960
2961 return suite;
2962 }
2963
2964 /*
2965 basic testing of SMB2 change notify
2966 */
2967 struct torture_suite *torture_smb2_notify_inotify_init(TALLOC_CTX *ctx)
2968 {
2969 struct torture_suite *suite = torture_suite_create(ctx, "notify-inotify");
2970
2971 suite->description = talloc_strdup(suite, "SMB2-NOTIFY tests that use inotify");
2972
2973 torture_suite_add_2smb2_test(suite, "inotify-rename", torture_smb2_inotify_rename);
2974
2975 return suite;
2976 }