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 "libcli/raw/libcliraw.h"
22 #include "libcli/raw/raw_proto.h"
23 #include "libcli/libcli.h"
24 #include "system/filesys.h"
25 #include "torture/util.h"
26 #include "torture/raw/proto.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->transport)) { \
49 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
54 #define CHECK_WSTR2(tctx, field, value, flags) \
56 if (!field.s || strcmp(field.s, value) || \
57 wire_bad_flags(&field, flags, cli->transport)) { \
58 torture_result(tctx, TORTURE_FAIL, \
59 "(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
64 basic testing of change notify on directories
66 static bool test_notify_dir(struct torture_context *mem_ctx,
67 struct smbcli_state *cli,
68 struct smbcli_state *cli2)
72 union smb_notify notify;
75 int i, count, fnum, fnum2;
76 struct smbcli_request *req, *req2;
77 extern int torture_numops;
79 printf("TESTING CHANGE NOTIFY ON DIRECTORIES\n");
81 if (!torture_setup_dir(cli, BASEDIR)) {
86 get a handle on the directory
88 io.generic.level = RAW_OPEN_NTCREATEX;
89 io.ntcreatex.in.root_fid.fnum = 0;
90 io.ntcreatex.in.flags = 0;
91 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
92 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
93 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
94 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
95 io.ntcreatex.in.alloc_size = 0;
96 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
97 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
98 io.ntcreatex.in.security_flags = 0;
99 io.ntcreatex.in.fname = BASEDIR;
101 status = smb_raw_open(cli->tree, mem_ctx, &io);
102 CHECK_STATUS(status, NT_STATUS_OK);
103 fnum = io.ntcreatex.out.file.fnum;
105 status = smb_raw_open(cli->tree, mem_ctx, &io);
106 CHECK_STATUS(status, NT_STATUS_OK);
107 fnum2 = io.ntcreatex.out.file.fnum;
109 /* ask for a change notify,
110 on file or directory name changes */
111 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
112 notify.nttrans.in.buffer_size = 1000;
113 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
114 notify.nttrans.in.file.fnum = fnum;
115 notify.nttrans.in.recursive = true;
117 printf("Testing notify cancel\n");
119 req = smb_raw_changenotify_send(cli->tree, ¬ify);
120 smb_raw_ntcancel(req);
121 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
122 CHECK_STATUS(status, NT_STATUS_CANCELLED);
124 printf("Testing notify mkdir\n");
126 req = smb_raw_changenotify_send(cli->tree, ¬ify);
127 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
129 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
130 CHECK_STATUS(status, NT_STATUS_OK);
132 CHECK_VAL(notify.nttrans.out.num_changes, 1);
133 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
134 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
136 printf("Testing notify rmdir\n");
138 req = smb_raw_changenotify_send(cli->tree, ¬ify);
139 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
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, 1);
144 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
145 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
147 printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
149 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
150 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
151 smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
152 smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
154 req = smb_raw_changenotify_send(cli->tree, ¬ify);
155 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
156 CHECK_STATUS(status, NT_STATUS_OK);
157 CHECK_VAL(notify.nttrans.out.num_changes, 4);
158 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
159 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
160 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
161 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
162 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
163 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name", STR_UNICODE);
164 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_REMOVED);
165 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name", STR_UNICODE);
167 count = torture_numops;
168 printf("Testing buffered notify on create of %d files\n", count);
169 for (i=0;i<count;i++) {
170 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
171 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
173 printf("Failed to create %s - %s\n",
174 fname, smbcli_errstr(cli->tree));
179 smbcli_close(cli->tree, fnum3);
182 /* (1st notify) setup a new notify on a different directory handle.
183 This new notify won't see the events above. */
184 notify.nttrans.in.file.fnum = fnum2;
185 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
187 /* (2nd notify) whereas this notify will see the above buffered events,
188 and it directly returns the buffered events */
189 notify.nttrans.in.file.fnum = fnum;
190 req = smb_raw_changenotify_send(cli->tree, ¬ify);
192 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
193 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
195 /* (1st unlink) as the 2nd notify directly returns,
196 this unlink is only seen by the 1st notify and
197 the 3rd notify (later) */
198 printf("Testing notify on unlink for the first file\n");
199 status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
200 CHECK_STATUS(status, NT_STATUS_OK);
202 /* receive the reply from the 2nd notify */
203 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
204 CHECK_STATUS(status, NT_STATUS_OK);
206 CHECK_VAL(notify.nttrans.out.num_changes, count);
207 for (i=1;i<count;i++) {
208 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_ADDED);
210 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
212 printf("and now from the 1st notify\n");
213 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
214 CHECK_STATUS(status, NT_STATUS_OK);
215 CHECK_VAL(notify.nttrans.out.num_changes, 1);
216 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
217 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
219 printf("(3rd notify) this notify will only see the 1st unlink\n");
220 req = smb_raw_changenotify_send(cli->tree, ¬ify);
222 status = smbcli_unlink(cli->tree, BASEDIR "\\nonexistant.txt");
223 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
225 printf("Testing notify on wildcard unlink for %d files\n", count-1);
226 /* (2nd unlink) do a wildcard unlink */
227 status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
228 CHECK_STATUS(status, NT_STATUS_OK);
230 /* receive the 3rd notify */
231 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
232 CHECK_STATUS(status, NT_STATUS_OK);
233 CHECK_VAL(notify.nttrans.out.num_changes, 1);
234 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
235 CHECK_WSTR(notify.nttrans.out.changes[0].name, "test0.txt", STR_UNICODE);
237 /* and we now see the rest of the unlink calls on both directory handles */
238 notify.nttrans.in.file.fnum = fnum;
240 req = smb_raw_changenotify_send(cli->tree, ¬ify);
241 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
242 CHECK_STATUS(status, NT_STATUS_OK);
243 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
244 for (i=0;i<notify.nttrans.out.num_changes;i++) {
245 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
247 notify.nttrans.in.file.fnum = fnum2;
248 req = smb_raw_changenotify_send(cli->tree, ¬ify);
249 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
250 CHECK_STATUS(status, NT_STATUS_OK);
251 CHECK_VAL(notify.nttrans.out.num_changes, count-1);
252 for (i=0;i<notify.nttrans.out.num_changes;i++) {
253 CHECK_VAL(notify.nttrans.out.changes[i].action, NOTIFY_ACTION_REMOVED);
256 printf("Testing if a close() on the dir handle triggers the notify reply\n");
258 notify.nttrans.in.file.fnum = fnum;
259 req = smb_raw_changenotify_send(cli->tree, ¬ify);
261 cl.close.level = RAW_CLOSE_CLOSE;
262 cl.close.in.file.fnum = fnum;
263 cl.close.in.write_time = 0;
264 status = smb_raw_close(cli->tree, &cl);
265 CHECK_STATUS(status, NT_STATUS_OK);
267 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
268 CHECK_STATUS(status, NT_STATUS_OK);
269 CHECK_VAL(notify.nttrans.out.num_changes, 0);
272 smb_raw_exit(cli->session);
273 smbcli_deltree(cli->tree, BASEDIR);
278 * Check notify reply for a rename action. Not sure if this is a valid thing
279 * to do, but depending on timing between inotify and messaging we get the
280 * add/remove/modify in any order. This routines tries to find the action/name
281 * pair in any of the three following notify_changes.
284 static bool check_rename_reply(struct smbcli_state *cli,
286 struct notify_changes *actions,
287 uint32_t action, const char *name)
291 for (i=0; i<3; i++) {
292 if (actions[i].action == action) {
293 if ((actions[i].name.s == NULL)
294 || (strcmp(actions[i].name.s, name) != 0)
295 || (wire_bad_flags(&actions[i].name, STR_UNICODE,
297 printf("(%d) name [%s] != %s\n", line,
298 actions[i].name.s, name);
305 printf("(%d) expected action %d, not found\n", line, action);
310 testing of recursive change notify
312 static bool test_notify_recursive(struct torture_context *mem_ctx,
313 struct smbcli_state *cli)
317 union smb_notify notify;
320 struct smbcli_request *req1, *req2;
322 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
324 if (!torture_setup_dir(cli, BASEDIR)) {
329 get a handle on the directory
331 io.generic.level = RAW_OPEN_NTCREATEX;
332 io.ntcreatex.in.root_fid.fnum = 0;
333 io.ntcreatex.in.flags = 0;
334 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
335 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
336 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
337 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
338 io.ntcreatex.in.alloc_size = 0;
339 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
340 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
341 io.ntcreatex.in.security_flags = 0;
342 io.ntcreatex.in.fname = BASEDIR;
344 status = smb_raw_open(cli->tree, mem_ctx, &io);
345 CHECK_STATUS(status, NT_STATUS_OK);
346 fnum = io.ntcreatex.out.file.fnum;
348 /* ask for a change notify, on file or directory name
349 changes. Setup both with and without recursion */
350 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
351 notify.nttrans.in.buffer_size = 1000;
352 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
353 notify.nttrans.in.file.fnum = fnum;
355 notify.nttrans.in.recursive = true;
356 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
358 notify.nttrans.in.recursive = false;
359 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
361 /* cancel initial requests so the buffer is setup */
362 smb_raw_ntcancel(req1);
363 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
364 CHECK_STATUS(status, NT_STATUS_CANCELLED);
366 smb_raw_ntcancel(req2);
367 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
368 CHECK_STATUS(status, NT_STATUS_CANCELLED);
370 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
371 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
372 smbcli_close(cli->tree,
373 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
374 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
375 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
376 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
378 notify.nttrans.in.completion_filter = 0;
379 notify.nttrans.in.recursive = true;
381 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
383 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
384 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
385 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
387 notify.nttrans.in.recursive = false;
388 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
390 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
391 CHECK_STATUS(status, NT_STATUS_OK);
393 CHECK_VAL(notify.nttrans.out.num_changes, 11);
394 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
395 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
396 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_ADDED);
397 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
398 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_ADDED);
399 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
400 CHECK_VAL(notify.nttrans.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
401 CHECK_WSTR(notify.nttrans.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
402 CHECK_VAL(notify.nttrans.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
403 CHECK_WSTR(notify.nttrans.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
405 ret &= check_rename_reply(
406 cli, __LINE__, ¬ify.nttrans.out.changes[5],
407 NOTIFY_ACTION_ADDED, "subname2-r");
408 ret &= check_rename_reply(
409 cli, __LINE__, ¬ify.nttrans.out.changes[5],
410 NOTIFY_ACTION_REMOVED, "subdir-name\\subname2");
411 ret &= check_rename_reply(
412 cli, __LINE__, ¬ify.nttrans.out.changes[5],
413 NOTIFY_ACTION_MODIFIED, "subname2-r");
415 ret &= check_rename_reply(
416 cli, __LINE__, ¬ify.nttrans.out.changes[8],
417 NOTIFY_ACTION_OLD_NAME, "subname2-r");
418 ret &= check_rename_reply(
419 cli, __LINE__, ¬ify.nttrans.out.changes[8],
420 NOTIFY_ACTION_NEW_NAME, "subname3-r");
421 ret &= check_rename_reply(
422 cli, __LINE__, ¬ify.nttrans.out.changes[8],
423 NOTIFY_ACTION_MODIFIED, "subname3-r");
429 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
430 CHECK_STATUS(status, NT_STATUS_OK);
432 CHECK_VAL(notify.nttrans.out.num_changes, 3);
433 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
434 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
435 CHECK_VAL(notify.nttrans.out.changes[1].action, NOTIFY_ACTION_REMOVED);
436 CHECK_WSTR(notify.nttrans.out.changes[1].name, "subdir-name", STR_UNICODE);
437 CHECK_VAL(notify.nttrans.out.changes[2].action, NOTIFY_ACTION_REMOVED);
438 CHECK_WSTR(notify.nttrans.out.changes[2].name, "subname3-r", STR_UNICODE);
441 smb_raw_exit(cli->session);
442 smbcli_deltree(cli->tree, BASEDIR);
447 testing of change notify mask change
449 static bool test_notify_mask_change(struct torture_context *mem_ctx,
450 struct smbcli_state *cli)
454 union smb_notify notify;
457 struct smbcli_request *req1, *req2;
459 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
461 if (!torture_setup_dir(cli, BASEDIR)) {
466 get a handle on the directory
468 io.generic.level = RAW_OPEN_NTCREATEX;
469 io.ntcreatex.in.root_fid.fnum = 0;
470 io.ntcreatex.in.flags = 0;
471 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
472 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
473 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
474 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
475 io.ntcreatex.in.alloc_size = 0;
476 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
477 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
478 io.ntcreatex.in.security_flags = 0;
479 io.ntcreatex.in.fname = BASEDIR;
481 status = smb_raw_open(cli->tree, mem_ctx, &io);
482 CHECK_STATUS(status, NT_STATUS_OK);
483 fnum = io.ntcreatex.out.file.fnum;
485 /* ask for a change notify, on file or directory name
486 changes. Setup both with and without recursion */
487 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
488 notify.nttrans.in.buffer_size = 1000;
489 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
490 notify.nttrans.in.file.fnum = fnum;
492 notify.nttrans.in.recursive = true;
493 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
495 notify.nttrans.in.recursive = false;
496 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
498 /* cancel initial requests so the buffer is setup */
499 smb_raw_ntcancel(req1);
500 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
501 CHECK_STATUS(status, NT_STATUS_CANCELLED);
503 smb_raw_ntcancel(req2);
504 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
505 CHECK_STATUS(status, NT_STATUS_CANCELLED);
507 notify.nttrans.in.recursive = true;
508 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
510 /* Set to hidden then back again. */
511 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));
512 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
513 smbcli_unlink(cli->tree, BASEDIR "\\tname1");
515 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
516 CHECK_STATUS(status, NT_STATUS_OK);
518 CHECK_VAL(notify.nttrans.out.num_changes, 1);
519 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
520 CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
522 /* Now try and change the mask to include other events.
523 * This should not work - once the mask is set on a directory
524 * fnum it seems to be fixed until the fnum is closed. */
526 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION;
527 notify.nttrans.in.recursive = true;
528 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
530 notify.nttrans.in.recursive = false;
531 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
533 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
534 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
535 smbcli_close(cli->tree,
536 smbcli_open(cli->tree, BASEDIR "\\subdir-name\\subname2", O_CREAT, 0));
537 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
538 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
539 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
541 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
542 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
543 smbcli_unlink(cli->tree, BASEDIR "\\subname3-r");
545 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
546 CHECK_STATUS(status, NT_STATUS_OK);
548 CHECK_VAL(notify.nttrans.out.num_changes, 1);
549 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
550 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname2-r", STR_UNICODE);
552 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
553 CHECK_STATUS(status, NT_STATUS_OK);
555 CHECK_VAL(notify.nttrans.out.num_changes, 1);
556 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
557 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subname3-r", STR_UNICODE);
564 smb_raw_exit(cli->session);
565 smbcli_deltree(cli->tree, BASEDIR);
571 testing of mask bits for change notify
573 static bool test_notify_mask(struct torture_context *tctx,
574 struct smbcli_state *cli)
578 union smb_notify notify;
587 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
589 if (!torture_setup_dir(cli, BASEDIR)) {
593 tv = timeval_current_ofs(1000, 0);
594 t = timeval_to_nttime(&tv);
597 get a handle on the directory
599 io.generic.level = RAW_OPEN_NTCREATEX;
600 io.ntcreatex.in.root_fid.fnum = 0;
601 io.ntcreatex.in.flags = 0;
602 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
603 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
604 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
605 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
606 io.ntcreatex.in.alloc_size = 0;
607 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
608 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
609 io.ntcreatex.in.security_flags = 0;
610 io.ntcreatex.in.fname = BASEDIR;
612 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
613 notify.nttrans.in.buffer_size = 1000;
614 notify.nttrans.in.recursive = true;
616 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
618 smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
619 do { for (mask=i=0;i<32;i++) { \
620 struct smbcli_request *req; \
621 status = smb_raw_open(cli->tree, tctx, &io); \
622 CHECK_STATUS(status, NT_STATUS_OK); \
623 fnum = io.ntcreatex.out.file.fnum; \
625 notify.nttrans.in.file.fnum = fnum; \
626 notify.nttrans.in.completion_filter = (1<<i); \
627 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
629 smb_msleep(200); smb_raw_ntcancel(req); \
630 status = smb_raw_changenotify_recv(req, tctx, ¬ify); \
632 smbcli_close(cli->tree, fnum); \
633 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
634 CHECK_STATUS(status, NT_STATUS_OK); \
635 /* special case to cope with file rename behaviour */ \
636 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
637 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
638 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
639 Action == NOTIFY_ACTION_OLD_NAME) { \
640 printf("(rename file special handling OK)\n"); \
641 } else if (nchanges != notify.nttrans.out.num_changes) { \
642 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
643 notify.nttrans.out.num_changes, \
645 notify.nttrans.out.changes[0].action, \
646 notify.nttrans.in.completion_filter); \
648 } else if (notify.nttrans.out.changes[0].action != Action) { \
649 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
650 notify.nttrans.out.num_changes, \
651 notify.nttrans.out.changes[0].action, \
653 notify.nttrans.in.completion_filter); \
655 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
656 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
657 notify.nttrans.out.num_changes, \
658 notify.nttrans.out.changes[0].action, \
659 notify.nttrans.in.completion_filter, \
660 notify.nttrans.out.changes[0].name.s); \
665 if ((expected) != mask) { \
666 if (((expected) & ~mask) != 0) { \
667 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
671 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
678 printf("Testing mkdir\n");
679 NOTIFY_MASK_TEST("Testing mkdir",;,
680 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
681 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
683 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
685 printf("Testing create file\n");
686 NOTIFY_MASK_TEST("Testing create file",;,
687 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
688 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
690 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
692 printf("Testing unlink\n");
693 NOTIFY_MASK_TEST("Testing unlink",
694 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
695 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
697 NOTIFY_ACTION_REMOVED,
698 FILE_NOTIFY_CHANGE_FILE_NAME, 1);
700 printf("Testing rmdir\n");
701 NOTIFY_MASK_TEST("Testing rmdir",
702 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
703 smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
705 NOTIFY_ACTION_REMOVED,
706 FILE_NOTIFY_CHANGE_DIR_NAME, 1);
708 printf("Testing rename file\n");
709 NOTIFY_MASK_TEST("Testing rename file",
710 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
711 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
712 smbcli_unlink(cli->tree, BASEDIR "\\tname2");,
713 NOTIFY_ACTION_OLD_NAME,
714 FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
716 printf("Testing rename dir\n");
717 NOTIFY_MASK_TEST("Testing rename dir",
718 smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
719 smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
720 smbcli_rmdir(cli->tree, BASEDIR "\\tname2");,
721 NOTIFY_ACTION_OLD_NAME,
722 FILE_NOTIFY_CHANGE_DIR_NAME, 2);
724 printf("Testing set path attribute\n");
725 NOTIFY_MASK_TEST("Testing set path attribute",
726 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
727 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
728 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
729 NOTIFY_ACTION_MODIFIED,
730 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
732 printf("Testing set path write time\n");
733 NOTIFY_MASK_TEST("Testing set path write time",
734 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
735 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
736 smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
737 NOTIFY_ACTION_MODIFIED,
738 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
740 printf("Testing set file attribute\n");
741 NOTIFY_MASK_TEST("Testing set file attribute",
742 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
743 smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
744 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
745 NOTIFY_ACTION_MODIFIED,
746 FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
748 if (torture_setting_bool(tctx, "samba3", false)) {
749 printf("Samba3 does not yet support create times "
753 printf("Testing set file create time\n");
754 NOTIFY_MASK_TEST("Testing set file create time",
755 fnum2 = create_complex_file(cli, tctx,
756 BASEDIR "\\tname1");,
757 smbcli_fsetatr(cli->tree, fnum2, 0, t, 0, 0, 0);,
758 (smbcli_close(cli->tree, fnum2),
759 smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
760 NOTIFY_ACTION_MODIFIED,
761 FILE_NOTIFY_CHANGE_CREATION, 1);
764 printf("Testing set file access time\n");
765 NOTIFY_MASK_TEST("Testing set file access time",
766 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
767 smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
768 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
769 NOTIFY_ACTION_MODIFIED,
770 FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
772 printf("Testing set file write time\n");
773 NOTIFY_MASK_TEST("Testing set file write time",
774 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
775 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
776 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
777 NOTIFY_ACTION_MODIFIED,
778 FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
780 printf("Testing set file change time\n");
781 NOTIFY_MASK_TEST("Testing set file change time",
782 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
783 smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
784 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
785 NOTIFY_ACTION_MODIFIED,
789 printf("Testing write\n");
790 NOTIFY_MASK_TEST("Testing write",
791 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
792 smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
793 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
794 NOTIFY_ACTION_MODIFIED,
797 printf("Testing truncate\n");
798 NOTIFY_MASK_TEST("Testing truncate",
799 fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
800 smbcli_ftruncate(cli->tree, fnum2, 10000);,
801 (smbcli_close(cli->tree, fnum2), smbcli_unlink(cli->tree, BASEDIR "\\tname1"));,
802 NOTIFY_ACTION_MODIFIED,
803 FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
806 smb_raw_exit(cli->session);
807 smbcli_deltree(cli->tree, BASEDIR);
812 basic testing of change notify on files
814 static bool test_notify_file(struct torture_context *mem_ctx,
815 struct smbcli_state *cli)
821 union smb_notify notify;
822 struct smbcli_request *req;
824 const char *fname = BASEDIR "\\file.txt";
826 printf("TESTING CHANGE NOTIFY ON FILES\n");
828 if (!torture_setup_dir(cli, BASEDIR)) {
832 io.generic.level = RAW_OPEN_NTCREATEX;
833 io.ntcreatex.in.root_fid.fnum = 0;
834 io.ntcreatex.in.flags = 0;
835 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
836 io.ntcreatex.in.create_options = 0;
837 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
838 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
839 io.ntcreatex.in.alloc_size = 0;
840 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
841 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
842 io.ntcreatex.in.security_flags = 0;
843 io.ntcreatex.in.fname = fname;
844 status = smb_raw_open(cli->tree, mem_ctx, &io);
845 CHECK_STATUS(status, NT_STATUS_OK);
846 fnum = io.ntcreatex.out.file.fnum;
848 /* ask for a change notify,
849 on file or directory name changes */
850 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
851 notify.nttrans.in.file.fnum = fnum;
852 notify.nttrans.in.buffer_size = 1000;
853 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
854 notify.nttrans.in.recursive = false;
856 printf("Testing if notifies on file handles are invalid (should be)\n");
858 req = smb_raw_changenotify_send(cli->tree, ¬ify);
859 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
860 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
862 cl.close.level = RAW_CLOSE_CLOSE;
863 cl.close.in.file.fnum = fnum;
864 cl.close.in.write_time = 0;
865 status = smb_raw_close(cli->tree, &cl);
866 CHECK_STATUS(status, NT_STATUS_OK);
868 status = smbcli_unlink(cli->tree, fname);
869 CHECK_STATUS(status, NT_STATUS_OK);
872 smb_raw_exit(cli->session);
873 smbcli_deltree(cli->tree, BASEDIR);
878 basic testing of change notifies followed by a tdis
880 static bool test_notify_tdis(struct torture_context *tctx,
881 struct smbcli_state *cli1)
885 union smb_notify notify;
888 struct smbcli_request *req;
889 struct smbcli_state *cli = NULL;
891 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
893 if (!torture_setup_dir(cli1, BASEDIR)) {
897 if (!torture_open_connection(&cli, tctx, 0)) {
902 get a handle on the directory
904 io.generic.level = RAW_OPEN_NTCREATEX;
905 io.ntcreatex.in.root_fid.fnum = 0;
906 io.ntcreatex.in.flags = 0;
907 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
908 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
909 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
910 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
911 io.ntcreatex.in.alloc_size = 0;
912 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
913 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
914 io.ntcreatex.in.security_flags = 0;
915 io.ntcreatex.in.fname = BASEDIR;
917 status = smb_raw_open(cli->tree, tctx, &io);
918 CHECK_STATUS(status, NT_STATUS_OK);
919 fnum = io.ntcreatex.out.file.fnum;
921 /* ask for a change notify,
922 on file or directory name changes */
923 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
924 notify.nttrans.in.buffer_size = 1000;
925 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
926 notify.nttrans.in.file.fnum = fnum;
927 notify.nttrans.in.recursive = true;
929 req = smb_raw_changenotify_send(cli->tree, ¬ify);
931 status = smbcli_tdis(cli);
932 CHECK_STATUS(status, NT_STATUS_OK);
935 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
936 CHECK_STATUS(status, NT_STATUS_OK);
937 CHECK_VAL(notify.nttrans.out.num_changes, 0);
940 torture_close_connection(cli);
941 smbcli_deltree(cli1->tree, BASEDIR);
946 basic testing of change notifies followed by a exit
948 static bool test_notify_exit(struct torture_context *tctx,
949 struct smbcli_state *cli1)
953 union smb_notify notify;
956 struct smbcli_request *req;
957 struct smbcli_state *cli = NULL;
959 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
961 if (!torture_setup_dir(cli1, BASEDIR)) {
965 if (!torture_open_connection(&cli, tctx, 0)) {
970 get a handle on the directory
972 io.generic.level = RAW_OPEN_NTCREATEX;
973 io.ntcreatex.in.root_fid.fnum = 0;
974 io.ntcreatex.in.flags = 0;
975 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
976 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
977 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
978 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
979 io.ntcreatex.in.alloc_size = 0;
980 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
981 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
982 io.ntcreatex.in.security_flags = 0;
983 io.ntcreatex.in.fname = BASEDIR;
985 status = smb_raw_open(cli->tree, tctx, &io);
986 CHECK_STATUS(status, NT_STATUS_OK);
987 fnum = io.ntcreatex.out.file.fnum;
989 /* ask for a change notify,
990 on file or directory name changes */
991 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
992 notify.nttrans.in.buffer_size = 1000;
993 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
994 notify.nttrans.in.file.fnum = fnum;
995 notify.nttrans.in.recursive = true;
997 req = smb_raw_changenotify_send(cli->tree, ¬ify);
999 status = smb_raw_exit(cli->session);
1000 CHECK_STATUS(status, NT_STATUS_OK);
1002 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1003 CHECK_STATUS(status, NT_STATUS_OK);
1004 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1007 torture_close_connection(cli);
1008 smbcli_deltree(cli1->tree, BASEDIR);
1013 basic testing of change notifies followed by a ulogoff
1015 static bool test_notify_ulogoff(struct torture_context *tctx)
1019 union smb_notify notify;
1022 struct smbcli_request *req;
1023 struct smbcli_state *cli = NULL;
1025 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1027 if (!torture_open_connection(&cli, tctx, 0)) {
1032 get a handle on the directory
1034 io.generic.level = RAW_OPEN_NTCREATEX;
1035 io.ntcreatex.in.root_fid.fnum = 0;
1036 io.ntcreatex.in.flags = 0;
1037 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1038 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1039 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1040 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1041 io.ntcreatex.in.alloc_size = 0;
1042 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1043 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1044 io.ntcreatex.in.security_flags = 0;
1045 io.ntcreatex.in.fname = BASEDIR;
1047 status = smb_raw_open(cli->tree, tctx, &io);
1048 CHECK_STATUS(status, NT_STATUS_OK);
1049 fnum = io.ntcreatex.out.file.fnum;
1051 /* ask for a change notify,
1052 on file or directory name changes */
1053 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1054 notify.nttrans.in.buffer_size = 1000;
1055 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1056 notify.nttrans.in.file.fnum = fnum;
1057 notify.nttrans.in.recursive = true;
1059 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1061 status = smb_raw_ulogoff(cli->session);
1062 CHECK_STATUS(status, NT_STATUS_OK);
1064 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1065 CHECK_STATUS(status, NT_STATUS_OK);
1066 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1069 torture_close_connection(cli);
1073 static void tcp_dis_handler(struct smbcli_transport *t, void *p)
1075 struct smbcli_state *cli = (struct smbcli_state *)p;
1076 smbcli_transport_dead(cli->transport, NT_STATUS_LOCAL_DISCONNECT);
1077 cli->transport = NULL;
1081 basic testing of change notifies followed by tcp disconnect
1083 static bool test_notify_tcp_dis(struct torture_context *tctx)
1087 union smb_notify notify;
1090 struct smbcli_request *req;
1091 struct smbcli_state *cli = NULL;
1093 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1095 if (!torture_open_connection(&cli, tctx, 0)) {
1100 get a handle on the directory
1102 io.generic.level = RAW_OPEN_NTCREATEX;
1103 io.ntcreatex.in.root_fid.fnum = 0;
1104 io.ntcreatex.in.flags = 0;
1105 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1106 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1107 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1108 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1109 io.ntcreatex.in.alloc_size = 0;
1110 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1111 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1112 io.ntcreatex.in.security_flags = 0;
1113 io.ntcreatex.in.fname = BASEDIR;
1115 status = smb_raw_open(cli->tree, tctx, &io);
1116 CHECK_STATUS(status, NT_STATUS_OK);
1117 fnum = io.ntcreatex.out.file.fnum;
1119 /* ask for a change notify,
1120 on file or directory name changes */
1121 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1122 notify.nttrans.in.buffer_size = 1000;
1123 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1124 notify.nttrans.in.file.fnum = fnum;
1125 notify.nttrans.in.recursive = true;
1127 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1129 smbcli_transport_idle_handler(cli->transport, tcp_dis_handler, 250, cli);
1131 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1132 CHECK_STATUS(status, NT_STATUS_LOCAL_DISCONNECT);
1135 torture_close_connection(cli);
1140 test setting up two change notify requests on one handle
1142 static bool test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1146 union smb_notify notify;
1149 struct smbcli_request *req1, *req2;
1151 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1154 get a handle on the directory
1156 io.generic.level = RAW_OPEN_NTCREATEX;
1157 io.ntcreatex.in.root_fid.fnum = 0;
1158 io.ntcreatex.in.flags = 0;
1159 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1160 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1161 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1162 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1163 io.ntcreatex.in.alloc_size = 0;
1164 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1165 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1166 io.ntcreatex.in.security_flags = 0;
1167 io.ntcreatex.in.fname = BASEDIR;
1169 status = smb_raw_open(cli->tree, mem_ctx, &io);
1170 CHECK_STATUS(status, NT_STATUS_OK);
1171 fnum = io.ntcreatex.out.file.fnum;
1173 /* ask for a change notify,
1174 on file or directory name changes */
1175 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1176 notify.nttrans.in.buffer_size = 1000;
1177 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1178 notify.nttrans.in.file.fnum = fnum;
1179 notify.nttrans.in.recursive = true;
1181 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1182 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
1184 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1186 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1187 CHECK_STATUS(status, NT_STATUS_OK);
1188 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1189 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1191 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
1193 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
1194 CHECK_STATUS(status, NT_STATUS_OK);
1195 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1196 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name2", STR_UNICODE);
1199 smb_raw_exit(cli->session);
1205 test multiple change notifies at different depths and with/without recursion
1207 static bool test_notify_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1210 union smb_notify notify;
1212 struct smbcli_request *req;
1222 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 30 },
1223 {BASEDIR "\\zqy", true, FILE_NOTIFY_CHANGE_NAME, 8 },
1224 {BASEDIR "\\atsy", true, FILE_NOTIFY_CHANGE_NAME, 4 },
1225 {BASEDIR "\\abc\\foo", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1226 {BASEDIR "\\abc\\blah", true, FILE_NOTIFY_CHANGE_NAME, 13 },
1227 {BASEDIR "\\abc\\blah", false, FILE_NOTIFY_CHANGE_NAME, 7 },
1228 {BASEDIR "\\abc\\blah\\a", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1229 {BASEDIR "\\abc\\blah\\b", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1230 {BASEDIR "\\abc\\blah\\c", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1231 {BASEDIR "\\abc\\fooblah", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1232 {BASEDIR "\\zqy\\xx", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1233 {BASEDIR "\\zqy\\yyy", true, FILE_NOTIFY_CHANGE_NAME, 2 },
1234 {BASEDIR "\\zqy\\..", true, FILE_NOTIFY_CHANGE_NAME, 40 },
1235 {BASEDIR, true, FILE_NOTIFY_CHANGE_NAME, 40 },
1236 {BASEDIR, false,FILE_NOTIFY_CHANGE_NAME, 6 },
1237 {BASEDIR "\\atsy", false,FILE_NOTIFY_CHANGE_NAME, 4 },
1238 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1239 {BASEDIR "\\abc", false,FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1240 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_FILE_NAME, 0 },
1241 {BASEDIR "\\abc", true, FILE_NOTIFY_CHANGE_NAME, 24 },
1245 bool all_done = false;
1247 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1249 io.generic.level = RAW_OPEN_NTCREATEX;
1250 io.ntcreatex.in.root_fid.fnum = 0;
1251 io.ntcreatex.in.flags = 0;
1252 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1253 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1254 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1255 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1256 io.ntcreatex.in.alloc_size = 0;
1257 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1258 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1259 io.ntcreatex.in.security_flags = 0;
1261 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1262 notify.nttrans.in.buffer_size = 20000;
1265 setup the directory tree, and the notify buffer on each directory
1267 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1268 io.ntcreatex.in.fname = dirs[i].path;
1269 status = smb_raw_open(cli->tree, mem_ctx, &io);
1270 CHECK_STATUS(status, NT_STATUS_OK);
1271 dirs[i].fnum = io.ntcreatex.out.file.fnum;
1273 notify.nttrans.in.completion_filter = dirs[i].filter;
1274 notify.nttrans.in.file.fnum = dirs[i].fnum;
1275 notify.nttrans.in.recursive = dirs[i].recursive;
1276 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1277 smb_raw_ntcancel(req);
1278 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1279 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1282 /* trigger 2 events in each dir */
1283 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1284 char *path = talloc_asprintf(mem_ctx, "%s\\test.dir", dirs[i].path);
1285 smbcli_mkdir(cli->tree, path);
1286 smbcli_rmdir(cli->tree, path);
1290 /* give a bit of time for the events to propogate */
1291 tv = timeval_current();
1294 /* count events that have happened in each dir */
1295 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1296 notify.nttrans.in.file.fnum = dirs[i].fnum;
1297 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1298 smb_raw_ntcancel(req);
1299 notify.nttrans.out.num_changes = 0;
1300 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
1301 dirs[i].counted += notify.nttrans.out.num_changes;
1306 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1307 if (dirs[i].counted != dirs[i].expected) {
1311 } while (!all_done && timeval_elapsed(&tv) < 20);
1313 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
1315 for (i=0;i<ARRAY_SIZE(dirs);i++) {
1316 if (dirs[i].counted != dirs[i].expected) {
1317 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1318 i, dirs[i].expected, dirs[i].counted, dirs[i].path);
1324 run from the back, closing and deleting
1326 for (i=ARRAY_SIZE(dirs)-1;i>=0;i--) {
1327 smbcli_close(cli->tree, dirs[i].fnum);
1328 smbcli_rmdir(cli->tree, dirs[i].path);
1332 smb_raw_exit(cli->session);
1337 Test response when cached server events exceed single NT NOTFIY response
1340 static bool test_notify_overflow(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1344 union smb_notify notify;
1348 struct smbcli_request *req1;
1351 printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
1353 /* get a handle on the directory */
1354 io.generic.level = RAW_OPEN_NTCREATEX;
1355 io.ntcreatex.in.root_fid.fnum = 0;
1356 io.ntcreatex.in.flags = 0;
1357 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1358 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1359 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1360 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1361 NTCREATEX_SHARE_ACCESS_WRITE;
1362 io.ntcreatex.in.alloc_size = 0;
1363 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1364 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1365 io.ntcreatex.in.security_flags = 0;
1366 io.ntcreatex.in.fname = BASEDIR;
1368 status = smb_raw_open(cli->tree, mem_ctx, &io);
1369 CHECK_STATUS(status, NT_STATUS_OK);
1370 fnum = io.ntcreatex.out.file.fnum;
1372 /* ask for a change notify, on name changes. */
1373 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1374 notify.nttrans.in.buffer_size = 1000;
1375 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1376 notify.nttrans.in.file.fnum = fnum;
1378 notify.nttrans.in.recursive = true;
1379 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1381 /* cancel initial requests so the buffer is setup */
1382 smb_raw_ntcancel(req1);
1383 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1384 CHECK_STATUS(status, NT_STATUS_CANCELLED);
1386 /* open a lot of files, filling up the server side notify buffer */
1387 printf("Testing overflowed buffer notify on create of %d files\n",
1389 for (i=0;i<count;i++) {
1390 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
1391 int fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR,
1394 printf("Failed to create %s - %s\n",
1395 fname, smbcli_errstr(cli->tree));
1400 smbcli_close(cli->tree, fnum2);
1403 /* expect that 0 events will be returned with NT_STATUS_OK */
1404 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1405 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1406 CHECK_STATUS(status, NT_STATUS_OK);
1407 CHECK_VAL(notify.nttrans.out.num_changes, 0);
1410 smb_raw_exit(cli->session);
1415 Test if notifications are returned for changes to the base directory.
1418 static bool test_notify_basedir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1422 union smb_notify notify;
1425 struct smbcli_request *req1;
1427 printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
1429 /* get a handle on the directory */
1430 io.generic.level = RAW_OPEN_NTCREATEX;
1431 io.ntcreatex.in.root_fid.fnum = 0;
1432 io.ntcreatex.in.flags = 0;
1433 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1434 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1435 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1436 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1437 NTCREATEX_SHARE_ACCESS_WRITE;
1438 io.ntcreatex.in.alloc_size = 0;
1439 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1440 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1441 io.ntcreatex.in.security_flags = 0;
1442 io.ntcreatex.in.fname = BASEDIR;
1444 status = smb_raw_open(cli->tree, mem_ctx, &io);
1445 CHECK_STATUS(status, NT_STATUS_OK);
1446 fnum = io.ntcreatex.out.file.fnum;
1448 /* create a test file that will also be modified */
1449 smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1",
1452 /* ask for a change notify, on attribute changes. */
1453 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1454 notify.nttrans.in.buffer_size = 1000;
1455 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
1456 notify.nttrans.in.file.fnum = fnum;
1457 notify.nttrans.in.recursive = true;
1459 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
1461 /* set attribute on the base dir */
1462 smbcli_setatr(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN, 0);
1464 /* set attribute on a file to assure we receive a notification */
1465 smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
1468 /* check how many responses were given, expect only 1 for the file */
1469 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
1470 CHECK_STATUS(status, NT_STATUS_OK);
1471 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1472 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
1473 CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
1476 smb_raw_exit(cli->session);
1482 create a secondary tree connect - used to test for a bug in Samba3 messaging
1485 static struct smbcli_tree *secondary_tcon(struct smbcli_state *cli,
1486 struct torture_context *tctx)
1489 const char *share, *host;
1490 struct smbcli_tree *tree;
1491 union smb_tcon tcon;
1493 share = torture_setting_string(tctx, "share", NULL);
1494 host = torture_setting_string(tctx, "host", NULL);
1496 printf("create a second tree context on the same session\n");
1497 tree = smbcli_tree_init(cli->session, tctx, false);
1499 tcon.generic.level = RAW_TCON_TCONX;
1500 tcon.tconx.in.flags = 0;
1501 tcon.tconx.in.password = data_blob(NULL, 0);
1502 tcon.tconx.in.path = talloc_asprintf(tctx, "\\\\%s\\%s", host, share);
1503 tcon.tconx.in.device = "A:";
1504 status = smb_raw_tcon(tree, tctx, &tcon);
1505 if (!NT_STATUS_IS_OK(status)) {
1507 printf("Failed to create secondary tree\n");
1511 tree->tid = tcon.tconx.out.tid;
1512 printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid);
1519 very simple change notify test
1521 static bool test_notify_tcon(struct torture_context *torture,
1522 struct smbcli_state *cli)
1526 union smb_notify notify;
1529 struct smbcli_request *req;
1530 extern int torture_numops;
1531 struct smbcli_tree *tree = NULL;
1533 printf("TESTING SIMPLE CHANGE NOTIFY\n");
1535 if (!torture_setup_dir(cli, BASEDIR)) {
1540 get a handle on the directory
1542 io.generic.level = RAW_OPEN_NTCREATEX;
1543 io.ntcreatex.in.root_fid.fnum = 0;
1544 io.ntcreatex.in.flags = 0;
1545 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1546 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1547 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1548 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1549 io.ntcreatex.in.alloc_size = 0;
1550 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1551 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1552 io.ntcreatex.in.security_flags = 0;
1553 io.ntcreatex.in.fname = BASEDIR;
1555 status = smb_raw_open(cli->tree, torture, &io);
1556 CHECK_STATUS(status, NT_STATUS_OK);
1557 fnum = io.ntcreatex.out.file.fnum;
1559 status = smb_raw_open(cli->tree, torture, &io);
1560 CHECK_STATUS(status, NT_STATUS_OK);
1562 /* ask for a change notify,
1563 on file or directory name changes */
1564 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1565 notify.nttrans.in.buffer_size = 1000;
1566 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
1567 notify.nttrans.in.file.fnum = fnum;
1568 notify.nttrans.in.recursive = true;
1570 printf("Testing notify mkdir\n");
1571 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1572 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1574 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1575 CHECK_STATUS(status, NT_STATUS_OK);
1577 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1578 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1579 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1581 printf("Testing notify rmdir\n");
1582 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1583 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1585 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1586 CHECK_STATUS(status, NT_STATUS_OK);
1587 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1588 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1589 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1591 printf("SIMPLE CHANGE NOTIFY OK\n");
1593 printf("TESTING WITH SECONDARY TCON\n");
1594 tree = secondary_tcon(cli, torture);
1596 printf("Testing notify mkdir\n");
1597 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1598 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1600 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1601 CHECK_STATUS(status, NT_STATUS_OK);
1603 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1604 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1605 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1607 printf("Testing notify rmdir\n");
1608 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1609 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1611 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1612 CHECK_STATUS(status, NT_STATUS_OK);
1613 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1614 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1615 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1617 printf("CHANGE NOTIFY WITH TCON OK\n");
1619 printf("Disconnecting secondary tree\n");
1620 status = smb_tree_disconnect(tree);
1621 CHECK_STATUS(status, NT_STATUS_OK);
1624 printf("Testing notify mkdir\n");
1625 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1626 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
1628 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1629 CHECK_STATUS(status, NT_STATUS_OK);
1631 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1632 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_ADDED);
1633 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1635 printf("Testing notify rmdir\n");
1636 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1637 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
1639 status = smb_raw_changenotify_recv(req, torture, ¬ify);
1640 CHECK_STATUS(status, NT_STATUS_OK);
1641 CHECK_VAL(notify.nttrans.out.num_changes, 1);
1642 CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_REMOVED);
1643 CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
1645 printf("CHANGE NOTIFY WITH TDIS OK\n");
1647 smb_raw_exit(cli->session);
1648 smbcli_deltree(cli->tree, BASEDIR);
1654 testing alignment of multiple change notify infos
1656 static bool test_notify_alignment(struct smbcli_state *cli,
1657 struct torture_context *tctx)
1660 union smb_notify notify;
1663 struct smbcli_request *req;
1664 const char *fname = BASEDIR "\\starter";
1665 const char *fnames[] = { "a",
1669 int num_names = ARRAY_SIZE(fnames);
1672 torture_comment(tctx, "TESTING CHANGE NOTIFY REPLY ALIGNMENT\n");
1674 /* get a handle on the directory */
1675 io.generic.level = RAW_OPEN_NTCREATEX;
1676 io.ntcreatex.in.root_fid.fnum = 0;
1677 io.ntcreatex.in.flags = 0;
1678 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
1679 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1680 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1681 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1682 NTCREATEX_SHARE_ACCESS_WRITE;
1683 io.ntcreatex.in.alloc_size = 0;
1684 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1685 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1686 io.ntcreatex.in.security_flags = 0;
1687 io.ntcreatex.in.fname = BASEDIR;
1689 status = smb_raw_open(cli->tree, tctx, &io);
1690 torture_assert_ntstatus_ok(tctx, status, "");
1691 fnum = io.ntcreatex.out.file.fnum;
1693 /* ask for a change notify, on file creation */
1694 notify.nttrans.level = RAW_NOTIFY_NTTRANS;
1695 notify.nttrans.in.buffer_size = 1000;
1696 notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_FILE_NAME;
1697 notify.nttrans.in.file.fnum = fnum;
1698 notify.nttrans.in.recursive = false;
1700 /* start change tracking */
1701 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1703 fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
1704 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1705 smbcli_close(cli->tree, fnum2);
1707 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1708 torture_assert_ntstatus_ok(tctx, status, "");
1710 /* create 4 files that will cause CHANGE_NOTIFY_INFO structures
1711 * to be returned in the same packet with all possible 4-byte padding
1712 * permutations. As per MS-CIFS 2.2.7.4.2 these structures should be
1713 * 4-byte aligned. */
1715 for (i = 0; i < num_names; i++) {
1716 fpath = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fnames[i]);
1717 fnum2 = smbcli_open(cli->tree, fpath,
1718 O_CREAT|O_RDWR, DENY_NONE);
1719 torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
1720 smbcli_close(cli->tree, fnum2);
1724 /* We send a notify packet, and let smb_raw_changenotify_recv() do
1725 * the alignment checking for us. */
1726 req = smb_raw_changenotify_send(cli->tree, ¬ify);
1727 status = smb_raw_changenotify_recv(req, tctx, ¬ify);
1728 torture_assert_ntstatus_ok(tctx, status, "");
1730 /* Do basic checking for correctness. */
1731 torture_assert(tctx, notify.nttrans.out.num_changes == num_names, "");
1732 for (i = 0; i < num_names; i++) {
1733 torture_assert(tctx, notify.nttrans.out.changes[i].action ==
1734 NOTIFY_ACTION_ADDED, "");
1735 CHECK_WSTR2(tctx, notify.nttrans.out.changes[i].name, fnames[i],
1743 basic testing of change notify
1745 static bool test_raw_notify_all(struct torture_context *torture,
1746 struct smbcli_state *cli,
1747 struct smbcli_state *cli2)
1751 if (!torture_setup_dir(cli, BASEDIR)) {
1755 ret &= test_notify_ulogoff(torture);
1756 ret &= test_notify_tcp_dis(torture);
1757 ret &= test_notify_double(cli, torture);
1758 ret &= test_notify_tree(cli, torture);
1759 ret &= test_notify_overflow(cli, torture);
1760 ret &= test_notify_basedir(cli, torture);
1761 ret &= test_notify_alignment(cli, torture);
1763 smb_raw_exit(cli->session);
1764 smbcli_deltree(cli->tree, BASEDIR);
1768 struct torture_suite *torture_raw_notify(TALLOC_CTX *mem_ctx)
1770 struct torture_suite *suite = torture_suite_create(mem_ctx, "notify");
1772 torture_suite_add_1smb_test(suite, "tcon", test_notify_tcon);
1773 torture_suite_add_2smb_test(suite, "dir", test_notify_dir);
1774 torture_suite_add_1smb_test(suite, "mask", test_notify_mask);
1775 torture_suite_add_1smb_test(suite, "recursive", test_notify_recursive);
1776 torture_suite_add_1smb_test(suite, "mask_change",
1777 test_notify_mask_change);
1778 torture_suite_add_1smb_test(suite, "file", test_notify_file);
1779 torture_suite_add_1smb_test(suite, "tdis", test_notify_tdis);
1780 torture_suite_add_1smb_test(suite, "exit", test_notify_exit);
1781 torture_suite_add_2smb_test(suite, "all", test_raw_notify_all);