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, TALLOC_CTX *mem_ctx)
62 union smb_notify notify;
65 int i, count, fnum, fnum2;
66 struct smbcli_request *req, *req2;
67 extern int torture_numops;
69 printf("TESTING CHANGE NOTIFY ON DIRECTRIES\n");
72 get a handle on the directory
74 io.generic.level = RAW_OPEN_NTCREATEX;
75 io.ntcreatex.in.root_fid = 0;
76 io.ntcreatex.in.flags = 0;
77 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
78 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
79 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
80 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
81 io.ntcreatex.in.alloc_size = 0;
82 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
83 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
84 io.ntcreatex.in.security_flags = 0;
85 io.ntcreatex.in.fname = BASEDIR;
87 status = smb_raw_open(cli->tree, mem_ctx, &io);
88 CHECK_STATUS(status, NT_STATUS_OK);
89 fnum = io.ntcreatex.out.file.fnum;
91 status = smb_raw_open(cli->tree, mem_ctx, &io);
92 CHECK_STATUS(status, NT_STATUS_OK);
93 fnum2 = io.ntcreatex.out.file.fnum;
95 /* ask for a change notify,
96 on file or directory name changes */
97 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
98 notify.nttrans.in.buffer_size = 1000;
99 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
100 notify.nttrans.in.file.fnum = fnum;
101 notify.nttrans.in.recursive = True;
103 printf("testing notify cancel\n");
105 req = smb_raw_changenotify_send(cli->tree, ¬ify);
106 smb_raw_ntcancel(req);
107 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
108 CHECK_STATUS(status, NT_STATUS_CANCELLED);
110 printf("testing notify mkdir\n");
112 req = smb_raw_changenotify_send(cli->tree, ¬ify);
113 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
115 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
116 CHECK_STATUS(status, NT_STATUS_OK);
118 CHECK_VAL(notify.nttrans.out.num_changes, 1);
119 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
120 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
122 printf("testing notify rmdir\n");
124 req = smb_raw_changenotify_send(cli->tree, ¬ify);
125 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
127 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
128 CHECK_STATUS(status, NT_STATUS_OK);
129 CHECK_VAL(notify.nttrans.out.num_changes, 1);
130 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
131 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
133 printf("testing notify mkdir - rmdir - mkdir - rmdir\n");
135 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
136 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
137 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
138 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
139 req = smb_raw_changenotify_send(cli->tree, ¬ify);
140 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
141 CHECK_STATUS(status, NT_STATUS_OK);
142 CHECK_VAL(notify.nttrans.out.num_changes, 4);
143 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
144 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
145 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
146 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
147 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
148 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name", STR_UNICODE);
149 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_REMOVED);
150 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name", STR_UNICODE);
152 count = torture_numops;
153 printf("testing buffered notify on create of %d files\n", count);
154 for (i=0;i<count;i++) {
155 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
156 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
158 printf("Failed to create %s - %s\n",
159 fname, smbcli_errstr(cli->tree));
164 smbcli_close(cli->tree, fnum3);
167 /* (1st notify) setup a new notify on a different directory handle.
168 This new notify won't see the events above. */
169 notify.nttrans.in.file.fnum = fnum2;
170 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
172 /* (2nd notify) whereas this notify will see the above buffered events,
173 and it directly returns the buffered events */
174 notify.nttrans.in.file.fnum = fnum;
175 req = smb_raw_changenotify_send(cli->tree, ¬ify);
177 /* (1st unlink) as the 2nd notify directly returns,
178 this unlink is only seen by the 1st notify and
179 the 3rd notify (later) */
180 printf("testing notify on unlink for the first file\n");
181 status = smbcli_unlink(cli->tree, BASEDIR "\\test0.txt");
182 CHECK_STATUS(status, NT_STATUS_OK);
184 /* receive the reply from the 2nd notify */
185 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
186 CHECK_STATUS(status, NT_STATUS_OK);
188 CHECK_VAL(notify.nttrans.out.num_changes, count);
189 for (i=1;i<notify.nttrans.out.num_changes;i++) {
190 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_ADDED);
192 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
194 /* and now from the 1st notify */
195 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
196 CHECK_STATUS(status, NT_STATUS_OK);
197 CHECK_VAL(notify.nttrans.out.num_changes, 1);
198 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
199 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
201 /* (3rd notify) this notify will only see the 1st unlink */
202 req = smb_raw_changenotify_send(cli->tree, ¬ify);
204 printf("testing notify on wildcard unlink for %d files\n", count-1);
205 /* (2nd unlink) do a wildcard unlink */
206 status = smbcli_unlink(cli->tree, BASEDIR "\\test*.txt");
207 CHECK_STATUS(status, NT_STATUS_OK);
209 /* receive the 3rd notify */
210 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
211 CHECK_STATUS(status, NT_STATUS_OK);
212 CHECK_VAL(notify.nttrans.out.num_changes, 1);
213 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
214 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
216 /* and we now see the rest of the unlink calls on both directory handles */
217 notify.nttrans.in.file.fnum = fnum;
219 req = smb_raw_changenotify_send(cli->tree, ¬ify);
220 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
221 CHECK_STATUS(status, NT_STATUS_OK);
222 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
223 for (i=0;i<notify.nttrans.out.num_changes;i++) {
224 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
226 notify.nttrans.in.file.fnum = fnum2;
227 req = smb_raw_changenotify_send(cli->tree, ¬ify);
228 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
229 CHECK_STATUS(status, NT_STATUS_OK);
230 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
231 for (i=0;i<notify.nttrans.out.num_changes;i++) {
232 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
235 printf("testing if a close() on the dir handle triggers the notify reply\n");
237 notify.nttrans.in.file.fnum = fnum;
238 req = smb_raw_changenotify_send(cli->tree, ¬ify);
240 cl.close.level = RAW_CLOSE_CLOSE;
241 cl.close.in.file.fnum = fnum;
242 cl.close.in.write_time = 0;
243 status = smb_raw_close(cli->tree, &cl);
244 CHECK_STATUS(status, NT_STATUS_OK);
246 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
247 CHECK_STATUS(status, NT_STATUS_OK);
248 CHECK_VAL(notify.nttrans.out.num_changes, 0);
251 smb_raw_exit(cli->session);
257 testing of recursive change notify
259 static BOOL test_notify_recursive(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
263 union smb_notify notify;
266 struct smbcli_request *req1, *req2;
268 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
271 get a handle on the directory
273 io.generic.level = RAW_OPEN_NTCREATEX;
274 io.ntcreatex.in.root_fid = 0;
275 io.ntcreatex.in.flags = 0;
276 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
277 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
278 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
279 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
280 io.ntcreatex.in.alloc_size = 0;
281 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
282 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
283 io.ntcreatex.in.security_flags = 0;
284 io.ntcreatex.in.fname = BASEDIR;
286 status = smb_raw_open(cli->tree, mem_ctx, &io);
287 CHECK_STATUS(status, NT_STATUS_OK);
288 fnum = io.ntcreatex.out.file.fnum;
290 /* ask for a change notify, on file or directory name
291 changes. Setup both with and without recursion */
292 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
293 notify.nttrans.in.buffer_size = 1000;
294 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
295 notify.nttrans.in.file.fnum = fnum;
297 notify.nttrans.in.recursive = True;
298 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
300 notify.nttrans.in.recursive = False;
301 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
303 /* cancel initial requests so the buffer is setup */
304 smb_raw_ntcancel(req1);
305 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
306 CHECK_STATUS(status, NT_STATUS_CANCELLED);
308 smb_raw_ntcancel(req2);
309 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
310 CHECK_STATUS(status, NT_STATUS_CANCELLED);
312 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
313 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
314 smbcli_close(cli->tree,
315 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
316 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
317 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
318 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
320 notify.nttrans.in.completion_filter = 0;
321 notify.nttrans.in.recursive = True;
323 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
325 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
326 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
327 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
329 notify.nttrans.in.recursive = False;
330 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
332 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
333 CHECK_STATUS(status, NT_STATUS_OK);
335 CHECK_VAL(notify.nttrans.out.num_changes, 11);
336 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
337 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
338 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
339 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
340 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
341 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
342 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
343 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
344 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
345 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
347 /* the remove/add between directories is acceptable in either order */
348 if (notify.nttrans.out.changes[5].action == NOTIFY_ACTION_ADDED) {
349 CHECK_VAL(notify.nttrans.out.changes[6].action, NOTIFY_ACTION_REMOVED);
350 CHECK_WSTR(notify.nttrans.out.changes[6].name, "subdir-name\\subname2", STR_UNICODE);
351 CHECK_VAL(notify.nttrans.out.changes[5].action, NOTIFY_ACTION_ADDED);
352 CHECK_WSTR(notify.nttrans.out.changes[5].name, "subname2-r", STR_UNICODE);
354 CHECK_VAL(notify.nttrans.out.changes[5].action, NOTIFY_ACTION_REMOVED);
355 CHECK_WSTR(notify.nttrans.out.changes[5].name, "subdir-name\\subname2", STR_UNICODE);
356 CHECK_VAL(notify.nttrans.out.changes[6].action, NOTIFY_ACTION_ADDED);
357 CHECK_WSTR(notify.nttrans.out.changes[6].name, "subname2-r", STR_UNICODE);
360 CHECK_VAL(notify.nttrans.out.changes[7].action, NOTIFY_ACTION_MODIFIED);
361 CHECK_WSTR(notify.nttrans.out.changes[7].name, "subname2-r", STR_UNICODE);
363 CHECK_VAL(notify.nttrans.out.changes[8].action, NOTIFY_ACTION_OLD_NAME);
364 CHECK_WSTR(notify.nttrans.out.changes[8].name, "subname2-r", STR_UNICODE);
365 CHECK_VAL(notify.nttrans.out.changes[9].action, NOTIFY_ACTION_NEW_NAME);
366 CHECK_WSTR(notify.nttrans.out.changes[9].name, "subname3-r", STR_UNICODE);
367 CHECK_VAL(notify.nttrans.out.changes[10].action, NOTIFY_ACTION_MODIFIED);
368 CHECK_WSTR(notify.nttrans.out.changes[10].name, "subname3-r", STR_UNICODE);
370 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
371 CHECK_STATUS(status, NT_STATUS_OK);
373 CHECK_VAL(notify.nttrans.out.num_changes, 3);
374 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
375 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
376 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
377 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
378 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
379 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
382 smb_raw_exit(cli->session);
388 testing of mask bits for change notify
390 static BOOL test_notify_mask(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
394 union smb_notify notify;
403 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
405 tv = timeval_current_ofs(1000, 0);
406 t = timeval_to_nttime(&tv);
409 get a handle on the directory
411 io.generic.level = RAW_OPEN_NTCREATEX;
412 io.ntcreatex.in.root_fid = 0;
413 io.ntcreatex.in.flags = 0;
414 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
415 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
416 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
417 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
418 io.ntcreatex.in.alloc_size = 0;
419 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
420 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
421 io.ntcreatex.in.security_flags = 0;
422 io.ntcreatex.in.fname = BASEDIR;
424 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
425 notify.nttrans.in.buffer_size = 1000;
426 notify.nttrans.in.recursive = True;
428 #define NOTIFY_MASK_TEST(setup, op, cleanup, Action, expected, nchanges) \
429 do { for (mask=i=0;i<32;i++) { \
430 struct smbcli_request *req; \
431 status = smb_raw_open(cli->tree, mem_ctx, &io); \
432 CHECK_STATUS(status, NT_STATUS_OK); \
433 fnum = io.ntcreatex.out.file.fnum; \
435 notify.nttrans.in.file.fnum = fnum; \
436 notify.nttrans.in.completion_filter = (1<<i); \
437 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
439 msleep(10); smb_raw_ntcancel(req); \
440 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); \
442 smbcli_close(cli->tree, fnum); \
443 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
444 CHECK_STATUS(status, NT_STATUS_OK); \
445 /* special case to cope with file rename behaviour */ \
446 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
447 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
448 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
449 Action == NOTIFY_ACTION_OLD_NAME) { \
450 printf("(rename file special handling OK)\n"); \
451 } else if (nchanges != notify.nttrans.out.num_changes || \
452 notify.nttrans.out.changes[0].action != Action || \
453 strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
454 printf("ERROR: nchanges=%d action=%d filter=0x%08x\n", \
455 notify.nttrans.out.num_changes, \
456 notify.nttrans.out.changes[0].action, \
457 notify.nttrans.in.completion_filter); \
462 if ((expected) != mask) { \
463 if (((expected) & ~mask) != 0) { \
464 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
468 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
474 printf("testing mkdir\n");
476 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
477 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
479 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
481 printf("testing create file\n");
483 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
484 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
486 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
488 printf("testing unlink\n");
490 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
491 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
493 NOTIFY_ACTION_REMOVED,
494 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
496 printf("testing rmdir\n");
498 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
499 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
501 NOTIFY_ACTION_REMOVED,
502 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
504 printf("testing rename file\n");
506 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
507 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
508 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
509 NOTIFY_ACTION_OLD_NAME,
510 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
512 printf("testing rename dir\n");
514 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
515 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
516 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
517 NOTIFY_ACTION_OLD_NAME,
518 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
520 printf("testing set path attribute\n");
522 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
523 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
524 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
525 NOTIFY_ACTION_MODIFIED,
526 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
528 printf("testing set path write time\n");
530 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
531 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
532 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
533 NOTIFY_ACTION_MODIFIED,
534 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
536 printf("testing set file attribute\n");
538 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
539 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
540 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
541 NOTIFY_ACTION_MODIFIED,
542 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
544 printf("testing set file create time\n");
546 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
547 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
548 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
549 NOTIFY_ACTION_MODIFIED,
550 FILE_NOTIFY_CHANGE_CREATION, 1);
552 printf("testing set file access time\n");
554 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
555 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
556 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
557 NOTIFY_ACTION_MODIFIED,
558 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
560 printf("testing set file write time\n");
562 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
563 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
564 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
565 NOTIFY_ACTION_MODIFIED,
566 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
568 printf("testing set file change time\n");
570 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
571 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
572 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
573 NOTIFY_ACTION_MODIFIED,
577 printf("testing write\n");
579 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
580 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
581 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
582 NOTIFY_ACTION_MODIFIED,
585 printf("testing truncate\n");
587 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
588 smbcli_ftruncate(cli->tree, fnum2, 10000);,
589 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
590 NOTIFY_ACTION_MODIFIED,
591 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
594 smb_raw_exit(cli->session);
599 basic testing of change notify on files
601 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
607 union smb_notify notify;
608 struct smbcli_request *req;
610 const char *fname = BASEDIR "\\file.txt";
612 printf("TESTING CHANGE NOTIFY ON FILES\n");
614 io.generic.level = RAW_OPEN_NTCREATEX;
615 io.ntcreatex.in.root_fid = 0;
616 io.ntcreatex.in.flags = 0;
617 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
618 io.ntcreatex.in.create_options = 0;
619 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
620 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
621 io.ntcreatex.in.alloc_size = 0;
622 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
623 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
624 io.ntcreatex.in.security_flags = 0;
625 io.ntcreatex.in.fname = fname;
626 status = smb_raw_open(cli->tree, mem_ctx, &io);
627 CHECK_STATUS(status, NT_STATUS_OK);
628 fnum = io.ntcreatex.out.file.fnum;
630 /* ask for a change notify,
631 on file or directory name changes */
632 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
633 notify.nttrans.in.file.fnum = fnum;
634 notify.nttrans.in.buffer_size = 1000;
635 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
636 notify.nttrans.in.recursive = False;
638 printf("testing if notifies on file handles are invalid (should be)\n");
640 req = smb_raw_changenotify_send(cli->tree, ¬ify);
641 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
642 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
644 cl.close.level = RAW_CLOSE_CLOSE;
645 cl.close.in.file.fnum = fnum;
646 cl.close.in.write_time = 0;
647 status = smb_raw_close(cli->tree, &cl);
648 CHECK_STATUS(status, NT_STATUS_OK);
650 status = smbcli_unlink(cli->tree, fname);
651 CHECK_STATUS(status, NT_STATUS_OK);
654 smb_raw_exit(cli->session);
659 basic testing of change notifies followed by a tdis
661 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
665 union smb_notify notify;
668 struct smbcli_request *req;
669 struct smbcli_state *cli = NULL;
671 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
673 if (!torture_open_connection(&cli, 0)) {
678 get a handle on the directory
680 io.generic.level = RAW_OPEN_NTCREATEX;
681 io.ntcreatex.in.root_fid = 0;
682 io.ntcreatex.in.flags = 0;
683 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
684 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
685 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
686 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
687 io.ntcreatex.in.alloc_size = 0;
688 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
689 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
690 io.ntcreatex.in.security_flags = 0;
691 io.ntcreatex.in.fname = BASEDIR;
693 status = smb_raw_open(cli->tree, mem_ctx, &io);
694 CHECK_STATUS(status, NT_STATUS_OK);
695 fnum = io.ntcreatex.out.file.fnum;
697 /* ask for a change notify,
698 on file or directory name changes */
699 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
700 notify.nttrans.in.buffer_size = 1000;
701 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
702 notify.nttrans.in.file.fnum = fnum;
703 notify.nttrans.in.recursive = True;
705 req = smb_raw_changenotify_send(cli->tree, ¬ify);
707 status = smbcli_tdis(cli);
708 CHECK_STATUS(status, NT_STATUS_OK);
711 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
712 CHECK_STATUS(status, NT_STATUS_OK);
713 CHECK_VAL(notify.nttrans.out.num_changes, 0);
716 torture_close_connection(cli);
721 basic testing of change notifies followed by a exit
723 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
727 union smb_notify notify;
730 struct smbcli_request *req;
731 struct smbcli_state *cli = NULL;
733 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
735 if (!torture_open_connection(&cli, 0)) {
740 get a handle on the directory
742 io.generic.level = RAW_OPEN_NTCREATEX;
743 io.ntcreatex.in.root_fid = 0;
744 io.ntcreatex.in.flags = 0;
745 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
746 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
747 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
748 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
749 io.ntcreatex.in.alloc_size = 0;
750 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
751 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
752 io.ntcreatex.in.security_flags = 0;
753 io.ntcreatex.in.fname = BASEDIR;
755 status = smb_raw_open(cli->tree, mem_ctx, &io);
756 CHECK_STATUS(status, NT_STATUS_OK);
757 fnum = io.ntcreatex.out.file.fnum;
759 /* ask for a change notify,
760 on file or directory name changes */
761 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
762 notify.nttrans.in.buffer_size = 1000;
763 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
764 notify.nttrans.in.file.fnum = fnum;
765 notify.nttrans.in.recursive = True;
767 req = smb_raw_changenotify_send(cli->tree, ¬ify);
769 status = smb_raw_exit(cli->session);
770 CHECK_STATUS(status, NT_STATUS_OK);
772 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
773 CHECK_STATUS(status, NT_STATUS_OK);
774 CHECK_VAL(notify.nttrans.out.num_changes, 0);
777 torture_close_connection(cli);
782 basic testing of change notifies followed by a ulogoff
784 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
788 union smb_notify notify;
791 struct smbcli_request *req;
792 struct smbcli_state *cli = NULL;
794 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
796 if (!torture_open_connection(&cli, 0)) {
801 get a handle on the directory
803 io.generic.level = RAW_OPEN_NTCREATEX;
804 io.ntcreatex.in.root_fid = 0;
805 io.ntcreatex.in.flags = 0;
806 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
807 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
808 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
809 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
810 io.ntcreatex.in.alloc_size = 0;
811 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
812 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
813 io.ntcreatex.in.security_flags = 0;
814 io.ntcreatex.in.fname = BASEDIR;
816 status = smb_raw_open(cli->tree, mem_ctx, &io);
817 CHECK_STATUS(status, NT_STATUS_OK);
818 fnum = io.ntcreatex.out.file.fnum;
820 /* ask for a change notify,
821 on file or directory name changes */
822 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
823 notify.nttrans.in.buffer_size = 1000;
824 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
825 notify.nttrans.in.file.fnum = fnum;
826 notify.nttrans.in.recursive = True;
828 req = smb_raw_changenotify_send(cli->tree, ¬ify);
830 status = smb_raw_ulogoff(cli->session);
831 CHECK_STATUS(status, NT_STATUS_OK);
833 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
834 CHECK_STATUS(status, NT_STATUS_OK);
835 CHECK_VAL(notify.nttrans.out.num_changes, 0);
838 torture_close_connection(cli);
842 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
844 struct smbcli_state *cli = p;
845 smbcli_transport_dead(cli->transport);
846 cli->transport = NULL;
850 basic testing of change notifies followed by tcp disconnect
852 static BOOL test_notify_tcp_dis(TALLOC_CTX *mem_ctx)
856 union smb_notify notify;
859 struct smbcli_request *req;
860 struct smbcli_state *cli = NULL;
862 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
864 if (!torture_open_connection(&cli, 0)) {
869 get a handle on the directory
871 io.generic.level = RAW_OPEN_NTCREATEX;
872 io.ntcreatex.in.root_fid = 0;
873 io.ntcreatex.in.flags = 0;
874 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
875 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
876 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
877 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
878 io.ntcreatex.in.alloc_size = 0;
879 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
880 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
881 io.ntcreatex.in.security_flags = 0;
882 io.ntcreatex.in.fname = BASEDIR;
884 status = smb_raw_open(cli->tree, mem_ctx, &io);
885 CHECK_STATUS(status, NT_STATUS_OK);
886 fnum = io.ntcreatex.out.file.fnum;
888 /* ask for a change notify,
889 on file or directory name changes */
890 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
891 notify.nttrans.in.buffer_size = 1000;
892 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
893 notify.nttrans.in.file.fnum = fnum;
894 notify.nttrans.in.recursive = True;
896 req = smb_raw_changenotify_send(cli->tree, ¬ify);
898 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
900 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
901 CHECK_STATUS(status, NT_STATUS_NET_WRITE_FAULT);
904 torture_close_connection(cli);
909 test setting up two change notify requests on one handle
911 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
915 union smb_notify notify;
918 struct smbcli_request *req1, *req2;
920 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
923 get a handle on the directory
925 io.generic.level = RAW_OPEN_NTCREATEX;
926 io.ntcreatex.in.root_fid = 0;
927 io.ntcreatex.in.flags = 0;
928 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
929 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
930 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
931 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
932 io.ntcreatex.in.alloc_size = 0;
933 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
934 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
935 io.ntcreatex.in.security_flags = 0;
936 io.ntcreatex.in.fname = BASEDIR;
938 status = smb_raw_open(cli->tree, mem_ctx, &io);
939 CHECK_STATUS(status, NT_STATUS_OK);
940 fnum = io.ntcreatex.out.file.fnum;
942 /* ask for a change notify,
943 on file or directory name changes */
944 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
945 notify.nttrans.in.buffer_size = 1000;
946 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
947 notify.nttrans.in.file.fnum = fnum;
948 notify.nttrans.in.recursive = True;
950 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
951 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
953 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
955 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
956 CHECK_STATUS(status, NT_STATUS_OK);
957 CHECK_VAL(notify.nttrans.out.num_changes, 1);
958 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
960 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
962 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
963 CHECK_STATUS(status, NT_STATUS_OK);
964 CHECK_VAL(notify.nttrans.out.num_changes, 1);
965 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
968 smb_raw_exit(cli->session);
974 test multiple change notifies at different depths and with/without recursion
976 static BOOL test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
979 union smb_notify notify;
981 struct smbcli_request *req;
989 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 30 },
990 {BASEDIR "\\zqy", True, FILE_NOTIFY_CHANGE_NAME, 8 },
991 {BASEDIR "\\atsy", True, FILE_NOTIFY_CHANGE_NAME, 4 },
992 {BASEDIR "\\abc\\foo", True, FILE_NOTIFY_CHANGE_NAME, 2 },
993 {BASEDIR "\\abc\\blah", True, FILE_NOTIFY_CHANGE_NAME, 13 },
994 {BASEDIR "\\abc\\blah", False, FILE_NOTIFY_CHANGE_NAME, 7 },
995 {BASEDIR "\\abc\\blah\\a", True, FILE_NOTIFY_CHANGE_NAME, 2 },
996 {BASEDIR "\\abc\\blah\\b", True, FILE_NOTIFY_CHANGE_NAME, 2 },
997 {BASEDIR "\\abc\\blah\\c", True, FILE_NOTIFY_CHANGE_NAME, 2 },
998 {BASEDIR "\\abc\\fooblah", True, FILE_NOTIFY_CHANGE_NAME, 2 },
999 {BASEDIR "\\zqy\\xx", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1000 {BASEDIR "\\zqy\\yyy", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1001 {BASEDIR "\\zqy\\..", True, FILE_NOTIFY_CHANGE_NAME, 40 },
1002 {BASEDIR, True, FILE_NOTIFY_CHANGE_NAME, 40 },
1003 {BASEDIR, False,FILE_NOTIFY_CHANGE_NAME, 6 },
1004 {BASEDIR "\\atsy", False,FILE_NOTIFY_CHANGE_NAME, 4 },
1005 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1006 {BASEDIR "\\abc", False,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1007 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1008 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1013 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1015 io.generic.level = RAW_OPEN_NTCREATEX;
1016 io.ntcreatex.in.root_fid = 0;
1017 io.ntcreatex.in.flags = 0;
1018 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1019 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1020 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1021 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1022 io.ntcreatex.in.alloc_size = 0;
1023 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1024 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1025 io.ntcreatex.in.security_flags = 0;
1027 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1028 notify.nttrans.in.buffer_size = 20000;
1031 setup the directory tree, and the notify buffer on each directory
1033 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1034 io.ntcreatex.in.fname = dirs[i].path;
1035 status = smb_raw_open(cli->tree, mem_ctx, &io);
1036 CHECK_STATUS(status, NT_STATUS_OK);
1037 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1039 notify.nttrans.in.completion_filter = dirs[i].filter;
1040 notify.nttrans.in.file.fnum = dirs[i].fnum;
1041 notify.nttrans.in.recursive = dirs[i].recursive;
1042 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1043 smb_raw_ntcancel(req);
1044 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1045 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1048 /* trigger 2 events in each dir */
1049 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1050 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1051 smbcli_mkdir(cli->tree, path);
1052 smbcli_rmdir(cli->tree, path);
1056 /* give a bit of time for all the events to propogate */
1059 /* count events that have happened in each dir */
1060 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1061 notify.nttrans.in.file.fnum = dirs[i].fnum;
1062 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1063 smb_raw_ntcancel(req);
1064 notify.nttrans.out.num_changes = 0;
1065 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1066 if (notify.nttrans.out.num_changes != dirs[i].expected) {
1067 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1068 i, dirs[i].expected, notify.nttrans.out.num_changes,
1075 run from the back, closing and deleting
1077 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1078 smbcli_close(cli->tree, dirs[i].fnum);
1079 smbcli_rmdir(cli->tree, dirs[i].path);
1083 smb_raw_exit(cli->session);
1088 basic testing of change notify
1090 BOOL torture_raw_notify(struct torture_context *torture)
1092 struct smbcli_state *cli;
1094 TALLOC_CTX *mem_ctx;
1096 if (!torture_open_connection(&cli, 0)) {
1100 mem_ctx = talloc_init("torture_raw_notify");
1102 if (!torture_setup_dir(cli, BASEDIR)) {
1106 ret &= test_notify_dir(cli, mem_ctx);
1107 ret &= test_notify_mask(cli, mem_ctx);
1108 ret &= test_notify_recursive(cli, mem_ctx);
1109 ret &= test_notify_file(cli, mem_ctx);
1110 ret &= test_notify_tdis(mem_ctx);
1111 ret &= test_notify_exit(mem_ctx);
1112 ret &= test_notify_ulogoff(mem_ctx);
1113 ret &= test_notify_tcp_dis(mem_ctx);
1114 ret &= test_notify_double(cli, mem_ctx);
1115 ret &= test_notify_tree(cli, mem_ctx);
1117 smb_raw_exit(cli->session);
1118 smbcli_deltree(cli->tree, BASEDIR);
1119 torture_close_connection(cli);
1120 talloc_free(mem_ctx);