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);
256 * Check notify reply for a rename action. Not sure if this is a valid thing
257 * to do, but depending on timing between inotify and messaging we get the
258 * add/remove/modify in any order. This routines tries to find the action/name
259 * pair in any of the three following notify_changes.
262 static BOOL check_rename_reply(struct smbcli_state *cli,
264 struct notify_changes *actions,
265 uint32_t action, const char *name)
269 for (i=0; i<3; i++) {
270 if (actions[i].action == action) {
271 if ((actions[i].name.s == NULL)
272 || (strcmp(actions[i].name.s, name) != 0)
273 || (wire_bad_flags(&actions[i].name, STR_UNICODE,
275 printf("(%d) name [%s] != %s\n", line,
276 actions[i].name.s, name);
283 printf("(%d) expected action %d, not found\n", line, action);
290 testing of recursive change notify
292 static BOOL test_notify_recursive(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
296 union smb_notify notify;
299 struct smbcli_request *req1, *req2;
301 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
304 get a handle on the directory
306 io.generic.level = RAW_OPEN_NTCREATEX;
307 io.ntcreatex.in.root_fid = 0;
308 io.ntcreatex.in.flags = 0;
309 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
310 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
311 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
312 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
313 io.ntcreatex.in.alloc_size = 0;
314 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
315 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
316 io.ntcreatex.in.security_flags = 0;
317 io.ntcreatex.in.fname = BASEDIR;
319 status = smb_raw_open(cli->tree, mem_ctx, &io);
320 CHECK_STATUS(status, NT_STATUS_OK);
321 fnum = io.ntcreatex.out.file.fnum;
323 /* ask for a change notify, on file or directory name
324 changes. Setup both with and without recursion */
325 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
326 notify.nttrans.in.buffer_size = 1000;
327 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
328 notify.nttrans.in.file.fnum = fnum;
330 notify.nttrans.in.recursive = True;
331 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
333 notify.nttrans.in.recursive = False;
334 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
336 /* cancel initial requests so the buffer is setup */
337 smb_raw_ntcancel(req1);
338 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
339 CHECK_STATUS(status, NT_STATUS_CANCELLED);
341 smb_raw_ntcancel(req2);
342 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
343 CHECK_STATUS(status, NT_STATUS_CANCELLED);
345 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
346 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
347 smbcli_close(cli->tree,
348 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
349 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
350 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
351 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
353 notify.nttrans.in.completion_filter = 0;
354 notify.nttrans.in.recursive = True;
356 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
358 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
359 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
360 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
362 notify.nttrans.in.recursive = False;
363 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
365 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
366 CHECK_STATUS(status, NT_STATUS_OK);
368 CHECK_VAL(notify.nttrans.out.num_changes, 11);
369 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
370 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
371 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
372 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
373 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
374 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
375 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
376 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
377 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
378 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
380 ret &= check_rename_reply(
381 cli, __LINE__, ¬ify.nttrans.out.changes[5],
382 NOTIFY_ACTION_ADDED, "subname2-r");
383 ret &= check_rename_reply(
384 cli, __LINE__, ¬ify.nttrans.out.changes[5],
385 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
386 ret &= check_rename_reply(
387 cli, __LINE__, ¬ify.nttrans.out.changes[5],
388 NOTIFY_ACTION_MODIFIED, "subname2-r");
390 ret &= check_rename_reply(
391 cli, __LINE__, ¬ify.nttrans.out.changes[8],
392 NOTIFY_ACTION_OLD_NAME, "subname2-r");
393 ret &= check_rename_reply(
394 cli, __LINE__, ¬ify.nttrans.out.changes[8],
395 NOTIFY_ACTION_NEW_NAME, "subname3-r");
396 ret &= check_rename_reply(
397 cli, __LINE__, ¬ify.nttrans.out.changes[8],
398 NOTIFY_ACTION_MODIFIED, "subname3-r");
404 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
405 CHECK_STATUS(status, NT_STATUS_OK);
407 CHECK_VAL(notify.nttrans.out.num_changes, 3);
408 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
409 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
410 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
411 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
412 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
413 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
416 smb_raw_exit(cli->session);
422 testing of mask bits for change notify
424 static BOOL test_notify_mask(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
428 union smb_notify notify;
437 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
439 tv = timeval_current_ofs(1000, 0);
440 t = timeval_to_nttime(&tv);
443 get a handle on the directory
445 io.generic.level = RAW_OPEN_NTCREATEX;
446 io.ntcreatex.in.root_fid = 0;
447 io.ntcreatex.in.flags = 0;
448 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
449 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
450 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
451 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
452 io.ntcreatex.in.alloc_size = 0;
453 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
454 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
455 io.ntcreatex.in.security_flags = 0;
456 io.ntcreatex.in.fname = BASEDIR;
458 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
459 notify.nttrans.in.buffer_size = 1000;
460 notify.nttrans.in.recursive = True;
462 #define NOTIFY_MASK_TEST(setup, op, cleanup, Action, expected, nchanges) \
463 do { for (mask=i=0;i<32;i++) { \
464 struct smbcli_request *req; \
465 status = smb_raw_open(cli->tree, mem_ctx, &io); \
466 CHECK_STATUS(status, NT_STATUS_OK); \
467 fnum = io.ntcreatex.out.file.fnum; \
469 notify.nttrans.in.file.fnum = fnum; \
470 notify.nttrans.in.completion_filter = (1<<i); \
471 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
473 msleep(200); smb_raw_ntcancel(req); \
474 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); \
476 smbcli_close(cli->tree, fnum); \
477 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
478 CHECK_STATUS(status, NT_STATUS_OK); \
479 /* special case to cope with file rename behaviour */ \
480 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
481 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
482 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
483 Action == NOTIFY_ACTION_OLD_NAME) { \
484 printf("(rename file special handling OK)\n"); \
485 } else if (nchanges != notify.nttrans.out.num_changes || \
486 notify.nttrans.out.changes[0].action != Action || \
487 strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
488 printf("ERROR: nchanges=%d action=%d filter=0x%08x\n", \
489 notify.nttrans.out.num_changes, \
490 notify.nttrans.out.changes[0].action, \
491 notify.nttrans.in.completion_filter); \
496 if ((expected) != mask) { \
497 if (((expected) & ~mask) != 0) { \
498 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
502 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
508 printf("testing mkdir\n");
510 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
511 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
513 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
515 printf("testing create file\n");
517 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
518 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
520 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
522 printf("testing unlink\n");
524 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
525 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
527 NOTIFY_ACTION_REMOVED,
528 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
530 printf("testing rmdir\n");
532 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
533 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
535 NOTIFY_ACTION_REMOVED,
536 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
538 printf("testing rename file\n");
540 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
541 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
542 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
543 NOTIFY_ACTION_OLD_NAME,
544 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
546 printf("testing rename dir\n");
548 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
549 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
550 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
551 NOTIFY_ACTION_OLD_NAME,
552 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
554 printf("testing set path attribute\n");
556 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
557 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
558 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
559 NOTIFY_ACTION_MODIFIED,
560 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
562 printf("testing set path write time\n");
564 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
565 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
566 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
567 NOTIFY_ACTION_MODIFIED,
568 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
570 printf("testing set file attribute\n");
572 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
573 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
574 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
575 NOTIFY_ACTION_MODIFIED,
576 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
578 if (lp_parm_bool(-1, "torture", "samba3", False)) {
579 printf("Samba3 does not yet support create times "
583 printf("testing set file create time\n");
585 fnum2 = create_complex_file(cli, mem_ctx,
586 BASEDIR "\\tname1");,
587 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
588 (smbcli_close(cli->tree, fnum2),
589 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
590 NOTIFY_ACTION_MODIFIED,
591 FILE_NOTIFY_CHANGE_CREATION, 1);
594 printf("testing set file access time\n");
596 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
597 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
598 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
599 NOTIFY_ACTION_MODIFIED,
600 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
602 printf("testing set file write time\n");
604 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
605 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
606 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
607 NOTIFY_ACTION_MODIFIED,
608 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
610 printf("testing set file change time\n");
612 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
613 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
614 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
615 NOTIFY_ACTION_MODIFIED,
619 printf("testing write\n");
621 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
622 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
623 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
624 NOTIFY_ACTION_MODIFIED,
627 printf("testing truncate\n");
629 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
630 smbcli_ftruncate(cli->tree, fnum2, 10000);,
631 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
632 NOTIFY_ACTION_MODIFIED,
633 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
636 smb_raw_exit(cli->session);
641 basic testing of change notify on files
643 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
649 union smb_notify notify;
650 struct smbcli_request *req;
652 const char *fname = BASEDIR "\\file.txt";
654 printf("TESTING CHANGE NOTIFY ON FILES\n");
656 io.generic.level = RAW_OPEN_NTCREATEX;
657 io.ntcreatex.in.root_fid = 0;
658 io.ntcreatex.in.flags = 0;
659 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
660 io.ntcreatex.in.create_options = 0;
661 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
662 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
663 io.ntcreatex.in.alloc_size = 0;
664 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
665 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
666 io.ntcreatex.in.security_flags = 0;
667 io.ntcreatex.in.fname = fname;
668 status = smb_raw_open(cli->tree, mem_ctx, &io);
669 CHECK_STATUS(status, NT_STATUS_OK);
670 fnum = io.ntcreatex.out.file.fnum;
672 /* ask for a change notify,
673 on file or directory name changes */
674 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
675 notify.nttrans.in.file.fnum = fnum;
676 notify.nttrans.in.buffer_size = 1000;
677 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
678 notify.nttrans.in.recursive = False;
680 printf("testing if notifies on file handles are invalid (should be)\n");
682 req = smb_raw_changenotify_send(cli->tree, ¬ify);
683 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
684 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
686 cl.close.level = RAW_CLOSE_CLOSE;
687 cl.close.in.file.fnum = fnum;
688 cl.close.in.write_time = 0;
689 status = smb_raw_close(cli->tree, &cl);
690 CHECK_STATUS(status, NT_STATUS_OK);
692 status = smbcli_unlink(cli->tree, fname);
693 CHECK_STATUS(status, NT_STATUS_OK);
696 smb_raw_exit(cli->session);
701 basic testing of change notifies followed by a tdis
703 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
707 union smb_notify notify;
710 struct smbcli_request *req;
711 struct smbcli_state *cli = NULL;
713 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
715 if (!torture_open_connection(&cli, 0)) {
720 get a handle on the directory
722 io.generic.level = RAW_OPEN_NTCREATEX;
723 io.ntcreatex.in.root_fid = 0;
724 io.ntcreatex.in.flags = 0;
725 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
726 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
727 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
728 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
729 io.ntcreatex.in.alloc_size = 0;
730 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
731 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
732 io.ntcreatex.in.security_flags = 0;
733 io.ntcreatex.in.fname = BASEDIR;
735 status = smb_raw_open(cli->tree, mem_ctx, &io);
736 CHECK_STATUS(status, NT_STATUS_OK);
737 fnum = io.ntcreatex.out.file.fnum;
739 /* ask for a change notify,
740 on file or directory name changes */
741 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
742 notify.nttrans.in.buffer_size = 1000;
743 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
744 notify.nttrans.in.file.fnum = fnum;
745 notify.nttrans.in.recursive = True;
747 req = smb_raw_changenotify_send(cli->tree, ¬ify);
749 status = smbcli_tdis(cli);
750 CHECK_STATUS(status, NT_STATUS_OK);
753 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
754 CHECK_STATUS(status, NT_STATUS_OK);
755 CHECK_VAL(notify.nttrans.out.num_changes, 0);
758 torture_close_connection(cli);
763 basic testing of change notifies followed by a exit
765 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
769 union smb_notify notify;
772 struct smbcli_request *req;
773 struct smbcli_state *cli = NULL;
775 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
777 if (!torture_open_connection(&cli, 0)) {
782 get a handle on the directory
784 io.generic.level = RAW_OPEN_NTCREATEX;
785 io.ntcreatex.in.root_fid = 0;
786 io.ntcreatex.in.flags = 0;
787 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
788 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
789 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
790 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
791 io.ntcreatex.in.alloc_size = 0;
792 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
793 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
794 io.ntcreatex.in.security_flags = 0;
795 io.ntcreatex.in.fname = BASEDIR;
797 status = smb_raw_open(cli->tree, mem_ctx, &io);
798 CHECK_STATUS(status, NT_STATUS_OK);
799 fnum = io.ntcreatex.out.file.fnum;
801 /* ask for a change notify,
802 on file or directory name changes */
803 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
804 notify.nttrans.in.buffer_size = 1000;
805 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
806 notify.nttrans.in.file.fnum = fnum;
807 notify.nttrans.in.recursive = True;
809 req = smb_raw_changenotify_send(cli->tree, ¬ify);
811 status = smb_raw_exit(cli->session);
812 CHECK_STATUS(status, NT_STATUS_OK);
814 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
815 CHECK_STATUS(status, NT_STATUS_OK);
816 CHECK_VAL(notify.nttrans.out.num_changes, 0);
819 torture_close_connection(cli);
824 basic testing of change notifies followed by a ulogoff
826 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
830 union smb_notify notify;
833 struct smbcli_request *req;
834 struct smbcli_state *cli = NULL;
836 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
838 if (!torture_open_connection(&cli, 0)) {
843 get a handle on the directory
845 io.generic.level = RAW_OPEN_NTCREATEX;
846 io.ntcreatex.in.root_fid = 0;
847 io.ntcreatex.in.flags = 0;
848 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
849 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
850 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
851 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
852 io.ntcreatex.in.alloc_size = 0;
853 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
854 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
855 io.ntcreatex.in.security_flags = 0;
856 io.ntcreatex.in.fname = BASEDIR;
858 status = smb_raw_open(cli->tree, mem_ctx, &io);
859 CHECK_STATUS(status, NT_STATUS_OK);
860 fnum = io.ntcreatex.out.file.fnum;
862 /* ask for a change notify,
863 on file or directory name changes */
864 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
865 notify.nttrans.in.buffer_size = 1000;
866 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
867 notify.nttrans.in.file.fnum = fnum;
868 notify.nttrans.in.recursive = True;
870 req = smb_raw_changenotify_send(cli->tree, ¬ify);
872 status = smb_raw_ulogoff(cli->session);
873 CHECK_STATUS(status, NT_STATUS_OK);
875 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
876 CHECK_STATUS(status, NT_STATUS_OK);
877 CHECK_VAL(notify.nttrans.out.num_changes, 0);
880 torture_close_connection(cli);
884 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
886 struct smbcli_state *cli = p;
887 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
888 cli->transport = NULL;
892 basic testing of change notifies followed by tcp disconnect
894 static BOOL test_notify_tcp_dis(TALLOC_CTX *mem_ctx)
898 union smb_notify notify;
901 struct smbcli_request *req;
902 struct smbcli_state *cli = NULL;
904 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
906 if (!torture_open_connection(&cli, 0)) {
911 get a handle on the directory
913 io.generic.level = RAW_OPEN_NTCREATEX;
914 io.ntcreatex.in.root_fid = 0;
915 io.ntcreatex.in.flags = 0;
916 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
917 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
918 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
919 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
920 io.ntcreatex.in.alloc_size = 0;
921 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
922 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
923 io.ntcreatex.in.security_flags = 0;
924 io.ntcreatex.in.fname = BASEDIR;
926 status = smb_raw_open(cli->tree, mem_ctx, &io);
927 CHECK_STATUS(status, NT_STATUS_OK);
928 fnum = io.ntcreatex.out.file.fnum;
930 /* ask for a change notify,
931 on file or directory name changes */
932 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
933 notify.nttrans.in.buffer_size = 1000;
934 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
935 notify.nttrans.in.file.fnum = fnum;
936 notify.nttrans.in.recursive = True;
938 req = smb_raw_changenotify_send(cli->tree, ¬ify);
940 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
942 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
943 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
946 torture_close_connection(cli);
951 test setting up two change notify requests on one handle
953 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
957 union smb_notify notify;
960 struct smbcli_request *req1, *req2;
962 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
965 get a handle on the directory
967 io.generic.level = RAW_OPEN_NTCREATEX;
968 io.ntcreatex.in.root_fid = 0;
969 io.ntcreatex.in.flags = 0;
970 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
971 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
972 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
973 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
974 io.ntcreatex.in.alloc_size = 0;
975 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
976 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
977 io.ntcreatex.in.security_flags = 0;
978 io.ntcreatex.in.fname = BASEDIR;
980 status = smb_raw_open(cli->tree, mem_ctx, &io);
981 CHECK_STATUS(status, NT_STATUS_OK);
982 fnum = io.ntcreatex.out.file.fnum;
984 /* ask for a change notify,
985 on file or directory name changes */
986 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
987 notify.nttrans.in.buffer_size = 1000;
988 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
989 notify.nttrans.in.file.fnum = fnum;
990 notify.nttrans.in.recursive = True;
992 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
993 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
995 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
997 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
998 CHECK_STATUS(status, NT_STATUS_OK);
999 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1000 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1002 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1004 status = smb_raw_changenotify_recv(req2, 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-name2", STR_UNICODE);
1010 smb_raw_exit(cli->session);
1016 test multiple change notifies at different depths and with/without recursion
1018 static BOOL test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1021 union smb_notify notify;
1023 struct smbcli_request *req;
1033 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 30 },
1034 {BASEDIR "\\zqy", True, FILE_NOTIFY_CHANGE_NAME, 8 },
1035 {BASEDIR "\\atsy", True, FILE_NOTIFY_CHANGE_NAME, 4 },
1036 {BASEDIR "\\abc\\foo", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1037 {BASEDIR "\\abc\\blah", True, FILE_NOTIFY_CHANGE_NAME, 13 },
1038 {BASEDIR "\\abc\\blah", False, FILE_NOTIFY_CHANGE_NAME, 7 },
1039 {BASEDIR "\\abc\\blah\\a", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1040 {BASEDIR "\\abc\\blah\\b", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1041 {BASEDIR "\\abc\\blah\\c", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1042 {BASEDIR "\\abc\\fooblah", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1043 {BASEDIR "\\zqy\\xx", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1044 {BASEDIR "\\zqy\\yyy", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1045 {BASEDIR "\\zqy\\..", True, FILE_NOTIFY_CHANGE_NAME, 40 },
1046 {BASEDIR, True, FILE_NOTIFY_CHANGE_NAME, 40 },
1047 {BASEDIR, False,FILE_NOTIFY_CHANGE_NAME, 6 },
1048 {BASEDIR "\\atsy", False,FILE_NOTIFY_CHANGE_NAME, 4 },
1049 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1050 {BASEDIR "\\abc", False,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1051 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1052 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1056 BOOL all_done = False;
1058 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1060 io.generic.level = RAW_OPEN_NTCREATEX;
1061 io.ntcreatex.in.root_fid = 0;
1062 io.ntcreatex.in.flags = 0;
1063 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1064 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1065 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1066 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1067 io.ntcreatex.in.alloc_size = 0;
1068 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1069 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1070 io.ntcreatex.in.security_flags = 0;
1072 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1073 notify.nttrans.in.buffer_size = 20000;
1076 setup the directory tree, and the notify buffer on each directory
1078 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1079 io.ntcreatex.in.fname = dirs[i].path;
1080 status = smb_raw_open(cli->tree, mem_ctx, &io);
1081 CHECK_STATUS(status, NT_STATUS_OK);
1082 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1084 notify.nttrans.in.completion_filter = dirs[i].filter;
1085 notify.nttrans.in.file.fnum = dirs[i].fnum;
1086 notify.nttrans.in.recursive = dirs[i].recursive;
1087 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1088 smb_raw_ntcancel(req);
1089 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1090 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1093 /* trigger 2 events in each dir */
1094 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1095 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1096 smbcli_mkdir(cli->tree, path);
1097 smbcli_rmdir(cli->tree, path);
1101 /* give a bit of time for the events to propogate */
1102 tv = timeval_current();
1105 /* count events that have happened in each dir */
1106 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1107 notify.nttrans.in.file.fnum = dirs[i].fnum;
1108 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1109 smb_raw_ntcancel(req);
1110 notify.nttrans.out.num_changes = 0;
1111 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1112 dirs[i].counted += notify.nttrans.out.num_changes;
1117 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1118 if (dirs[i].counted != dirs[i].expected) {
1122 } while (!all_done && timeval_elapsed(&tv) < 20);
1124 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1126 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1127 if (dirs[i].counted != dirs[i].expected) {
1128 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1129 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1135 run from the back, closing and deleting
1137 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1138 smbcli_close(cli->tree, dirs[i].fnum);
1139 smbcli_rmdir(cli->tree, dirs[i].path);
1143 smb_raw_exit(cli->session);
1148 basic testing of change notify
1150 BOOL torture_raw_notify(struct torture_context *torture)
1152 struct smbcli_state *cli;
1154 TALLOC_CTX *mem_ctx;
1156 if (!torture_open_connection(&cli, 0)) {
1160 mem_ctx = talloc_init("torture_raw_notify");
1162 if (!torture_setup_dir(cli, BASEDIR)) {
1166 ret &= test_notify_dir(cli, mem_ctx);
1167 ret &= test_notify_mask(cli, mem_ctx);
1168 ret &= test_notify_recursive(cli, mem_ctx);
1169 ret &= test_notify_file(cli, mem_ctx);
1170 ret &= test_notify_tdis(mem_ctx);
1171 ret &= test_notify_exit(mem_ctx);
1172 ret &= test_notify_ulogoff(mem_ctx);
1173 ret &= test_notify_tcp_dis(mem_ctx);
1174 ret &= test_notify_double(cli, mem_ctx);
1175 ret &= test_notify_tree(cli, mem_ctx);
1177 smb_raw_exit(cli->session);
1178 smbcli_deltree(cli->tree, BASEDIR);
1179 torture_close_connection(cli);
1180 talloc_free(mem_ctx);