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(200); 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 if (lp_parm_bool(-1, "torture", "samba3", False)) {
545 printf("Samba3 does not yet support create times "
549 printf("testing set file create time\n");
551 fnum2 = create_complex_file(cli, mem_ctx,
552 BASEDIR "\\tname1");,
553 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
554 (smbcli_close(cli->tree, fnum2),
555 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
556 NOTIFY_ACTION_MODIFIED,
557 FILE_NOTIFY_CHANGE_CREATION, 1);
560 printf("testing set file access time\n");
562 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
563 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
564 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
565 NOTIFY_ACTION_MODIFIED,
566 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
568 printf("testing set file write time\n");
570 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
571 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
572 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
573 NOTIFY_ACTION_MODIFIED,
574 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
576 printf("testing set file change time\n");
578 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
579 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
580 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
581 NOTIFY_ACTION_MODIFIED,
585 printf("testing write\n");
587 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
588 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
589 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
590 NOTIFY_ACTION_MODIFIED,
593 printf("testing truncate\n");
595 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
596 smbcli_ftruncate(cli->tree, fnum2, 10000);,
597 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
598 NOTIFY_ACTION_MODIFIED,
599 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
602 smb_raw_exit(cli->session);
607 basic testing of change notify on files
609 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
615 union smb_notify notify;
616 struct smbcli_request *req;
618 const char *fname = BASEDIR "\\file.txt";
620 printf("TESTING CHANGE NOTIFY ON FILES\n");
622 io.generic.level = RAW_OPEN_NTCREATEX;
623 io.ntcreatex.in.root_fid = 0;
624 io.ntcreatex.in.flags = 0;
625 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
626 io.ntcreatex.in.create_options = 0;
627 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
628 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
629 io.ntcreatex.in.alloc_size = 0;
630 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
631 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
632 io.ntcreatex.in.security_flags = 0;
633 io.ntcreatex.in.fname = fname;
634 status = smb_raw_open(cli->tree, mem_ctx, &io);
635 CHECK_STATUS(status, NT_STATUS_OK);
636 fnum = io.ntcreatex.out.file.fnum;
638 /* ask for a change notify,
639 on file or directory name changes */
640 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
641 notify.nttrans.in.file.fnum = fnum;
642 notify.nttrans.in.buffer_size = 1000;
643 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
644 notify.nttrans.in.recursive = False;
646 printf("testing if notifies on file handles are invalid (should be)\n");
648 req = smb_raw_changenotify_send(cli->tree, ¬ify);
649 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
650 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
652 cl.close.level = RAW_CLOSE_CLOSE;
653 cl.close.in.file.fnum = fnum;
654 cl.close.in.write_time = 0;
655 status = smb_raw_close(cli->tree, &cl);
656 CHECK_STATUS(status, NT_STATUS_OK);
658 status = smbcli_unlink(cli->tree, fname);
659 CHECK_STATUS(status, NT_STATUS_OK);
662 smb_raw_exit(cli->session);
667 basic testing of change notifies followed by a tdis
669 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
673 union smb_notify notify;
676 struct smbcli_request *req;
677 struct smbcli_state *cli = NULL;
679 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
681 if (!torture_open_connection(&cli, 0)) {
686 get a handle on the directory
688 io.generic.level = RAW_OPEN_NTCREATEX;
689 io.ntcreatex.in.root_fid = 0;
690 io.ntcreatex.in.flags = 0;
691 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
692 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
693 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
694 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
695 io.ntcreatex.in.alloc_size = 0;
696 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
697 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
698 io.ntcreatex.in.security_flags = 0;
699 io.ntcreatex.in.fname = BASEDIR;
701 status = smb_raw_open(cli->tree, mem_ctx, &io);
702 CHECK_STATUS(status, NT_STATUS_OK);
703 fnum = io.ntcreatex.out.file.fnum;
705 /* ask for a change notify,
706 on file or directory name changes */
707 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
708 notify.nttrans.in.buffer_size = 1000;
709 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
710 notify.nttrans.in.file.fnum = fnum;
711 notify.nttrans.in.recursive = True;
713 req = smb_raw_changenotify_send(cli->tree, ¬ify);
715 status = smbcli_tdis(cli);
716 CHECK_STATUS(status, NT_STATUS_OK);
719 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
720 CHECK_STATUS(status, NT_STATUS_OK);
721 CHECK_VAL(notify.nttrans.out.num_changes, 0);
724 torture_close_connection(cli);
729 basic testing of change notifies followed by a exit
731 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
735 union smb_notify notify;
738 struct smbcli_request *req;
739 struct smbcli_state *cli = NULL;
741 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
743 if (!torture_open_connection(&cli, 0)) {
748 get a handle on the directory
750 io.generic.level = RAW_OPEN_NTCREATEX;
751 io.ntcreatex.in.root_fid = 0;
752 io.ntcreatex.in.flags = 0;
753 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
754 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
755 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
756 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
757 io.ntcreatex.in.alloc_size = 0;
758 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
759 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
760 io.ntcreatex.in.security_flags = 0;
761 io.ntcreatex.in.fname = BASEDIR;
763 status = smb_raw_open(cli->tree, mem_ctx, &io);
764 CHECK_STATUS(status, NT_STATUS_OK);
765 fnum = io.ntcreatex.out.file.fnum;
767 /* ask for a change notify,
768 on file or directory name changes */
769 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
770 notify.nttrans.in.buffer_size = 1000;
771 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
772 notify.nttrans.in.file.fnum = fnum;
773 notify.nttrans.in.recursive = True;
775 req = smb_raw_changenotify_send(cli->tree, ¬ify);
777 status = smb_raw_exit(cli->session);
778 CHECK_STATUS(status, NT_STATUS_OK);
780 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
781 CHECK_STATUS(status, NT_STATUS_OK);
782 CHECK_VAL(notify.nttrans.out.num_changes, 0);
785 torture_close_connection(cli);
790 basic testing of change notifies followed by a ulogoff
792 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
796 union smb_notify notify;
799 struct smbcli_request *req;
800 struct smbcli_state *cli = NULL;
802 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
804 if (!torture_open_connection(&cli, 0)) {
809 get a handle on the directory
811 io.generic.level = RAW_OPEN_NTCREATEX;
812 io.ntcreatex.in.root_fid = 0;
813 io.ntcreatex.in.flags = 0;
814 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
815 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
816 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
817 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
818 io.ntcreatex.in.alloc_size = 0;
819 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
820 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
821 io.ntcreatex.in.security_flags = 0;
822 io.ntcreatex.in.fname = BASEDIR;
824 status = smb_raw_open(cli->tree, mem_ctx, &io);
825 CHECK_STATUS(status, NT_STATUS_OK);
826 fnum = io.ntcreatex.out.file.fnum;
828 /* ask for a change notify,
829 on file or directory name changes */
830 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
831 notify.nttrans.in.buffer_size = 1000;
832 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
833 notify.nttrans.in.file.fnum = fnum;
834 notify.nttrans.in.recursive = True;
836 req = smb_raw_changenotify_send(cli->tree, ¬ify);
838 status = smb_raw_ulogoff(cli->session);
839 CHECK_STATUS(status, NT_STATUS_OK);
841 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
842 CHECK_STATUS(status, NT_STATUS_OK);
843 CHECK_VAL(notify.nttrans.out.num_changes, 0);
846 torture_close_connection(cli);
850 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
852 struct smbcli_state *cli = p;
853 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
854 cli->transport = NULL;
858 basic testing of change notifies followed by tcp disconnect
860 static BOOL test_notify_tcp_dis(TALLOC_CTX *mem_ctx)
864 union smb_notify notify;
867 struct smbcli_request *req;
868 struct smbcli_state *cli = NULL;
870 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
872 if (!torture_open_connection(&cli, 0)) {
877 get a handle on the directory
879 io.generic.level = RAW_OPEN_NTCREATEX;
880 io.ntcreatex.in.root_fid = 0;
881 io.ntcreatex.in.flags = 0;
882 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
883 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
884 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
885 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
886 io.ntcreatex.in.alloc_size = 0;
887 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
888 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
889 io.ntcreatex.in.security_flags = 0;
890 io.ntcreatex.in.fname = BASEDIR;
892 status = smb_raw_open(cli->tree, mem_ctx, &io);
893 CHECK_STATUS(status, NT_STATUS_OK);
894 fnum = io.ntcreatex.out.file.fnum;
896 /* ask for a change notify,
897 on file or directory name changes */
898 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
899 notify.nttrans.in.buffer_size = 1000;
900 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
901 notify.nttrans.in.file.fnum = fnum;
902 notify.nttrans.in.recursive = True;
904 req = smb_raw_changenotify_send(cli->tree, ¬ify);
906 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
908 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
909 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
912 torture_close_connection(cli);
917 test setting up two change notify requests on one handle
919 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
923 union smb_notify notify;
926 struct smbcli_request *req1, *req2;
928 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
931 get a handle on the directory
933 io.generic.level = RAW_OPEN_NTCREATEX;
934 io.ntcreatex.in.root_fid = 0;
935 io.ntcreatex.in.flags = 0;
936 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
937 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
938 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
939 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
940 io.ntcreatex.in.alloc_size = 0;
941 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
942 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
943 io.ntcreatex.in.security_flags = 0;
944 io.ntcreatex.in.fname = BASEDIR;
946 status = smb_raw_open(cli->tree, mem_ctx, &io);
947 CHECK_STATUS(status, NT_STATUS_OK);
948 fnum = io.ntcreatex.out.file.fnum;
950 /* ask for a change notify,
951 on file or directory name changes */
952 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
953 notify.nttrans.in.buffer_size = 1000;
954 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
955 notify.nttrans.in.file.fnum = fnum;
956 notify.nttrans.in.recursive = True;
958 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
959 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
961 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
963 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
964 CHECK_STATUS(status, NT_STATUS_OK);
965 CHECK_VAL(notify.nttrans.out.num_changes, 1);
966 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
968 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
970 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
971 CHECK_STATUS(status, NT_STATUS_OK);
972 CHECK_VAL(notify.nttrans.out.num_changes, 1);
973 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
976 smb_raw_exit(cli->session);
982 test multiple change notifies at different depths and with/without recursion
984 static BOOL test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
987 union smb_notify notify;
989 struct smbcli_request *req;
999 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 30 },
1000 {BASEDIR "\\zqy", True, FILE_NOTIFY_CHANGE_NAME, 8 },
1001 {BASEDIR "\\atsy", True, FILE_NOTIFY_CHANGE_NAME, 4 },
1002 {BASEDIR "\\abc\\foo", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1003 {BASEDIR "\\abc\\blah", True, FILE_NOTIFY_CHANGE_NAME, 13 },
1004 {BASEDIR "\\abc\\blah", False, FILE_NOTIFY_CHANGE_NAME, 7 },
1005 {BASEDIR "\\abc\\blah\\a", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1006 {BASEDIR "\\abc\\blah\\b", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1007 {BASEDIR "\\abc\\blah\\c", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1008 {BASEDIR "\\abc\\fooblah", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1009 {BASEDIR "\\zqy\\xx", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1010 {BASEDIR "\\zqy\\yyy", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1011 {BASEDIR "\\zqy\\..", True, FILE_NOTIFY_CHANGE_NAME, 40 },
1012 {BASEDIR, True, FILE_NOTIFY_CHANGE_NAME, 40 },
1013 {BASEDIR, False,FILE_NOTIFY_CHANGE_NAME, 6 },
1014 {BASEDIR "\\atsy", False,FILE_NOTIFY_CHANGE_NAME, 4 },
1015 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1016 {BASEDIR "\\abc", False,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1017 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1018 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1022 BOOL all_done = False;
1024 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1026 io.generic.level = RAW_OPEN_NTCREATEX;
1027 io.ntcreatex.in.root_fid = 0;
1028 io.ntcreatex.in.flags = 0;
1029 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1030 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1031 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1032 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1033 io.ntcreatex.in.alloc_size = 0;
1034 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1035 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1036 io.ntcreatex.in.security_flags = 0;
1038 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1039 notify.nttrans.in.buffer_size = 20000;
1042 setup the directory tree, and the notify buffer on each directory
1044 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1045 io.ntcreatex.in.fname = dirs[i].path;
1046 status = smb_raw_open(cli->tree, mem_ctx, &io);
1047 CHECK_STATUS(status, NT_STATUS_OK);
1048 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1050 notify.nttrans.in.completion_filter = dirs[i].filter;
1051 notify.nttrans.in.file.fnum = dirs[i].fnum;
1052 notify.nttrans.in.recursive = dirs[i].recursive;
1053 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1054 smb_raw_ntcancel(req);
1055 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1056 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1059 /* trigger 2 events in each dir */
1060 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1061 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1062 smbcli_mkdir(cli->tree, path);
1063 smbcli_rmdir(cli->tree, path);
1067 /* give a bit of time for the events to propogate */
1068 tv = timeval_current();
1071 /* count events that have happened in each dir */
1072 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1073 notify.nttrans.in.file.fnum = dirs[i].fnum;
1074 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1075 smb_raw_ntcancel(req);
1076 notify.nttrans.out.num_changes = 0;
1077 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1078 dirs[i].counted += notify.nttrans.out.num_changes;
1083 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1084 if (dirs[i].counted != dirs[i].expected) {
1088 } while (!all_done && timeval_elapsed(&tv) < 20);
1090 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1092 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1093 if (dirs[i].counted != dirs[i].expected) {
1094 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1095 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1101 run from the back, closing and deleting
1103 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1104 smbcli_close(cli->tree, dirs[i].fnum);
1105 smbcli_rmdir(cli->tree, dirs[i].path);
1109 smb_raw_exit(cli->session);
1114 basic testing of change notify
1116 BOOL torture_raw_notify(struct torture_context *torture)
1118 struct smbcli_state *cli;
1120 TALLOC_CTX *mem_ctx;
1122 if (!torture_open_connection(&cli, 0)) {
1126 mem_ctx = talloc_init("torture_raw_notify");
1128 if (!torture_setup_dir(cli, BASEDIR)) {
1132 ret &= test_notify_dir(cli, mem_ctx);
1133 ret &= test_notify_mask(cli, mem_ctx);
1134 ret &= test_notify_recursive(cli, mem_ctx);
1135 ret &= test_notify_file(cli, mem_ctx);
1136 ret &= test_notify_tdis(mem_ctx);
1137 ret &= test_notify_exit(mem_ctx);
1138 ret &= test_notify_ulogoff(mem_ctx);
1139 ret &= test_notify_tcp_dis(mem_ctx);
1140 ret &= test_notify_double(cli, mem_ctx);
1141 ret &= test_notify_tree(cli, mem_ctx);
1143 smb_raw_exit(cli->session);
1144 smbcli_deltree(cli->tree, BASEDIR);
1145 torture_close_connection(cli);
1146 talloc_free(mem_ctx);