2 Unix SMB/CIFS implementation.
3 basic raw test suite for change notify
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/torture.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/libcli.h"
24 #include "system/filesys.h"
25 #include "torture/util.h"
27 #define BASEDIR "\\test_notify"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 printf("(%d) Incorrect status %s - should be %s\n", \
32 __LINE__, nt_errstr(status), nt_errstr(correct)); \
38 #define CHECK_VAL(v, correct) do { \
39 if ((v) != (correct)) { \
40 printf("(%d) wrong value for %s 0x%x should be 0x%x\n", \
41 __LINE__, #v, (int)v, (int)correct); \
46 #define CHECK_WSTR(field, value, flags) do { \
47 if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli->transport)) { \
48 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
55 basic testing of change notify on directories
57 static BOOL test_notify_dir(struct smbcli_state *cli, struct smbcli_state *cli2,
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(cli2->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(cli2->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(cli2->tree, BASEDIR "\\subdir-name");
136 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
137 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
138 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
140 req = smb_raw_changenotify_send(cli->tree, ¬ify);
141 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
142 CHECK_STATUS(status, NT_STATUS_OK);
143 CHECK_VAL(notify.nttrans.out.num_changes, 4);
144 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
145 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
146 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
147 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
148 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
149 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name", STR_UNICODE);
150 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_REMOVED);
151 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name", STR_UNICODE);
153 count = torture_numops;
154 printf("testing buffered notify on create of %d files\n", count);
155 for (i=0;i<count;i++) {
156 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
157 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
159 printf("Failed to create %s - %s\n",
160 fname, smbcli_errstr(cli->tree));
165 smbcli_close(cli->tree, fnum3);
168 /* (1st notify) setup a new notify on a different directory handle.
169 This new notify won't see the events above. */
170 notify.nttrans.in.file.fnum = fnum2;
171 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
173 /* (2nd notify) whereas this notify will see the above buffered events,
174 and it directly returns the buffered events */
175 notify.nttrans.in.file.fnum = fnum;
176 req = smb_raw_changenotify_send(cli->tree, ¬ify);
178 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
179 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
181 /* (1st unlink) as the 2nd notify directly returns,
182 this unlink is only seen by the 1st notify and
183 the 3rd notify (later) */
184 printf("testing notify on unlink for the first file\n");
185 status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
186 CHECK_STATUS(status, NT_STATUS_OK);
188 /* receive the reply from the 2nd notify */
189 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
190 CHECK_STATUS(status, NT_STATUS_OK);
192 CHECK_VAL(notify.nttrans.out.num_changes, count);
193 for (i=1;i<count;i++) {
194 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_ADDED);
196 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
198 printf("and now from the 1st notify\n");
199 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
200 CHECK_STATUS(status, NT_STATUS_OK);
201 CHECK_VAL(notify.nttrans.out.num_changes, 1);
202 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
203 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
205 printf("(3rd notify) this notify will only see the 1st unlink\n");
206 req = smb_raw_changenotify_send(cli->tree, ¬ify);
208 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
209 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
211 printf("testing notify on wildcard unlink for %d files\n", count-1);
212 /* (2nd unlink) do a wildcard unlink */
213 status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
214 CHECK_STATUS(status, NT_STATUS_OK);
216 /* receive the 3rd notify */
217 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
218 CHECK_STATUS(status, NT_STATUS_OK);
219 CHECK_VAL(notify.nttrans.out.num_changes, 1);
220 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
221 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
223 /* and we now see the rest of the unlink calls on both directory handles */
224 notify.nttrans.in.file.fnum = fnum;
226 req = smb_raw_changenotify_send(cli->tree, ¬ify);
227 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
228 CHECK_STATUS(status, NT_STATUS_OK);
229 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
230 for (i=0;i<notify.nttrans.out.num_changes;i++) {
231 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
233 notify.nttrans.in.file.fnum = fnum2;
234 req = smb_raw_changenotify_send(cli->tree, ¬ify);
235 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
236 CHECK_STATUS(status, NT_STATUS_OK);
237 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
238 for (i=0;i<notify.nttrans.out.num_changes;i++) {
239 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
242 printf("testing if a close() on the dir handle triggers the notify reply\n");
244 notify.nttrans.in.file.fnum = fnum;
245 req = smb_raw_changenotify_send(cli->tree, ¬ify);
247 cl.close.level = RAW_CLOSE_CLOSE;
248 cl.close.in.file.fnum = fnum;
249 cl.close.in.write_time = 0;
250 status = smb_raw_close(cli->tree, &cl);
251 CHECK_STATUS(status, NT_STATUS_OK);
253 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
254 CHECK_STATUS(status, NT_STATUS_OK);
255 CHECK_VAL(notify.nttrans.out.num_changes, 0);
258 smb_raw_exit(cli->session);
263 * Check notify reply for a rename action. Not sure if this is a valid thing
264 * to do, but depending on timing between inotify and messaging we get the
265 * add/remove/modify in any order. This routines tries to find the action/name
266 * pair in any of the three following notify_changes.
269 static BOOL check_rename_reply(struct smbcli_state *cli,
271 struct notify_changes *actions,
272 uint32_t action, const char *name)
276 for (i=0; i<3; i++) {
277 if (actions[i].action == action) {
278 if ((actions[i].name.s == NULL)
279 || (strcmp(actions[i].name.s, name) != 0)
280 || (wire_bad_flags(&actions[i].name, STR_UNICODE,
282 printf("(%d) name [%s] != %s\n", line,
283 actions[i].name.s, name);
290 printf("(%d) expected action %d, not found\n", line, action);
295 testing of recursive change notify
297 static BOOL test_notify_recursive(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
301 union smb_notify notify;
304 struct smbcli_request *req1, *req2;
306 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
309 get a handle on the directory
311 io.generic.level = RAW_OPEN_NTCREATEX;
312 io.ntcreatex.in.root_fid = 0;
313 io.ntcreatex.in.flags = 0;
314 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
315 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
316 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
317 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
318 io.ntcreatex.in.alloc_size = 0;
319 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
320 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
321 io.ntcreatex.in.security_flags = 0;
322 io.ntcreatex.in.fname = BASEDIR;
324 status = smb_raw_open(cli->tree, mem_ctx, &io);
325 CHECK_STATUS(status, NT_STATUS_OK);
326 fnum = io.ntcreatex.out.file.fnum;
328 /* ask for a change notify, on file or directory name
329 changes. Setup both with and without recursion */
330 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
331 notify.nttrans.in.buffer_size = 1000;
332 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
333 notify.nttrans.in.file.fnum = fnum;
335 notify.nttrans.in.recursive = True;
336 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
338 notify.nttrans.in.recursive = False;
339 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
341 /* cancel initial requests so the buffer is setup */
342 smb_raw_ntcancel(req1);
343 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
344 CHECK_STATUS(status, NT_STATUS_CANCELLED);
346 smb_raw_ntcancel(req2);
347 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
348 CHECK_STATUS(status, NT_STATUS_CANCELLED);
350 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
351 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
352 smbcli_close(cli->tree,
353 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
354 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
355 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
356 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
358 notify.nttrans.in.completion_filter = 0;
359 notify.nttrans.in.recursive = True;
361 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
363 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
364 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
365 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
367 notify.nttrans.in.recursive = False;
368 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
370 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
371 CHECK_STATUS(status, NT_STATUS_OK);
373 CHECK_VAL(notify.nttrans.out.num_changes, 11);
374 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
375 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
376 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
377 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
378 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
379 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
380 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
381 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
382 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
383 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
385 ret &= check_rename_reply(
386 cli, __LINE__, ¬ify.nttrans.out.changes[5],
387 NOTIFY_ACTION_ADDED, "subname2-r");
388 ret &= check_rename_reply(
389 cli, __LINE__, ¬ify.nttrans.out.changes[5],
390 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
391 ret &= check_rename_reply(
392 cli, __LINE__, ¬ify.nttrans.out.changes[5],
393 NOTIFY_ACTION_MODIFIED, "subname2-r");
395 ret &= check_rename_reply(
396 cli, __LINE__, ¬ify.nttrans.out.changes[8],
397 NOTIFY_ACTION_OLD_NAME, "subname2-r");
398 ret &= check_rename_reply(
399 cli, __LINE__, ¬ify.nttrans.out.changes[8],
400 NOTIFY_ACTION_NEW_NAME, "subname3-r");
401 ret &= check_rename_reply(
402 cli, __LINE__, ¬ify.nttrans.out.changes[8],
403 NOTIFY_ACTION_MODIFIED, "subname3-r");
409 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
410 CHECK_STATUS(status, NT_STATUS_OK);
412 CHECK_VAL(notify.nttrans.out.num_changes, 3);
413 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
414 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
415 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
416 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
417 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
418 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
421 smb_raw_exit(cli->session);
426 testing of change notify mask change
428 static BOOL test_notify_mask_change(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
432 union smb_notify notify;
435 struct smbcli_request *req1, *req2;
436 union smb_setfileinfo sfinfo;
438 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
441 get a handle on the directory
443 io.generic.level = RAW_OPEN_NTCREATEX;
444 io.ntcreatex.in.root_fid = 0;
445 io.ntcreatex.in.flags = 0;
446 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
447 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
448 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
449 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
450 io.ntcreatex.in.alloc_size = 0;
451 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
452 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
453 io.ntcreatex.in.security_flags = 0;
454 io.ntcreatex.in.fname = BASEDIR;
456 status = smb_raw_open(cli->tree, mem_ctx, &io);
457 CHECK_STATUS(status, NT_STATUS_OK);
458 fnum = io.ntcreatex.out.file.fnum;
460 /* ask for a change notify, on file or directory name
461 changes. Setup both with and without recursion */
462 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
463 notify.nttrans.in.buffer_size = 1000;
464 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
465 notify.nttrans.in.file.fnum = fnum;
467 notify.nttrans.in.recursive = True;
468 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
470 notify.nttrans.in.recursive = False;
471 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
473 /* cancel initial requests so the buffer is setup */
474 smb_raw_ntcancel(req1);
475 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
476 CHECK_STATUS(status, NT_STATUS_CANCELLED);
478 smb_raw_ntcancel(req2);
479 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
480 CHECK_STATUS(status, NT_STATUS_CANCELLED);
482 notify.nttrans.in.recursive = True;
483 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
485 /* Set to hidden then back again. */
486 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));
487 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
488 smbcli_unlink(cli->tree, BASEDIR "\\tname1");
490 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
491 CHECK_STATUS(status, NT_STATUS_OK);
493 CHECK_VAL(notify.nttrans.out.num_changes, 1);
494 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
495 CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
497 /* Now try and change the mask to include other events.
498 * This should not work - once the mask is set on a directory
499 * fnum it seems to be fixed until the fnum is closed. */
501 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
502 notify.nttrans.in.recursive = True;
503 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
505 notify.nttrans.in.recursive = False;
506 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
508 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
509 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
510 smbcli_close(cli->tree,
511 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
512 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
513 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
514 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
516 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
517 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
518 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
520 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
521 CHECK_STATUS(status, NT_STATUS_OK);
523 CHECK_VAL(notify.nttrans.out.num_changes, 1);
524 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
525 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname2-r", STR_UNICODE);
527 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
528 CHECK_STATUS(status, NT_STATUS_OK);
530 CHECK_VAL(notify.nttrans.out.num_changes, 1);
531 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
532 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname3-r", STR_UNICODE);
539 smb_raw_exit(cli->session);
545 testing of mask bits for change notify
547 static BOOL test_notify_mask(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
551 union smb_notify notify;
560 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
562 tv = timeval_current_ofs(1000, 0);
563 t = timeval_to_nttime(&tv);
566 get a handle on the directory
568 io.generic.level = RAW_OPEN_NTCREATEX;
569 io.ntcreatex.in.root_fid = 0;
570 io.ntcreatex.in.flags = 0;
571 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
572 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
573 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
574 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
575 io.ntcreatex.in.alloc_size = 0;
576 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
577 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
578 io.ntcreatex.in.security_flags = 0;
579 io.ntcreatex.in.fname = BASEDIR;
581 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
582 notify.nttrans.in.buffer_size = 1000;
583 notify.nttrans.in.recursive = True;
585 #define NOTIFY_MASK_TEST(setup, op, cleanup, Action, expected, nchanges) \
586 do { for (mask=i=0;i<32;i++) { \
587 struct smbcli_request *req; \
588 status = smb_raw_open(cli->tree, mem_ctx, &io); \
589 CHECK_STATUS(status, NT_STATUS_OK); \
590 fnum = io.ntcreatex.out.file.fnum; \
592 notify.nttrans.in.file.fnum = fnum; \
593 notify.nttrans.in.completion_filter = (1<<i); \
594 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
596 msleep(200); smb_raw_ntcancel(req); \
597 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify); \
599 smbcli_close(cli->tree, fnum); \
600 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
601 CHECK_STATUS(status, NT_STATUS_OK); \
602 /* special case to cope with file rename behaviour */ \
603 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
604 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
605 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
606 Action == NOTIFY_ACTION_OLD_NAME) { \
607 printf("(rename file special handling OK)\n"); \
608 } else if (nchanges != notify.nttrans.out.num_changes) { \
609 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
610 notify.nttrans.out.num_changes, \
612 notify.nttrans.out.changes[0].action, \
613 notify.nttrans.in.completion_filter); \
615 } else if (notify.nttrans.out.changes[0].action != Action) { \
616 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
617 notify.nttrans.out.num_changes, \
618 notify.nttrans.out.changes[0].action, \
620 notify.nttrans.in.completion_filter); \
622 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
623 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
624 notify.nttrans.out.num_changes, \
625 notify.nttrans.out.changes[0].action, \
626 notify.nttrans.in.completion_filter, \
627 notify.nttrans.out.changes[0].name.s); \
632 if ((expected) != mask) { \
633 if (((expected) & ~mask) != 0) { \
634 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
638 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
644 printf("testing mkdir\n");
646 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
647 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
649 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
651 printf("testing create file\n");
653 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
654 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
656 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
658 printf("testing unlink\n");
660 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
661 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
663 NOTIFY_ACTION_REMOVED,
664 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
666 printf("testing rmdir\n");
668 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
669 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
671 NOTIFY_ACTION_REMOVED,
672 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
674 printf("testing rename file\n");
676 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
677 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
678 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
679 NOTIFY_ACTION_OLD_NAME,
680 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
682 printf("testing rename dir\n");
684 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
685 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
686 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
687 NOTIFY_ACTION_OLD_NAME,
688 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
690 printf("testing set path attribute\n");
692 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
693 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
694 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
695 NOTIFY_ACTION_MODIFIED,
696 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
698 printf("testing set path write time\n");
700 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
701 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
702 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
703 NOTIFY_ACTION_MODIFIED,
704 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
706 printf("testing set file attribute\n");
708 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
709 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
710 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
711 NOTIFY_ACTION_MODIFIED,
712 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
714 if (lp_parm_bool(-1, "torture", "samba3", False)) {
715 printf("Samba3 does not yet support create times "
719 printf("testing set file create time\n");
721 fnum2 = create_complex_file(cli, mem_ctx,
722 BASEDIR "\\tname1");,
723 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
724 (smbcli_close(cli->tree, fnum2),
725 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
726 NOTIFY_ACTION_MODIFIED,
727 FILE_NOTIFY_CHANGE_CREATION, 1);
730 printf("testing set file access time\n");
732 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
733 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
734 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
735 NOTIFY_ACTION_MODIFIED,
736 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
738 printf("testing set file write time\n");
740 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
741 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
742 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
743 NOTIFY_ACTION_MODIFIED,
744 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
746 printf("testing set file change time\n");
748 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
749 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
750 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
751 NOTIFY_ACTION_MODIFIED,
755 printf("testing write\n");
757 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
758 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
759 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
760 NOTIFY_ACTION_MODIFIED,
763 printf("testing truncate\n");
765 fnum2 = create_complex_file(cli, mem_ctx, BASEDIR "\\tname1");,
766 smbcli_ftruncate(cli->tree, fnum2, 10000);,
767 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
768 NOTIFY_ACTION_MODIFIED,
769 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
772 smb_raw_exit(cli->session);
777 basic testing of change notify on files
779 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
785 union smb_notify notify;
786 struct smbcli_request *req;
788 const char *fname = BASEDIR "\\file.txt";
790 printf("TESTING CHANGE NOTIFY ON FILES\n");
792 io.generic.level = RAW_OPEN_NTCREATEX;
793 io.ntcreatex.in.root_fid = 0;
794 io.ntcreatex.in.flags = 0;
795 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
796 io.ntcreatex.in.create_options = 0;
797 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
798 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
799 io.ntcreatex.in.alloc_size = 0;
800 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
801 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
802 io.ntcreatex.in.security_flags = 0;
803 io.ntcreatex.in.fname = fname;
804 status = smb_raw_open(cli->tree, mem_ctx, &io);
805 CHECK_STATUS(status, NT_STATUS_OK);
806 fnum = io.ntcreatex.out.file.fnum;
808 /* ask for a change notify,
809 on file or directory name changes */
810 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
811 notify.nttrans.in.file.fnum = fnum;
812 notify.nttrans.in.buffer_size = 1000;
813 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
814 notify.nttrans.in.recursive = False;
816 printf("testing if notifies on file handles are invalid (should be)\n");
818 req = smb_raw_changenotify_send(cli->tree, ¬ify);
819 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
820 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
822 cl.close.level = RAW_CLOSE_CLOSE;
823 cl.close.in.file.fnum = fnum;
824 cl.close.in.write_time = 0;
825 status = smb_raw_close(cli->tree, &cl);
826 CHECK_STATUS(status, NT_STATUS_OK);
828 status = smbcli_unlink(cli->tree, fname);
829 CHECK_STATUS(status, NT_STATUS_OK);
832 smb_raw_exit(cli->session);
837 basic testing of change notifies followed by a tdis
839 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
843 union smb_notify notify;
846 struct smbcli_request *req;
847 struct smbcli_state *cli = NULL;
849 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
851 if (!torture_open_connection(&cli, 0)) {
856 get a handle on the directory
858 io.generic.level = RAW_OPEN_NTCREATEX;
859 io.ntcreatex.in.root_fid = 0;
860 io.ntcreatex.in.flags = 0;
861 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
862 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
863 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
864 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
865 io.ntcreatex.in.alloc_size = 0;
866 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
867 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
868 io.ntcreatex.in.security_flags = 0;
869 io.ntcreatex.in.fname = BASEDIR;
871 status = smb_raw_open(cli->tree, mem_ctx, &io);
872 CHECK_STATUS(status, NT_STATUS_OK);
873 fnum = io.ntcreatex.out.file.fnum;
875 /* ask for a change notify,
876 on file or directory name changes */
877 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
878 notify.nttrans.in.buffer_size = 1000;
879 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
880 notify.nttrans.in.file.fnum = fnum;
881 notify.nttrans.in.recursive = True;
883 req = smb_raw_changenotify_send(cli->tree, ¬ify);
885 status = smbcli_tdis(cli);
886 CHECK_STATUS(status, NT_STATUS_OK);
889 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
890 CHECK_STATUS(status, NT_STATUS_OK);
891 CHECK_VAL(notify.nttrans.out.num_changes, 0);
894 torture_close_connection(cli);
899 basic testing of change notifies followed by a exit
901 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
905 union smb_notify notify;
908 struct smbcli_request *req;
909 struct smbcli_state *cli = NULL;
911 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
913 if (!torture_open_connection(&cli, 0)) {
918 get a handle on the directory
920 io.generic.level = RAW_OPEN_NTCREATEX;
921 io.ntcreatex.in.root_fid = 0;
922 io.ntcreatex.in.flags = 0;
923 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
924 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
925 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
926 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
927 io.ntcreatex.in.alloc_size = 0;
928 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
929 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
930 io.ntcreatex.in.security_flags = 0;
931 io.ntcreatex.in.fname = BASEDIR;
933 status = smb_raw_open(cli->tree, mem_ctx, &io);
934 CHECK_STATUS(status, NT_STATUS_OK);
935 fnum = io.ntcreatex.out.file.fnum;
937 /* ask for a change notify,
938 on file or directory name changes */
939 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
940 notify.nttrans.in.buffer_size = 1000;
941 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
942 notify.nttrans.in.file.fnum = fnum;
943 notify.nttrans.in.recursive = True;
945 req = smb_raw_changenotify_send(cli->tree, ¬ify);
947 status = smb_raw_exit(cli->session);
948 CHECK_STATUS(status, NT_STATUS_OK);
950 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
951 CHECK_STATUS(status, NT_STATUS_OK);
952 CHECK_VAL(notify.nttrans.out.num_changes, 0);
955 torture_close_connection(cli);
960 basic testing of change notifies followed by a ulogoff
962 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
966 union smb_notify notify;
969 struct smbcli_request *req;
970 struct smbcli_state *cli = NULL;
972 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
974 if (!torture_open_connection(&cli, 0)) {
979 get a handle on the directory
981 io.generic.level = RAW_OPEN_NTCREATEX;
982 io.ntcreatex.in.root_fid = 0;
983 io.ntcreatex.in.flags = 0;
984 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
985 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
986 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
987 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
988 io.ntcreatex.in.alloc_size = 0;
989 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
990 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
991 io.ntcreatex.in.security_flags = 0;
992 io.ntcreatex.in.fname = BASEDIR;
994 status = smb_raw_open(cli->tree, mem_ctx, &io);
995 CHECK_STATUS(status, NT_STATUS_OK);
996 fnum = io.ntcreatex.out.file.fnum;
998 /* ask for a change notify,
999 on file or directory name changes */
1000 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1001 notify.nttrans.in.buffer_size = 1000;
1002 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1003 notify.nttrans.in.file.fnum = fnum;
1004 notify.nttrans.in.recursive = True;
1006 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1008 status = smb_raw_ulogoff(cli->session);
1009 CHECK_STATUS(status, NT_STATUS_OK);
1011 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1012 CHECK_STATUS(status, NT_STATUS_OK);
1013 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1016 torture_close_connection(cli);
1020 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
1022 struct smbcli_state *cli = p;
1023 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
1024 cli->transport = NULL;
1028 basic testing of change notifies followed by tcp disconnect
1030 static BOOL test_notify_tcp_dis(TALLOC_CTX *mem_ctx)
1034 union smb_notify notify;
1037 struct smbcli_request *req;
1038 struct smbcli_state *cli = NULL;
1040 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1042 if (!torture_open_connection(&cli, 0)) {
1047 get a handle on the directory
1049 io.generic.level = RAW_OPEN_NTCREATEX;
1050 io.ntcreatex.in.root_fid = 0;
1051 io.ntcreatex.in.flags = 0;
1052 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1053 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1054 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1055 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1056 io.ntcreatex.in.alloc_size = 0;
1057 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1058 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1059 io.ntcreatex.in.security_flags = 0;
1060 io.ntcreatex.in.fname = BASEDIR;
1062 status = smb_raw_open(cli->tree, mem_ctx, &io);
1063 CHECK_STATUS(status, NT_STATUS_OK);
1064 fnum = io.ntcreatex.out.file.fnum;
1066 /* ask for a change notify,
1067 on file or directory name changes */
1068 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1069 notify.nttrans.in.buffer_size = 1000;
1070 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1071 notify.nttrans.in.file.fnum = fnum;
1072 notify.nttrans.in.recursive = True;
1074 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1076 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
1078 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1079 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
1082 torture_close_connection(cli);
1087 test setting up two change notify requests on one handle
1089 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1093 union smb_notify notify;
1096 struct smbcli_request *req1, *req2;
1098 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1101 get a handle on the directory
1103 io.generic.level = RAW_OPEN_NTCREATEX;
1104 io.ntcreatex.in.root_fid = 0;
1105 io.ntcreatex.in.flags = 0;
1106 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1107 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1108 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1109 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1110 io.ntcreatex.in.alloc_size = 0;
1111 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1112 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1113 io.ntcreatex.in.security_flags = 0;
1114 io.ntcreatex.in.fname = BASEDIR;
1116 status = smb_raw_open(cli->tree, mem_ctx, &io);
1117 CHECK_STATUS(status, NT_STATUS_OK);
1118 fnum = io.ntcreatex.out.file.fnum;
1120 /* ask for a change notify,
1121 on file or directory name changes */
1122 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1123 notify.nttrans.in.buffer_size = 1000;
1124 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1125 notify.nttrans.in.file.fnum = fnum;
1126 notify.nttrans.in.recursive = True;
1128 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1129 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
1131 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1133 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1134 CHECK_STATUS(status, NT_STATUS_OK);
1135 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1136 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1138 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1140 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
1141 CHECK_STATUS(status, NT_STATUS_OK);
1142 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1143 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
1146 smb_raw_exit(cli->session);
1152 test multiple change notifies at different depths and with/without recursion
1154 static BOOL test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1157 union smb_notify notify;
1159 struct smbcli_request *req;
1169 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 30 },
1170 {BASEDIR "\\zqy", True, FILE_NOTIFY_CHANGE_NAME, 8 },
1171 {BASEDIR "\\atsy", True, FILE_NOTIFY_CHANGE_NAME, 4 },
1172 {BASEDIR "\\abc\\foo", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1173 {BASEDIR "\\abc\\blah", True, FILE_NOTIFY_CHANGE_NAME, 13 },
1174 {BASEDIR "\\abc\\blah", False, FILE_NOTIFY_CHANGE_NAME, 7 },
1175 {BASEDIR "\\abc\\blah\\a", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1176 {BASEDIR "\\abc\\blah\\b", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1177 {BASEDIR "\\abc\\blah\\c", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1178 {BASEDIR "\\abc\\fooblah", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1179 {BASEDIR "\\zqy\\xx", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1180 {BASEDIR "\\zqy\\yyy", True, FILE_NOTIFY_CHANGE_NAME, 2 },
1181 {BASEDIR "\\zqy\\..", True, FILE_NOTIFY_CHANGE_NAME, 40 },
1182 {BASEDIR, True, FILE_NOTIFY_CHANGE_NAME, 40 },
1183 {BASEDIR, False,FILE_NOTIFY_CHANGE_NAME, 6 },
1184 {BASEDIR "\\atsy", False,FILE_NOTIFY_CHANGE_NAME, 4 },
1185 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1186 {BASEDIR "\\abc", False,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1187 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1188 {BASEDIR "\\abc", True, FILE_NOTIFY_CHANGE_NAME, 24 },
1192 BOOL all_done = False;
1194 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1196 io.generic.level = RAW_OPEN_NTCREATEX;
1197 io.ntcreatex.in.root_fid = 0;
1198 io.ntcreatex.in.flags = 0;
1199 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1200 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1201 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1202 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1203 io.ntcreatex.in.alloc_size = 0;
1204 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1205 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1206 io.ntcreatex.in.security_flags = 0;
1208 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1209 notify.nttrans.in.buffer_size = 20000;
1212 setup the directory tree, and the notify buffer on each directory
1214 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1215 io.ntcreatex.in.fname = dirs[i].path;
1216 status = smb_raw_open(cli->tree, mem_ctx, &io);
1217 CHECK_STATUS(status, NT_STATUS_OK);
1218 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1220 notify.nttrans.in.completion_filter = dirs[i].filter;
1221 notify.nttrans.in.file.fnum = dirs[i].fnum;
1222 notify.nttrans.in.recursive = dirs[i].recursive;
1223 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1224 smb_raw_ntcancel(req);
1225 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1226 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1229 /* trigger 2 events in each dir */
1230 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1231 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1232 smbcli_mkdir(cli->tree, path);
1233 smbcli_rmdir(cli->tree, path);
1237 /* give a bit of time for the events to propogate */
1238 tv = timeval_current();
1241 /* count events that have happened in each dir */
1242 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1243 notify.nttrans.in.file.fnum = dirs[i].fnum;
1244 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1245 smb_raw_ntcancel(req);
1246 notify.nttrans.out.num_changes = 0;
1247 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1248 dirs[i].counted += notify.nttrans.out.num_changes;
1253 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1254 if (dirs[i].counted != dirs[i].expected) {
1258 } while (!all_done && timeval_elapsed(&tv) < 20);
1260 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1262 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1263 if (dirs[i].counted != dirs[i].expected) {
1264 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1265 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1271 run from the back, closing and deleting
1273 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1274 smbcli_close(cli->tree, dirs[i].fnum);
1275 smbcli_rmdir(cli->tree, dirs[i].path);
1279 smb_raw_exit(cli->session);
1284 basic testing of change notify
1286 bool torture_raw_notify(struct torture_context *torture,
1287 struct smbcli_state *cli,
1288 struct smbcli_state *cli2)
1292 if (!torture_setup_dir(cli, BASEDIR)) {
1296 ret &= test_notify_dir(cli, cli2, torture);
1297 ret &= test_notify_mask(cli, torture);
1298 ret &= test_notify_recursive(cli, torture);
1299 ret &= test_notify_mask_change(cli, torture);
1300 ret &= test_notify_file(cli, torture);
1301 ret &= test_notify_tdis(torture);
1302 ret &= test_notify_exit(torture);
1303 ret &= test_notify_ulogoff(torture);
1304 ret &= test_notify_tcp_dis(torture);
1305 ret &= test_notify_double(cli, torture);
1306 ret &= test_notify_tree(cli, torture);
1308 smb_raw_exit(cli->session);
1309 smbcli_deltree(cli->tree, BASEDIR);