2 Unix SMB/CIFS implementation.
3 basic raw test suite for change notify
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/libcli.h"
25 #include "system/filesys.h"
26 #include "torture/util.h"
28 #define BASEDIR "\\test_notify"
30 #define CHECK_STATUS(status, correct) do { \
31 if (!NT_STATUS_EQUAL(status, correct)) { \
32 printf("(%d) Incorrect status %s - should be %s\n", \
33 __LINE__, nt_errstr(status), nt_errstr(correct)); \
39 #define CHECK_VAL(v, correct) do { \
40 if ((v) != (correct)) { \
41 printf("(%d) wrong value for %s 0x%x should be 0x%x\n", \
42 __LINE__, #v, (int)v, (int)correct); \
47 #define CHECK_WSTR(field, value, flags) do { \
48 if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli)) { \
49 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
56 basic testing of change notify on directories
58 static BOOL test_notify_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
62 struct 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.in.buffer_size = 1000;
98 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
99 notify.in.file.fnum = fnum;
100 notify.in.recursive = True;
102 printf("testing notify cancel\n");
104 req = smb_raw_changenotify_send(cli->tree, ¬ify);
105 smb_raw_ntcancel(req);
106 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
107 CHECK_STATUS(status, NT_STATUS_CANCELLED);
109 printf("testing notify mkdir\n");
111 req = smb_raw_changenotify_send(cli->tree, ¬ify);
112 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
114 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
115 CHECK_STATUS(status, NT_STATUS_OK);
117 CHECK_VAL(notify.out.num_changes, 1);
118 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
119 CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
121 printf("testing notify rmdir\n");
123 req = smb_raw_changenotify_send(cli->tree, ¬ify);
124 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
126 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
127 CHECK_STATUS(status, NT_STATUS_OK);
128 CHECK_VAL(notify.out.num_changes, 1);
129 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
130 CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
132 printf("testing notify mkdir - rmdir - mkdir - rmdir\n");
134 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
135 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
136 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
137 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
138 req = smb_raw_changenotify_send(cli->tree, ¬ify);
139 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
140 CHECK_STATUS(status, NT_STATUS_OK);
141 CHECK_VAL(notify.out.num_changes, 4);
142 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
143 CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
144 CHECK_VAL(notify.out.changes[1].action, NOTIFY_ACTION_REMOVED);
145 CHECK_WSTR(notify.out.changes[1].name, "subdir-name", STR_UNICODE);
146 CHECK_VAL(notify.out.changes[2].action, NOTIFY_ACTION_ADDED);
147 CHECK_WSTR(notify.out.changes[2].name, "subdir-name", STR_UNICODE);
148 CHECK_VAL(notify.out.changes[3].action, NOTIFY_ACTION_REMOVED);
149 CHECK_WSTR(notify.out.changes[3].name, "subdir-name", STR_UNICODE);
151 count = torture_numops;
152 printf("testing buffered notify on create of %d files\n", count);
153 for (i=0;i<count;i++) {
154 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
155 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
157 printf("Failed to create %s - %s\n",
158 fname, smbcli_errstr(cli->tree));
163 smbcli_close(cli->tree, fnum3);
166 /* (1st notify) setup a new notify on a different directory handle.
167 This new notify won't see the events above. */
168 notify.in.file.fnum = fnum2;
169 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
171 /* (2nd notify) whereas this notify will see the above buffered events,
172 and it directly returns the buffered events */
173 notify.in.file.fnum = fnum;
174 req = smb_raw_changenotify_send(cli->tree, ¬ify);
176 /* (1st unlink) as the 2nd notify directly returns,
177 this unlink is only seen by the 1st notify and
178 the 3rd notify (later) */
179 printf("testing notify on unlink for the first file\n");
180 status = smbcli_unlink(cli->tree, BASEDIR "\\test0.txt");
181 CHECK_STATUS(status, NT_STATUS_OK);
183 /* receive the reply from the 2nd notify */
184 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
185 CHECK_STATUS(status, NT_STATUS_OK);
187 CHECK_VAL(notify.out.num_changes, count);
188 for (i=1;i<notify.out.num_changes;i++) {
189 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_ADDED);
191 CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
193 /* and now from the 1st notify */
194 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
195 CHECK_STATUS(status, NT_STATUS_OK);
196 CHECK_VAL(notify.out.num_changes, 1);
197 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
198 CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
200 /* (3rd notify) this notify will only see the 1st unlink */
201 req = smb_raw_changenotify_send(cli->tree, ¬ify);
203 printf("testing notify on wildcard unlink for %d files\n", count-1);
204 /* (2nd unlink) do a wildcard unlink */
205 status = smbcli_unlink(cli->tree, BASEDIR "\\test*.txt");
206 CHECK_STATUS(status, NT_STATUS_OK);
208 /* recev the 3rd notify */
209 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
210 CHECK_STATUS(status, NT_STATUS_OK);
211 CHECK_VAL(notify.out.num_changes, 1);
212 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
213 CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
215 /* and we now see the rest of the unlink calls on both directory handles */
216 notify.in.file.fnum = fnum;
217 req = smb_raw_changenotify_send(cli->tree, ¬ify);
218 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
219 CHECK_STATUS(status, NT_STATUS_OK);
220 CHECK_VAL(notify.out.num_changes, count-1);
221 for (i=0;i<notify.out.num_changes;i++) {
222 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_REMOVED);
224 notify.in.file.fnum = fnum2;
225 req = smb_raw_changenotify_send(cli->tree, ¬ify);
226 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
227 CHECK_STATUS(status, NT_STATUS_OK);
228 CHECK_VAL(notify.out.num_changes, count-1);
229 for (i=0;i<notify.out.num_changes;i++) {
230 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_REMOVED);
233 printf("testing if a close() on the dir handle triggers the notify reply\n");
235 notify.in.file.fnum = fnum;
236 req = smb_raw_changenotify_send(cli->tree, ¬ify);
238 cl.close.level = RAW_CLOSE_CLOSE;
239 cl.close.in.file.fnum = fnum;
240 cl.close.in.write_time = 0;
241 status = smb_raw_close(cli->tree, &cl);
242 CHECK_STATUS(status, NT_STATUS_OK);
244 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
245 CHECK_STATUS(status, NT_STATUS_OK);
246 CHECK_VAL(notify.out.num_changes, 0);
249 smb_raw_exit(cli->session);
255 testing of recursive change notify
257 static BOOL test_notify_recursive(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
261 struct smb_notify notify;
264 struct smbcli_request *req1, *req2;
266 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
269 get a handle on the directory
271 io.generic.level = RAW_OPEN_NTCREATEX;
272 io.ntcreatex.in.root_fid = 0;
273 io.ntcreatex.in.flags = 0;
274 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
275 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
276 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
277 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
278 io.ntcreatex.in.alloc_size = 0;
279 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
280 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
281 io.ntcreatex.in.security_flags = 0;
282 io.ntcreatex.in.fname = BASEDIR;
284 status = smb_raw_open(cli->tree, mem_ctx, &io);
285 CHECK_STATUS(status, NT_STATUS_OK);
286 fnum = io.ntcreatex.out.file.fnum;
288 /* ask for a change notify, on file or directory name
289 changes. Setup both with and without recursion */
290 notify.in.buffer_size = 1000;
291 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
292 notify.in.file.fnum = fnum;
294 notify.in.recursive = True;
295 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
297 notify.in.recursive = False;
298 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
300 /* cancel initial requests so the buffer is setup */
301 smb_raw_ntcancel(req1);
302 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
303 CHECK_STATUS(status, NT_STATUS_CANCELLED);
305 smb_raw_ntcancel(req2);
306 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
307 CHECK_STATUS(status, NT_STATUS_CANCELLED);
309 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
310 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname1");
311 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name\\subname2");
312 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname1", BASEDIR "\\subdir-name\\subname1-r");
313 smbcli_rename(cli->tree, BASEDIR "\\subdir-name\\subname2", BASEDIR "\\subname2-r");
314 smbcli_rename(cli->tree, BASEDIR "\\subname2-r", BASEDIR "\\subname3-r");
316 notify.in.completion_filter = 0;
317 notify.in.recursive = True;
318 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
320 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name\\subname1-r");
321 smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
322 smbcli_rmdir(cli->tree, BASEDIR "\\subname3-r");
324 notify.in.recursive = False;
325 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
327 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
328 CHECK_STATUS(status, NT_STATUS_OK);
330 CHECK_VAL(notify.out.num_changes, 9);
331 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
332 CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
333 CHECK_VAL(notify.out.changes[1].action, NOTIFY_ACTION_ADDED);
334 CHECK_WSTR(notify.out.changes[1].name, "subdir-name\\subname1", STR_UNICODE);
335 CHECK_VAL(notify.out.changes[2].action, NOTIFY_ACTION_ADDED);
336 CHECK_WSTR(notify.out.changes[2].name, "subdir-name\\subname2", STR_UNICODE);
337 CHECK_VAL(notify.out.changes[3].action, NOTIFY_ACTION_OLD_NAME);
338 CHECK_WSTR(notify.out.changes[3].name, "subdir-name\\subname1", STR_UNICODE);
339 CHECK_VAL(notify.out.changes[4].action, NOTIFY_ACTION_NEW_NAME);
340 CHECK_WSTR(notify.out.changes[4].name, "subdir-name\\subname1-r", STR_UNICODE);
342 CHECK_VAL(notify.out.changes[5].action, NOTIFY_ACTION_REMOVED);
343 CHECK_WSTR(notify.out.changes[5].name, "subdir-name\\subname2", STR_UNICODE);
344 CHECK_VAL(notify.out.changes[6].action, NOTIFY_ACTION_ADDED);
345 CHECK_WSTR(notify.out.changes[6].name, "subname2-r", STR_UNICODE);
347 CHECK_VAL(notify.out.changes[7].action, NOTIFY_ACTION_OLD_NAME);
348 CHECK_WSTR(notify.out.changes[7].name, "subname2-r", STR_UNICODE);
349 CHECK_VAL(notify.out.changes[8].action, NOTIFY_ACTION_NEW_NAME);
350 CHECK_WSTR(notify.out.changes[8].name, "subname3-r", STR_UNICODE);
352 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
353 CHECK_STATUS(status, NT_STATUS_OK);
355 CHECK_VAL(notify.out.num_changes, 3);
356 CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
357 CHECK_WSTR(notify.out.changes[0].name, "subdir-name\\subname1-r", STR_UNICODE);
358 CHECK_VAL(notify.out.changes[1].action, NOTIFY_ACTION_REMOVED);
359 CHECK_WSTR(notify.out.changes[1].name, "subdir-name", STR_UNICODE);
360 CHECK_VAL(notify.out.changes[2].action, NOTIFY_ACTION_REMOVED);
361 CHECK_WSTR(notify.out.changes[2].name, "subname3-r", STR_UNICODE);
364 smb_raw_exit(cli->session);
369 basic testing of change notify on files
371 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
377 struct smb_notify notify;
378 struct smbcli_request *req;
380 const char *fname = BASEDIR "\\file.txt";
382 printf("TESTING CHANGE NOTIFY ON FILES\n");
384 io.generic.level = RAW_OPEN_NTCREATEX;
385 io.ntcreatex.in.root_fid = 0;
386 io.ntcreatex.in.flags = 0;
387 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
388 io.ntcreatex.in.create_options = 0;
389 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
390 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
391 io.ntcreatex.in.alloc_size = 0;
392 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
393 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
394 io.ntcreatex.in.security_flags = 0;
395 io.ntcreatex.in.fname = fname;
396 status = smb_raw_open(cli->tree, mem_ctx, &io);
397 CHECK_STATUS(status, NT_STATUS_OK);
398 fnum = io.ntcreatex.out.file.fnum;
400 /* ask for a change notify,
401 on file or directory name changes */
402 notify.in.file.fnum = fnum;
403 notify.in.buffer_size = 1000;
404 notify.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
405 notify.in.recursive = False;
407 printf("testing if notifies on file handles are invalid (should be)\n");
409 req = smb_raw_changenotify_send(cli->tree, ¬ify);
410 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
411 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
413 cl.close.level = RAW_CLOSE_CLOSE;
414 cl.close.in.file.fnum = fnum;
415 cl.close.in.write_time = 0;
416 status = smb_raw_close(cli->tree, &cl);
417 CHECK_STATUS(status, NT_STATUS_OK);
419 status = smbcli_unlink(cli->tree, fname);
420 CHECK_STATUS(status, NT_STATUS_OK);
423 smb_raw_exit(cli->session);
428 basic testing of change notifies followed by a tdis
430 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
434 struct smb_notify notify;
437 struct smbcli_request *req;
438 struct smbcli_state *cli = NULL;
440 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
442 if (!torture_open_connection(&cli)) {
447 get a handle on the directory
449 io.generic.level = RAW_OPEN_NTCREATEX;
450 io.ntcreatex.in.root_fid = 0;
451 io.ntcreatex.in.flags = 0;
452 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
453 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
454 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
455 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
456 io.ntcreatex.in.alloc_size = 0;
457 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
458 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
459 io.ntcreatex.in.security_flags = 0;
460 io.ntcreatex.in.fname = BASEDIR;
462 status = smb_raw_open(cli->tree, mem_ctx, &io);
463 CHECK_STATUS(status, NT_STATUS_OK);
464 fnum = io.ntcreatex.out.file.fnum;
466 /* ask for a change notify,
467 on file or directory name changes */
468 notify.in.buffer_size = 1000;
469 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
470 notify.in.file.fnum = fnum;
471 notify.in.recursive = True;
473 req = smb_raw_changenotify_send(cli->tree, ¬ify);
475 status = smbcli_tdis(cli);
476 CHECK_STATUS(status, NT_STATUS_OK);
478 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
479 CHECK_STATUS(status, NT_STATUS_OK);
480 CHECK_VAL(notify.out.num_changes, 0);
483 torture_close_connection(cli);
488 basic testing of change notifies followed by a exit
490 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
494 struct smb_notify notify;
497 struct smbcli_request *req;
498 struct smbcli_state *cli = NULL;
500 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
502 if (!torture_open_connection(&cli)) {
507 get a handle on the directory
509 io.generic.level = RAW_OPEN_NTCREATEX;
510 io.ntcreatex.in.root_fid = 0;
511 io.ntcreatex.in.flags = 0;
512 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
513 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
514 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
515 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
516 io.ntcreatex.in.alloc_size = 0;
517 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
518 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
519 io.ntcreatex.in.security_flags = 0;
520 io.ntcreatex.in.fname = BASEDIR;
522 status = smb_raw_open(cli->tree, mem_ctx, &io);
523 CHECK_STATUS(status, NT_STATUS_OK);
524 fnum = io.ntcreatex.out.file.fnum;
526 /* ask for a change notify,
527 on file or directory name changes */
528 notify.in.buffer_size = 1000;
529 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
530 notify.in.file.fnum = fnum;
531 notify.in.recursive = True;
533 req = smb_raw_changenotify_send(cli->tree, ¬ify);
535 status = smb_raw_exit(cli->session);
536 CHECK_STATUS(status, NT_STATUS_OK);
538 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
539 CHECK_STATUS(status, NT_STATUS_OK);
540 CHECK_VAL(notify.out.num_changes, 0);
543 torture_close_connection(cli);
548 basic testing of change notifies followed by a ulogoff
550 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
554 struct smb_notify notify;
557 struct smbcli_request *req;
558 struct smbcli_state *cli = NULL;
560 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
562 if (!torture_open_connection(&cli)) {
567 get a handle on the directory
569 io.generic.level = RAW_OPEN_NTCREATEX;
570 io.ntcreatex.in.root_fid = 0;
571 io.ntcreatex.in.flags = 0;
572 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
573 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
574 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
575 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
576 io.ntcreatex.in.alloc_size = 0;
577 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
578 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
579 io.ntcreatex.in.security_flags = 0;
580 io.ntcreatex.in.fname = BASEDIR;
582 status = smb_raw_open(cli->tree, mem_ctx, &io);
583 CHECK_STATUS(status, NT_STATUS_OK);
584 fnum = io.ntcreatex.out.file.fnum;
586 /* ask for a change notify,
587 on file or directory name changes */
588 notify.in.buffer_size = 1000;
589 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
590 notify.in.file.fnum = fnum;
591 notify.in.recursive = True;
593 req = smb_raw_changenotify_send(cli->tree, ¬ify);
595 status = smb_raw_ulogoff(cli->session);
596 CHECK_STATUS(status, NT_STATUS_OK);
598 status = smb_raw_changenotify_recv(req, mem_ctx, ¬ify);
599 CHECK_STATUS(status, NT_STATUS_OK);
600 CHECK_VAL(notify.out.num_changes, 0);
603 torture_close_connection(cli);
609 test setting up two change notify requests on one handle
611 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
615 struct smb_notify notify;
618 struct smbcli_request *req1, *req2;
620 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
623 get a handle on the directory
625 io.generic.level = RAW_OPEN_NTCREATEX;
626 io.ntcreatex.in.root_fid = 0;
627 io.ntcreatex.in.flags = 0;
628 io.ntcreatex.in.access_mask = SEC_FILE_ALL;
629 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
630 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
631 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
632 io.ntcreatex.in.alloc_size = 0;
633 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
634 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
635 io.ntcreatex.in.security_flags = 0;
636 io.ntcreatex.in.fname = BASEDIR;
638 status = smb_raw_open(cli->tree, mem_ctx, &io);
639 CHECK_STATUS(status, NT_STATUS_OK);
640 fnum = io.ntcreatex.out.file.fnum;
642 /* ask for a change notify,
643 on file or directory name changes */
644 notify.in.buffer_size = 1000;
645 notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
646 notify.in.file.fnum = fnum;
647 notify.in.recursive = True;
649 req1 = smb_raw_changenotify_send(cli->tree, ¬ify);
650 req2 = smb_raw_changenotify_send(cli->tree, ¬ify);
652 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
654 status = smb_raw_changenotify_recv(req1, mem_ctx, ¬ify);
655 CHECK_STATUS(status, NT_STATUS_OK);
656 CHECK_VAL(notify.out.num_changes, 1);
657 CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
659 smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
661 status = smb_raw_changenotify_recv(req2, mem_ctx, ¬ify);
662 CHECK_STATUS(status, NT_STATUS_OK);
663 CHECK_VAL(notify.out.num_changes, 1);
664 CHECK_WSTR(notify.out.changes[0].name, "subdir-name2", STR_UNICODE);
667 smb_raw_exit(cli->session);
672 basic testing of change notify
674 BOOL torture_raw_notify(struct torture_context *torture)
676 struct smbcli_state *cli;
680 if (!torture_open_connection(&cli)) {
684 mem_ctx = talloc_init("torture_raw_notify");
686 if (!torture_setup_dir(cli, BASEDIR)) {
690 ret &= test_notify_dir(cli, mem_ctx);
691 ret &= test_notify_recursive(cli, mem_ctx);
692 ret &= test_notify_file(cli, mem_ctx);
693 ret &= test_notify_tdis(mem_ctx);
694 ret &= test_notify_exit(mem_ctx);
695 ret &= test_notify_ulogoff(mem_ctx);
696 ret &= test_notify_double(cli, mem_ctx);
698 smb_raw_exit(cli->session);
699 smbcli_deltree(cli->tree, BASEDIR);
700 torture_close_connection(cli);
701 talloc_free(mem_ctx);