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_STATUS(status, correct) do { \
31 if (!NT_STATUS_EQUAL(status, correct)) { \
32 printf("(%d) Incorrect status %s - should be %s\n", \
33 __LINE__, nt_errstr(status), nt_errstr(correct)); \
39 #define CHECK_VAL(v, correct) do { \
40 if ((v) != (correct)) { \
41 printf("(%d) wrong value for %s 0x%x should be 0x%x\n", \
42 __LINE__, #v, (int)v, (int)correct); \
47 #define CHECK_WSTR(field, value, flags) do { \
48 if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli->transport)) { \
49 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
54 #define CHECK_WSTR2(tctx, field, value, flags) \
56 if (!field.s || strcmp(field.s, value) || \
57 wire_bad_flags(&field, flags, cli->transport)) { \
58 torture_result(tctx, TORTURE_FAIL, \
59 "(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
64 basic testing of change notify on directories
66 static bool test_notify_dir(struct torture_context *mem_ctx,
67 struct smbcli_state *cli,
68 struct smbcli_state *cli2)
72 union smb_notify notify;
75 int i, count, fnum, fnum2;
76 struct smbcli_request *req, *req2;
77 extern int torture_numops;
79 printf("TESTING CHANGE NOTIFY ON DIRECTORIES\n");
81 if (!torture_setup_dir(cli, BASEDIR)) {
86 get a handle on the directory
88 io.generic.level = RAW_OPEN_NTCREATEX;
89 io.ntcreatex.in.root_fid.fnum = 0;
90 io.ntcreatex.in.flags = 0;
91 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
92 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
93 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
94 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
95 io.ntcreatex.in.alloc_size = 0;
96 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
97 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
98 io.ntcreatex.in.security_flags = 0;
99 io.ntcreatex.in.fname = BASEDIR;
101 status = smb_raw_open(cli->tree, mem_ctx, &io);
102 CHECK_STATUS(status, NT_STATUS_OK);
103 fnum = io.ntcreatex.out.file.fnum;
105 status = smb_raw_open(cli->tree, mem_ctx, &io);
106 CHECK_STATUS(status, NT_STATUS_OK);
107 fnum2 = io.ntcreatex.out.file.fnum;
109 /* ask for a change notify,
110 on file or directory name changes */
111 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
112 notify.nttrans.in.buffer_size = 1000;
113 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
114 notify.nttrans.in.file.fnum = fnum;
115 notify.nttrans.in.recursive = true;
117 printf("Testing notify cancel\n");
119 req = smb_raw_changenotify_send(cli->tree, ¬ify);
120 smb_raw_ntcancel(req);
121 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
122 CHECK_STATUS(status, NT_STATUS_CANCELLED);
124 printf("Testing notify mkdir\n");
126 req = smb_raw_changenotify_send(cli->tree, ¬ify);
127 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
129 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
130 CHECK_STATUS(status, NT_STATUS_OK);
132 CHECK_VAL(notify.nttrans.out.num_changes, 1);
133 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
134 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
136 printf("Testing notify rmdir\n");
138 req = smb_raw_changenotify_send(cli->tree, ¬ify);
139 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
141 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
142 CHECK_STATUS(status, NT_STATUS_OK);
143 CHECK_VAL(notify.nttrans.out.num_changes, 1);
144 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
145 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
147 printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
149 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
150 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
151 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
152 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
154 req = smb_raw_changenotify_send(cli->tree, ¬ify);
155 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
156 CHECK_STATUS(status, NT_STATUS_OK);
157 CHECK_VAL(notify.nttrans.out.num_changes, 4);
158 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
159 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
160 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
161 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
162 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
163 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name", STR_UNICODE);
164 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_REMOVED);
165 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name", STR_UNICODE);
167 count = torture_numops;
168 printf("Testing buffered notify on create of %d files\n", count);
169 for (i=0;i<count;i++) {
170 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
171 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
173 printf("Failed to create %s - %s\n",
174 fname, smbcli_errstr(cli->tree));
179 smbcli_close(cli->tree, fnum3);
182 /* (1st notify) setup a new notify on a different directory handle.
183 This new notify won't see the events above. */
184 notify.nttrans.in.file.fnum = fnum2;
185 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
187 /* (2nd notify) whereas this notify will see the above buffered events,
188 and it directly returns the buffered events */
189 notify.nttrans.in.file.fnum = fnum;
190 req = smb_raw_changenotify_send(cli->tree, ¬ify);
192 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
193 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
195 /* (1st unlink) as the 2nd notify directly returns,
196 this unlink is only seen by the 1st notify and
197 the 3rd notify (later) */
198 printf("Testing notify on unlink for the first file\n");
199 status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
200 CHECK_STATUS(status, NT_STATUS_OK);
202 /* receive the reply from the 2nd notify */
203 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
204 CHECK_STATUS(status, NT_STATUS_OK);
206 CHECK_VAL(notify.nttrans.out.num_changes, count);
207 for (i=1;i<count;i++) {
208 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_ADDED);
210 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
212 printf("and now from the 1st notify\n");
213 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
214 CHECK_STATUS(status, NT_STATUS_OK);
215 CHECK_VAL(notify.nttrans.out.num_changes, 1);
216 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
217 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
219 printf("(3rd notify) this notify will only see the 1st unlink\n");
220 req = smb_raw_changenotify_send(cli->tree, ¬ify);
222 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
223 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
225 printf("Testing notify on wildcard unlink for %d files\n", count-1);
226 /* (2nd unlink) do a wildcard unlink */
227 status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
228 CHECK_STATUS(status, NT_STATUS_OK);
230 /* receive the 3rd notify */
231 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
232 CHECK_STATUS(status, NT_STATUS_OK);
233 CHECK_VAL(notify.nttrans.out.num_changes, 1);
234 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
235 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
237 /* and we now see the rest of the unlink calls on both directory handles */
238 notify.nttrans.in.file.fnum = fnum;
240 req = smb_raw_changenotify_send(cli->tree, ¬ify);
241 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
242 CHECK_STATUS(status, NT_STATUS_OK);
243 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
244 for (i=0;i<notify.nttrans.out.num_changes;i++) {
245 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
247 notify.nttrans.in.file.fnum = fnum2;
248 req = smb_raw_changenotify_send(cli->tree, ¬ify);
249 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
250 CHECK_STATUS(status, NT_STATUS_OK);
251 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
252 for (i=0;i<notify.nttrans.out.num_changes;i++) {
253 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
256 printf("Testing if a close() on the dir handle triggers the notify reply\n");
258 notify.nttrans.in.file.fnum = fnum;
259 req = smb_raw_changenotify_send(cli->tree, ¬ify);
261 cl.close.level = RAW_CLOSE_CLOSE;
262 cl.close.in.file.fnum = fnum;
263 cl.close.in.write_time = 0;
264 status = smb_raw_close(cli->tree, &cl);
265 CHECK_STATUS(status, NT_STATUS_OK);
267 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
268 CHECK_STATUS(status, NT_STATUS_OK);
269 CHECK_VAL(notify.nttrans.out.num_changes, 0);
272 smb_raw_exit(cli->session);
273 smbcli_deltree(cli->tree, BASEDIR);
278 * Check notify reply for a rename action. Not sure if this is a valid thing
279 * to do, but depending on timing between inotify and messaging we get the
280 * add/remove/modify in any order. This routines tries to find the action/name
281 * pair in any of the three following notify_changes.
284 static bool check_rename_reply(struct smbcli_state *cli,
286 struct notify_changes *actions,
287 uint32_t action, const char *name)
291 for (i=0; i<3; i++) {
292 if (actions[i].action == action) {
293 if ((actions[i].name.s == NULL)
294 || (strcmp(actions[i].name.s, name) != 0)
295 || (wire_bad_flags(&actions[i].name, STR_UNICODE,
297 printf("(%d) name [%s] != %s\n", line,
298 actions[i].name.s, name);
305 printf("(%d) expected action %d, not found\n", line, action);
310 testing of recursive change notify
312 static bool test_notify_recursive(struct torture_context *mem_ctx,
313 struct smbcli_state *cli,
314 struct smbcli_state *cli2)
318 union smb_notify notify;
321 struct smbcli_request *req1, *req2;
323 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
325 if (!torture_setup_dir(cli, BASEDIR)) {
330 get a handle on the directory
332 io.generic.level = RAW_OPEN_NTCREATEX;
333 io.ntcreatex.in.root_fid.fnum = 0;
334 io.ntcreatex.in.flags = 0;
335 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
336 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
337 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
338 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
339 io.ntcreatex.in.alloc_size = 0;
340 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
341 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
342 io.ntcreatex.in.security_flags = 0;
343 io.ntcreatex.in.fname = BASEDIR;
345 status = smb_raw_open(cli->tree, mem_ctx, &io);
346 CHECK_STATUS(status, NT_STATUS_OK);
347 fnum = io.ntcreatex.out.file.fnum;
349 /* ask for a change notify, on file or directory name
350 changes. Setup both with and without recursion */
351 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
352 notify.nttrans.in.buffer_size = 1000;
353 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
354 notify.nttrans.in.file.fnum = fnum;
356 notify.nttrans.in.recursive = true;
357 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
359 notify.nttrans.in.recursive = false;
360 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
362 /* cancel initial requests so the buffer is setup */
363 smb_raw_ntcancel(req1);
364 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
365 CHECK_STATUS(status, NT_STATUS_CANCELLED);
367 smb_raw_ntcancel(req2);
368 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
369 CHECK_STATUS(status, NT_STATUS_CANCELLED);
372 * Make notifies a bit more interesting in a cluster by doing
373 * the changes against different nodes with --unclist
375 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
376 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name\\subname1");
377 smbcli_close(cli->tree,
378 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
379 smbcli_rename(cli2->tree, BASEDIR "\\subdir-name\\subname1",
380 BASEDIR "\\subdir-name\\subname1-r");
381 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
382 smbcli_rename(cli2->tree, BASEDIR "\\subname2-r",
383 BASEDIR "\\subname3-r");
385 notify.nttrans.in.completion_filter = 0;
386 notify.nttrans.in.recursive = true;
388 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
390 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
391 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
392 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
394 notify.nttrans.in.recursive = false;
395 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
397 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
398 CHECK_STATUS(status, NT_STATUS_OK);
400 CHECK_VAL(notify.nttrans.out.num_changes, 11);
401 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
402 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
403 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
404 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
405 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
406 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
407 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
408 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
409 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
410 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
412 ret &= check_rename_reply(
413 cli, __LINE__, ¬ify.nttrans.out.changes[5],
414 NOTIFY_ACTION_ADDED, "subname2-r");
415 ret &= check_rename_reply(
416 cli, __LINE__, ¬ify.nttrans.out.changes[5],
417 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
418 ret &= check_rename_reply(
419 cli, __LINE__, ¬ify.nttrans.out.changes[5],
420 NOTIFY_ACTION_MODIFIED, "subname2-r");
422 ret &= check_rename_reply(
423 cli, __LINE__, ¬ify.nttrans.out.changes[8],
424 NOTIFY_ACTION_OLD_NAME, "subname2-r");
425 ret &= check_rename_reply(
426 cli, __LINE__, ¬ify.nttrans.out.changes[8],
427 NOTIFY_ACTION_NEW_NAME, "subname3-r");
428 ret &= check_rename_reply(
429 cli, __LINE__, ¬ify.nttrans.out.changes[8],
430 NOTIFY_ACTION_MODIFIED, "subname3-r");
436 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
437 CHECK_STATUS(status, NT_STATUS_OK);
439 CHECK_VAL(notify.nttrans.out.num_changes, 3);
440 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
441 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
442 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
443 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
444 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
445 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
448 smb_raw_exit(cli->session);
449 smbcli_deltree(cli->tree, BASEDIR);
454 testing of change notify mask change
456 static bool test_notify_mask_change(struct torture_context *mem_ctx,
457 struct smbcli_state *cli)
461 union smb_notify notify;
464 struct smbcli_request *req1, *req2;
466 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
468 if (!torture_setup_dir(cli, BASEDIR)) {
473 get a handle on the directory
475 io.generic.level = RAW_OPEN_NTCREATEX;
476 io.ntcreatex.in.root_fid.fnum = 0;
477 io.ntcreatex.in.flags = 0;
478 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
479 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
480 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
481 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
482 io.ntcreatex.in.alloc_size = 0;
483 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
484 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
485 io.ntcreatex.in.security_flags = 0;
486 io.ntcreatex.in.fname = BASEDIR;
488 status = smb_raw_open(cli->tree, mem_ctx, &io);
489 CHECK_STATUS(status, NT_STATUS_OK);
490 fnum = io.ntcreatex.out.file.fnum;
492 /* ask for a change notify, on file or directory name
493 changes. Setup both with and without recursion */
494 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
495 notify.nttrans.in.buffer_size = 1000;
496 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
497 notify.nttrans.in.file.fnum = fnum;
499 notify.nttrans.in.recursive = true;
500 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
502 notify.nttrans.in.recursive = false;
503 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
505 /* cancel initial requests so the buffer is setup */
506 smb_raw_ntcancel(req1);
507 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
508 CHECK_STATUS(status, NT_STATUS_CANCELLED);
510 smb_raw_ntcancel(req2);
511 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
512 CHECK_STATUS(status, NT_STATUS_CANCELLED);
514 notify.nttrans.in.recursive = true;
515 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
517 /* Set to hidden then back again. */
518 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));
519 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
520 smbcli_unlink(cli->tree, BASEDIR "\\tname1");
522 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
523 CHECK_STATUS(status, NT_STATUS_OK);
525 CHECK_VAL(notify.nttrans.out.num_changes, 1);
526 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
527 CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
529 /* Now try and change the mask to include other events.
530 * This should not work - once the mask is set on a directory
531 * fnum it seems to be fixed until the fnum is closed. */
533 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
534 notify.nttrans.in.recursive = true;
535 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
537 notify.nttrans.in.recursive = false;
538 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
540 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
541 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
542 smbcli_close(cli->tree,
543 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
544 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
545 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
546 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
548 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
549 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
550 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
552 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
553 CHECK_STATUS(status, NT_STATUS_OK);
555 CHECK_VAL(notify.nttrans.out.num_changes, 1);
556 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
557 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname2-r", STR_UNICODE);
559 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
560 CHECK_STATUS(status, NT_STATUS_OK);
562 CHECK_VAL(notify.nttrans.out.num_changes, 1);
563 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
564 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname3-r", STR_UNICODE);
571 smb_raw_exit(cli->session);
572 smbcli_deltree(cli->tree, BASEDIR);
578 testing of mask bits for change notify
580 static bool test_notify_mask(struct torture_context *tctx,
581 struct smbcli_state *cli)
585 union smb_notify notify;
594 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
596 if (!torture_setup_dir(cli, BASEDIR)) {
600 tv = timeval_current_ofs(1000, 0);
601 t = timeval_to_nttime(&tv);
604 get a handle on the directory
606 io.generic.level = RAW_OPEN_NTCREATEX;
607 io.ntcreatex.in.root_fid.fnum = 0;
608 io.ntcreatex.in.flags = 0;
609 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
610 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
611 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
612 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
613 io.ntcreatex.in.alloc_size = 0;
614 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
615 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
616 io.ntcreatex.in.security_flags = 0;
617 io.ntcreatex.in.fname = BASEDIR;
619 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
620 notify.nttrans.in.buffer_size = 1000;
621 notify.nttrans.in.recursive = true;
623 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
625 smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
626 do { for (mask=i=0;i<32;i++) { \
627 struct smbcli_request *req; \
628 status = smb_raw_open(cli->tree, tctx, &io); \
629 CHECK_STATUS(status, NT_STATUS_OK); \
630 fnum = io.ntcreatex.out.file.fnum; \
632 notify.nttrans.in.file.fnum = fnum; \
633 notify.nttrans.in.completion_filter = (1<<i); \
634 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
636 smb_msleep(200); smb_raw_ntcancel(req); \
637 status = smb_raw_changenotify_recv(req, tctx, ¬ify); \
639 smbcli_close(cli->tree, fnum); \
640 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
641 CHECK_STATUS(status, NT_STATUS_OK); \
642 /* special case to cope with file rename behaviour */ \
643 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
644 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
645 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
646 Action == NOTIFY_ACTION_OLD_NAME) { \
647 printf("(rename file special handling OK)\n"); \
648 } else if (nchanges != notify.nttrans.out.num_changes) { \
649 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
650 notify.nttrans.out.num_changes, \
652 notify.nttrans.out.changes[0].action, \
653 notify.nttrans.in.completion_filter); \
655 } else if (notify.nttrans.out.changes[0].action != Action) { \
656 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
657 notify.nttrans.out.num_changes, \
658 notify.nttrans.out.changes[0].action, \
660 notify.nttrans.in.completion_filter); \
662 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
663 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
664 notify.nttrans.out.num_changes, \
665 notify.nttrans.out.changes[0].action, \
666 notify.nttrans.in.completion_filter, \
667 notify.nttrans.out.changes[0].name.s); \
672 if ((expected) != mask) { \
673 if (((expected) & ~mask) != 0) { \
674 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
678 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
685 printf("Testing mkdir\n");
686 NOTIFY_MASK_TEST("Testing mkdir",;,
687 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
688 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
690 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
692 printf("Testing create file\n");
693 NOTIFY_MASK_TEST("Testing create file",;,
694 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
695 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
697 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
699 printf("Testing unlink\n");
700 NOTIFY_MASK_TEST("Testing unlink",
701 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
702 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
704 NOTIFY_ACTION_REMOVED,
705 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
707 printf("Testing rmdir\n");
708 NOTIFY_MASK_TEST("Testing rmdir",
709 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
710 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
712 NOTIFY_ACTION_REMOVED,
713 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
715 printf("Testing rename file\n");
716 NOTIFY_MASK_TEST("Testing rename file",
717 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
718 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
719 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
720 NOTIFY_ACTION_OLD_NAME,
721 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
723 printf("Testing rename dir\n");
724 NOTIFY_MASK_TEST("Testing rename dir",
725 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
726 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
727 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
728 NOTIFY_ACTION_OLD_NAME,
729 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
731 printf("Testing set path attribute\n");
732 NOTIFY_MASK_TEST("Testing set path attribute",
733 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
734 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
735 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
736 NOTIFY_ACTION_MODIFIED,
737 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
739 printf("Testing set path write time\n");
740 NOTIFY_MASK_TEST("Testing set path write time",
741 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
742 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
743 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
744 NOTIFY_ACTION_MODIFIED,
745 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
747 printf("Testing set file attribute\n");
748 NOTIFY_MASK_TEST("Testing set file attribute",
749 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
750 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
751 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
752 NOTIFY_ACTION_MODIFIED,
753 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
755 if (torture_setting_bool(tctx, "samba3", false)) {
756 printf("Samba3 does not yet support create times "
760 printf("Testing set file create time\n");
761 NOTIFY_MASK_TEST("Testing set file create time",
762 fnum2 = create_complex_file(cli, tctx,
763 BASEDIR "\\tname1");,
764 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
765 (smbcli_close(cli->tree, fnum2),
766 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
767 NOTIFY_ACTION_MODIFIED,
768 FILE_NOTIFY_CHANGE_CREATION, 1);
771 printf("Testing set file access time\n");
772 NOTIFY_MASK_TEST("Testing set file access time",
773 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
774 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
775 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
776 NOTIFY_ACTION_MODIFIED,
777 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
779 printf("Testing set file write time\n");
780 NOTIFY_MASK_TEST("Testing set file write time",
781 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
782 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
783 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
784 NOTIFY_ACTION_MODIFIED,
785 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
787 printf("Testing set file change time\n");
788 NOTIFY_MASK_TEST("Testing set file change time",
789 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
790 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
791 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
792 NOTIFY_ACTION_MODIFIED,
796 printf("Testing write\n");
797 NOTIFY_MASK_TEST("Testing write",
798 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
799 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
800 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
801 NOTIFY_ACTION_MODIFIED,
804 printf("Testing truncate\n");
805 NOTIFY_MASK_TEST("Testing truncate",
806 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
807 smbcli_ftruncate(cli->tree, fnum2, 10000);,
808 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
809 NOTIFY_ACTION_MODIFIED,
810 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
813 smb_raw_exit(cli->session);
814 smbcli_deltree(cli->tree, BASEDIR);
819 basic testing of change notify on files
821 static bool test_notify_file(struct torture_context *mem_ctx,
822 struct smbcli_state *cli)
828 union smb_notify notify;
829 struct smbcli_request *req;
831 const char *fname = BASEDIR "\\file.txt";
833 printf("TESTING CHANGE NOTIFY ON FILES\n");
835 if (!torture_setup_dir(cli, BASEDIR)) {
839 io.generic.level = RAW_OPEN_NTCREATEX;
840 io.ntcreatex.in.root_fid.fnum = 0;
841 io.ntcreatex.in.flags = 0;
842 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
843 io.ntcreatex.in.create_options = 0;
844 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
845 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
846 io.ntcreatex.in.alloc_size = 0;
847 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
848 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
849 io.ntcreatex.in.security_flags = 0;
850 io.ntcreatex.in.fname = fname;
851 status = smb_raw_open(cli->tree, mem_ctx, &io);
852 CHECK_STATUS(status, NT_STATUS_OK);
853 fnum = io.ntcreatex.out.file.fnum;
855 /* ask for a change notify,
856 on file or directory name changes */
857 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
858 notify.nttrans.in.file.fnum = fnum;
859 notify.nttrans.in.buffer_size = 1000;
860 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
861 notify.nttrans.in.recursive = false;
863 printf("Testing if notifies on file handles are invalid (should be)\n");
865 req = smb_raw_changenotify_send(cli->tree, ¬ify);
866 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
867 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
869 cl.close.level = RAW_CLOSE_CLOSE;
870 cl.close.in.file.fnum = fnum;
871 cl.close.in.write_time = 0;
872 status = smb_raw_close(cli->tree, &cl);
873 CHECK_STATUS(status, NT_STATUS_OK);
875 status = smbcli_unlink(cli->tree, fname);
876 CHECK_STATUS(status, NT_STATUS_OK);
879 smb_raw_exit(cli->session);
880 smbcli_deltree(cli->tree, BASEDIR);
885 basic testing of change notifies followed by a tdis
887 static bool test_notify_tdis(struct torture_context *tctx,
888 struct smbcli_state *cli1)
892 union smb_notify notify;
895 struct smbcli_request *req;
896 struct smbcli_state *cli = NULL;
898 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
900 if (!torture_setup_dir(cli1, BASEDIR)) {
904 if (!torture_open_connection(&cli, tctx, 0)) {
909 get a handle on the directory
911 io.generic.level = RAW_OPEN_NTCREATEX;
912 io.ntcreatex.in.root_fid.fnum = 0;
913 io.ntcreatex.in.flags = 0;
914 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
915 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
916 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
917 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
918 io.ntcreatex.in.alloc_size = 0;
919 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
920 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
921 io.ntcreatex.in.security_flags = 0;
922 io.ntcreatex.in.fname = BASEDIR;
924 status = smb_raw_open(cli->tree, tctx, &io);
925 CHECK_STATUS(status, NT_STATUS_OK);
926 fnum = io.ntcreatex.out.file.fnum;
928 /* ask for a change notify,
929 on file or directory name changes */
930 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
931 notify.nttrans.in.buffer_size = 1000;
932 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
933 notify.nttrans.in.file.fnum = fnum;
934 notify.nttrans.in.recursive = true;
936 req = smb_raw_changenotify_send(cli->tree, ¬ify);
938 status = smbcli_tdis(cli);
939 CHECK_STATUS(status, NT_STATUS_OK);
942 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
943 CHECK_STATUS(status, NT_STATUS_OK);
944 CHECK_VAL(notify.nttrans.out.num_changes, 0);
947 torture_close_connection(cli);
948 smbcli_deltree(cli1->tree, BASEDIR);
953 basic testing of change notifies followed by a exit
955 static bool test_notify_exit(struct torture_context *tctx,
956 struct smbcli_state *cli1)
960 union smb_notify notify;
963 struct smbcli_request *req;
964 struct smbcli_state *cli = NULL;
966 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
968 if (!torture_setup_dir(cli1, BASEDIR)) {
972 if (!torture_open_connection(&cli, tctx, 0)) {
977 get a handle on the directory
979 io.generic.level = RAW_OPEN_NTCREATEX;
980 io.ntcreatex.in.root_fid.fnum = 0;
981 io.ntcreatex.in.flags = 0;
982 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
983 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
984 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
985 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
986 io.ntcreatex.in.alloc_size = 0;
987 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
988 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
989 io.ntcreatex.in.security_flags = 0;
990 io.ntcreatex.in.fname = BASEDIR;
992 status = smb_raw_open(cli->tree, tctx, &io);
993 CHECK_STATUS(status, NT_STATUS_OK);
994 fnum = io.ntcreatex.out.file.fnum;
996 /* ask for a change notify,
997 on file or directory name changes */
998 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
999 notify.nttrans.in.buffer_size = 1000;
1000 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1001 notify.nttrans.in.file.fnum = fnum;
1002 notify.nttrans.in.recursive = true;
1004 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1006 status = smb_raw_exit(cli->session);
1007 CHECK_STATUS(status, NT_STATUS_OK);
1009 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1010 CHECK_STATUS(status, NT_STATUS_OK);
1011 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1014 torture_close_connection(cli);
1015 smbcli_deltree(cli1->tree, BASEDIR);
1020 basic testing of change notifies followed by a ulogoff
1022 static bool test_notify_ulogoff(struct torture_context *tctx,
1023 struct smbcli_state *cli1)
1027 union smb_notify notify;
1030 struct smbcli_request *req;
1031 struct smbcli_state *cli = NULL;
1033 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1035 if (!torture_setup_dir(cli1, BASEDIR)) {
1039 if (!torture_open_connection(&cli, tctx, 0)) {
1044 get a handle on the directory
1046 io.generic.level = RAW_OPEN_NTCREATEX;
1047 io.ntcreatex.in.root_fid.fnum = 0;
1048 io.ntcreatex.in.flags = 0;
1049 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1050 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1051 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1052 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1053 io.ntcreatex.in.alloc_size = 0;
1054 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1055 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1056 io.ntcreatex.in.security_flags = 0;
1057 io.ntcreatex.in.fname = BASEDIR;
1059 status = smb_raw_open(cli->tree, tctx, &io);
1060 CHECK_STATUS(status, NT_STATUS_OK);
1061 fnum = io.ntcreatex.out.file.fnum;
1063 /* ask for a change notify,
1064 on file or directory name changes */
1065 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1066 notify.nttrans.in.buffer_size = 1000;
1067 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1068 notify.nttrans.in.file.fnum = fnum;
1069 notify.nttrans.in.recursive = true;
1071 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1073 status = smb_raw_ulogoff(cli->session);
1074 CHECK_STATUS(status, NT_STATUS_OK);
1076 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1077 CHECK_STATUS(status, NT_STATUS_OK);
1078 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1081 torture_close_connection(cli);
1082 smbcli_deltree(cli1->tree, BASEDIR);
1086 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
1088 struct smbcli_state *cli = (struct smbcli_state *)p;
1089 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
1090 cli->transport = NULL;
1094 basic testing of change notifies followed by tcp disconnect
1096 static bool test_notify_tcp_dis(struct torture_context *tctx,
1097 struct smbcli_state *cli1)
1101 union smb_notify notify;
1104 struct smbcli_request *req;
1105 struct smbcli_state *cli = NULL;
1107 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1109 if (!torture_setup_dir(cli1, BASEDIR)) {
1113 if (!torture_open_connection(&cli, tctx, 0)) {
1118 get a handle on the directory
1120 io.generic.level = RAW_OPEN_NTCREATEX;
1121 io.ntcreatex.in.root_fid.fnum = 0;
1122 io.ntcreatex.in.flags = 0;
1123 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1124 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1125 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1126 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1127 io.ntcreatex.in.alloc_size = 0;
1128 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1129 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1130 io.ntcreatex.in.security_flags = 0;
1131 io.ntcreatex.in.fname = BASEDIR;
1133 status = smb_raw_open(cli->tree, tctx, &io);
1134 CHECK_STATUS(status, NT_STATUS_OK);
1135 fnum = io.ntcreatex.out.file.fnum;
1137 /* ask for a change notify,
1138 on file or directory name changes */
1139 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1140 notify.nttrans.in.buffer_size = 1000;
1141 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1142 notify.nttrans.in.file.fnum = fnum;
1143 notify.nttrans.in.recursive = true;
1145 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1147 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
1149 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1150 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
1153 torture_close_connection(cli);
1154 smbcli_deltree(cli1->tree, BASEDIR);
1159 test setting up two change notify requests on one handle
1161 static bool test_notify_double(struct torture_context *mem_ctx,
1162 struct smbcli_state *cli)
1166 union smb_notify notify;
1169 struct smbcli_request *req1, *req2;
1171 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1173 if (!torture_setup_dir(cli, BASEDIR)) {
1177 get a handle on the directory
1179 io.generic.level = RAW_OPEN_NTCREATEX;
1180 io.ntcreatex.in.root_fid.fnum = 0;
1181 io.ntcreatex.in.flags = 0;
1182 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1183 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1184 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1185 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1186 io.ntcreatex.in.alloc_size = 0;
1187 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1188 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1189 io.ntcreatex.in.security_flags = 0;
1190 io.ntcreatex.in.fname = BASEDIR;
1192 status = smb_raw_open(cli->tree, mem_ctx, &io);
1193 CHECK_STATUS(status, NT_STATUS_OK);
1194 fnum = io.ntcreatex.out.file.fnum;
1196 /* ask for a change notify,
1197 on file or directory name changes */
1198 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1199 notify.nttrans.in.buffer_size = 1000;
1200 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1201 notify.nttrans.in.file.fnum = fnum;
1202 notify.nttrans.in.recursive = true;
1204 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1205 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
1207 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1209 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1210 CHECK_STATUS(status, NT_STATUS_OK);
1211 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1212 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1214 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1216 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
1217 CHECK_STATUS(status, NT_STATUS_OK);
1218 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1219 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
1222 smb_raw_exit(cli->session);
1223 smbcli_deltree(cli->tree, BASEDIR);
1229 test multiple change notifies at different depths and with/without recursion
1231 static bool test_notify_tree(struct torture_context *mem_ctx,
1232 struct smbcli_state *cli,
1233 struct smbcli_state *cli2)
1236 union smb_notify notify;
1238 struct smbcli_request *req;
1248 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 30 },
1249 {BASEDIR "\\zqy", true, FILE_NOTIFY_CHANGE_NAME, 8 },
1250 {BASEDIR "\\atsy", true, FILE_NOTIFY_CHANGE_NAME, 4 },
1251 {BASEDIR "\\abc\\foo", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1252 {BASEDIR "\\abc\\blah", true, FILE_NOTIFY_CHANGE_NAME, 13 },
1253 {BASEDIR "\\abc\\blah", false, FILE_NOTIFY_CHANGE_NAME, 7 },
1254 {BASEDIR "\\abc\\blah\\a", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1255 {BASEDIR "\\abc\\blah\\b", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1256 {BASEDIR "\\abc\\blah\\c", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1257 {BASEDIR "\\abc\\fooblah", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1258 {BASEDIR "\\zqy\\xx", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1259 {BASEDIR "\\zqy\\yyy", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1260 {BASEDIR "\\zqy\\..", true, FILE_NOTIFY_CHANGE_NAME, 40 },
1261 {BASEDIR, true, FILE_NOTIFY_CHANGE_NAME, 40 },
1262 {BASEDIR, false,FILE_NOTIFY_CHANGE_NAME, 6 },
1263 {BASEDIR "\\atsy", false,FILE_NOTIFY_CHANGE_NAME, 4 },
1264 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1265 {BASEDIR "\\abc", false,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1266 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1267 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1271 bool all_done = false;
1273 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1275 if (!torture_setup_dir(cli, BASEDIR)) {
1279 io.generic.level = RAW_OPEN_NTCREATEX;
1280 io.ntcreatex.in.root_fid.fnum = 0;
1281 io.ntcreatex.in.flags = 0;
1282 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1283 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1284 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1285 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1286 io.ntcreatex.in.alloc_size = 0;
1287 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1288 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1289 io.ntcreatex.in.security_flags = 0;
1291 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1292 notify.nttrans.in.buffer_size = 20000;
1295 setup the directory tree, and the notify buffer on each directory
1297 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1298 io.ntcreatex.in.fname = dirs[i].path;
1299 status = smb_raw_open(cli->tree, mem_ctx, &io);
1300 CHECK_STATUS(status, NT_STATUS_OK);
1301 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1303 notify.nttrans.in.completion_filter = dirs[i].filter;
1304 notify.nttrans.in.file.fnum = dirs[i].fnum;
1305 notify.nttrans.in.recursive = dirs[i].recursive;
1306 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1307 smb_raw_ntcancel(req);
1308 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1309 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1312 /* trigger 2 events in each dir */
1313 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1314 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1316 * Make notifies a bit more interesting in a cluster
1317 * by doing the changes against different nodes with
1320 smbcli_mkdir(cli->tree, path);
1321 smbcli_rmdir(cli2->tree, path);
1325 /* give a bit of time for the events to propogate */
1326 tv = timeval_current();
1329 /* count events that have happened in each dir */
1330 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1331 notify.nttrans.in.file.fnum = dirs[i].fnum;
1332 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1333 smb_raw_ntcancel(req);
1334 notify.nttrans.out.num_changes = 0;
1335 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1336 dirs[i].counted += notify.nttrans.out.num_changes;
1341 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1342 if (dirs[i].counted != dirs[i].expected) {
1346 } while (!all_done && timeval_elapsed(&tv) < 20);
1348 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1350 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1351 if (dirs[i].counted != dirs[i].expected) {
1352 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1353 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1359 run from the back, closing and deleting
1361 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1362 smbcli_close(cli->tree, dirs[i].fnum);
1363 smbcli_rmdir(cli->tree, dirs[i].path);
1367 smb_raw_exit(cli->session);
1368 smbcli_deltree(cli->tree, BASEDIR);
1373 Test response when cached server events exceed single NT NOTFIY response
1376 static bool test_notify_overflow(struct torture_context *mem_ctx,
1377 struct smbcli_state *cli)
1381 union smb_notify notify;
1385 struct smbcli_request *req1;
1388 printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
1390 if (!torture_setup_dir(cli, BASEDIR)) {
1394 /* get a handle on the directory */
1395 io.generic.level = RAW_OPEN_NTCREATEX;
1396 io.ntcreatex.in.root_fid.fnum = 0;
1397 io.ntcreatex.in.flags = 0;
1398 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1399 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1400 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1401 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1402 NTCREATEX_SHARE_ACCESS_WRITE;
1403 io.ntcreatex.in.alloc_size = 0;
1404 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1405 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1406 io.ntcreatex.in.security_flags = 0;
1407 io.ntcreatex.in.fname = BASEDIR;
1409 status = smb_raw_open(cli->tree, mem_ctx, &io);
1410 CHECK_STATUS(status, NT_STATUS_OK);
1411 fnum = io.ntcreatex.out.file.fnum;
1413 /* ask for a change notify, on name changes. */
1414 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1415 notify.nttrans.in.buffer_size = 1000;
1416 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1417 notify.nttrans.in.file.fnum = fnum;
1419 notify.nttrans.in.recursive = true;
1420 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1422 /* cancel initial requests so the buffer is setup */
1423 smb_raw_ntcancel(req1);
1424 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1425 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1427 /* open a lot of files, filling up the server side notify buffer */
1428 printf("Testing overflowed buffer notify on create of %d files\n",
1430 for (i=0;i<count;i++) {
1431 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
1432 int fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR,
1435 printf("Failed to create %s - %s\n",
1436 fname, smbcli_errstr(cli->tree));
1441 smbcli_close(cli->tree, fnum2);
1444 /* expect that 0 events will be returned with NT_STATUS_OK */
1445 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1446 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1447 CHECK_STATUS(status, NT_STATUS_OK);
1448 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1451 smb_raw_exit(cli->session);
1452 smbcli_deltree(cli->tree, BASEDIR);
1457 Test if notifications are returned for changes to the base directory.
1460 static bool test_notify_basedir(struct torture_context *mem_ctx,
1461 struct smbcli_state *cli)
1465 union smb_notify notify;
1468 struct smbcli_request *req1;
1470 printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
1472 if (!torture_setup_dir(cli, BASEDIR)) {
1476 /* get a handle on the directory */
1477 io.generic.level = RAW_OPEN_NTCREATEX;
1478 io.ntcreatex.in.root_fid.fnum = 0;
1479 io.ntcreatex.in.flags = 0;
1480 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1481 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1482 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1483 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1484 NTCREATEX_SHARE_ACCESS_WRITE;
1485 io.ntcreatex.in.alloc_size = 0;
1486 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1487 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1488 io.ntcreatex.in.security_flags = 0;
1489 io.ntcreatex.in.fname = BASEDIR;
1491 status = smb_raw_open(cli->tree, mem_ctx, &io);
1492 CHECK_STATUS(status, NT_STATUS_OK);
1493 fnum = io.ntcreatex.out.file.fnum;
1495 /* create a test file that will also be modified */
1496 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1",
1499 /* ask for a change notify, on attribute changes. */
1500 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1501 notify.nttrans.in.buffer_size = 1000;
1502 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
1503 notify.nttrans.in.file.fnum = fnum;
1504 notify.nttrans.in.recursive = true;
1506 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1508 /* set attribute on the base dir */
1509 smbcli_setatr(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN, 0);
1511 /* set attribute on a file to assure we receive a notification */
1512 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
1515 /* check how many responses were given, expect only 1 for the file */
1516 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1517 CHECK_STATUS(status, NT_STATUS_OK);
1518 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1519 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
1520 CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
1523 smb_raw_exit(cli->session);
1524 smbcli_deltree(cli->tree, BASEDIR);
1530 create a secondary tree connect - used to test for a bug in Samba3 messaging
1533 static struct smbcli_tree *secondary_tcon(struct smbcli_state *cli,
1534 struct torture_context *tctx)
1537 const char *share, *host;
1538 struct smbcli_tree *tree;
1539 union smb_tcon tcon;
1541 share = torture_setting_string(tctx, "share", NULL);
1542 host = torture_setting_string(tctx, "host", NULL);
1544 printf("create a second tree context on the same session\n");
1545 tree = smbcli_tree_init(cli->session, tctx, false);
1547 tcon.generic.level = RAW_TCON_TCONX;
1548 tcon.tconx.in.flags = 0;
1549 tcon.tconx.in.password = data_blob(NULL, 0);
1550 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
1551 tcon.tconx.in.device = "A:";
1552 status = smb_raw_tcon(tree, tctx, &tcon);
1553 if (!NT_STATUS_IS_OK(status)) {
1555 printf("Failed to create secondary tree\n");
1559 tree->tid = tcon.tconx.out.tid;
1560 printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid);
1567 very simple change notify test
1569 static bool test_notify_tcon(struct torture_context *torture,
1570 struct smbcli_state *cli)
1574 union smb_notify notify;
1577 struct smbcli_request *req;
1578 extern int torture_numops;
1579 struct smbcli_tree *tree = NULL;
1581 printf("TESTING SIMPLE CHANGE NOTIFY\n");
1583 if (!torture_setup_dir(cli, BASEDIR)) {
1588 get a handle on the directory
1590 io.generic.level = RAW_OPEN_NTCREATEX;
1591 io.ntcreatex.in.root_fid.fnum = 0;
1592 io.ntcreatex.in.flags = 0;
1593 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1594 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1595 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1596 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1597 io.ntcreatex.in.alloc_size = 0;
1598 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1599 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1600 io.ntcreatex.in.security_flags = 0;
1601 io.ntcreatex.in.fname = BASEDIR;
1603 status = smb_raw_open(cli->tree, torture, &io);
1604 CHECK_STATUS(status, NT_STATUS_OK);
1605 fnum = io.ntcreatex.out.file.fnum;
1607 status = smb_raw_open(cli->tree, torture, &io);
1608 CHECK_STATUS(status, NT_STATUS_OK);
1610 /* ask for a change notify,
1611 on file or directory name changes */
1612 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1613 notify.nttrans.in.buffer_size = 1000;
1614 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1615 notify.nttrans.in.file.fnum = fnum;
1616 notify.nttrans.in.recursive = true;
1618 printf("Testing notify mkdir\n");
1619 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1620 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1622 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1623 CHECK_STATUS(status, NT_STATUS_OK);
1625 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1626 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1627 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1629 printf("Testing notify rmdir\n");
1630 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1631 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1633 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1634 CHECK_STATUS(status, NT_STATUS_OK);
1635 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1636 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1637 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1639 printf("SIMPLE CHANGE NOTIFY OK\n");
1641 printf("TESTING WITH SECONDARY TCON\n");
1642 tree = secondary_tcon(cli, torture);
1644 printf("Testing notify mkdir\n");
1645 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1646 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1648 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1649 CHECK_STATUS(status, NT_STATUS_OK);
1651 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1652 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1653 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1655 printf("Testing notify rmdir\n");
1656 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1657 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1659 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1660 CHECK_STATUS(status, NT_STATUS_OK);
1661 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1662 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1663 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1665 printf("CHANGE NOTIFY WITH TCON OK\n");
1667 printf("Disconnecting secondary tree\n");
1668 status = smb_tree_disconnect(tree);
1669 CHECK_STATUS(status, NT_STATUS_OK);
1672 printf("Testing notify mkdir\n");
1673 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1674 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1676 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1677 CHECK_STATUS(status, NT_STATUS_OK);
1679 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1680 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1681 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1683 printf("Testing notify rmdir\n");
1684 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1685 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1687 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1688 CHECK_STATUS(status, NT_STATUS_OK);
1689 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1690 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1691 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1693 printf("CHANGE NOTIFY WITH TDIS OK\n");
1695 smb_raw_exit(cli->session);
1696 smbcli_deltree(cli->tree, BASEDIR);
1702 testing alignment of multiple change notify infos
1704 static bool test_notify_alignment(struct torture_context *tctx,
1705 struct smbcli_state *cli)
1708 union smb_notify notify;
1711 struct smbcli_request *req;
1712 const char *fname = BASEDIR "\\starter";
1713 const char *fnames[] = { "a",
1717 int num_names = ARRAY_SIZE(fnames);
1720 torture_comment(tctx, "TESTING CHANGE NOTIFY REPLY ALIGNMENT\n");
1722 if (!torture_setup_dir(cli, BASEDIR)) {
1726 /* get a handle on the directory */
1727 io.generic.level = RAW_OPEN_NTCREATEX;
1728 io.ntcreatex.in.root_fid.fnum = 0;
1729 io.ntcreatex.in.flags = 0;
1730 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1731 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1732 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1733 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1734 NTCREATEX_SHARE_ACCESS_WRITE;
1735 io.ntcreatex.in.alloc_size = 0;
1736 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1737 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1738 io.ntcreatex.in.security_flags = 0;
1739 io.ntcreatex.in.fname = BASEDIR;
1741 status = smb_raw_open(cli->tree, tctx, &io);
1742 torture_assert_ntstatus_ok(tctx, status, "");
1743 fnum = io.ntcreatex.out.file.fnum;
1745 /* ask for a change notify, on file creation */
1746 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1747 notify.nttrans.in.buffer_size = 1000;
1748 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_FILE_NAME;
1749 notify.nttrans.in.file.fnum = fnum;
1750 notify.nttrans.in.recursive = false;
1752 /* start change tracking */
1753 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1755 fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1756 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1757 smbcli_close(cli->tree, fnum2);
1759 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1760 torture_assert_ntstatus_ok(tctx, status, "");
1762 /* create 4 files that will cause CHANGE_NOTIFY_INFO structures
1763 * to be returned in the same packet with all possible 4-byte padding
1764 * permutations. As per MS-CIFS 2.2.7.4.2 these structures should be
1765 * 4-byte aligned. */
1767 for (i = 0; i < num_names; i++) {
1768 fpath = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fnames[i]);
1769 fnum2 = smbcli_open(cli->tree, fpath,
1770 O_CREAT|O_RDWR, DENY_NONE);
1771 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1772 smbcli_close(cli->tree, fnum2);
1776 /* We send a notify packet, and let smb_raw_changenotify_recv() do
1777 * the alignment checking for us. */
1778 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1779 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1780 torture_assert_ntstatus_ok(tctx, status, "");
1782 /* Do basic checking for correctness. */
1783 torture_assert(tctx, notify.nttrans.out.num_changes == num_names, "");
1784 for (i = 0; i < num_names; i++) {
1785 torture_assert(tctx, notify.nttrans.out.changes[i].action ==
1786 NOTIFY_ACTION_ADDED, "");
1787 CHECK_WSTR2(tctx, notify.nttrans.out.changes[i].name, fnames[i],
1791 smb_raw_exit(cli->session);
1792 smbcli_deltree(cli->tree, BASEDIR);
1796 struct torture_suite *torture_raw_notify(TALLOC_CTX *mem_ctx)
1798 struct torture_suite *suite = torture_suite_create(mem_ctx, "notify");
1800 torture_suite_add_1smb_test(suite, "tcon", test_notify_tcon);
1801 torture_suite_add_2smb_test(suite, "dir", test_notify_dir);
1802 torture_suite_add_1smb_test(suite, "mask", test_notify_mask);
1803 torture_suite_add_2smb_test(suite, "recursive", test_notify_recursive);
1804 torture_suite_add_1smb_test(suite, "mask_change",
1805 test_notify_mask_change);
1806 torture_suite_add_1smb_test(suite, "file", test_notify_file);
1807 torture_suite_add_1smb_test(suite, "tdis", test_notify_tdis);
1808 torture_suite_add_1smb_test(suite, "exit", test_notify_exit);
1809 torture_suite_add_1smb_test(suite, "ulogoff", test_notify_ulogoff);
1810 torture_suite_add_1smb_test(suite, "tcp_dis", test_notify_tcp_dis);
1811 torture_suite_add_1smb_test(suite, "double", test_notify_double);
1812 torture_suite_add_2smb_test(suite, "tree", test_notify_tree);
1813 torture_suite_add_1smb_test(suite, "overflow", test_notify_overflow);
1814 torture_suite_add_1smb_test(suite, "basedir", test_notify_basedir);
1815 torture_suite_add_1smb_test(suite, "alignment", test_notify_alignment);