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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/libcli.h"
25 #include "system/filesys.h"
26 #include "torture/util.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)) { \
49 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
56 basic testing of change notify on directories
58 static BOOL test_notify_dir(struct smbcli_state *cli, struct smbcli_state *cli2,
63 union smb_notify notify;
66 int i, count, fnum, fnum2;
67 struct smbcli_request *req, *req2;
68 extern int torture_numops;
70 printf("TESTING CHANGE NOTIFY ON DIRECTRIES\n");
73 get a handle on the directory
75 io.generic.level = RAW_OPEN_NTCREATEX;
76 io.ntcreatex.in.root_fid = 0;
77 io.ntcreatex.in.flags = 0;
78 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
79 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
80 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
81 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
82 io.ntcreatex.in.alloc_size = 0;
83 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
84 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
85 io.ntcreatex.in.security_flags = 0;
86 io.ntcreatex.in.fname = BASEDIR;
88 status = smb_raw_open(cli->tree, mem_ctx, &io);
89 CHECK_STATUS(status, NT_STATUS_OK);
90 fnum = io.ntcreatex.out.file.fnum;
92 status = smb_raw_open(cli->tree, mem_ctx, &io);
93 CHECK_STATUS(status, NT_STATUS_OK);
94 fnum2 = io.ntcreatex.out.file.fnum;
96 /* ask for a change notify,
97 on file or directory name changes */
98 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
99 notify.nttrans.in.buffer_size = 1000;
100 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
101 notify.nttrans.in.file.fnum = fnum;
102 notify.nttrans.in.recursive = True;
104 printf("testing notify cancel\n");
106 req = smb_raw_changenotify_send(cli->tree, ¬ify);
107 smb_raw_ntcancel(req);
108 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
109 CHECK_STATUS(status, NT_STATUS_CANCELLED);
111 printf("testing notify mkdir\n");
113 req = smb_raw_changenotify_send(cli->tree, ¬ify);
114 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
116 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
117 CHECK_STATUS(status, NT_STATUS_OK);
119 CHECK_VAL(notify.nttrans.out.num_changes, 1);
120 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
121 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
123 printf("testing notify rmdir\n");
125 req = smb_raw_changenotify_send(cli->tree, ¬ify);
126 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
128 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
129 CHECK_STATUS(status, NT_STATUS_OK);
130 CHECK_VAL(notify.nttrans.out.num_changes, 1);
131 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
132 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
134 printf("testing notify mkdir - rmdir - mkdir - rmdir\n");
136 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
137 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
138 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
139 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
140 req = smb_raw_changenotify_send(cli->tree, ¬ify);
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, 4);
144 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
145 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
146 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
147 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
148 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
149 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name", STR_UNICODE);
150 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_REMOVED);
151 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name", STR_UNICODE);
153 count = torture_numops;
154 printf("testing buffered notify on create of %d files\n", count);
155 for (i=0;i<count;i++) {
156 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
157 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
159 printf("Failed to create %s - %s\n",
160 fname, smbcli_errstr(cli->tree));
165 smbcli_close(cli->tree, fnum3);
168 /* (1st notify) setup a new notify on a different directory handle.
169 This new notify won't see the events above. */
170 notify.nttrans.in.file.fnum = fnum2;
171 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
173 /* (2nd notify) whereas this notify will see the above buffered events,
174 and it directly returns the buffered events */
175 notify.nttrans.in.file.fnum = fnum;
176 req = smb_raw_changenotify_send(cli->tree, ¬ify);
178 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
179 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
181 /* (1st unlink) as the 2nd notify directly returns,
182 this unlink is only seen by the 1st notify and
183 the 3rd notify (later) */
184 printf("testing notify on unlink for the first file\n");
185 status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
186 CHECK_STATUS(status, NT_STATUS_OK);
188 /* receive the reply from the 2nd notify */
189 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
190 CHECK_STATUS(status, NT_STATUS_OK);
192 CHECK_VAL(notify.nttrans.out.num_changes, count);
193 for (i=1;i<count;i++) {
194 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_ADDED);
196 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
198 printf("and now from the 1st notify\n");
199 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
200 CHECK_STATUS(status, NT_STATUS_OK);
201 CHECK_VAL(notify.nttrans.out.num_changes, 1);
202 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
203 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
205 printf("(3rd notify) this notify will only see the 1st unlink\n");
206 req = smb_raw_changenotify_send(cli->tree, ¬ify);
208 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
209 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
211 printf("testing notify on wildcard unlink for %d files\n", count-1);
212 /* (2nd unlink) do a wildcard unlink */
213 status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
214 CHECK_STATUS(status, NT_STATUS_OK);
216 /* receive the 3rd notify */
217 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
218 CHECK_STATUS(status, NT_STATUS_OK);
219 CHECK_VAL(notify.nttrans.out.num_changes, 1);
220 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
221 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
223 /* and we now see the rest of the unlink calls on both directory handles */
224 notify.nttrans.in.file.fnum = fnum;
226 req = smb_raw_changenotify_send(cli->tree, ¬ify);
227 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
228 CHECK_STATUS(status, NT_STATUS_OK);
229 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
230 for (i=0;i<notify.nttrans.out.num_changes;i++) {
231 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
233 notify.nttrans.in.file.fnum = fnum2;
234 req = smb_raw_changenotify_send(cli->tree, ¬ify);
235 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
236 CHECK_STATUS(status, NT_STATUS_OK);
237 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
238 for (i=0;i<notify.nttrans.out.num_changes;i++) {
239 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
242 printf("testing if a close() on the dir handle triggers the notify reply\n");
244 notify.nttrans.in.file.fnum = fnum;
245 req = smb_raw_changenotify_send(cli->tree, ¬ify);
247 cl.close.level = RAW_CLOSE_CLOSE;
248 cl.close.in.file.fnum = fnum;
249 cl.close.in.write_time = 0;
250 status = smb_raw_close(cli->tree, &cl);
251 CHECK_STATUS(status, NT_STATUS_OK);
253 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
254 CHECK_STATUS(status, NT_STATUS_OK);
255 CHECK_VAL(notify.nttrans.out.num_changes, 0);
258 smb_raw_exit(cli->session);
263 * Check notify reply for a rename action. Not sure if this is a valid thing
264 * to do, but depending on timing between inotify and messaging we get the
265 * add/remove/modify in any order. This routines tries to find the action/name
266 * pair in any of the three following notify_changes.
269 static BOOL check_rename_reply(struct smbcli_state *cli,
271 struct notify_changes *actions,
272 uint32_t action, const char *name)
276 for (i=0; i<3; i++) {
277 if (actions[i].action == action) {
278 if ((actions[i].name.s == NULL)
279 || (strcmp(actions[i].name.s, name) != 0)
280 || (wire_bad_flags(&actions[i].name, STR_UNICODE,
282 printf("(%d) name [%s] != %s\n", line,
283 actions[i].name.s, name);
290 printf("(%d) expected action %d, not found\n", line, action);
297 testing of recursive change notify
299 static BOOL test_notify_recursive(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
303 union smb_notify notify;
306 struct smbcli_request *req1, *req2;
308 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
311 get a handle on the directory
313 io.generic.level = RAW_OPEN_NTCREATEX;
314 io.ntcreatex.in.root_fid = 0;
315 io.ntcreatex.in.flags = 0;
316 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
317 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
318 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
319 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
320 io.ntcreatex.in.alloc_size = 0;
321 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
322 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
323 io.ntcreatex.in.security_flags = 0;
324 io.ntcreatex.in.fname = BASEDIR;
326 status = smb_raw_open(cli->tree, mem_ctx, &io);
327 CHECK_STATUS(status, NT_STATUS_OK);
328 fnum = io.ntcreatex.out.file.fnum;
330 /* ask for a change notify, on file or directory name
331 changes. Setup both with and without recursion */
332 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
333 notify.nttrans.in.buffer_size = 1000;
334 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
335 notify.nttrans.in.file.fnum = fnum;
337 notify.nttrans.in.recursive = True;
338 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
340 notify.nttrans.in.recursive = False;
341 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
343 /* cancel initial requests so the buffer is setup */
344 smb_raw_ntcancel(req1);
345 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
346 CHECK_STATUS(status, NT_STATUS_CANCELLED);
348 smb_raw_ntcancel(req2);
349 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
350 CHECK_STATUS(status, NT_STATUS_CANCELLED);
352 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
353 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
354 smbcli_close(cli->tree,
355 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
356 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
357 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
358 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
360 notify.nttrans.in.completion_filter = 0;
361 notify.nttrans.in.recursive = True;
363 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
365 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
366 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
367 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
369 notify.nttrans.in.recursive = False;
370 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
372 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
373 CHECK_STATUS(status, NT_STATUS_OK);
375 CHECK_VAL(notify.nttrans.out.num_changes, 11);
376 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
377 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
378 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
379 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
380 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
381 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
382 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
383 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
384 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
385 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
387 ret &= check_rename_reply(
388 cli, __LINE__, ¬ify.nttrans.out.changes[5],
389 NOTIFY_ACTION_ADDED, "subname2-r");
390 ret &= check_rename_reply(
391 cli, __LINE__, ¬ify.nttrans.out.changes[5],
392 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
393 ret &= check_rename_reply(
394 cli, __LINE__, ¬ify.nttrans.out.changes[5],
395 NOTIFY_ACTION_MODIFIED, "subname2-r");
397 ret &= check_rename_reply(
398 cli, __LINE__, ¬ify.nttrans.out.changes[8],
399 NOTIFY_ACTION_OLD_NAME, "subname2-r");
400 ret &= check_rename_reply(
401 cli, __LINE__, ¬ify.nttrans.out.changes[8],
402 NOTIFY_ACTION_NEW_NAME, "subname3-r");
403 ret &= check_rename_reply(
404 cli, __LINE__, ¬ify.nttrans.out.changes[8],
405 NOTIFY_ACTION_MODIFIED, "subname3-r");
411 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
412 CHECK_STATUS(status, NT_STATUS_OK);
414 CHECK_VAL(notify.nttrans.out.num_changes, 3);
415 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
416 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
417 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
418 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
419 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
420 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
423 smb_raw_exit(cli->session);
429 testing of mask bits for change notify
431 static BOOL test_notify_mask(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
435 union smb_notify notify;
444 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
446 tv = timeval_current_ofs(1000, 0);
447 t = timeval_to_nttime(&tv);
450 get a handle on the directory
452 io.generic.level = RAW_OPEN_NTCREATEX;
453 io.ntcreatex.in.root_fid = 0;
454 io.ntcreatex.in.flags = 0;
455 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
456 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
457 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
458 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
459 io.ntcreatex.in.alloc_size = 0;
460 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
461 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
462 io.ntcreatex.in.security_flags = 0;
463 io.ntcreatex.in.fname = BASEDIR;
465 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
466 notify.nttrans.in.buffer_size = 1000;
467 notify.nttrans.in.recursive = True;
469 #define NOTIFY_MASK_TEST(setup, op, cleanup, Action, expected, nchanges) \
470 do { for (mask=i=0;i<32;i++) { \
471 struct smbcli_request *req; \
472 status = smb_raw_open(cli->tree, mem_ctx, &io); \
473 CHECK_STATUS(status, NT_STATUS_OK); \
474 fnum = io.ntcreatex.out.file.fnum; \
476 notify.nttrans.in.file.fnum = fnum; \
477 notify.nttrans.in.completion_filter = (1<<i); \
478 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
480 msleep(200); smb_raw_ntcancel(req); \
481 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); \
483 smbcli_close(cli->tree, fnum); \
484 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
485 CHECK_STATUS(status, NT_STATUS_OK); \
486 /* special case to cope with file rename behaviour */ \
487 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
488 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
489 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
490 Action == NOTIFY_ACTION_OLD_NAME) { \
491 printf("(rename file special handling OK)\n"); \
492 } else if (nchanges != notify.nttrans.out.num_changes || \
493 notify.nttrans.out.changes[0].action != Action || \
494 strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
495 printf("ERROR: nchanges=%d action=%d filter=0x%08x\n", \
496 notify.nttrans.out.num_changes, \
497 notify.nttrans.out.changes[0].action, \
498 notify.nttrans.in.completion_filter); \
503 if ((expected) != mask) { \
504 if (((expected) & ~mask) != 0) { \
505 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
509 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
515 printf("testing mkdir\n");
517 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
518 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
520 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
522 printf("testing create file\n");
524 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
525 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
527 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
529 printf("testing unlink\n");
531 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
532 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
534 NOTIFY_ACTION_REMOVED,
535 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
537 printf("testing rmdir\n");
539 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
540 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
542 NOTIFY_ACTION_REMOVED,
543 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
545 printf("testing rename file\n");
547 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
548 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
549 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
550 NOTIFY_ACTION_OLD_NAME,
551 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
553 printf("testing rename dir\n");
555 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
556 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
557 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
558 NOTIFY_ACTION_OLD_NAME,
559 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
561 printf("testing set path attribute\n");
563 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
564 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
565 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
566 NOTIFY_ACTION_MODIFIED,
567 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
569 printf("testing set path write time\n");
571 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
572 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
573 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
574 NOTIFY_ACTION_MODIFIED,
575 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
577 printf("testing set file attribute\n");
579 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
580 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
581 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
582 NOTIFY_ACTION_MODIFIED,
583 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
585 if (lp_parm_bool(-1, "torture", "samba3", False)) {
586 printf("Samba3 does not yet support create times "
590 printf("testing set file create time\n");
592 fnum2 = create_complex_file(cli, mem_ctx,
593 BASEDIR "\\tname1");,
594 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
595 (smbcli_close(cli->tree, fnum2),
596 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
597 NOTIFY_ACTION_MODIFIED,
598 FILE_NOTIFY_CHANGE_CREATION, 1);
601 printf("testing set file access time\n");
603 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
604 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
605 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
606 NOTIFY_ACTION_MODIFIED,
607 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
609 printf("testing set file write time\n");
611 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
612 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
613 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
614 NOTIFY_ACTION_MODIFIED,
615 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
617 printf("testing set file change time\n");
619 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
620 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
621 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
622 NOTIFY_ACTION_MODIFIED,
626 printf("testing write\n");
628 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
629 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
630 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
631 NOTIFY_ACTION_MODIFIED,
634 printf("testing truncate\n");
636 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
637 smbcli_ftruncate(cli->tree, fnum2, 10000);,
638 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
639 NOTIFY_ACTION_MODIFIED,
640 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
643 smb_raw_exit(cli->session);
648 basic testing of change notify on files
650 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
656 union smb_notify notify;
657 struct smbcli_request *req;
659 const char *fname = BASEDIR "\\file.txt";
661 printf("TESTING CHANGE NOTIFY ON FILES\n");
663 io.generic.level = RAW_OPEN_NTCREATEX;
664 io.ntcreatex.in.root_fid = 0;
665 io.ntcreatex.in.flags = 0;
666 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
667 io.ntcreatex.in.create_options = 0;
668 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
669 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
670 io.ntcreatex.in.alloc_size = 0;
671 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
672 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
673 io.ntcreatex.in.security_flags = 0;
674 io.ntcreatex.in.fname = fname;
675 status = smb_raw_open(cli->tree, mem_ctx, &io);
676 CHECK_STATUS(status, NT_STATUS_OK);
677 fnum = io.ntcreatex.out.file.fnum;
679 /* ask for a change notify,
680 on file or directory name changes */
681 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
682 notify.nttrans.in.file.fnum = fnum;
683 notify.nttrans.in.buffer_size = 1000;
684 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
685 notify.nttrans.in.recursive = False;
687 printf("testing if notifies on file handles are invalid (should be)\n");
689 req = smb_raw_changenotify_send(cli->tree, ¬ify);
690 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
691 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
693 cl.close.level = RAW_CLOSE_CLOSE;
694 cl.close.in.file.fnum = fnum;
695 cl.close.in.write_time = 0;
696 status = smb_raw_close(cli->tree, &cl);
697 CHECK_STATUS(status, NT_STATUS_OK);
699 status = smbcli_unlink(cli->tree, fname);
700 CHECK_STATUS(status, NT_STATUS_OK);
703 smb_raw_exit(cli->session);
708 basic testing of change notifies followed by a tdis
710 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
714 union smb_notify notify;
717 struct smbcli_request *req;
718 struct smbcli_state *cli = NULL;
720 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
722 if (!torture_open_connection(&cli, 0)) {
727 get a handle on the directory
729 io.generic.level = RAW_OPEN_NTCREATEX;
730 io.ntcreatex.in.root_fid = 0;
731 io.ntcreatex.in.flags = 0;
732 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
733 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
734 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
735 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
736 io.ntcreatex.in.alloc_size = 0;
737 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
738 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
739 io.ntcreatex.in.security_flags = 0;
740 io.ntcreatex.in.fname = BASEDIR;
742 status = smb_raw_open(cli->tree, mem_ctx, &io);
743 CHECK_STATUS(status, NT_STATUS_OK);
744 fnum = io.ntcreatex.out.file.fnum;
746 /* ask for a change notify,
747 on file or directory name changes */
748 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
749 notify.nttrans.in.buffer_size = 1000;
750 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
751 notify.nttrans.in.file.fnum = fnum;
752 notify.nttrans.in.recursive = True;
754 req = smb_raw_changenotify_send(cli->tree, ¬ify);
756 status = smbcli_tdis(cli);
757 CHECK_STATUS(status, NT_STATUS_OK);
760 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
761 CHECK_STATUS(status, NT_STATUS_OK);
762 CHECK_VAL(notify.nttrans.out.num_changes, 0);
765 torture_close_connection(cli);
770 basic testing of change notifies followed by a exit
772 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
776 union smb_notify notify;
779 struct smbcli_request *req;
780 struct smbcli_state *cli = NULL;
782 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
784 if (!torture_open_connection(&cli, 0)) {
789 get a handle on the directory
791 io.generic.level = RAW_OPEN_NTCREATEX;
792 io.ntcreatex.in.root_fid = 0;
793 io.ntcreatex.in.flags = 0;
794 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
795 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
796 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
797 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
798 io.ntcreatex.in.alloc_size = 0;
799 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
800 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
801 io.ntcreatex.in.security_flags = 0;
802 io.ntcreatex.in.fname = BASEDIR;
804 status = smb_raw_open(cli->tree, mem_ctx, &io);
805 CHECK_STATUS(status, NT_STATUS_OK);
806 fnum = io.ntcreatex.out.file.fnum;
808 /* ask for a change notify,
809 on file or directory name changes */
810 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
811 notify.nttrans.in.buffer_size = 1000;
812 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
813 notify.nttrans.in.file.fnum = fnum;
814 notify.nttrans.in.recursive = True;
816 req = smb_raw_changenotify_send(cli->tree, ¬ify);
818 status = smb_raw_exit(cli->session);
819 CHECK_STATUS(status, NT_STATUS_OK);
821 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
822 CHECK_STATUS(status, NT_STATUS_OK);
823 CHECK_VAL(notify.nttrans.out.num_changes, 0);
826 torture_close_connection(cli);
831 basic testing of change notifies followed by a ulogoff
833 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
837 union smb_notify notify;
840 struct smbcli_request *req;
841 struct smbcli_state *cli = NULL;
843 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
845 if (!torture_open_connection(&cli, 0)) {
850 get a handle on the directory
852 io.generic.level = RAW_OPEN_NTCREATEX;
853 io.ntcreatex.in.root_fid = 0;
854 io.ntcreatex.in.flags = 0;
855 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
856 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
857 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
858 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
859 io.ntcreatex.in.alloc_size = 0;
860 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
861 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
862 io.ntcreatex.in.security_flags = 0;
863 io.ntcreatex.in.fname = BASEDIR;
865 status = smb_raw_open(cli->tree, mem_ctx, &io);
866 CHECK_STATUS(status, NT_STATUS_OK);
867 fnum = io.ntcreatex.out.file.fnum;
869 /* ask for a change notify,
870 on file or directory name changes */
871 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
872 notify.nttrans.in.buffer_size = 1000;
873 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
874 notify.nttrans.in.file.fnum = fnum;
875 notify.nttrans.in.recursive = True;
877 req = smb_raw_changenotify_send(cli->tree, ¬ify);
879 status = smb_raw_ulogoff(cli->session);
880 CHECK_STATUS(status, NT_STATUS_OK);
882 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
883 CHECK_STATUS(status, NT_STATUS_OK);
884 CHECK_VAL(notify.nttrans.out.num_changes, 0);
887 torture_close_connection(cli);
891 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
893 struct smbcli_state *cli = p;
894 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
895 cli->transport = NULL;
899 basic testing of change notifies followed by tcp disconnect
901 static BOOL test_notify_tcp_dis(TALLOC_CTX *mem_ctx)
905 union smb_notify notify;
908 struct smbcli_request *req;
909 struct smbcli_state *cli = NULL;
911 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
913 if (!torture_open_connection(&cli, 0)) {
918 get a handle on the directory
920 io.generic.level = RAW_OPEN_NTCREATEX;
921 io.ntcreatex.in.root_fid = 0;
922 io.ntcreatex.in.flags = 0;
923 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
924 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
925 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
926 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
927 io.ntcreatex.in.alloc_size = 0;
928 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
929 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
930 io.ntcreatex.in.security_flags = 0;
931 io.ntcreatex.in.fname = BASEDIR;
933 status = smb_raw_open(cli->tree, mem_ctx, &io);
934 CHECK_STATUS(status, NT_STATUS_OK);
935 fnum = io.ntcreatex.out.file.fnum;
937 /* ask for a change notify,
938 on file or directory name changes */
939 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
940 notify.nttrans.in.buffer_size = 1000;
941 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
942 notify.nttrans.in.file.fnum = fnum;
943 notify.nttrans.in.recursive = True;
945 req = smb_raw_changenotify_send(cli->tree, ¬ify);
947 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
949 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
950 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
953 torture_close_connection(cli);
958 test setting up two change notify requests on one handle
960 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
964 union smb_notify notify;
967 struct smbcli_request *req1, *req2;
969 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
972 get a handle on the directory
974 io.generic.level = RAW_OPEN_NTCREATEX;
975 io.ntcreatex.in.root_fid = 0;
976 io.ntcreatex.in.flags = 0;
977 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
978 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
979 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
980 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
981 io.ntcreatex.in.alloc_size = 0;
982 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
983 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
984 io.ntcreatex.in.security_flags = 0;
985 io.ntcreatex.in.fname = BASEDIR;
987 status = smb_raw_open(cli->tree, mem_ctx, &io);
988 CHECK_STATUS(status, NT_STATUS_OK);
989 fnum = io.ntcreatex.out.file.fnum;
991 /* ask for a change notify,
992 on file or directory name changes */
993 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
994 notify.nttrans.in.buffer_size = 1000;
995 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
996 notify.nttrans.in.file.fnum = fnum;
997 notify.nttrans.in.recursive = True;
999 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1000 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
1002 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1004 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1005 CHECK_STATUS(status, NT_STATUS_OK);
1006 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1007 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1009 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1011 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
1012 CHECK_STATUS(status, NT_STATUS_OK);
1013 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1014 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
1017 smb_raw_exit(cli->session);
1023 test multiple change notifies at different depths and with/without recursion
1025 static BOOL test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1028 union smb_notify notify;
1030 struct smbcli_request *req;
1040 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 30 },
1041 {BASEDIR "\\zqy", True, FILE_NOTIFY_CHANGE_NAME, 8 },
1042 {BASEDIR "\\atsy", True, FILE_NOTIFY_CHANGE_NAME, 4 },
1043 {BASEDIR "\\abc\\foo", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1044 {BASEDIR "\\abc\\blah", True, FILE_NOTIFY_CHANGE_NAME, 13 },
1045 {BASEDIR "\\abc\\blah", False, FILE_NOTIFY_CHANGE_NAME, 7 },
1046 {BASEDIR "\\abc\\blah\\a", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1047 {BASEDIR "\\abc\\blah\\b", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1048 {BASEDIR "\\abc\\blah\\c", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1049 {BASEDIR "\\abc\\fooblah", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1050 {BASEDIR "\\zqy\\xx", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1051 {BASEDIR "\\zqy\\yyy", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1052 {BASEDIR "\\zqy\\..", True, FILE_NOTIFY_CHANGE_NAME, 40 },
1053 {BASEDIR, True, FILE_NOTIFY_CHANGE_NAME, 40 },
1054 {BASEDIR, False,FILE_NOTIFY_CHANGE_NAME, 6 },
1055 {BASEDIR "\\atsy", False,FILE_NOTIFY_CHANGE_NAME, 4 },
1056 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1057 {BASEDIR "\\abc", False,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1058 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1059 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1063 BOOL all_done = False;
1065 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1067 io.generic.level = RAW_OPEN_NTCREATEX;
1068 io.ntcreatex.in.root_fid = 0;
1069 io.ntcreatex.in.flags = 0;
1070 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1071 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1072 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1073 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1074 io.ntcreatex.in.alloc_size = 0;
1075 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1076 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1077 io.ntcreatex.in.security_flags = 0;
1079 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1080 notify.nttrans.in.buffer_size = 20000;
1083 setup the directory tree, and the notify buffer on each directory
1085 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1086 io.ntcreatex.in.fname = dirs[i].path;
1087 status = smb_raw_open(cli->tree, mem_ctx, &io);
1088 CHECK_STATUS(status, NT_STATUS_OK);
1089 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1091 notify.nttrans.in.completion_filter = dirs[i].filter;
1092 notify.nttrans.in.file.fnum = dirs[i].fnum;
1093 notify.nttrans.in.recursive = dirs[i].recursive;
1094 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1095 smb_raw_ntcancel(req);
1096 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1097 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1100 /* trigger 2 events in each dir */
1101 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1102 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1103 smbcli_mkdir(cli->tree, path);
1104 smbcli_rmdir(cli->tree, path);
1108 /* give a bit of time for the events to propogate */
1109 tv = timeval_current();
1112 /* count events that have happened in each dir */
1113 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1114 notify.nttrans.in.file.fnum = dirs[i].fnum;
1115 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1116 smb_raw_ntcancel(req);
1117 notify.nttrans.out.num_changes = 0;
1118 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1119 dirs[i].counted += notify.nttrans.out.num_changes;
1124 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1125 if (dirs[i].counted != dirs[i].expected) {
1129 } while (!all_done && timeval_elapsed(&tv) < 20);
1131 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1133 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1134 if (dirs[i].counted != dirs[i].expected) {
1135 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1136 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1142 run from the back, closing and deleting
1144 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1145 smbcli_close(cli->tree, dirs[i].fnum);
1146 smbcli_rmdir(cli->tree, dirs[i].path);
1150 smb_raw_exit(cli->session);
1155 basic testing of change notify
1157 BOOL torture_raw_notify(struct torture_context *torture)
1159 struct smbcli_state *cli, *cli2;
1161 TALLOC_CTX *mem_ctx;
1163 if (!torture_open_connection(&cli, 0)) {
1166 if (!torture_open_connection(&cli2, 0)) {
1170 mem_ctx = talloc_init("torture_raw_notify");
1172 if (!torture_setup_dir(cli, BASEDIR)) {
1176 ret &= test_notify_dir(cli, cli2, mem_ctx);
1177 ret &= test_notify_mask(cli, mem_ctx);
1178 ret &= test_notify_recursive(cli, mem_ctx);
1179 ret &= test_notify_file(cli, mem_ctx);
1180 ret &= test_notify_tdis(mem_ctx);
1181 ret &= test_notify_exit(mem_ctx);
1182 ret &= test_notify_ulogoff(mem_ctx);
1183 ret &= test_notify_tcp_dis(mem_ctx);
1184 ret &= test_notify_double(cli, mem_ctx);
1185 ret &= test_notify_tree(cli, mem_ctx);
1187 smb_raw_exit(cli->session);
1188 smbcli_deltree(cli->tree, BASEDIR);
1189 torture_close_connection(cli);
1190 torture_close_connection(cli2);
1191 talloc_free(mem_ctx);