2 Unix SMB/CIFS implementation.
3 basic raw test suite for change notify
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libcli/raw/libcliraw.h"
22 #include "libcli/raw/raw_proto.h"
23 #include "libcli/libcli.h"
24 #include "system/filesys.h"
25 #include "torture/util.h"
26 #include "torture/raw/proto.h"
28 #define BASEDIR "\\test_notify"
30 #define CHECK_WSTR(tctx, field, value, flags) \
32 if (!field.s || strcmp(field.s, value) || \
33 wire_bad_flags(&field, flags, cli->transport)) { \
34 torture_result(tctx, TORTURE_FAIL, \
35 "(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
40 basic testing of change notify on directories
42 static bool test_notify_dir(struct torture_context *mem_ctx,
43 struct smbcli_state *cli,
44 struct smbcli_state *cli2)
48 union smb_notify notify;
51 int i, count, fnum, fnum2;
52 struct smbcli_request *req, *req2;
53 extern int torture_numops;
55 printf("TESTING CHANGE NOTIFY ON DIRECTORIES\n");
57 if (!torture_setup_dir(cli, BASEDIR)) {
62 get a handle on the directory
64 io.generic.level = RAW_OPEN_NTCREATEX;
65 io.ntcreatex.in.root_fid.fnum = 0;
66 io.ntcreatex.in.flags = 0;
67 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
68 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
69 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
70 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
71 io.ntcreatex.in.alloc_size = 0;
72 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
73 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
74 io.ntcreatex.in.security_flags = 0;
75 io.ntcreatex.in.fname = BASEDIR;
77 status = smb_raw_open(cli->tree, mem_ctx, &io);
78 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
80 fnum = io.ntcreatex.out.file.fnum;
82 status = smb_raw_open(cli->tree, mem_ctx, &io);
83 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
85 fnum2 = io.ntcreatex.out.file.fnum;
87 /* ask for a change notify,
88 on file or directory name changes */
89 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
90 notify.nttrans.in.buffer_size = 1000;
91 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
92 notify.nttrans.in.file.fnum = fnum;
93 notify.nttrans.in.recursive = true;
95 printf("Testing notify cancel\n");
97 req = smb_raw_changenotify_send(cli->tree, ¬ify);
98 smb_raw_ntcancel(req);
99 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
100 torture_assert_ntstatus_equal_goto(mem_ctx, status, NT_STATUS_CANCELLED,
102 "smb_raw_changenotify_recv");
104 printf("Testing notify mkdir\n");
106 req = smb_raw_changenotify_send(cli->tree, ¬ify);
107 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
109 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
110 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
111 "smb_raw_changenotify_recv");
113 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
114 1, ret, done, "more than one change");
115 torture_assert_int_equal_goto(mem_ctx,
116 notify.nttrans.out.changes[0].action,
117 NOTIFY_ACTION_ADDED, ret, done,
118 "wrong action (exp: ADDED)");
119 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name",
122 printf("Testing notify rmdir\n");
124 req = smb_raw_changenotify_send(cli->tree, ¬ify);
125 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
127 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
128 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
129 "smb_raw_changenotify_recv");
130 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
131 1, ret, done, "more than one change");
132 torture_assert_int_equal_goto(mem_ctx,
133 notify.nttrans.out.changes[0].action,
134 NOTIFY_ACTION_REMOVED, ret, done,
135 "wrong action (exp: REMOVED)");
136 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name",
139 printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
141 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
142 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
143 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
144 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
146 req = smb_raw_changenotify_send(cli->tree, ¬ify);
147 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
148 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
149 "smb_raw_changenotify_recv");
150 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
151 4, ret, done, "wrong number of changes");
152 torture_assert_int_equal_goto(mem_ctx,
153 notify.nttrans.out.changes[0].action,
154 NOTIFY_ACTION_ADDED, ret, done,
155 "wrong action (exp: ADDED)");
156 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name",
158 torture_assert_int_equal_goto(mem_ctx,
159 notify.nttrans.out.changes[1].action,
160 NOTIFY_ACTION_REMOVED, ret, done,
161 "wrong action (exp: REMOVED)");
162 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[1].name, "subdir-name",
164 torture_assert_int_equal_goto(mem_ctx,
165 notify.nttrans.out.changes[2].action,
166 NOTIFY_ACTION_ADDED, ret, done,
167 "wrong action (exp: ADDED)");
168 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[2].name, "subdir-name",
170 torture_assert_int_equal_goto(mem_ctx,
171 notify.nttrans.out.changes[3].action,
172 NOTIFY_ACTION_REMOVED, ret, done,
173 "wrong action (exp: REMOVED)");
174 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[3].name, "subdir-name",
177 count = torture_numops;
178 printf("Testing buffered notify on create of %d files\n", count);
179 for (i=0;i<count;i++) {
180 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
181 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
183 printf("Failed to create %s - %s\n",
184 fname, smbcli_errstr(cli->tree));
189 smbcli_close(cli->tree, fnum3);
192 /* (1st notify) setup a new notify on a different directory handle.
193 This new notify won't see the events above. */
194 notify.nttrans.in.file.fnum = fnum2;
195 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
197 /* (2nd notify) whereas this notify will see the above buffered events,
198 and it directly returns the buffered events */
199 notify.nttrans.in.file.fnum = fnum;
200 req = smb_raw_changenotify_send(cli->tree, ¬ify);
202 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistent.txt");
203 torture_assert_ntstatus_equal_goto(mem_ctx, status,
204 NT_STATUS_OBJECT_NAME_NOT_FOUND,
208 /* (1st unlink) as the 2nd notify directly returns,
209 this unlink is only seen by the 1st notify and
210 the 3rd notify (later) */
211 printf("Testing notify on unlink for the first file\n");
212 status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
213 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
216 /* receive the reply from the 2nd notify */
217 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
218 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
219 "smb_raw_changenotify_recv");
221 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
223 "wrong number of changes");
224 for (i=1;i<count;i++) {
225 torture_assert_int_equal_goto(mem_ctx,
226 notify.nttrans.out.changes[i].action,
227 NOTIFY_ACTION_ADDED, ret, done,
228 "wrong action (exp: ADDED)");
230 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "test0.txt",
233 printf("and now from the 1st notify\n");
234 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
235 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
236 "smb_raw_changenotify_recv");
237 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
238 1, ret, done, "wrong number of changes");
239 torture_assert_int_equal_goto(mem_ctx,
240 notify.nttrans.out.changes[0].action,
241 NOTIFY_ACTION_REMOVED, ret, done,
242 "wrong action (exp: REMOVED)");
243 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "test0.txt",
246 printf("(3rd notify) this notify will only see the 1st unlink\n");
247 req = smb_raw_changenotify_send(cli->tree, ¬ify);
249 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistent.txt");
250 torture_assert_ntstatus_equal_goto(mem_ctx, status,
251 NT_STATUS_OBJECT_NAME_NOT_FOUND,
255 printf("Testing notify on wildcard unlink for %d files\n", count-1);
256 /* (2nd unlink) do a wildcard unlink */
257 status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
258 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
259 "smb_raw_changenotify_recv");
261 /* receive the 3rd notify */
262 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
263 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
264 "smb_raw_changenotify_recv");
265 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
266 1, ret, done, "wrong number of changes");
267 torture_assert_int_equal_goto(mem_ctx,
268 notify.nttrans.out.changes[0].action,
269 NOTIFY_ACTION_REMOVED, ret, done,
270 "wrong action (exp: REMOVED)");
271 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "test0.txt",
274 /* and we now see the rest of the unlink calls on both directory handles */
275 notify.nttrans.in.file.fnum = fnum;
277 req = smb_raw_changenotify_send(cli->tree, ¬ify);
278 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
279 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
280 "smb_raw_changenotify_recv");
281 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
282 count - 1, ret, done,
283 "wrong number of changes");
284 for (i=0;i<notify.nttrans.out.num_changes;i++) {
285 torture_assert_int_equal_goto(mem_ctx,
286 notify.nttrans.out.changes[i].action,
287 NOTIFY_ACTION_REMOVED, ret, done,
288 "wrong action (exp: REMOVED)");
290 notify.nttrans.in.file.fnum = fnum2;
291 req = smb_raw_changenotify_send(cli->tree, ¬ify);
292 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
293 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
294 "smb_raw_changenotify_recv");
295 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
296 count - 1, ret, done,
297 "wrong number of changes");
298 for (i=0;i<notify.nttrans.out.num_changes;i++) {
299 torture_assert_int_equal_goto(mem_ctx,
300 notify.nttrans.out.changes[i].action,
301 NOTIFY_ACTION_REMOVED, ret, done,
302 "wrong action (exp: REMOVED)");
305 printf("Testing if a close() on the dir handle triggers the notify reply\n");
307 notify.nttrans.in.file.fnum = fnum;
308 req = smb_raw_changenotify_send(cli->tree, ¬ify);
310 cl.close.level = RAW_CLOSE_CLOSE;
311 cl.close.in.file.fnum = fnum;
312 cl.close.in.write_time = 0;
313 status = smb_raw_close(cli->tree, &cl);
314 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
317 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
318 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
319 "smb_raw_changenotify_recv");
320 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
321 0, ret, done, "no changes expected");
324 smb_raw_exit(cli->session);
325 smbcli_deltree(cli->tree, BASEDIR);
330 * Check notify reply for a rename action. Not sure if this is a valid thing
331 * to do, but depending on timing between inotify and messaging we get the
332 * add/remove/modify in any order. This routines tries to find the action/name
333 * pair in any of the three following notify_changes.
336 static bool check_rename_reply(struct torture_context *tctx,
337 struct smbcli_state *cli,
339 struct notify_changes *actions,
340 uint32_t action, const char *name)
344 for (i=0; i<3; i++) {
345 if (actions[i].action == action) {
346 CHECK_WSTR(tctx, actions[i].name, name, STR_UNICODE);
351 torture_result(tctx, TORTURE_FAIL,
352 __location__": (%d) expected action %d, not found\n",
358 testing of recursive change notify
360 static bool test_notify_recursive(struct torture_context *mem_ctx,
361 struct smbcli_state *cli,
362 struct smbcli_state *cli2)
366 union smb_notify notify;
369 struct smbcli_request *req1, *req2;
371 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
373 if (!torture_setup_dir(cli, BASEDIR)) {
378 get a handle on the directory
380 io.generic.level = RAW_OPEN_NTCREATEX;
381 io.ntcreatex.in.root_fid.fnum = 0;
382 io.ntcreatex.in.flags = 0;
383 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
384 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
385 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
386 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
387 io.ntcreatex.in.alloc_size = 0;
388 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
389 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
390 io.ntcreatex.in.security_flags = 0;
391 io.ntcreatex.in.fname = BASEDIR;
393 status = smb_raw_open(cli->tree, mem_ctx, &io);
394 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
396 fnum = io.ntcreatex.out.file.fnum;
398 /* ask for a change notify, on file or directory name
399 changes. Setup both with and without recursion */
400 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
401 notify.nttrans.in.buffer_size = 1000;
402 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
403 notify.nttrans.in.file.fnum = fnum;
405 notify.nttrans.in.recursive = true;
406 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
408 notify.nttrans.in.recursive = false;
409 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
411 /* cancel initial requests so the buffer is setup */
412 smb_raw_ntcancel(req1);
413 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
414 torture_assert_ntstatus_equal_goto(mem_ctx, status,
417 "smb_raw_changenotify_recv");
419 smb_raw_ntcancel(req2);
420 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
421 torture_assert_ntstatus_equal_goto(mem_ctx, status,
424 "smb_raw_changenotify_recv");
427 * Make notifies a bit more interesting in a cluster by doing
428 * the changes against different nodes with --unclist
430 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
431 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name\\subname1");
432 smbcli_close(cli->tree,
433 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
434 smbcli_rename(cli2->tree, BASEDIR "\\subdir-name\\subname1",
435 BASEDIR "\\subdir-name\\subname1-r");
436 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
437 smbcli_rename(cli2->tree, BASEDIR "\\subname2-r",
438 BASEDIR "\\subname3-r");
440 notify.nttrans.in.completion_filter = 0;
441 notify.nttrans.in.recursive = true;
443 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
445 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
446 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
447 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
449 notify.nttrans.in.recursive = false;
450 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
452 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
453 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
454 "smb_raw_changenotify_recv");
456 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
457 11, ret, done, "wrong number of changes");
458 torture_assert_int_equal_goto(mem_ctx,
459 notify.nttrans.out.changes[0].action,
460 NOTIFY_ACTION_ADDED, ret, done,
461 "wrong action (exp: ADDED)");
462 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name",
464 torture_assert_int_equal_goto(mem_ctx,
465 notify.nttrans.out.changes[1].action,
466 NOTIFY_ACTION_ADDED, ret, done,
467 "wrong action (exp: ADDED)");
468 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[1].name,
469 "subdir-name\\subname1", STR_UNICODE);
470 torture_assert_int_equal_goto(mem_ctx,
471 notify.nttrans.out.changes[2].action,
472 NOTIFY_ACTION_ADDED, ret, done,
473 "wrong action (exp: ADDED)");
474 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[2].name,
475 "subdir-name\\subname2", STR_UNICODE);
476 torture_assert_int_equal_goto(mem_ctx,
477 notify.nttrans.out.changes[3].action,
478 NOTIFY_ACTION_OLD_NAME, ret, done,
479 "wrong action (exp: OLD_NAME)");
480 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[3].name,
481 "subdir-name\\subname1", STR_UNICODE);
482 torture_assert_int_equal_goto(mem_ctx,
483 notify.nttrans.out.changes[4].action,
484 NOTIFY_ACTION_NEW_NAME, ret, done,
485 "wrong action (exp: NEW_NAME)");
486 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[4].name,
487 "subdir-name\\subname1-r", STR_UNICODE);
489 ret &= check_rename_reply(mem_ctx,
490 cli, __LINE__, ¬ify.nttrans.out.changes[5],
491 NOTIFY_ACTION_ADDED, "subname2-r");
492 ret &= check_rename_reply(mem_ctx,
493 cli, __LINE__, ¬ify.nttrans.out.changes[5],
494 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
495 ret &= check_rename_reply(mem_ctx,
496 cli, __LINE__, ¬ify.nttrans.out.changes[5],
497 NOTIFY_ACTION_MODIFIED, "subname2-r");
499 ret &= check_rename_reply(mem_ctx,
500 cli, __LINE__, ¬ify.nttrans.out.changes[8],
501 NOTIFY_ACTION_OLD_NAME, "subname2-r");
502 ret &= check_rename_reply(mem_ctx,
503 cli, __LINE__, ¬ify.nttrans.out.changes[8],
504 NOTIFY_ACTION_NEW_NAME, "subname3-r");
505 ret &= check_rename_reply(mem_ctx,
506 cli, __LINE__, ¬ify.nttrans.out.changes[8],
507 NOTIFY_ACTION_MODIFIED, "subname3-r");
513 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
514 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
515 "smb_raw_changenotify_recv");
517 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
518 3, ret, done, "wrong number of changes");
519 torture_assert_int_equal_goto(mem_ctx,
520 notify.nttrans.out.changes[0].action,
521 NOTIFY_ACTION_REMOVED, ret, done,
522 "wrong action (exp: REMOVED)");
523 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name,
524 "subdir-name\\subname1-r", STR_UNICODE);
525 torture_assert_int_equal_goto(mem_ctx,
526 notify.nttrans.out.changes[1].action,
527 NOTIFY_ACTION_REMOVED, ret, done,
528 "wrong action (exp: REMOVED)");
529 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[1].name, "subdir-name",
531 torture_assert_int_equal_goto(mem_ctx,
532 notify.nttrans.out.changes[2].action,
533 NOTIFY_ACTION_REMOVED, ret, done,
534 "wrong action (exp: REMOVED)");
535 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[2].name, "subname3-r",
539 smb_raw_exit(cli->session);
540 smbcli_deltree(cli->tree, BASEDIR);
545 testing of change notify mask change
547 static bool test_notify_mask_change(struct torture_context *mem_ctx,
548 struct smbcli_state *cli)
552 union smb_notify notify;
555 struct smbcli_request *req1, *req2;
557 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
559 if (!torture_setup_dir(cli, BASEDIR)) {
564 get a handle on the directory
566 io.generic.level = RAW_OPEN_NTCREATEX;
567 io.ntcreatex.in.root_fid.fnum = 0;
568 io.ntcreatex.in.flags = 0;
569 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
570 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
571 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
572 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
573 io.ntcreatex.in.alloc_size = 0;
574 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
575 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
576 io.ntcreatex.in.security_flags = 0;
577 io.ntcreatex.in.fname = BASEDIR;
579 status = smb_raw_open(cli->tree, mem_ctx, &io);
580 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
582 fnum = io.ntcreatex.out.file.fnum;
584 /* ask for a change notify, on file or directory name
585 changes. Setup both with and without recursion */
586 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
587 notify.nttrans.in.buffer_size = 1000;
588 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
589 notify.nttrans.in.file.fnum = fnum;
591 notify.nttrans.in.recursive = true;
592 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
594 notify.nttrans.in.recursive = false;
595 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
597 /* cancel initial requests so the buffer is setup */
598 smb_raw_ntcancel(req1);
599 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
600 torture_assert_ntstatus_equal_goto(mem_ctx, status,
603 "smb_raw_changenotify_recv");
605 smb_raw_ntcancel(req2);
606 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
607 torture_assert_ntstatus_equal_goto(mem_ctx, status,
610 "smb_raw_changenotify_recv");
612 notify.nttrans.in.recursive = true;
613 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
615 /* Set to hidden then back again. */
616 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));
617 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
618 smbcli_unlink(cli->tree, BASEDIR "\\tname1");
620 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
621 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
622 "smb_raw_changenotify_recv");
624 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
625 1, ret, done, "wrong number of changes");
626 torture_assert_int_equal_goto(mem_ctx,
627 notify.nttrans.out.changes[0].action,
628 NOTIFY_ACTION_MODIFIED, ret, done,
629 "wrong action (exp: MODIFIED)");
630 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "tname1",
633 /* Now try and change the mask to include other events.
634 * This should not work - once the mask is set on a directory
635 * fnum it seems to be fixed until the fnum is closed. */
637 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
638 notify.nttrans.in.recursive = true;
639 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
641 notify.nttrans.in.recursive = false;
642 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
644 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
645 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
646 smbcli_close(cli->tree,
647 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
648 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
649 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
650 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
652 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
653 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
654 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
656 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
657 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
658 "smb_raw_changenotify_recv");
660 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
661 1, ret, done, "wrong number of changes");
662 torture_assert_int_equal_goto(mem_ctx,
663 notify.nttrans.out.changes[0].action,
664 NOTIFY_ACTION_MODIFIED, ret, done,
665 "wrong action (exp: MODIFIED)");
666 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subname2-r",
669 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
670 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
671 "smb_raw_changenotify_recv");
673 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
674 1, ret, done, "wrong number of changes");
675 torture_assert_int_equal_goto(mem_ctx,
676 notify.nttrans.out.changes[0].action,
677 NOTIFY_ACTION_MODIFIED, ret, done,
678 "wrong action (exp: MODIFIED)");
679 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subname3-r",
687 smb_raw_exit(cli->session);
688 smbcli_deltree(cli->tree, BASEDIR);
694 testing of mask bits for change notify
696 static bool test_notify_mask(struct torture_context *tctx,
697 struct smbcli_state *cli,
698 struct smbcli_state *cli2)
702 union smb_notify notify;
704 union smb_chkpath chkpath;
712 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
714 if (!torture_setup_dir(cli, BASEDIR)) {
718 tv = timeval_current_ofs(1000, 0);
719 t = timeval_to_nttime(&tv);
722 get a handle on the directory
724 io.generic.level = RAW_OPEN_NTCREATEX;
725 io.ntcreatex.in.root_fid.fnum = 0;
726 io.ntcreatex.in.flags = 0;
727 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
728 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
729 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
730 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
731 io.ntcreatex.in.alloc_size = 0;
732 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
733 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
734 io.ntcreatex.in.security_flags = 0;
735 io.ntcreatex.in.fname = BASEDIR;
737 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
738 notify.nttrans.in.buffer_size = 1000;
739 notify.nttrans.in.recursive = true;
741 chkpath.chkpath.in.path = "\\";
743 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
745 smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
746 do { for (mask=i=0;i<32;i++) { \
747 struct smbcli_request *req; \
748 status = smb_raw_open(cli->tree, tctx, &io); \
749 torture_assert_ntstatus_ok_goto(tctx, status, ret, done, \
751 fnum = io.ntcreatex.out.file.fnum; \
753 notify.nttrans.in.file.fnum = fnum; \
754 notify.nttrans.in.completion_filter = (1<<i); \
755 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
756 smb_raw_chkpath(cli->tree, &chkpath); \
758 smb_msleep(200); smb_raw_ntcancel(req); \
759 status = smb_raw_changenotify_recv(req, tctx, ¬ify); \
761 smbcli_close(cli->tree, fnum); \
762 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
763 torture_assert_ntstatus_ok_goto(tctx, status, ret, done, \
765 /* special case to cope with file rename behaviour */ \
766 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
767 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
768 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
769 Action == NOTIFY_ACTION_OLD_NAME) { \
770 printf("(rename file special handling OK)\n"); \
771 } else if (nchanges != notify.nttrans.out.num_changes) { \
772 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
773 notify.nttrans.out.num_changes, \
775 notify.nttrans.out.changes[0].action, \
776 notify.nttrans.in.completion_filter); \
778 } else if (notify.nttrans.out.changes[0].action != Action) { \
779 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
780 notify.nttrans.out.num_changes, \
781 notify.nttrans.out.changes[0].action, \
783 notify.nttrans.in.completion_filter); \
785 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
786 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
787 notify.nttrans.out.num_changes, \
788 notify.nttrans.out.changes[0].action, \
789 notify.nttrans.in.completion_filter, \
790 notify.nttrans.out.changes[0].name.s); \
795 if ((expected) != mask) { \
796 if (((expected) & ~mask) != 0) { \
797 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
801 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
808 printf("Testing mkdir\n");
809 NOTIFY_MASK_TEST("Testing mkdir",;,
810 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
811 smbcli_rmdir(cli2->tree, BASEDIR "\\tname1");,
813 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
815 printf("Testing create file\n");
816 NOTIFY_MASK_TEST("Testing create file",;,
817 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
818 smbcli_unlink(cli2->tree, BASEDIR "\\tname1");,
820 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
822 printf("Testing unlink\n");
823 NOTIFY_MASK_TEST("Testing unlink",
824 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
825 smbcli_unlink(cli2->tree, BASEDIR "\\tname1");,
827 NOTIFY_ACTION_REMOVED,
828 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
830 printf("Testing rmdir\n");
831 NOTIFY_MASK_TEST("Testing rmdir",
832 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
833 smbcli_rmdir(cli2->tree, BASEDIR "\\tname1");,
835 NOTIFY_ACTION_REMOVED,
836 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
838 printf("Testing rename file\n");
839 NOTIFY_MASK_TEST("Testing rename file",
840 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
841 smbcli_rename(cli2->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
842 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
843 NOTIFY_ACTION_OLD_NAME,
844 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
846 printf("Testing rename dir\n");
847 NOTIFY_MASK_TEST("Testing rename dir",
848 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
849 smbcli_rename(cli2->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
850 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
851 NOTIFY_ACTION_OLD_NAME,
852 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
854 printf("Testing set path attribute\n");
855 NOTIFY_MASK_TEST("Testing set path attribute",
856 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
857 smbcli_setatr(cli2->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
858 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
859 NOTIFY_ACTION_MODIFIED,
860 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
862 printf("Testing set path write time\n");
863 NOTIFY_MASK_TEST("Testing set path write time",
864 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
865 smbcli_setatr(cli2->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
866 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
867 NOTIFY_ACTION_MODIFIED,
868 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
870 printf("Testing set file attribute\n");
871 NOTIFY_MASK_TEST("Testing set file attribute",
872 fnum2 = create_complex_file(cli2, tctx, BASEDIR "\\tname1");,
873 smbcli_fsetatr(cli2->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
874 (smbcli_close(cli2->tree, fnum2), smbcli_unlink(cli2->tree, BASEDIR "\\tname1"));,
875 NOTIFY_ACTION_MODIFIED,
876 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
878 if (torture_setting_bool(tctx, "samba3", false)) {
879 printf("Samba3 does not yet support create times "
883 printf("Testing set file create time\n");
884 NOTIFY_MASK_TEST("Testing set file create time",
885 fnum2 = create_complex_file(cli, tctx,
886 BASEDIR "\\tname1");,
887 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
888 (smbcli_close(cli->tree, fnum2),
889 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
890 NOTIFY_ACTION_MODIFIED,
891 FILE_NOTIFY_CHANGE_CREATION, 1);
894 printf("Testing set file access time\n");
895 NOTIFY_MASK_TEST("Testing set file access time",
896 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
897 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
898 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
899 NOTIFY_ACTION_MODIFIED,
900 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
902 printf("Testing set file write time\n");
903 NOTIFY_MASK_TEST("Testing set file write time",
904 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
905 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
906 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
907 NOTIFY_ACTION_MODIFIED,
908 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
910 printf("Testing set file change time\n");
911 NOTIFY_MASK_TEST("Testing set file change time",
912 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
913 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
914 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
915 NOTIFY_ACTION_MODIFIED,
919 printf("Testing write\n");
920 NOTIFY_MASK_TEST("Testing write",
921 fnum2 = create_complex_file(cli2, tctx, BASEDIR "\\tname1");,
922 smbcli_write(cli2->tree, fnum2, 1, &c, 10000, 1);,
923 (smbcli_close(cli2->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
924 NOTIFY_ACTION_MODIFIED,
927 printf("Testing truncate\n");
928 NOTIFY_MASK_TEST("Testing truncate",
929 fnum2 = create_complex_file(cli2, tctx, BASEDIR "\\tname1");,
930 smbcli_ftruncate(cli2->tree, fnum2, 10000);,
931 (smbcli_close(cli2->tree, fnum2), smbcli_unlink(cli2->tree, BASEDIR "\\tname1"));,
932 NOTIFY_ACTION_MODIFIED,
933 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
936 smb_raw_exit(cli->session);
937 smbcli_deltree(cli->tree, BASEDIR);
942 basic testing of change notify on files
944 static bool test_notify_file(struct torture_context *mem_ctx,
945 struct smbcli_state *cli)
951 union smb_notify notify;
952 struct smbcli_request *req;
954 const char *fname = BASEDIR "\\file.txt";
956 printf("TESTING CHANGE NOTIFY ON FILES\n");
958 if (!torture_setup_dir(cli, BASEDIR)) {
962 io.generic.level = RAW_OPEN_NTCREATEX;
963 io.ntcreatex.in.root_fid.fnum = 0;
964 io.ntcreatex.in.flags = 0;
965 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
966 io.ntcreatex.in.create_options = 0;
967 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
968 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
969 io.ntcreatex.in.alloc_size = 0;
970 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
971 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
972 io.ntcreatex.in.security_flags = 0;
973 io.ntcreatex.in.fname = fname;
974 status = smb_raw_open(cli->tree, mem_ctx, &io);
975 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
977 fnum = io.ntcreatex.out.file.fnum;
979 /* ask for a change notify,
980 on file or directory name changes */
981 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
982 notify.nttrans.in.file.fnum = fnum;
983 notify.nttrans.in.buffer_size = 1000;
984 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
985 notify.nttrans.in.recursive = false;
987 printf("Testing if notifies on file handles are invalid (should be)\n");
989 req = smb_raw_changenotify_send(cli->tree, ¬ify);
990 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
991 torture_assert_ntstatus_equal_goto(mem_ctx, status,
992 NT_STATUS_INVALID_PARAMETER,
994 "smb_raw_changenotify_recv");
996 cl.close.level = RAW_CLOSE_CLOSE;
997 cl.close.in.file.fnum = fnum;
998 cl.close.in.write_time = 0;
999 status = smb_raw_close(cli->tree, &cl);
1000 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1003 status = smbcli_unlink(cli->tree, fname);
1004 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1008 smb_raw_exit(cli->session);
1009 smbcli_deltree(cli->tree, BASEDIR);
1014 basic testing of change notifies followed by a tdis
1016 static bool test_notify_tdis(struct torture_context *tctx,
1017 struct smbcli_state *cli1)
1021 union smb_notify notify;
1024 struct smbcli_request *req;
1025 struct smbcli_state *cli = NULL;
1027 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
1029 if (!torture_setup_dir(cli1, BASEDIR)) {
1033 if (!torture_open_connection(&cli, tctx, 0)) {
1038 get a handle on the directory
1040 io.generic.level = RAW_OPEN_NTCREATEX;
1041 io.ntcreatex.in.root_fid.fnum = 0;
1042 io.ntcreatex.in.flags = 0;
1043 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1044 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1045 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1046 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1047 io.ntcreatex.in.alloc_size = 0;
1048 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1049 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1050 io.ntcreatex.in.security_flags = 0;
1051 io.ntcreatex.in.fname = BASEDIR;
1053 status = smb_raw_open(cli->tree, tctx, &io);
1054 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1056 fnum = io.ntcreatex.out.file.fnum;
1058 /* ask for a change notify,
1059 on file or directory name changes */
1060 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1061 notify.nttrans.in.buffer_size = 1000;
1062 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1063 notify.nttrans.in.file.fnum = fnum;
1064 notify.nttrans.in.recursive = true;
1066 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1068 status = smbcli_tdis(cli);
1069 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1073 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1074 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1075 "smb_raw_changenotify_recv");
1076 torture_assert_int_equal_goto(tctx, notify.nttrans.out.num_changes,
1077 0, ret, done, "no changes expected");
1080 torture_close_connection(cli);
1081 smbcli_deltree(cli1->tree, BASEDIR);
1086 basic testing of change notifies followed by a exit
1088 static bool test_notify_exit(struct torture_context *tctx,
1089 struct smbcli_state *cli1)
1093 union smb_notify notify;
1096 struct smbcli_request *req;
1097 struct smbcli_state *cli = NULL;
1099 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
1101 if (!torture_setup_dir(cli1, BASEDIR)) {
1105 if (!torture_open_connection(&cli, tctx, 0)) {
1110 get a handle on the directory
1112 io.generic.level = RAW_OPEN_NTCREATEX;
1113 io.ntcreatex.in.root_fid.fnum = 0;
1114 io.ntcreatex.in.flags = 0;
1115 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1116 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1117 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1118 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1119 io.ntcreatex.in.alloc_size = 0;
1120 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1121 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1122 io.ntcreatex.in.security_flags = 0;
1123 io.ntcreatex.in.fname = BASEDIR;
1125 status = smb_raw_open(cli->tree, tctx, &io);
1126 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1128 fnum = io.ntcreatex.out.file.fnum;
1130 /* ask for a change notify,
1131 on file or directory name changes */
1132 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1133 notify.nttrans.in.buffer_size = 1000;
1134 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1135 notify.nttrans.in.file.fnum = fnum;
1136 notify.nttrans.in.recursive = true;
1138 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1140 status = smb_raw_exit(cli->session);
1141 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1144 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1145 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1146 "smb_raw_changenotify_recv");
1147 torture_assert_int_equal_goto(tctx, notify.nttrans.out.num_changes,
1148 0, ret, done, "no changes expected");
1151 torture_close_connection(cli);
1152 smbcli_deltree(cli1->tree, BASEDIR);
1157 basic testing of change notifies followed by a ulogoff
1159 static bool test_notify_ulogoff(struct torture_context *tctx,
1160 struct smbcli_state *cli1)
1164 union smb_notify notify;
1167 struct smbcli_request *req;
1168 struct smbcli_state *cli = NULL;
1170 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1172 if (!torture_setup_dir(cli1, BASEDIR)) {
1176 if (!torture_open_connection(&cli, tctx, 0)) {
1181 get a handle on the directory
1183 io.generic.level = RAW_OPEN_NTCREATEX;
1184 io.ntcreatex.in.root_fid.fnum = 0;
1185 io.ntcreatex.in.flags = 0;
1186 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1187 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1188 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1189 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1190 io.ntcreatex.in.alloc_size = 0;
1191 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1192 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1193 io.ntcreatex.in.security_flags = 0;
1194 io.ntcreatex.in.fname = BASEDIR;
1196 status = smb_raw_open(cli->tree, tctx, &io);
1197 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1199 fnum = io.ntcreatex.out.file.fnum;
1201 /* ask for a change notify,
1202 on file or directory name changes */
1203 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1204 notify.nttrans.in.buffer_size = 1000;
1205 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1206 notify.nttrans.in.file.fnum = fnum;
1207 notify.nttrans.in.recursive = true;
1209 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1211 status = smb_raw_ulogoff(cli->session);
1212 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1215 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1216 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1217 "smb_raw_changenotify_recv");
1218 torture_assert_int_equal_goto(tctx, notify.nttrans.out.num_changes,
1219 0, ret, done, "no changes expected");
1222 torture_close_connection(cli);
1223 smbcli_deltree(cli1->tree, BASEDIR);
1227 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
1229 struct smbcli_state *cli = (struct smbcli_state *)p;
1230 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
1231 cli->transport = NULL;
1235 basic testing of change notifies followed by tcp disconnect
1237 static bool test_notify_tcp_dis(struct torture_context *tctx,
1238 struct smbcli_state *cli1)
1242 union smb_notify notify;
1245 struct smbcli_request *req;
1246 struct smbcli_state *cli = NULL;
1248 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1250 if (!torture_setup_dir(cli1, BASEDIR)) {
1254 if (!torture_open_connection(&cli, tctx, 0)) {
1259 get a handle on the directory
1261 io.generic.level = RAW_OPEN_NTCREATEX;
1262 io.ntcreatex.in.root_fid.fnum = 0;
1263 io.ntcreatex.in.flags = 0;
1264 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1265 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1266 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1267 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1268 io.ntcreatex.in.alloc_size = 0;
1269 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1270 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1271 io.ntcreatex.in.security_flags = 0;
1272 io.ntcreatex.in.fname = BASEDIR;
1274 status = smb_raw_open(cli->tree, tctx, &io);
1275 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1277 fnum = io.ntcreatex.out.file.fnum;
1279 /* ask for a change notify,
1280 on file or directory name changes */
1281 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1282 notify.nttrans.in.buffer_size = 1000;
1283 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1284 notify.nttrans.in.file.fnum = fnum;
1285 notify.nttrans.in.recursive = true;
1287 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1289 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
1291 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1292 torture_assert_ntstatus_equal_goto(tctx, status,
1293 NT_STATUS_LOCAL_DISCONNECT,
1295 "smb_raw_changenotify_recv");
1298 torture_close_connection(cli);
1299 smbcli_deltree(cli1->tree, BASEDIR);
1304 test setting up two change notify requests on one handle
1306 static bool test_notify_double(struct torture_context *mem_ctx,
1307 struct smbcli_state *cli)
1311 union smb_notify notify;
1314 struct smbcli_request *req1, *req2;
1316 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1318 if (!torture_setup_dir(cli, BASEDIR)) {
1322 get a handle on the directory
1324 io.generic.level = RAW_OPEN_NTCREATEX;
1325 io.ntcreatex.in.root_fid.fnum = 0;
1326 io.ntcreatex.in.flags = 0;
1327 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1328 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1329 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1330 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1331 io.ntcreatex.in.alloc_size = 0;
1332 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1333 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1334 io.ntcreatex.in.security_flags = 0;
1335 io.ntcreatex.in.fname = BASEDIR;
1337 status = smb_raw_open(cli->tree, mem_ctx, &io);
1338 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1340 fnum = io.ntcreatex.out.file.fnum;
1342 /* ask for a change notify,
1343 on file or directory name changes */
1344 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1345 notify.nttrans.in.buffer_size = 1000;
1346 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1347 notify.nttrans.in.file.fnum = fnum;
1348 notify.nttrans.in.recursive = true;
1350 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1351 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
1353 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1355 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1356 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1357 "smb_raw_changenotify_recv");
1358 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
1359 1, ret, done, "wrong number of changes");
1360 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name",
1363 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1365 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
1366 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1367 "smb_raw_changenotify_recv");
1368 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
1369 1, ret, done, "wrong number of changes");
1370 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subdir-name2",
1374 smb_raw_exit(cli->session);
1375 smbcli_deltree(cli->tree, BASEDIR);
1381 test multiple change notifies at different depths and with/without recursion
1383 static bool test_notify_tree(struct torture_context *mem_ctx,
1384 struct smbcli_state *cli,
1385 struct smbcli_state *cli2)
1388 union smb_notify notify;
1390 struct smbcli_request *req;
1400 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 30 },
1401 {BASEDIR "\\zqy", true, FILE_NOTIFY_CHANGE_NAME, 8 },
1402 {BASEDIR "\\atsy", true, FILE_NOTIFY_CHANGE_NAME, 4 },
1403 {BASEDIR "\\abc\\foo", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1404 {BASEDIR "\\abc\\blah", true, FILE_NOTIFY_CHANGE_NAME, 13 },
1405 {BASEDIR "\\abc\\blah", false, FILE_NOTIFY_CHANGE_NAME, 7 },
1406 {BASEDIR "\\abc\\blah\\a", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1407 {BASEDIR "\\abc\\blah\\b", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1408 {BASEDIR "\\abc\\blah\\c", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1409 {BASEDIR "\\abc\\fooblah", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1410 {BASEDIR "\\zqy\\xx", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1411 {BASEDIR "\\zqy\\yyy", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1412 {BASEDIR "\\zqy\\..", true, FILE_NOTIFY_CHANGE_NAME, 40 },
1413 {BASEDIR, true, FILE_NOTIFY_CHANGE_NAME, 40 },
1414 {BASEDIR, false,FILE_NOTIFY_CHANGE_NAME, 6 },
1415 {BASEDIR "\\atsy", false,FILE_NOTIFY_CHANGE_NAME, 4 },
1416 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1417 {BASEDIR "\\abc", false,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1418 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1419 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1423 bool all_done = false;
1425 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1427 if (!torture_setup_dir(cli, BASEDIR)) {
1431 io.generic.level = RAW_OPEN_NTCREATEX;
1432 io.ntcreatex.in.root_fid.fnum = 0;
1433 io.ntcreatex.in.flags = 0;
1434 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1435 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1436 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1437 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1438 io.ntcreatex.in.alloc_size = 0;
1439 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1440 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1441 io.ntcreatex.in.security_flags = 0;
1443 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1444 notify.nttrans.in.buffer_size = 20000;
1447 setup the directory tree, and the notify buffer on each directory
1449 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1450 io.ntcreatex.in.fname = dirs[i].path;
1451 status = smb_raw_open(cli->tree, mem_ctx, &io);
1452 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1454 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1456 notify.nttrans.in.completion_filter = dirs[i].filter;
1457 notify.nttrans.in.file.fnum = dirs[i].fnum;
1458 notify.nttrans.in.recursive = dirs[i].recursive;
1459 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1460 smb_raw_ntcancel(req);
1461 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1462 torture_assert_ntstatus_equal_goto(mem_ctx, status,
1463 NT_STATUS_CANCELLED,
1465 "smb_raw_changenotify_recv");
1468 /* trigger 2 events in each dir */
1469 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1470 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1472 * Make notifies a bit more interesting in a cluster
1473 * by doing the changes against different nodes with
1476 smbcli_mkdir(cli->tree, path);
1477 smbcli_rmdir(cli2->tree, path);
1481 /* give a bit of time for the events to propogate */
1482 tv = timeval_current();
1485 /* count events that have happened in each dir */
1486 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1487 notify.nttrans.in.file.fnum = dirs[i].fnum;
1488 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1489 smb_raw_ntcancel(req);
1490 notify.nttrans.out.num_changes = 0;
1491 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1492 dirs[i].counted += notify.nttrans.out.num_changes;
1497 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1498 if (dirs[i].counted != dirs[i].expected) {
1502 } while (!all_done && timeval_elapsed(&tv) < 20);
1504 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1506 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1507 if (dirs[i].counted != dirs[i].expected) {
1508 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1509 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1515 run from the back, closing and deleting
1517 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1518 smbcli_close(cli->tree, dirs[i].fnum);
1519 smbcli_rmdir(cli->tree, dirs[i].path);
1523 smb_raw_exit(cli->session);
1524 smbcli_deltree(cli->tree, BASEDIR);
1529 Test response when cached server events exceed single NT NOTFIY response
1532 static bool test_notify_overflow(struct torture_context *mem_ctx,
1533 struct smbcli_state *cli)
1537 union smb_notify notify;
1541 struct smbcli_request *req1;
1544 printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
1546 if (!torture_setup_dir(cli, BASEDIR)) {
1550 /* get a handle on the directory */
1551 io.generic.level = RAW_OPEN_NTCREATEX;
1552 io.ntcreatex.in.root_fid.fnum = 0;
1553 io.ntcreatex.in.flags = 0;
1554 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1555 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1556 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1557 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1558 NTCREATEX_SHARE_ACCESS_WRITE;
1559 io.ntcreatex.in.alloc_size = 0;
1560 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1561 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1562 io.ntcreatex.in.security_flags = 0;
1563 io.ntcreatex.in.fname = BASEDIR;
1565 status = smb_raw_open(cli->tree, mem_ctx, &io);
1566 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1568 fnum = io.ntcreatex.out.file.fnum;
1570 /* ask for a change notify, on name changes. */
1571 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1572 notify.nttrans.in.buffer_size = 1000;
1573 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1574 notify.nttrans.in.file.fnum = fnum;
1576 notify.nttrans.in.recursive = true;
1577 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1579 /* cancel initial requests so the buffer is setup */
1580 smb_raw_ntcancel(req1);
1581 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1582 torture_assert_ntstatus_equal_goto(mem_ctx, status,
1583 NT_STATUS_CANCELLED,
1585 "smb_raw_changenotify_recv");
1587 /* open a lot of files, filling up the server side notify buffer */
1588 printf("Testing overflowed buffer notify on create of %d files\n",
1590 for (i=0;i<count;i++) {
1591 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
1592 int fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR,
1595 printf("Failed to create %s - %s\n",
1596 fname, smbcli_errstr(cli->tree));
1601 smbcli_close(cli->tree, fnum2);
1604 /* expect that 0 events will be returned with NT_STATUS_OK */
1605 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1606 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1607 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1608 "smb_raw_changenotify_recv");
1609 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
1610 0, ret, done, "no changes expected");
1613 smb_raw_exit(cli->session);
1614 smbcli_deltree(cli->tree, BASEDIR);
1619 Test if notifications are returned for changes to the base directory.
1622 static bool test_notify_basedir(struct torture_context *mem_ctx,
1623 struct smbcli_state *cli)
1627 union smb_notify notify;
1630 struct smbcli_request *req1;
1632 printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
1634 if (!torture_setup_dir(cli, BASEDIR)) {
1638 /* get a handle on the directory */
1639 io.generic.level = RAW_OPEN_NTCREATEX;
1640 io.ntcreatex.in.root_fid.fnum = 0;
1641 io.ntcreatex.in.flags = 0;
1642 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1643 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1644 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1645 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1646 NTCREATEX_SHARE_ACCESS_WRITE;
1647 io.ntcreatex.in.alloc_size = 0;
1648 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1649 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1650 io.ntcreatex.in.security_flags = 0;
1651 io.ntcreatex.in.fname = BASEDIR;
1653 status = smb_raw_open(cli->tree, mem_ctx, &io);
1654 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1656 fnum = io.ntcreatex.out.file.fnum;
1658 /* create a test file that will also be modified */
1659 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1",
1662 /* ask for a change notify, on attribute changes. */
1663 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1664 notify.nttrans.in.buffer_size = 1000;
1665 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
1666 notify.nttrans.in.file.fnum = fnum;
1667 notify.nttrans.in.recursive = true;
1669 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1671 /* set attribute on the base dir */
1672 smbcli_setatr(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN, 0);
1674 /* set attribute on a file to assure we receive a notification */
1675 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
1678 /* check how many responses were given, expect only 1 for the file */
1679 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1680 torture_assert_ntstatus_ok_goto(mem_ctx, status, ret, done,
1681 "smb_raw_changenotify_recv");
1682 torture_assert_int_equal_goto(mem_ctx, notify.nttrans.out.num_changes,
1683 1, ret, done, "wrong number of changes");
1684 torture_assert_int_equal_goto(mem_ctx,
1685 notify.nttrans.out.changes[0].action,
1686 NOTIFY_ACTION_MODIFIED, ret, done,
1687 "wrong action (exp: MODIFIED)");
1688 CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "tname1",
1692 smb_raw_exit(cli->session);
1693 smbcli_deltree(cli->tree, BASEDIR);
1699 create a secondary tree connect - used to test for a bug in Samba3 messaging
1702 static struct smbcli_tree *secondary_tcon(struct smbcli_state *cli,
1703 struct torture_context *tctx)
1706 const char *share, *host;
1707 struct smbcli_tree *tree;
1708 union smb_tcon tcon;
1710 share = torture_setting_string(tctx, "share", NULL);
1711 host = torture_setting_string(tctx, "host", NULL);
1713 printf("create a second tree context on the same session\n");
1714 tree = smbcli_tree_init(cli->session, tctx, false);
1716 tcon.generic.level = RAW_TCON_TCONX;
1717 tcon.tconx.in.flags = TCONX_FLAG_EXTENDED_RESPONSE;
1718 tcon.tconx.in.password = data_blob(NULL, 0);
1719 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
1720 tcon.tconx.in.device = "A:";
1721 status = smb_raw_tcon(tree, tctx, &tcon);
1722 if (!NT_STATUS_IS_OK(status)) {
1724 printf("Failed to create secondary tree\n");
1728 tree->tid = tcon.tconx.out.tid;
1729 printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid);
1736 very simple change notify test
1738 static bool test_notify_tcon(struct torture_context *torture,
1739 struct smbcli_state *cli)
1743 union smb_notify notify;
1746 struct smbcli_request *req;
1747 extern int torture_numops;
1748 struct smbcli_tree *tree = NULL;
1750 printf("TESTING SIMPLE CHANGE NOTIFY\n");
1752 if (!torture_setup_dir(cli, BASEDIR)) {
1757 get a handle on the directory
1759 io.generic.level = RAW_OPEN_NTCREATEX;
1760 io.ntcreatex.in.root_fid.fnum = 0;
1761 io.ntcreatex.in.flags = 0;
1762 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1763 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1764 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1765 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1766 io.ntcreatex.in.alloc_size = 0;
1767 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1768 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1769 io.ntcreatex.in.security_flags = 0;
1770 io.ntcreatex.in.fname = BASEDIR;
1772 status = smb_raw_open(cli->tree, torture, &io);
1773 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1775 fnum = io.ntcreatex.out.file.fnum;
1777 status = smb_raw_open(cli->tree, torture, &io);
1778 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1781 /* ask for a change notify,
1782 on file or directory name changes */
1783 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1784 notify.nttrans.in.buffer_size = 1000;
1785 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1786 notify.nttrans.in.file.fnum = fnum;
1787 notify.nttrans.in.recursive = true;
1789 printf("Testing notify mkdir\n");
1790 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1791 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1793 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1794 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1795 "smb_raw_changenotify_recv");
1797 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1798 1, ret, done, "wrong number of changes");
1799 torture_assert_int_equal_goto(torture,
1800 notify.nttrans.out.changes[0].action,
1801 NOTIFY_ACTION_ADDED, ret, done,
1802 "wrong action (exp: ADDED)");
1803 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1806 printf("Testing notify rmdir\n");
1807 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1808 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1810 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1811 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1812 "smb_raw_changenotify_recv");
1813 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1814 1, ret, done, "wrong number of changes");
1815 torture_assert_int_equal_goto(torture,
1816 notify.nttrans.out.changes[0].action,
1817 NOTIFY_ACTION_REMOVED, ret, done,
1818 "wrong action (exp: REMOVED)");
1819 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1822 printf("SIMPLE CHANGE NOTIFY OK\n");
1824 printf("TESTING WITH SECONDARY TCON\n");
1825 tree = secondary_tcon(cli, torture);
1827 printf("Testing notify mkdir\n");
1828 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1829 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1831 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1832 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1833 "smb_raw_changenotify_recv");
1835 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1836 1, ret, done, "wrong number of changes");
1837 torture_assert_int_equal_goto(torture,
1838 notify.nttrans.out.changes[0].action,
1839 NOTIFY_ACTION_ADDED, ret, done,
1840 "wrong action (exp: ADDED)");
1841 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1844 printf("Testing notify rmdir\n");
1845 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1846 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1848 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1849 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1850 "smb_raw_changenotify_recv");
1851 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1852 1, ret, done, "wrong number of changes");
1853 torture_assert_int_equal_goto(torture,
1854 notify.nttrans.out.changes[0].action,
1855 NOTIFY_ACTION_REMOVED, ret, done,
1856 "wrong action (exp: REMOVED)");
1857 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1860 printf("CHANGE NOTIFY WITH TCON OK\n");
1862 printf("Disconnecting secondary tree\n");
1863 status = smb_tree_disconnect(tree);
1864 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1865 "smb_tree_disconnect");
1868 printf("Testing notify mkdir\n");
1869 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1870 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1872 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1873 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1874 "smb_raw_changenotify_recv");
1876 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1877 1, ret, done, "wrong number of changes");
1878 torture_assert_int_equal_goto(torture,
1879 notify.nttrans.out.changes[0].action,
1880 NOTIFY_ACTION_ADDED, ret, done,
1881 "wrong action (exp: ADDED)");
1882 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1885 printf("Testing notify rmdir\n");
1886 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1887 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1889 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1890 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
1891 "smb_raw_changenotify_recv");
1892 torture_assert_int_equal_goto(torture, notify.nttrans.out.num_changes,
1893 1, ret, done, "wrong number of changes");
1894 torture_assert_int_equal_goto(torture,
1895 notify.nttrans.out.changes[0].action,
1896 NOTIFY_ACTION_REMOVED, ret, done,
1897 "wrong action (exp: REMOVED)");
1898 CHECK_WSTR(torture, notify.nttrans.out.changes[0].name, "subdir-name",
1901 printf("CHANGE NOTIFY WITH TDIS OK\n");
1903 smb_raw_exit(cli->session);
1904 smbcli_deltree(cli->tree, BASEDIR);
1910 testing alignment of multiple change notify infos
1912 static bool test_notify_alignment(struct torture_context *tctx,
1913 struct smbcli_state *cli)
1916 union smb_notify notify;
1919 struct smbcli_request *req;
1920 const char *fname = BASEDIR "\\starter";
1921 const char *fnames[] = { "a",
1925 int num_names = ARRAY_SIZE(fnames);
1928 torture_comment(tctx, "TESTING CHANGE NOTIFY REPLY ALIGNMENT\n");
1930 if (!torture_setup_dir(cli, BASEDIR)) {
1934 /* get a handle on the directory */
1935 io.generic.level = RAW_OPEN_NTCREATEX;
1936 io.ntcreatex.in.root_fid.fnum = 0;
1937 io.ntcreatex.in.flags = 0;
1938 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1939 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1940 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1941 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1942 NTCREATEX_SHARE_ACCESS_WRITE;
1943 io.ntcreatex.in.alloc_size = 0;
1944 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1945 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1946 io.ntcreatex.in.security_flags = 0;
1947 io.ntcreatex.in.fname = BASEDIR;
1949 status = smb_raw_open(cli->tree, tctx, &io);
1950 torture_assert_ntstatus_ok(tctx, status, "");
1951 fnum = io.ntcreatex.out.file.fnum;
1953 /* ask for a change notify, on file creation */
1954 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1955 notify.nttrans.in.buffer_size = 1000;
1956 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_FILE_NAME;
1957 notify.nttrans.in.file.fnum = fnum;
1958 notify.nttrans.in.recursive = false;
1960 /* start change tracking */
1961 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1963 fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1964 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1965 smbcli_close(cli->tree, fnum2);
1967 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1968 torture_assert_ntstatus_ok(tctx, status, "");
1970 /* create 4 files that will cause CHANGE_NOTIFY_INFO structures
1971 * to be returned in the same packet with all possible 4-byte padding
1972 * permutations. As per MS-CIFS 2.2.7.4.2 these structures should be
1973 * 4-byte aligned. */
1975 for (i = 0; i < num_names; i++) {
1976 fpath = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fnames[i]);
1977 fnum2 = smbcli_open(cli->tree, fpath,
1978 O_CREAT|O_RDWR, DENY_NONE);
1979 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1980 smbcli_close(cli->tree, fnum2);
1984 /* We send a notify packet, and let smb_raw_changenotify_recv() do
1985 * the alignment checking for us. */
1986 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1987 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1988 torture_assert_ntstatus_ok(tctx, status, "");
1990 /* Do basic checking for correctness. */
1991 torture_assert(tctx, notify.nttrans.out.num_changes == num_names, "");
1992 for (i = 0; i < num_names; i++) {
1993 torture_assert(tctx, notify.nttrans.out.changes[i].action ==
1994 NOTIFY_ACTION_ADDED, "");
1995 CHECK_WSTR(tctx, notify.nttrans.out.changes[i].name, fnames[i],
1999 smb_raw_exit(cli->session);
2000 smbcli_deltree(cli->tree, BASEDIR);
2004 struct torture_suite *torture_raw_notify(TALLOC_CTX *mem_ctx)
2006 struct torture_suite *suite = torture_suite_create(mem_ctx, "notify");
2008 torture_suite_add_1smb_test(suite, "tcon", test_notify_tcon);
2009 torture_suite_add_2smb_test(suite, "dir", test_notify_dir);
2010 torture_suite_add_2smb_test(suite, "mask", test_notify_mask);
2011 torture_suite_add_2smb_test(suite, "recursive", test_notify_recursive);
2012 torture_suite_add_1smb_test(suite, "mask_change",
2013 test_notify_mask_change);
2014 torture_suite_add_1smb_test(suite, "file", test_notify_file);
2015 torture_suite_add_1smb_test(suite, "tdis", test_notify_tdis);
2016 torture_suite_add_1smb_test(suite, "exit", test_notify_exit);
2017 torture_suite_add_1smb_test(suite, "ulogoff", test_notify_ulogoff);
2018 torture_suite_add_1smb_test(suite, "tcp_dis", test_notify_tcp_dis);
2019 torture_suite_add_1smb_test(suite, "double", test_notify_double);
2020 torture_suite_add_2smb_test(suite, "tree", test_notify_tree);
2021 torture_suite_add_1smb_test(suite, "overflow", test_notify_overflow);
2022 torture_suite_add_1smb_test(suite, "basedir", test_notify_basedir);
2023 torture_suite_add_1smb_test(suite, "alignment", test_notify_alignment);