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_VAL(v, correct) do { \
31 if ((v) != (correct)) { \
32 printf("(%d) wrong value for %s 0x%x should be 0x%x\n", \
33 __LINE__, #v, (int)v, (int)correct); \
38 #define CHECK_WSTR(field, value, flags) do { \
39 if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli->transport)) { \
40 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
45 #define CHECK_WSTR2(tctx, field, value, flags) \
47 if (!field.s || strcmp(field.s, value) || \
48 wire_bad_flags(&field, flags, cli->transport)) { \
49 torture_result(tctx, TORTURE_FAIL, \
50 "(%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 torture_context
*mem_ctx
,
58 struct smbcli_state
*cli
,
59 struct smbcli_state
*cli2
)
63 union smb_notify notify
;
66 int i
, count
, fnum
, fnum2
;
67 struct smbcli_request
*req
, *req2
;
68 extern int torture_numops
;
70 printf("TESTING CHANGE NOTIFY ON DIRECTORIES\n");
72 if (!torture_setup_dir(cli
, BASEDIR
)) {
77 get a handle on the directory
79 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
80 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
81 io
.ntcreatex
.in
.flags
= 0;
82 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
83 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
84 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
85 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
86 io
.ntcreatex
.in
.alloc_size
= 0;
87 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
88 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
89 io
.ntcreatex
.in
.security_flags
= 0;
90 io
.ntcreatex
.in
.fname
= BASEDIR
;
92 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
93 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
95 fnum
= io
.ntcreatex
.out
.file
.fnum
;
97 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
98 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
100 fnum2
= io
.ntcreatex
.out
.file
.fnum
;
102 /* ask for a change notify,
103 on file or directory name changes */
104 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
105 notify
.nttrans
.in
.buffer_size
= 1000;
106 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
107 notify
.nttrans
.in
.file
.fnum
= fnum
;
108 notify
.nttrans
.in
.recursive
= true;
110 printf("Testing notify cancel\n");
112 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
113 smb_raw_ntcancel(req
);
114 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
115 torture_assert_ntstatus_equal_goto(mem_ctx
, status
, NT_STATUS_CANCELLED
,
117 "smb_raw_changenotify_recv");
119 printf("Testing notify mkdir\n");
121 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
122 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
124 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
125 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
126 "smb_raw_changenotify_recv");
128 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
129 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
130 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
132 printf("Testing notify rmdir\n");
134 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
135 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
137 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
138 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
139 "smb_raw_changenotify_recv");
140 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
141 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
142 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
144 printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
146 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
147 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
148 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
149 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
151 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
152 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
153 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
154 "smb_raw_changenotify_recv");
155 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 4);
156 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
157 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
158 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_REMOVED
);
159 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name", STR_UNICODE
);
160 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_ADDED
);
161 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subdir-name", STR_UNICODE
);
162 CHECK_VAL(notify
.nttrans
.out
.changes
[3].action
, NOTIFY_ACTION_REMOVED
);
163 CHECK_WSTR(notify
.nttrans
.out
.changes
[3].name
, "subdir-name", STR_UNICODE
);
165 count
= torture_numops
;
166 printf("Testing buffered notify on create of %d files\n", count
);
167 for (i
=0;i
<count
;i
++) {
168 char *fname
= talloc_asprintf(cli
, BASEDIR
"\\test%d.txt", i
);
169 int fnum3
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
171 printf("Failed to create %s - %s\n",
172 fname
, smbcli_errstr(cli
->tree
));
177 smbcli_close(cli
->tree
, fnum3
);
180 /* (1st notify) setup a new notify on a different directory handle.
181 This new notify won't see the events above. */
182 notify
.nttrans
.in
.file
.fnum
= fnum2
;
183 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
185 /* (2nd notify) whereas this notify will see the above buffered events,
186 and it directly returns the buffered events */
187 notify
.nttrans
.in
.file
.fnum
= fnum
;
188 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
190 status
= smbcli_unlink(cli
->tree
, BASEDIR
"\\nonexistent.txt");
191 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
192 NT_STATUS_OBJECT_NAME_NOT_FOUND
,
196 /* (1st unlink) as the 2nd notify directly returns,
197 this unlink is only seen by the 1st notify and
198 the 3rd notify (later) */
199 printf("Testing notify on unlink for the first file\n");
200 status
= smbcli_unlink(cli2
->tree
, BASEDIR
"\\test0.txt");
201 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
204 /* receive the reply from the 2nd notify */
205 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
206 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
207 "smb_raw_changenotify_recv");
209 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
);
210 for (i
=1;i
<count
;i
++) {
211 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_ADDED
);
213 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "test0.txt", STR_UNICODE
);
215 printf("and now from the 1st notify\n");
216 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
217 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
218 "smb_raw_changenotify_recv");
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 printf("(3rd notify) this notify will only see the 1st unlink\n");
224 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
226 status
= smbcli_unlink(cli
->tree
, BASEDIR
"\\nonexistent.txt");
227 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
228 NT_STATUS_OBJECT_NAME_NOT_FOUND
,
232 printf("Testing notify on wildcard unlink for %d files\n", count
-1);
233 /* (2nd unlink) do a wildcard unlink */
234 status
= smbcli_unlink(cli2
->tree
, BASEDIR
"\\test*.txt");
235 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
236 "smb_raw_changenotify_recv");
238 /* receive the 3rd notify */
239 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
240 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
241 "smb_raw_changenotify_recv");
242 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
243 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
244 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "test0.txt", STR_UNICODE
);
246 /* and we now see the rest of the unlink calls on both directory handles */
247 notify
.nttrans
.in
.file
.fnum
= fnum
;
249 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
250 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
251 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
252 "smb_raw_changenotify_recv");
253 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
-1);
254 for (i
=0;i
<notify
.nttrans
.out
.num_changes
;i
++) {
255 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_REMOVED
);
257 notify
.nttrans
.in
.file
.fnum
= fnum2
;
258 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
259 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
260 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
261 "smb_raw_changenotify_recv");
262 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
-1);
263 for (i
=0;i
<notify
.nttrans
.out
.num_changes
;i
++) {
264 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_REMOVED
);
267 printf("Testing if a close() on the dir handle triggers the notify reply\n");
269 notify
.nttrans
.in
.file
.fnum
= fnum
;
270 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
272 cl
.close
.level
= RAW_CLOSE_CLOSE
;
273 cl
.close
.in
.file
.fnum
= fnum
;
274 cl
.close
.in
.write_time
= 0;
275 status
= smb_raw_close(cli
->tree
, &cl
);
276 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
279 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
280 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
281 "smb_raw_changenotify_recv");
282 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
285 smb_raw_exit(cli
->session
);
286 smbcli_deltree(cli
->tree
, BASEDIR
);
291 * Check notify reply for a rename action. Not sure if this is a valid thing
292 * to do, but depending on timing between inotify and messaging we get the
293 * add/remove/modify in any order. This routines tries to find the action/name
294 * pair in any of the three following notify_changes.
297 static bool check_rename_reply(struct smbcli_state
*cli
,
299 struct notify_changes
*actions
,
300 uint32_t action
, const char *name
)
304 for (i
=0; i
<3; i
++) {
305 if (actions
[i
].action
== action
) {
306 if ((actions
[i
].name
.s
== NULL
)
307 || (strcmp(actions
[i
].name
.s
, name
) != 0)
308 || (wire_bad_flags(&actions
[i
].name
, STR_UNICODE
,
310 printf("(%d) name [%s] != %s\n", line
,
311 actions
[i
].name
.s
, name
);
318 printf("(%d) expected action %d, not found\n", line
, action
);
323 testing of recursive change notify
325 static bool test_notify_recursive(struct torture_context
*mem_ctx
,
326 struct smbcli_state
*cli
,
327 struct smbcli_state
*cli2
)
331 union smb_notify notify
;
334 struct smbcli_request
*req1
, *req2
;
336 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
338 if (!torture_setup_dir(cli
, BASEDIR
)) {
343 get a handle on the directory
345 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
346 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
347 io
.ntcreatex
.in
.flags
= 0;
348 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
349 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
350 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
351 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
352 io
.ntcreatex
.in
.alloc_size
= 0;
353 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
354 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
355 io
.ntcreatex
.in
.security_flags
= 0;
356 io
.ntcreatex
.in
.fname
= BASEDIR
;
358 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
359 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
361 fnum
= io
.ntcreatex
.out
.file
.fnum
;
363 /* ask for a change notify, on file or directory name
364 changes. Setup both with and without recursion */
365 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
366 notify
.nttrans
.in
.buffer_size
= 1000;
367 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
| FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_CREATION
;
368 notify
.nttrans
.in
.file
.fnum
= fnum
;
370 notify
.nttrans
.in
.recursive
= true;
371 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
373 notify
.nttrans
.in
.recursive
= false;
374 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
376 /* cancel initial requests so the buffer is setup */
377 smb_raw_ntcancel(req1
);
378 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
379 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
382 "smb_raw_changenotify_recv");
384 smb_raw_ntcancel(req2
);
385 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
386 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
389 "smb_raw_changenotify_recv");
392 * Make notifies a bit more interesting in a cluster by doing
393 * the changes against different nodes with --unclist
395 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
396 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name\\subname1");
397 smbcli_close(cli
->tree
,
398 smbcli_open(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", O_CREAT
, 0));
399 smbcli_rename(cli2
->tree
, BASEDIR
"\\subdir-name\\subname1",
400 BASEDIR
"\\subdir-name\\subname1-r");
401 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", BASEDIR
"\\subname2-r");
402 smbcli_rename(cli2
->tree
, BASEDIR
"\\subname2-r",
403 BASEDIR
"\\subname3-r");
405 notify
.nttrans
.in
.completion_filter
= 0;
406 notify
.nttrans
.in
.recursive
= true;
408 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
410 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1-r");
411 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
412 smbcli_unlink(cli
->tree
, BASEDIR
"\\subname3-r");
414 notify
.nttrans
.in
.recursive
= false;
415 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
417 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
418 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
419 "smb_raw_changenotify_recv");
421 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 11);
422 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
423 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
424 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_ADDED
);
425 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name\\subname1", STR_UNICODE
);
426 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_ADDED
);
427 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subdir-name\\subname2", STR_UNICODE
);
428 CHECK_VAL(notify
.nttrans
.out
.changes
[3].action
, NOTIFY_ACTION_OLD_NAME
);
429 CHECK_WSTR(notify
.nttrans
.out
.changes
[3].name
, "subdir-name\\subname1", STR_UNICODE
);
430 CHECK_VAL(notify
.nttrans
.out
.changes
[4].action
, NOTIFY_ACTION_NEW_NAME
);
431 CHECK_WSTR(notify
.nttrans
.out
.changes
[4].name
, "subdir-name\\subname1-r", STR_UNICODE
);
433 ret
&= check_rename_reply(
434 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
435 NOTIFY_ACTION_ADDED
, "subname2-r");
436 ret
&= check_rename_reply(
437 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
438 NOTIFY_ACTION_REMOVED
, "subdir-name\\subname2");
439 ret
&= check_rename_reply(
440 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
441 NOTIFY_ACTION_MODIFIED
, "subname2-r");
443 ret
&= check_rename_reply(
444 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
445 NOTIFY_ACTION_OLD_NAME
, "subname2-r");
446 ret
&= check_rename_reply(
447 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
448 NOTIFY_ACTION_NEW_NAME
, "subname3-r");
449 ret
&= check_rename_reply(
450 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
451 NOTIFY_ACTION_MODIFIED
, "subname3-r");
457 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
458 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
459 "smb_raw_changenotify_recv");
461 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 3);
462 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
463 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name\\subname1-r", STR_UNICODE
);
464 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_REMOVED
);
465 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name", STR_UNICODE
);
466 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_REMOVED
);
467 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subname3-r", STR_UNICODE
);
470 smb_raw_exit(cli
->session
);
471 smbcli_deltree(cli
->tree
, BASEDIR
);
476 testing of change notify mask change
478 static bool test_notify_mask_change(struct torture_context
*mem_ctx
,
479 struct smbcli_state
*cli
)
483 union smb_notify notify
;
486 struct smbcli_request
*req1
, *req2
;
488 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
490 if (!torture_setup_dir(cli
, BASEDIR
)) {
495 get a handle on the directory
497 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
498 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
499 io
.ntcreatex
.in
.flags
= 0;
500 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
501 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
502 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
503 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
504 io
.ntcreatex
.in
.alloc_size
= 0;
505 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
506 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
507 io
.ntcreatex
.in
.security_flags
= 0;
508 io
.ntcreatex
.in
.fname
= BASEDIR
;
510 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
511 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
513 fnum
= io
.ntcreatex
.out
.file
.fnum
;
515 /* ask for a change notify, on file or directory name
516 changes. Setup both with and without recursion */
517 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
518 notify
.nttrans
.in
.buffer_size
= 1000;
519 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
520 notify
.nttrans
.in
.file
.fnum
= fnum
;
522 notify
.nttrans
.in
.recursive
= true;
523 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
525 notify
.nttrans
.in
.recursive
= false;
526 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
528 /* cancel initial requests so the buffer is setup */
529 smb_raw_ntcancel(req1
);
530 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
531 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
534 "smb_raw_changenotify_recv");
536 smb_raw_ntcancel(req2
);
537 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
538 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
541 "smb_raw_changenotify_recv");
543 notify
.nttrans
.in
.recursive
= true;
544 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
546 /* Set to hidden then back again. */
547 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));
548 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);
549 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");
551 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
552 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
553 "smb_raw_changenotify_recv");
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
, "tname1", STR_UNICODE
);
559 /* Now try and change the mask to include other events.
560 * This should not work - once the mask is set on a directory
561 * fnum it seems to be fixed until the fnum is closed. */
563 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
| FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_CREATION
;
564 notify
.nttrans
.in
.recursive
= true;
565 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
567 notify
.nttrans
.in
.recursive
= false;
568 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
570 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
571 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1");
572 smbcli_close(cli
->tree
,
573 smbcli_open(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", O_CREAT
, 0));
574 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname1", BASEDIR
"\\subdir-name\\subname1-r");
575 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", BASEDIR
"\\subname2-r");
576 smbcli_rename(cli
->tree
, BASEDIR
"\\subname2-r", BASEDIR
"\\subname3-r");
578 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1-r");
579 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
580 smbcli_unlink(cli
->tree
, BASEDIR
"\\subname3-r");
582 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
583 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
584 "smb_raw_changenotify_recv");
586 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
587 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
588 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subname2-r", STR_UNICODE
);
590 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
591 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
592 "smb_raw_changenotify_recv");
594 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
595 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
596 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subname3-r", STR_UNICODE
);
603 smb_raw_exit(cli
->session
);
604 smbcli_deltree(cli
->tree
, BASEDIR
);
610 testing of mask bits for change notify
612 static bool test_notify_mask(struct torture_context
*tctx
,
613 struct smbcli_state
*cli
,
614 struct smbcli_state
*cli2
)
618 union smb_notify notify
;
620 union smb_chkpath chkpath
;
628 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
630 if (!torture_setup_dir(cli
, BASEDIR
)) {
634 tv
= timeval_current_ofs(1000, 0);
635 t
= timeval_to_nttime(&tv
);
638 get a handle on the directory
640 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
641 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
642 io
.ntcreatex
.in
.flags
= 0;
643 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
644 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
645 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
646 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
647 io
.ntcreatex
.in
.alloc_size
= 0;
648 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
649 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
650 io
.ntcreatex
.in
.security_flags
= 0;
651 io
.ntcreatex
.in
.fname
= BASEDIR
;
653 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
654 notify
.nttrans
.in
.buffer_size
= 1000;
655 notify
.nttrans
.in
.recursive
= true;
657 chkpath
.chkpath
.in
.path
= "\\";
659 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
661 smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
662 do { for (mask=i=0;i<32;i++) { \
663 struct smbcli_request *req; \
664 status = smb_raw_open(cli->tree, tctx, &io); \
665 torture_assert_ntstatus_ok_goto(tctx, status, ret, done, \
667 fnum = io.ntcreatex.out.file.fnum; \
669 notify.nttrans.in.file.fnum = fnum; \
670 notify.nttrans.in.completion_filter = (1<<i); \
671 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
672 smb_raw_chkpath(cli->tree, &chkpath); \
674 smb_msleep(200); smb_raw_ntcancel(req); \
675 status = smb_raw_changenotify_recv(req, tctx, ¬ify); \
677 smbcli_close(cli->tree, fnum); \
678 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
679 torture_assert_ntstatus_ok_goto(tctx, status, ret, done, \
681 /* special case to cope with file rename behaviour */ \
682 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
683 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
684 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
685 Action == NOTIFY_ACTION_OLD_NAME) { \
686 printf("(rename file special handling OK)\n"); \
687 } else if (nchanges != notify.nttrans.out.num_changes) { \
688 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
689 notify.nttrans.out.num_changes, \
691 notify.nttrans.out.changes[0].action, \
692 notify.nttrans.in.completion_filter); \
694 } else if (notify.nttrans.out.changes[0].action != Action) { \
695 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
696 notify.nttrans.out.num_changes, \
697 notify.nttrans.out.changes[0].action, \
699 notify.nttrans.in.completion_filter); \
701 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
702 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
703 notify.nttrans.out.num_changes, \
704 notify.nttrans.out.changes[0].action, \
705 notify.nttrans.in.completion_filter, \
706 notify.nttrans.out.changes[0].name.s); \
711 if ((expected) != mask) { \
712 if (((expected) & ~mask) != 0) { \
713 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
717 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
724 printf("Testing mkdir\n");
725 NOTIFY_MASK_TEST("Testing mkdir",;,
726 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
727 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\tname1");,
729 FILE_NOTIFY_CHANGE_DIR_NAME
, 1);
731 printf("Testing create file\n");
732 NOTIFY_MASK_TEST("Testing create file",;,
733 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
734 smbcli_unlink(cli2
->tree
, BASEDIR
"\\tname1");,
736 FILE_NOTIFY_CHANGE_FILE_NAME
, 1);
738 printf("Testing unlink\n");
739 NOTIFY_MASK_TEST("Testing unlink",
740 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
741 smbcli_unlink(cli2
->tree
, BASEDIR
"\\tname1");,
743 NOTIFY_ACTION_REMOVED
,
744 FILE_NOTIFY_CHANGE_FILE_NAME
, 1);
746 printf("Testing rmdir\n");
747 NOTIFY_MASK_TEST("Testing rmdir",
748 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
749 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\tname1");,
751 NOTIFY_ACTION_REMOVED
,
752 FILE_NOTIFY_CHANGE_DIR_NAME
, 1);
754 printf("Testing rename file\n");
755 NOTIFY_MASK_TEST("Testing rename file",
756 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
757 smbcli_rename(cli2
->tree
, BASEDIR
"\\tname1", BASEDIR
"\\tname2");,
758 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname2");,
759 NOTIFY_ACTION_OLD_NAME
,
760 FILE_NOTIFY_CHANGE_FILE_NAME
|FILE_NOTIFY_CHANGE_ATTRIBUTES
|FILE_NOTIFY_CHANGE_CREATION
, 2);
762 printf("Testing rename dir\n");
763 NOTIFY_MASK_TEST("Testing rename dir",
764 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
765 smbcli_rename(cli2
->tree
, BASEDIR
"\\tname1", BASEDIR
"\\tname2");,
766 smbcli_rmdir(cli
->tree
, BASEDIR
"\\tname2");,
767 NOTIFY_ACTION_OLD_NAME
,
768 FILE_NOTIFY_CHANGE_DIR_NAME
, 2);
770 printf("Testing set path attribute\n");
771 NOTIFY_MASK_TEST("Testing set path attribute",
772 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
773 smbcli_setatr(cli2
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);,
774 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
775 NOTIFY_ACTION_MODIFIED
,
776 FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
778 printf("Testing set path write time\n");
779 NOTIFY_MASK_TEST("Testing set path write time",
780 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
781 smbcli_setatr(cli2
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_NORMAL
, 1000);,
782 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
783 NOTIFY_ACTION_MODIFIED
,
784 FILE_NOTIFY_CHANGE_LAST_WRITE
, 1);
786 printf("Testing set file attribute\n");
787 NOTIFY_MASK_TEST("Testing set file attribute",
788 fnum2
= create_complex_file(cli2
, tctx
, BASEDIR
"\\tname1");,
789 smbcli_fsetatr(cli2
->tree
, fnum2
, FILE_ATTRIBUTE_HIDDEN
, 0, 0, 0, 0);,
790 (smbcli_close(cli2
->tree
, fnum2
), smbcli_unlink(cli2
->tree
, BASEDIR
"\\tname1"));,
791 NOTIFY_ACTION_MODIFIED
,
792 FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
794 if (torture_setting_bool(tctx
, "samba3", false)) {
795 printf("Samba3 does not yet support create times "
799 printf("Testing set file create time\n");
800 NOTIFY_MASK_TEST("Testing set file create time",
801 fnum2
= create_complex_file(cli
, tctx
,
802 BASEDIR
"\\tname1");,
803 smbcli_fsetatr(cli
->tree
, fnum2
, 0, t
, 0, 0, 0);,
804 (smbcli_close(cli
->tree
, fnum2
),
805 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
806 NOTIFY_ACTION_MODIFIED
,
807 FILE_NOTIFY_CHANGE_CREATION
, 1);
810 printf("Testing set file access time\n");
811 NOTIFY_MASK_TEST("Testing set file access time",
812 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
813 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, t
, 0, 0);,
814 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
815 NOTIFY_ACTION_MODIFIED
,
816 FILE_NOTIFY_CHANGE_LAST_ACCESS
, 1);
818 printf("Testing set file write time\n");
819 NOTIFY_MASK_TEST("Testing set file write time",
820 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
821 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, 0, t
, 0);,
822 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
823 NOTIFY_ACTION_MODIFIED
,
824 FILE_NOTIFY_CHANGE_LAST_WRITE
, 1);
826 printf("Testing set file change time\n");
827 NOTIFY_MASK_TEST("Testing set file change time",
828 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
829 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, 0, 0, t
);,
830 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
831 NOTIFY_ACTION_MODIFIED
,
835 printf("Testing write\n");
836 NOTIFY_MASK_TEST("Testing write",
837 fnum2
= create_complex_file(cli2
, tctx
, BASEDIR
"\\tname1");,
838 smbcli_write(cli2
->tree
, fnum2
, 1, &c
, 10000, 1);,
839 (smbcli_close(cli2
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
840 NOTIFY_ACTION_MODIFIED
,
843 printf("Testing truncate\n");
844 NOTIFY_MASK_TEST("Testing truncate",
845 fnum2
= create_complex_file(cli2
, tctx
, BASEDIR
"\\tname1");,
846 smbcli_ftruncate(cli2
->tree
, fnum2
, 10000);,
847 (smbcli_close(cli2
->tree
, fnum2
), smbcli_unlink(cli2
->tree
, BASEDIR
"\\tname1"));,
848 NOTIFY_ACTION_MODIFIED
,
849 FILE_NOTIFY_CHANGE_SIZE
| FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
852 smb_raw_exit(cli
->session
);
853 smbcli_deltree(cli
->tree
, BASEDIR
);
858 basic testing of change notify on files
860 static bool test_notify_file(struct torture_context
*mem_ctx
,
861 struct smbcli_state
*cli
)
867 union smb_notify notify
;
868 struct smbcli_request
*req
;
870 const char *fname
= BASEDIR
"\\file.txt";
872 printf("TESTING CHANGE NOTIFY ON FILES\n");
874 if (!torture_setup_dir(cli
, BASEDIR
)) {
878 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
879 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
880 io
.ntcreatex
.in
.flags
= 0;
881 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
882 io
.ntcreatex
.in
.create_options
= 0;
883 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
884 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
885 io
.ntcreatex
.in
.alloc_size
= 0;
886 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
887 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
888 io
.ntcreatex
.in
.security_flags
= 0;
889 io
.ntcreatex
.in
.fname
= fname
;
890 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
891 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
893 fnum
= io
.ntcreatex
.out
.file
.fnum
;
895 /* ask for a change notify,
896 on file or directory name changes */
897 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
898 notify
.nttrans
.in
.file
.fnum
= fnum
;
899 notify
.nttrans
.in
.buffer_size
= 1000;
900 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_STREAM_NAME
;
901 notify
.nttrans
.in
.recursive
= false;
903 printf("Testing if notifies on file handles are invalid (should be)\n");
905 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
906 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
907 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
908 NT_STATUS_INVALID_PARAMETER
,
910 "smb_raw_changenotify_recv");
912 cl
.close
.level
= RAW_CLOSE_CLOSE
;
913 cl
.close
.in
.file
.fnum
= fnum
;
914 cl
.close
.in
.write_time
= 0;
915 status
= smb_raw_close(cli
->tree
, &cl
);
916 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
919 status
= smbcli_unlink(cli
->tree
, fname
);
920 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
924 smb_raw_exit(cli
->session
);
925 smbcli_deltree(cli
->tree
, BASEDIR
);
930 basic testing of change notifies followed by a tdis
932 static bool test_notify_tdis(struct torture_context
*tctx
,
933 struct smbcli_state
*cli1
)
937 union smb_notify notify
;
940 struct smbcli_request
*req
;
941 struct smbcli_state
*cli
= NULL
;
943 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
945 if (!torture_setup_dir(cli1
, BASEDIR
)) {
949 if (!torture_open_connection(&cli
, tctx
, 0)) {
954 get a handle on the directory
956 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
957 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
958 io
.ntcreatex
.in
.flags
= 0;
959 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
960 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
961 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
962 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
963 io
.ntcreatex
.in
.alloc_size
= 0;
964 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
965 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
966 io
.ntcreatex
.in
.security_flags
= 0;
967 io
.ntcreatex
.in
.fname
= BASEDIR
;
969 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
970 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
972 fnum
= io
.ntcreatex
.out
.file
.fnum
;
974 /* ask for a change notify,
975 on file or directory name changes */
976 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
977 notify
.nttrans
.in
.buffer_size
= 1000;
978 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
979 notify
.nttrans
.in
.file
.fnum
= fnum
;
980 notify
.nttrans
.in
.recursive
= true;
982 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
984 status
= smbcli_tdis(cli
);
985 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
989 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
990 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
991 "smb_raw_changenotify_recv");
992 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
995 torture_close_connection(cli
);
996 smbcli_deltree(cli1
->tree
, BASEDIR
);
1001 basic testing of change notifies followed by a exit
1003 static bool test_notify_exit(struct torture_context
*tctx
,
1004 struct smbcli_state
*cli1
)
1008 union smb_notify notify
;
1011 struct smbcli_request
*req
;
1012 struct smbcli_state
*cli
= NULL
;
1014 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
1016 if (!torture_setup_dir(cli1
, BASEDIR
)) {
1020 if (!torture_open_connection(&cli
, tctx
, 0)) {
1025 get a handle on the directory
1027 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1028 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1029 io
.ntcreatex
.in
.flags
= 0;
1030 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1031 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1032 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1033 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1034 io
.ntcreatex
.in
.alloc_size
= 0;
1035 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1036 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1037 io
.ntcreatex
.in
.security_flags
= 0;
1038 io
.ntcreatex
.in
.fname
= BASEDIR
;
1040 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1041 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1043 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1045 /* ask for a change notify,
1046 on file or directory name changes */
1047 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1048 notify
.nttrans
.in
.buffer_size
= 1000;
1049 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1050 notify
.nttrans
.in
.file
.fnum
= fnum
;
1051 notify
.nttrans
.in
.recursive
= true;
1053 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1055 status
= smb_raw_exit(cli
->session
);
1056 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1059 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1060 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1061 "smb_raw_changenotify_recv");
1062 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
1065 torture_close_connection(cli
);
1066 smbcli_deltree(cli1
->tree
, BASEDIR
);
1071 basic testing of change notifies followed by a ulogoff
1073 static bool test_notify_ulogoff(struct torture_context
*tctx
,
1074 struct smbcli_state
*cli1
)
1078 union smb_notify notify
;
1081 struct smbcli_request
*req
;
1082 struct smbcli_state
*cli
= NULL
;
1084 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
1086 if (!torture_setup_dir(cli1
, BASEDIR
)) {
1090 if (!torture_open_connection(&cli
, tctx
, 0)) {
1095 get a handle on the directory
1097 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1098 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1099 io
.ntcreatex
.in
.flags
= 0;
1100 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1101 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1102 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1103 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1104 io
.ntcreatex
.in
.alloc_size
= 0;
1105 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1106 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1107 io
.ntcreatex
.in
.security_flags
= 0;
1108 io
.ntcreatex
.in
.fname
= BASEDIR
;
1110 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1111 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1113 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1115 /* ask for a change notify,
1116 on file or directory name changes */
1117 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1118 notify
.nttrans
.in
.buffer_size
= 1000;
1119 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1120 notify
.nttrans
.in
.file
.fnum
= fnum
;
1121 notify
.nttrans
.in
.recursive
= true;
1123 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1125 status
= smb_raw_ulogoff(cli
->session
);
1126 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1129 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1130 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1131 "smb_raw_changenotify_recv");
1132 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
1135 torture_close_connection(cli
);
1136 smbcli_deltree(cli1
->tree
, BASEDIR
);
1140 static void tcp_dis_handler(struct smbcli_transport
*t
, void *p
)
1142 struct smbcli_state
*cli
= (struct smbcli_state
*)p
;
1143 smbcli_transport_dead(cli
->transport
, NT_STATUS_LOCAL_DISCONNECT
);
1144 cli
->transport
= NULL
;
1148 basic testing of change notifies followed by tcp disconnect
1150 static bool test_notify_tcp_dis(struct torture_context
*tctx
,
1151 struct smbcli_state
*cli1
)
1155 union smb_notify notify
;
1158 struct smbcli_request
*req
;
1159 struct smbcli_state
*cli
= NULL
;
1161 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1163 if (!torture_setup_dir(cli1
, BASEDIR
)) {
1167 if (!torture_open_connection(&cli
, tctx
, 0)) {
1172 get a handle on the directory
1174 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1175 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1176 io
.ntcreatex
.in
.flags
= 0;
1177 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1178 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1179 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1180 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1181 io
.ntcreatex
.in
.alloc_size
= 0;
1182 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1183 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1184 io
.ntcreatex
.in
.security_flags
= 0;
1185 io
.ntcreatex
.in
.fname
= BASEDIR
;
1187 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1188 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1190 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1192 /* ask for a change notify,
1193 on file or directory name changes */
1194 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1195 notify
.nttrans
.in
.buffer_size
= 1000;
1196 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1197 notify
.nttrans
.in
.file
.fnum
= fnum
;
1198 notify
.nttrans
.in
.recursive
= true;
1200 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1202 smbcli_transport_idle_handler(cli
->transport
, tcp_dis_handler
, 250, cli
);
1204 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1205 torture_assert_ntstatus_equal_goto(tctx
, status
,
1206 NT_STATUS_LOCAL_DISCONNECT
,
1208 "smb_raw_changenotify_recv");
1211 torture_close_connection(cli
);
1212 smbcli_deltree(cli1
->tree
, BASEDIR
);
1217 test setting up two change notify requests on one handle
1219 static bool test_notify_double(struct torture_context
*mem_ctx
,
1220 struct smbcli_state
*cli
)
1224 union smb_notify notify
;
1227 struct smbcli_request
*req1
, *req2
;
1229 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1231 if (!torture_setup_dir(cli
, BASEDIR
)) {
1235 get a handle on the directory
1237 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1238 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1239 io
.ntcreatex
.in
.flags
= 0;
1240 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1241 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1242 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1243 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1244 io
.ntcreatex
.in
.alloc_size
= 0;
1245 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1246 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1247 io
.ntcreatex
.in
.security_flags
= 0;
1248 io
.ntcreatex
.in
.fname
= BASEDIR
;
1250 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1251 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1253 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1255 /* ask for a change notify,
1256 on file or directory name changes */
1257 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1258 notify
.nttrans
.in
.buffer_size
= 1000;
1259 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1260 notify
.nttrans
.in
.file
.fnum
= fnum
;
1261 notify
.nttrans
.in
.recursive
= true;
1263 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1264 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1266 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1268 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1269 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1270 "smb_raw_changenotify_recv");
1271 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1272 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1274 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name2");
1276 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
1277 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1278 "smb_raw_changenotify_recv");
1279 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1280 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name2", STR_UNICODE
);
1283 smb_raw_exit(cli
->session
);
1284 smbcli_deltree(cli
->tree
, BASEDIR
);
1290 test multiple change notifies at different depths and with/without recursion
1292 static bool test_notify_tree(struct torture_context
*mem_ctx
,
1293 struct smbcli_state
*cli
,
1294 struct smbcli_state
*cli2
)
1297 union smb_notify notify
;
1299 struct smbcli_request
*req
;
1309 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 30 },
1310 {BASEDIR
"\\zqy", true, FILE_NOTIFY_CHANGE_NAME
, 8 },
1311 {BASEDIR
"\\atsy", true, FILE_NOTIFY_CHANGE_NAME
, 4 },
1312 {BASEDIR
"\\abc\\foo", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1313 {BASEDIR
"\\abc\\blah", true, FILE_NOTIFY_CHANGE_NAME
, 13 },
1314 {BASEDIR
"\\abc\\blah", false, FILE_NOTIFY_CHANGE_NAME
, 7 },
1315 {BASEDIR
"\\abc\\blah\\a", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1316 {BASEDIR
"\\abc\\blah\\b", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1317 {BASEDIR
"\\abc\\blah\\c", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1318 {BASEDIR
"\\abc\\fooblah", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1319 {BASEDIR
"\\zqy\\xx", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1320 {BASEDIR
"\\zqy\\yyy", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1321 {BASEDIR
"\\zqy\\..", true, FILE_NOTIFY_CHANGE_NAME
, 40 },
1322 {BASEDIR
, true, FILE_NOTIFY_CHANGE_NAME
, 40 },
1323 {BASEDIR
, false,FILE_NOTIFY_CHANGE_NAME
, 6 },
1324 {BASEDIR
"\\atsy", false,FILE_NOTIFY_CHANGE_NAME
, 4 },
1325 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 24 },
1326 {BASEDIR
"\\abc", false,FILE_NOTIFY_CHANGE_FILE_NAME
, 0 },
1327 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_FILE_NAME
, 0 },
1328 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 24 },
1332 bool all_done
= false;
1334 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1336 if (!torture_setup_dir(cli
, BASEDIR
)) {
1340 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1341 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1342 io
.ntcreatex
.in
.flags
= 0;
1343 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1344 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1345 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1346 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1347 io
.ntcreatex
.in
.alloc_size
= 0;
1348 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
1349 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1350 io
.ntcreatex
.in
.security_flags
= 0;
1352 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1353 notify
.nttrans
.in
.buffer_size
= 20000;
1356 setup the directory tree, and the notify buffer on each directory
1358 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1359 io
.ntcreatex
.in
.fname
= dirs
[i
].path
;
1360 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1361 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1363 dirs
[i
].fnum
= io
.ntcreatex
.out
.file
.fnum
;
1365 notify
.nttrans
.in
.completion_filter
= dirs
[i
].filter
;
1366 notify
.nttrans
.in
.file
.fnum
= dirs
[i
].fnum
;
1367 notify
.nttrans
.in
.recursive
= dirs
[i
].recursive
;
1368 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1369 smb_raw_ntcancel(req
);
1370 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
1371 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
1372 NT_STATUS_CANCELLED
,
1374 "smb_raw_changenotify_recv");
1377 /* trigger 2 events in each dir */
1378 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1379 char *path
= talloc_asprintf(mem_ctx
, "%s\\test.dir", dirs
[i
].path
);
1381 * Make notifies a bit more interesting in a cluster
1382 * by doing the changes against different nodes with
1385 smbcli_mkdir(cli
->tree
, path
);
1386 smbcli_rmdir(cli2
->tree
, path
);
1390 /* give a bit of time for the events to propogate */
1391 tv
= timeval_current();
1394 /* count events that have happened in each dir */
1395 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1396 notify
.nttrans
.in
.file
.fnum
= dirs
[i
].fnum
;
1397 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1398 smb_raw_ntcancel(req
);
1399 notify
.nttrans
.out
.num_changes
= 0;
1400 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
1401 dirs
[i
].counted
+= notify
.nttrans
.out
.num_changes
;
1406 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1407 if (dirs
[i
].counted
!= dirs
[i
].expected
) {
1411 } while (!all_done
&& timeval_elapsed(&tv
) < 20);
1413 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv
));
1415 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1416 if (dirs
[i
].counted
!= dirs
[i
].expected
) {
1417 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1418 i
, dirs
[i
].expected
, dirs
[i
].counted
, dirs
[i
].path
);
1424 run from the back, closing and deleting
1426 for (i
=ARRAY_SIZE(dirs
)-1;i
>=0;i
--) {
1427 smbcli_close(cli
->tree
, dirs
[i
].fnum
);
1428 smbcli_rmdir(cli
->tree
, dirs
[i
].path
);
1432 smb_raw_exit(cli
->session
);
1433 smbcli_deltree(cli
->tree
, BASEDIR
);
1438 Test response when cached server events exceed single NT NOTFIY response
1441 static bool test_notify_overflow(struct torture_context
*mem_ctx
,
1442 struct smbcli_state
*cli
)
1446 union smb_notify notify
;
1450 struct smbcli_request
*req1
;
1453 printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
1455 if (!torture_setup_dir(cli
, BASEDIR
)) {
1459 /* get a handle on the directory */
1460 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1461 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1462 io
.ntcreatex
.in
.flags
= 0;
1463 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1464 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1465 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1466 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1467 NTCREATEX_SHARE_ACCESS_WRITE
;
1468 io
.ntcreatex
.in
.alloc_size
= 0;
1469 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1470 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1471 io
.ntcreatex
.in
.security_flags
= 0;
1472 io
.ntcreatex
.in
.fname
= BASEDIR
;
1474 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1475 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1477 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1479 /* ask for a change notify, on name changes. */
1480 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1481 notify
.nttrans
.in
.buffer_size
= 1000;
1482 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1483 notify
.nttrans
.in
.file
.fnum
= fnum
;
1485 notify
.nttrans
.in
.recursive
= true;
1486 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1488 /* cancel initial requests so the buffer is setup */
1489 smb_raw_ntcancel(req1
);
1490 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1491 torture_assert_ntstatus_equal_goto(mem_ctx
, status
,
1492 NT_STATUS_CANCELLED
,
1494 "smb_raw_changenotify_recv");
1496 /* open a lot of files, filling up the server side notify buffer */
1497 printf("Testing overflowed buffer notify on create of %d files\n",
1499 for (i
=0;i
<count
;i
++) {
1500 char *fname
= talloc_asprintf(cli
, BASEDIR
"\\test%d.txt", i
);
1501 int fnum2
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
,
1504 printf("Failed to create %s - %s\n",
1505 fname
, smbcli_errstr(cli
->tree
));
1510 smbcli_close(cli
->tree
, fnum2
);
1513 /* expect that 0 events will be returned with NT_STATUS_OK */
1514 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1515 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1516 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1517 "smb_raw_changenotify_recv");
1518 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
1521 smb_raw_exit(cli
->session
);
1522 smbcli_deltree(cli
->tree
, BASEDIR
);
1527 Test if notifications are returned for changes to the base directory.
1530 static bool test_notify_basedir(struct torture_context
*mem_ctx
,
1531 struct smbcli_state
*cli
)
1535 union smb_notify notify
;
1538 struct smbcli_request
*req1
;
1540 printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
1542 if (!torture_setup_dir(cli
, BASEDIR
)) {
1546 /* get a handle on the directory */
1547 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1548 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1549 io
.ntcreatex
.in
.flags
= 0;
1550 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1551 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1552 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1553 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1554 NTCREATEX_SHARE_ACCESS_WRITE
;
1555 io
.ntcreatex
.in
.alloc_size
= 0;
1556 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1557 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1558 io
.ntcreatex
.in
.security_flags
= 0;
1559 io
.ntcreatex
.in
.fname
= BASEDIR
;
1561 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1562 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1564 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1566 /* create a test file that will also be modified */
1567 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1",
1570 /* ask for a change notify, on attribute changes. */
1571 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1572 notify
.nttrans
.in
.buffer_size
= 1000;
1573 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
1574 notify
.nttrans
.in
.file
.fnum
= fnum
;
1575 notify
.nttrans
.in
.recursive
= true;
1577 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1579 /* set attribute on the base dir */
1580 smbcli_setatr(cli
->tree
, BASEDIR
, FILE_ATTRIBUTE_HIDDEN
, 0);
1582 /* set attribute on a file to assure we receive a notification */
1583 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);
1586 /* check how many responses were given, expect only 1 for the file */
1587 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1588 torture_assert_ntstatus_ok_goto(mem_ctx
, status
, ret
, done
,
1589 "smb_raw_changenotify_recv");
1590 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1591 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
1592 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "tname1", STR_UNICODE
);
1595 smb_raw_exit(cli
->session
);
1596 smbcli_deltree(cli
->tree
, BASEDIR
);
1602 create a secondary tree connect - used to test for a bug in Samba3 messaging
1605 static struct smbcli_tree
*secondary_tcon(struct smbcli_state
*cli
,
1606 struct torture_context
*tctx
)
1609 const char *share
, *host
;
1610 struct smbcli_tree
*tree
;
1611 union smb_tcon tcon
;
1613 share
= torture_setting_string(tctx
, "share", NULL
);
1614 host
= torture_setting_string(tctx
, "host", NULL
);
1616 printf("create a second tree context on the same session\n");
1617 tree
= smbcli_tree_init(cli
->session
, tctx
, false);
1619 tcon
.generic
.level
= RAW_TCON_TCONX
;
1620 tcon
.tconx
.in
.flags
= TCONX_FLAG_EXTENDED_RESPONSE
;
1621 tcon
.tconx
.in
.password
= data_blob(NULL
, 0);
1622 tcon
.tconx
.in
.path
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
1623 tcon
.tconx
.in
.device
= "A:";
1624 status
= smb_raw_tcon(tree
, tctx
, &tcon
);
1625 if (!NT_STATUS_IS_OK(status
)) {
1627 printf("Failed to create secondary tree\n");
1631 tree
->tid
= tcon
.tconx
.out
.tid
;
1632 printf("tid1=%d tid2=%d\n", cli
->tree
->tid
, tree
->tid
);
1639 very simple change notify test
1641 static bool test_notify_tcon(struct torture_context
*torture
,
1642 struct smbcli_state
*cli
)
1646 union smb_notify notify
;
1649 struct smbcli_request
*req
;
1650 extern int torture_numops
;
1651 struct smbcli_tree
*tree
= NULL
;
1653 printf("TESTING SIMPLE CHANGE NOTIFY\n");
1655 if (!torture_setup_dir(cli
, BASEDIR
)) {
1660 get a handle on the directory
1662 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1663 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1664 io
.ntcreatex
.in
.flags
= 0;
1665 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1666 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1667 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1668 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1669 io
.ntcreatex
.in
.alloc_size
= 0;
1670 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1671 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1672 io
.ntcreatex
.in
.security_flags
= 0;
1673 io
.ntcreatex
.in
.fname
= BASEDIR
;
1675 status
= smb_raw_open(cli
->tree
, torture
, &io
);
1676 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1678 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1680 status
= smb_raw_open(cli
->tree
, torture
, &io
);
1681 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1684 /* ask for a change notify,
1685 on file or directory name changes */
1686 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1687 notify
.nttrans
.in
.buffer_size
= 1000;
1688 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1689 notify
.nttrans
.in
.file
.fnum
= fnum
;
1690 notify
.nttrans
.in
.recursive
= true;
1692 printf("Testing notify mkdir\n");
1693 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1694 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1696 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1697 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1698 "smb_raw_changenotify_recv");
1700 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1701 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1702 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1704 printf("Testing notify rmdir\n");
1705 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1706 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1708 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1709 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1710 "smb_raw_changenotify_recv");
1711 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1712 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1713 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1715 printf("SIMPLE CHANGE NOTIFY OK\n");
1717 printf("TESTING WITH SECONDARY TCON\n");
1718 tree
= secondary_tcon(cli
, torture
);
1720 printf("Testing notify mkdir\n");
1721 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1722 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1724 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1725 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1726 "smb_raw_changenotify_recv");
1728 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1729 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1730 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1732 printf("Testing notify rmdir\n");
1733 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1734 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1736 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1737 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1738 "smb_raw_changenotify_recv");
1739 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1740 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1741 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1743 printf("CHANGE NOTIFY WITH TCON OK\n");
1745 printf("Disconnecting secondary tree\n");
1746 status
= smb_tree_disconnect(tree
);
1747 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1748 "smb_tree_disconnect");
1751 printf("Testing notify mkdir\n");
1752 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1753 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1755 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1756 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1757 "smb_raw_changenotify_recv");
1759 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1760 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1761 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1763 printf("Testing notify rmdir\n");
1764 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1765 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1767 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1768 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
1769 "smb_raw_changenotify_recv");
1770 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1771 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1772 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1774 printf("CHANGE NOTIFY WITH TDIS OK\n");
1776 smb_raw_exit(cli
->session
);
1777 smbcli_deltree(cli
->tree
, BASEDIR
);
1783 testing alignment of multiple change notify infos
1785 static bool test_notify_alignment(struct torture_context
*tctx
,
1786 struct smbcli_state
*cli
)
1789 union smb_notify notify
;
1792 struct smbcli_request
*req
;
1793 const char *fname
= BASEDIR
"\\starter";
1794 const char *fnames
[] = { "a",
1798 int num_names
= ARRAY_SIZE(fnames
);
1801 torture_comment(tctx
, "TESTING CHANGE NOTIFY REPLY ALIGNMENT\n");
1803 if (!torture_setup_dir(cli
, BASEDIR
)) {
1807 /* get a handle on the directory */
1808 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1809 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1810 io
.ntcreatex
.in
.flags
= 0;
1811 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1812 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1813 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1814 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1815 NTCREATEX_SHARE_ACCESS_WRITE
;
1816 io
.ntcreatex
.in
.alloc_size
= 0;
1817 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1818 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1819 io
.ntcreatex
.in
.security_flags
= 0;
1820 io
.ntcreatex
.in
.fname
= BASEDIR
;
1822 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1823 torture_assert_ntstatus_ok(tctx
, status
, "");
1824 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1826 /* ask for a change notify, on file creation */
1827 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1828 notify
.nttrans
.in
.buffer_size
= 1000;
1829 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_FILE_NAME
;
1830 notify
.nttrans
.in
.file
.fnum
= fnum
;
1831 notify
.nttrans
.in
.recursive
= false;
1833 /* start change tracking */
1834 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1836 fnum2
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
1837 torture_assert(tctx
, fnum2
!= -1, smbcli_errstr(cli
->tree
));
1838 smbcli_close(cli
->tree
, fnum2
);
1840 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1841 torture_assert_ntstatus_ok(tctx
, status
, "");
1843 /* create 4 files that will cause CHANGE_NOTIFY_INFO structures
1844 * to be returned in the same packet with all possible 4-byte padding
1845 * permutations. As per MS-CIFS 2.2.7.4.2 these structures should be
1846 * 4-byte aligned. */
1848 for (i
= 0; i
< num_names
; i
++) {
1849 fpath
= talloc_asprintf(tctx
, "%s\\%s", BASEDIR
, fnames
[i
]);
1850 fnum2
= smbcli_open(cli
->tree
, fpath
,
1851 O_CREAT
|O_RDWR
, DENY_NONE
);
1852 torture_assert(tctx
, fnum2
!= -1, smbcli_errstr(cli
->tree
));
1853 smbcli_close(cli
->tree
, fnum2
);
1857 /* We send a notify packet, and let smb_raw_changenotify_recv() do
1858 * the alignment checking for us. */
1859 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1860 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1861 torture_assert_ntstatus_ok(tctx
, status
, "");
1863 /* Do basic checking for correctness. */
1864 torture_assert(tctx
, notify
.nttrans
.out
.num_changes
== num_names
, "");
1865 for (i
= 0; i
< num_names
; i
++) {
1866 torture_assert(tctx
, notify
.nttrans
.out
.changes
[i
].action
==
1867 NOTIFY_ACTION_ADDED
, "");
1868 CHECK_WSTR2(tctx
, notify
.nttrans
.out
.changes
[i
].name
, fnames
[i
],
1872 smb_raw_exit(cli
->session
);
1873 smbcli_deltree(cli
->tree
, BASEDIR
);
1877 struct torture_suite
*torture_raw_notify(TALLOC_CTX
*mem_ctx
)
1879 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "notify");
1881 torture_suite_add_1smb_test(suite
, "tcon", test_notify_tcon
);
1882 torture_suite_add_2smb_test(suite
, "dir", test_notify_dir
);
1883 torture_suite_add_2smb_test(suite
, "mask", test_notify_mask
);
1884 torture_suite_add_2smb_test(suite
, "recursive", test_notify_recursive
);
1885 torture_suite_add_1smb_test(suite
, "mask_change",
1886 test_notify_mask_change
);
1887 torture_suite_add_1smb_test(suite
, "file", test_notify_file
);
1888 torture_suite_add_1smb_test(suite
, "tdis", test_notify_tdis
);
1889 torture_suite_add_1smb_test(suite
, "exit", test_notify_exit
);
1890 torture_suite_add_1smb_test(suite
, "ulogoff", test_notify_ulogoff
);
1891 torture_suite_add_1smb_test(suite
, "tcp_dis", test_notify_tcp_dis
);
1892 torture_suite_add_1smb_test(suite
, "double", test_notify_double
);
1893 torture_suite_add_2smb_test(suite
, "tree", test_notify_tree
);
1894 torture_suite_add_1smb_test(suite
, "overflow", test_notify_overflow
);
1895 torture_suite_add_1smb_test(suite
, "basedir", test_notify_basedir
);
1896 torture_suite_add_1smb_test(suite
, "alignment", test_notify_alignment
);