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"
27 #define BASEDIR "\\test_notify"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 printf("(%d) Incorrect status %s - should be %s\n", \
32 __LINE__, nt_errstr(status), nt_errstr(correct)); \
38 #define CHECK_VAL(v, correct) do { \
39 if ((v) != (correct)) { \
40 printf("(%d) wrong value for %s 0x%x should be 0x%x\n", \
41 __LINE__, #v, (int)v, (int)correct); \
46 #define CHECK_WSTR(field, value, flags) do { \
47 if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli->transport)) { \
48 printf("(%d) %s [%s] != %s\n", __LINE__, #field, field.s, value); \
55 basic testing of change notify on directories
57 static bool test_notify_dir(struct smbcli_state
*cli
, struct smbcli_state
*cli2
,
62 union smb_notify notify
;
65 int i
, count
, fnum
, fnum2
;
66 struct smbcli_request
*req
, *req2
;
67 extern int torture_numops
;
69 printf("TESTING CHANGE NOTIFY ON DIRECTRIES\n");
72 get a handle on the directory
74 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
75 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
76 io
.ntcreatex
.in
.flags
= 0;
77 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
78 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
79 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
80 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
81 io
.ntcreatex
.in
.alloc_size
= 0;
82 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
83 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
84 io
.ntcreatex
.in
.security_flags
= 0;
85 io
.ntcreatex
.in
.fname
= BASEDIR
;
87 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
88 CHECK_STATUS(status
, NT_STATUS_OK
);
89 fnum
= io
.ntcreatex
.out
.file
.fnum
;
91 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
92 CHECK_STATUS(status
, NT_STATUS_OK
);
93 fnum2
= io
.ntcreatex
.out
.file
.fnum
;
95 /* ask for a change notify,
96 on file or directory name changes */
97 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
98 notify
.nttrans
.in
.buffer_size
= 1000;
99 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
100 notify
.nttrans
.in
.file
.fnum
= fnum
;
101 notify
.nttrans
.in
.recursive
= true;
103 printf("Testing notify cancel\n");
105 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
106 smb_raw_ntcancel(req
);
107 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
108 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
110 printf("Testing notify mkdir\n");
112 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
113 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
115 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
116 CHECK_STATUS(status
, NT_STATUS_OK
);
118 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
119 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
120 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
122 printf("Testing notify rmdir\n");
124 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
125 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
127 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
128 CHECK_STATUS(status
, NT_STATUS_OK
);
129 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
130 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
131 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
133 printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
135 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
136 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
137 smbcli_mkdir(cli2
->tree
, BASEDIR
"\\subdir-name");
138 smbcli_rmdir(cli2
->tree
, BASEDIR
"\\subdir-name");
140 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
141 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
142 CHECK_STATUS(status
, NT_STATUS_OK
);
143 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 4);
144 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
145 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
146 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_REMOVED
);
147 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name", STR_UNICODE
);
148 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_ADDED
);
149 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subdir-name", STR_UNICODE
);
150 CHECK_VAL(notify
.nttrans
.out
.changes
[3].action
, NOTIFY_ACTION_REMOVED
);
151 CHECK_WSTR(notify
.nttrans
.out
.changes
[3].name
, "subdir-name", STR_UNICODE
);
153 count
= torture_numops
;
154 printf("Testing buffered notify on create of %d files\n", count
);
155 for (i
=0;i
<count
;i
++) {
156 char *fname
= talloc_asprintf(cli
, BASEDIR
"\\test%d.txt", i
);
157 int fnum3
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
, DENY_NONE
);
159 printf("Failed to create %s - %s\n",
160 fname
, smbcli_errstr(cli
->tree
));
165 smbcli_close(cli
->tree
, fnum3
);
168 /* (1st notify) setup a new notify on a different directory handle.
169 This new notify won't see the events above. */
170 notify
.nttrans
.in
.file
.fnum
= fnum2
;
171 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
173 /* (2nd notify) whereas this notify will see the above buffered events,
174 and it directly returns the buffered events */
175 notify
.nttrans
.in
.file
.fnum
= fnum
;
176 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
178 status
= smbcli_unlink(cli
->tree
, BASEDIR
"\\nonexistant.txt");
179 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
181 /* (1st unlink) as the 2nd notify directly returns,
182 this unlink is only seen by the 1st notify and
183 the 3rd notify (later) */
184 printf("Testing notify on unlink for the first file\n");
185 status
= smbcli_unlink(cli2
->tree
, BASEDIR
"\\test0.txt");
186 CHECK_STATUS(status
, NT_STATUS_OK
);
188 /* receive the reply from the 2nd notify */
189 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
190 CHECK_STATUS(status
, NT_STATUS_OK
);
192 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
);
193 for (i
=1;i
<count
;i
++) {
194 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_ADDED
);
196 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "test0.txt", STR_UNICODE
);
198 printf("and now from the 1st notify\n");
199 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
200 CHECK_STATUS(status
, NT_STATUS_OK
);
201 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
202 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
203 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "test0.txt", STR_UNICODE
);
205 printf("(3rd notify) this notify will only see the 1st unlink\n");
206 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
208 status
= smbcli_unlink(cli
->tree
, BASEDIR
"\\nonexistant.txt");
209 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
211 printf("Testing notify on wildcard unlink for %d files\n", count
-1);
212 /* (2nd unlink) do a wildcard unlink */
213 status
= smbcli_unlink(cli2
->tree
, BASEDIR
"\\test*.txt");
214 CHECK_STATUS(status
, NT_STATUS_OK
);
216 /* receive the 3rd notify */
217 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
218 CHECK_STATUS(status
, NT_STATUS_OK
);
219 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
220 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
221 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "test0.txt", STR_UNICODE
);
223 /* and we now see the rest of the unlink calls on both directory handles */
224 notify
.nttrans
.in
.file
.fnum
= fnum
;
226 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
227 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
228 CHECK_STATUS(status
, NT_STATUS_OK
);
229 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
-1);
230 for (i
=0;i
<notify
.nttrans
.out
.num_changes
;i
++) {
231 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_REMOVED
);
233 notify
.nttrans
.in
.file
.fnum
= fnum2
;
234 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
235 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
236 CHECK_STATUS(status
, NT_STATUS_OK
);
237 CHECK_VAL(notify
.nttrans
.out
.num_changes
, count
-1);
238 for (i
=0;i
<notify
.nttrans
.out
.num_changes
;i
++) {
239 CHECK_VAL(notify
.nttrans
.out
.changes
[i
].action
, NOTIFY_ACTION_REMOVED
);
242 printf("Testing if a close() on the dir handle triggers the notify reply\n");
244 notify
.nttrans
.in
.file
.fnum
= fnum
;
245 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
247 cl
.close
.level
= RAW_CLOSE_CLOSE
;
248 cl
.close
.in
.file
.fnum
= fnum
;
249 cl
.close
.in
.write_time
= 0;
250 status
= smb_raw_close(cli
->tree
, &cl
);
251 CHECK_STATUS(status
, NT_STATUS_OK
);
253 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
254 CHECK_STATUS(status
, NT_STATUS_OK
);
255 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
258 smb_raw_exit(cli
->session
);
263 * Check notify reply for a rename action. Not sure if this is a valid thing
264 * to do, but depending on timing between inotify and messaging we get the
265 * add/remove/modify in any order. This routines tries to find the action/name
266 * pair in any of the three following notify_changes.
269 static bool check_rename_reply(struct smbcli_state
*cli
,
271 struct notify_changes
*actions
,
272 uint32_t action
, const char *name
)
276 for (i
=0; i
<3; i
++) {
277 if (actions
[i
].action
== action
) {
278 if ((actions
[i
].name
.s
== NULL
)
279 || (strcmp(actions
[i
].name
.s
, name
) != 0)
280 || (wire_bad_flags(&actions
[i
].name
, STR_UNICODE
,
282 printf("(%d) name [%s] != %s\n", line
,
283 actions
[i
].name
.s
, name
);
290 printf("(%d) expected action %d, not found\n", line
, action
);
295 testing of recursive change notify
297 static bool test_notify_recursive(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
301 union smb_notify notify
;
304 struct smbcli_request
*req1
, *req2
;
306 printf("TESTING CHANGE NOTIFY WITH RECURSION\n");
309 get a handle on the directory
311 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
312 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
313 io
.ntcreatex
.in
.flags
= 0;
314 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
315 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
316 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
317 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
318 io
.ntcreatex
.in
.alloc_size
= 0;
319 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
320 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
321 io
.ntcreatex
.in
.security_flags
= 0;
322 io
.ntcreatex
.in
.fname
= BASEDIR
;
324 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
325 CHECK_STATUS(status
, NT_STATUS_OK
);
326 fnum
= io
.ntcreatex
.out
.file
.fnum
;
328 /* ask for a change notify, on file or directory name
329 changes. Setup both with and without recursion */
330 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
331 notify
.nttrans
.in
.buffer_size
= 1000;
332 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
| FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_CREATION
;
333 notify
.nttrans
.in
.file
.fnum
= fnum
;
335 notify
.nttrans
.in
.recursive
= true;
336 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
338 notify
.nttrans
.in
.recursive
= false;
339 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
341 /* cancel initial requests so the buffer is setup */
342 smb_raw_ntcancel(req1
);
343 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
344 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
346 smb_raw_ntcancel(req2
);
347 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
348 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
350 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
351 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1");
352 smbcli_close(cli
->tree
,
353 smbcli_open(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", O_CREAT
, 0));
354 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname1", BASEDIR
"\\subdir-name\\subname1-r");
355 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", BASEDIR
"\\subname2-r");
356 smbcli_rename(cli
->tree
, BASEDIR
"\\subname2-r", BASEDIR
"\\subname3-r");
358 notify
.nttrans
.in
.completion_filter
= 0;
359 notify
.nttrans
.in
.recursive
= true;
361 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
363 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1-r");
364 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
365 smbcli_unlink(cli
->tree
, BASEDIR
"\\subname3-r");
367 notify
.nttrans
.in
.recursive
= false;
368 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
370 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
371 CHECK_STATUS(status
, NT_STATUS_OK
);
373 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 11);
374 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
375 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
376 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_ADDED
);
377 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name\\subname1", STR_UNICODE
);
378 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_ADDED
);
379 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subdir-name\\subname2", STR_UNICODE
);
380 CHECK_VAL(notify
.nttrans
.out
.changes
[3].action
, NOTIFY_ACTION_OLD_NAME
);
381 CHECK_WSTR(notify
.nttrans
.out
.changes
[3].name
, "subdir-name\\subname1", STR_UNICODE
);
382 CHECK_VAL(notify
.nttrans
.out
.changes
[4].action
, NOTIFY_ACTION_NEW_NAME
);
383 CHECK_WSTR(notify
.nttrans
.out
.changes
[4].name
, "subdir-name\\subname1-r", STR_UNICODE
);
385 ret
&= check_rename_reply(
386 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
387 NOTIFY_ACTION_ADDED
, "subname2-r");
388 ret
&= check_rename_reply(
389 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
390 NOTIFY_ACTION_REMOVED
, "subdir-name\\subname2");
391 ret
&= check_rename_reply(
392 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[5],
393 NOTIFY_ACTION_MODIFIED
, "subname2-r");
395 ret
&= check_rename_reply(
396 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
397 NOTIFY_ACTION_OLD_NAME
, "subname2-r");
398 ret
&= check_rename_reply(
399 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
400 NOTIFY_ACTION_NEW_NAME
, "subname3-r");
401 ret
&= check_rename_reply(
402 cli
, __LINE__
, ¬ify
.nttrans
.out
.changes
[8],
403 NOTIFY_ACTION_MODIFIED
, "subname3-r");
409 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
410 CHECK_STATUS(status
, NT_STATUS_OK
);
412 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 3);
413 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
414 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name\\subname1-r", STR_UNICODE
);
415 CHECK_VAL(notify
.nttrans
.out
.changes
[1].action
, NOTIFY_ACTION_REMOVED
);
416 CHECK_WSTR(notify
.nttrans
.out
.changes
[1].name
, "subdir-name", STR_UNICODE
);
417 CHECK_VAL(notify
.nttrans
.out
.changes
[2].action
, NOTIFY_ACTION_REMOVED
);
418 CHECK_WSTR(notify
.nttrans
.out
.changes
[2].name
, "subname3-r", STR_UNICODE
);
421 smb_raw_exit(cli
->session
);
426 testing of change notify mask change
428 static bool test_notify_mask_change(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
432 union smb_notify notify
;
435 struct smbcli_request
*req1
, *req2
;
437 printf("TESTING CHANGE NOTIFY WITH MASK CHANGE\n");
440 get a handle on the directory
442 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
443 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
444 io
.ntcreatex
.in
.flags
= 0;
445 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
446 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
447 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
448 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
449 io
.ntcreatex
.in
.alloc_size
= 0;
450 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
451 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
452 io
.ntcreatex
.in
.security_flags
= 0;
453 io
.ntcreatex
.in
.fname
= BASEDIR
;
455 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
456 CHECK_STATUS(status
, NT_STATUS_OK
);
457 fnum
= io
.ntcreatex
.out
.file
.fnum
;
459 /* ask for a change notify, on file or directory name
460 changes. Setup both with and without recursion */
461 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
462 notify
.nttrans
.in
.buffer_size
= 1000;
463 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
464 notify
.nttrans
.in
.file
.fnum
= fnum
;
466 notify
.nttrans
.in
.recursive
= true;
467 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
469 notify
.nttrans
.in
.recursive
= false;
470 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
472 /* cancel initial requests so the buffer is setup */
473 smb_raw_ntcancel(req1
);
474 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
475 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
477 smb_raw_ntcancel(req2
);
478 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
479 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
481 notify
.nttrans
.in
.recursive
= true;
482 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
484 /* Set to hidden then back again. */
485 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));
486 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);
487 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");
489 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
490 CHECK_STATUS(status
, NT_STATUS_OK
);
492 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
493 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
494 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "tname1", STR_UNICODE
);
496 /* Now try and change the mask to include other events.
497 * This should not work - once the mask is set on a directory
498 * fnum it seems to be fixed until the fnum is closed. */
500 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
| FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_CREATION
;
501 notify
.nttrans
.in
.recursive
= true;
502 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
504 notify
.nttrans
.in
.recursive
= false;
505 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
507 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
508 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1");
509 smbcli_close(cli
->tree
,
510 smbcli_open(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", O_CREAT
, 0));
511 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname1", BASEDIR
"\\subdir-name\\subname1-r");
512 smbcli_rename(cli
->tree
, BASEDIR
"\\subdir-name\\subname2", BASEDIR
"\\subname2-r");
513 smbcli_rename(cli
->tree
, BASEDIR
"\\subname2-r", BASEDIR
"\\subname3-r");
515 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name\\subname1-r");
516 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
517 smbcli_unlink(cli
->tree
, BASEDIR
"\\subname3-r");
519 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
520 CHECK_STATUS(status
, NT_STATUS_OK
);
522 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
523 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
524 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subname2-r", STR_UNICODE
);
526 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
527 CHECK_STATUS(status
, NT_STATUS_OK
);
529 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
530 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
531 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subname3-r", STR_UNICODE
);
538 smb_raw_exit(cli
->session
);
544 testing of mask bits for change notify
546 static bool test_notify_mask(struct smbcli_state
*cli
, struct torture_context
*tctx
)
550 union smb_notify notify
;
559 printf("TESTING CHANGE NOTIFY COMPLETION FILTERS\n");
561 tv
= timeval_current_ofs(1000, 0);
562 t
= timeval_to_nttime(&tv
);
565 get a handle on the directory
567 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
568 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
569 io
.ntcreatex
.in
.flags
= 0;
570 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
571 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
572 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
573 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
574 io
.ntcreatex
.in
.alloc_size
= 0;
575 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
576 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
577 io
.ntcreatex
.in
.security_flags
= 0;
578 io
.ntcreatex
.in
.fname
= BASEDIR
;
580 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
581 notify
.nttrans
.in
.buffer_size
= 1000;
582 notify
.nttrans
.in
.recursive
= true;
584 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
586 smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
587 do { for (mask=i=0;i<32;i++) { \
588 struct smbcli_request *req; \
589 status = smb_raw_open(cli->tree, tctx, &io); \
590 CHECK_STATUS(status, NT_STATUS_OK); \
591 fnum = io.ntcreatex.out.file.fnum; \
593 notify.nttrans.in.file.fnum = fnum; \
594 notify.nttrans.in.completion_filter = (1<<i); \
595 req = smb_raw_changenotify_send(cli->tree, ¬ify); \
597 msleep(200); smb_raw_ntcancel(req); \
598 status = smb_raw_changenotify_recv(req, tctx, ¬ify); \
600 smbcli_close(cli->tree, fnum); \
601 if (NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) continue; \
602 CHECK_STATUS(status, NT_STATUS_OK); \
603 /* special case to cope with file rename behaviour */ \
604 if (nchanges == 2 && notify.nttrans.out.num_changes == 1 && \
605 notify.nttrans.out.changes[0].action == NOTIFY_ACTION_MODIFIED && \
606 ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
607 Action == NOTIFY_ACTION_OLD_NAME) { \
608 printf("(rename file special handling OK)\n"); \
609 } else if (nchanges != notify.nttrans.out.num_changes) { \
610 printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
611 notify.nttrans.out.num_changes, \
613 notify.nttrans.out.changes[0].action, \
614 notify.nttrans.in.completion_filter); \
616 } else if (notify.nttrans.out.changes[0].action != Action) { \
617 printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
618 notify.nttrans.out.num_changes, \
619 notify.nttrans.out.changes[0].action, \
621 notify.nttrans.in.completion_filter); \
623 } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
624 printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
625 notify.nttrans.out.num_changes, \
626 notify.nttrans.out.changes[0].action, \
627 notify.nttrans.in.completion_filter, \
628 notify.nttrans.out.changes[0].name.s); \
633 if ((expected) != mask) { \
634 if (((expected) & ~mask) != 0) { \
635 printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
639 printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
646 printf("Testing mkdir\n");
647 NOTIFY_MASK_TEST("Testing mkdir",;,
648 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
649 smbcli_rmdir(cli
->tree
, BASEDIR
"\\tname1");,
651 FILE_NOTIFY_CHANGE_DIR_NAME
, 1);
653 printf("Testing create file\n");
654 NOTIFY_MASK_TEST("Testing create file",;,
655 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
656 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
658 FILE_NOTIFY_CHANGE_FILE_NAME
, 1);
660 printf("Testing unlink\n");
661 NOTIFY_MASK_TEST("Testing unlink",
662 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
663 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
665 NOTIFY_ACTION_REMOVED
,
666 FILE_NOTIFY_CHANGE_FILE_NAME
, 1);
668 printf("Testing rmdir\n");
669 NOTIFY_MASK_TEST("Testing rmdir",
670 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
671 smbcli_rmdir(cli
->tree
, BASEDIR
"\\tname1");,
673 NOTIFY_ACTION_REMOVED
,
674 FILE_NOTIFY_CHANGE_DIR_NAME
, 1);
676 printf("Testing rename file\n");
677 NOTIFY_MASK_TEST("Testing rename file",
678 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
679 smbcli_rename(cli
->tree
, BASEDIR
"\\tname1", BASEDIR
"\\tname2");,
680 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname2");,
681 NOTIFY_ACTION_OLD_NAME
,
682 FILE_NOTIFY_CHANGE_FILE_NAME
|FILE_NOTIFY_CHANGE_ATTRIBUTES
|FILE_NOTIFY_CHANGE_CREATION
, 2);
684 printf("Testing rename dir\n");
685 NOTIFY_MASK_TEST("Testing rename dir",
686 smbcli_mkdir(cli
->tree
, BASEDIR
"\\tname1");,
687 smbcli_rename(cli
->tree
, BASEDIR
"\\tname1", BASEDIR
"\\tname2");,
688 smbcli_rmdir(cli
->tree
, BASEDIR
"\\tname2");,
689 NOTIFY_ACTION_OLD_NAME
,
690 FILE_NOTIFY_CHANGE_DIR_NAME
, 2);
692 printf("Testing set path attribute\n");
693 NOTIFY_MASK_TEST("Testing set path attribute",
694 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
695 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);,
696 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
697 NOTIFY_ACTION_MODIFIED
,
698 FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
700 printf("Testing set path write time\n");
701 NOTIFY_MASK_TEST("Testing set path write time",
702 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1", O_CREAT
, 0));,
703 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_NORMAL
, 1000);,
704 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1");,
705 NOTIFY_ACTION_MODIFIED
,
706 FILE_NOTIFY_CHANGE_LAST_WRITE
, 1);
708 printf("Testing set file attribute\n");
709 NOTIFY_MASK_TEST("Testing set file attribute",
710 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
711 smbcli_fsetatr(cli
->tree
, fnum2
, FILE_ATTRIBUTE_HIDDEN
, 0, 0, 0, 0);,
712 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
713 NOTIFY_ACTION_MODIFIED
,
714 FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
716 if (torture_setting_bool(tctx
, "samba3", false)) {
717 printf("Samba3 does not yet support create times "
721 printf("Testing set file create time\n");
722 NOTIFY_MASK_TEST("Testing set file create time",
723 fnum2
= create_complex_file(cli
, tctx
,
724 BASEDIR
"\\tname1");,
725 smbcli_fsetatr(cli
->tree
, fnum2
, 0, t
, 0, 0, 0);,
726 (smbcli_close(cli
->tree
, fnum2
),
727 smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
728 NOTIFY_ACTION_MODIFIED
,
729 FILE_NOTIFY_CHANGE_CREATION
, 1);
732 printf("Testing set file access time\n");
733 NOTIFY_MASK_TEST("Testing set file access time",
734 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
735 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, t
, 0, 0);,
736 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
737 NOTIFY_ACTION_MODIFIED
,
738 FILE_NOTIFY_CHANGE_LAST_ACCESS
, 1);
740 printf("Testing set file write time\n");
741 NOTIFY_MASK_TEST("Testing set file write time",
742 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
743 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, 0, t
, 0);,
744 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
745 NOTIFY_ACTION_MODIFIED
,
746 FILE_NOTIFY_CHANGE_LAST_WRITE
, 1);
748 printf("Testing set file change time\n");
749 NOTIFY_MASK_TEST("Testing set file change time",
750 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
751 smbcli_fsetatr(cli
->tree
, fnum2
, 0, 0, 0, 0, t
);,
752 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
753 NOTIFY_ACTION_MODIFIED
,
757 printf("Testing write\n");
758 NOTIFY_MASK_TEST("Testing write",
759 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
760 smbcli_write(cli
->tree
, fnum2
, 1, &c
, 10000, 1);,
761 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
762 NOTIFY_ACTION_MODIFIED
,
765 printf("Testing truncate\n");
766 NOTIFY_MASK_TEST("Testing truncate",
767 fnum2
= create_complex_file(cli
, tctx
, BASEDIR
"\\tname1");,
768 smbcli_ftruncate(cli
->tree
, fnum2
, 10000);,
769 (smbcli_close(cli
->tree
, fnum2
), smbcli_unlink(cli
->tree
, BASEDIR
"\\tname1"));,
770 NOTIFY_ACTION_MODIFIED
,
771 FILE_NOTIFY_CHANGE_SIZE
| FILE_NOTIFY_CHANGE_ATTRIBUTES
, 1);
774 smb_raw_exit(cli
->session
);
779 basic testing of change notify on files
781 static bool test_notify_file(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
787 union smb_notify notify
;
788 struct smbcli_request
*req
;
790 const char *fname
= BASEDIR
"\\file.txt";
792 printf("TESTING CHANGE NOTIFY ON FILES\n");
794 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
795 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
796 io
.ntcreatex
.in
.flags
= 0;
797 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
798 io
.ntcreatex
.in
.create_options
= 0;
799 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
800 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
801 io
.ntcreatex
.in
.alloc_size
= 0;
802 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
803 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
804 io
.ntcreatex
.in
.security_flags
= 0;
805 io
.ntcreatex
.in
.fname
= fname
;
806 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
807 CHECK_STATUS(status
, NT_STATUS_OK
);
808 fnum
= io
.ntcreatex
.out
.file
.fnum
;
810 /* ask for a change notify,
811 on file or directory name changes */
812 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
813 notify
.nttrans
.in
.file
.fnum
= fnum
;
814 notify
.nttrans
.in
.buffer_size
= 1000;
815 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_STREAM_NAME
;
816 notify
.nttrans
.in
.recursive
= false;
818 printf("Testing if notifies on file handles are invalid (should be)\n");
820 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
821 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
822 CHECK_STATUS(status
, NT_STATUS_INVALID_PARAMETER
);
824 cl
.close
.level
= RAW_CLOSE_CLOSE
;
825 cl
.close
.in
.file
.fnum
= fnum
;
826 cl
.close
.in
.write_time
= 0;
827 status
= smb_raw_close(cli
->tree
, &cl
);
828 CHECK_STATUS(status
, NT_STATUS_OK
);
830 status
= smbcli_unlink(cli
->tree
, fname
);
831 CHECK_STATUS(status
, NT_STATUS_OK
);
834 smb_raw_exit(cli
->session
);
839 basic testing of change notifies followed by a tdis
841 static bool test_notify_tdis(struct torture_context
*tctx
)
845 union smb_notify notify
;
848 struct smbcli_request
*req
;
849 struct smbcli_state
*cli
= NULL
;
851 printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
853 if (!torture_open_connection(&cli
, tctx
, 0)) {
858 get a handle on the directory
860 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
861 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
862 io
.ntcreatex
.in
.flags
= 0;
863 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
864 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
865 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
866 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
867 io
.ntcreatex
.in
.alloc_size
= 0;
868 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
869 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
870 io
.ntcreatex
.in
.security_flags
= 0;
871 io
.ntcreatex
.in
.fname
= BASEDIR
;
873 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
874 CHECK_STATUS(status
, NT_STATUS_OK
);
875 fnum
= io
.ntcreatex
.out
.file
.fnum
;
877 /* ask for a change notify,
878 on file or directory name changes */
879 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
880 notify
.nttrans
.in
.buffer_size
= 1000;
881 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
882 notify
.nttrans
.in
.file
.fnum
= fnum
;
883 notify
.nttrans
.in
.recursive
= true;
885 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
887 status
= smbcli_tdis(cli
);
888 CHECK_STATUS(status
, NT_STATUS_OK
);
891 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
892 CHECK_STATUS(status
, NT_STATUS_OK
);
893 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
896 torture_close_connection(cli
);
901 basic testing of change notifies followed by a exit
903 static bool test_notify_exit(struct torture_context
*tctx
)
907 union smb_notify notify
;
910 struct smbcli_request
*req
;
911 struct smbcli_state
*cli
= NULL
;
913 printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
915 if (!torture_open_connection(&cli
, tctx
, 0)) {
920 get a handle on the directory
922 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
923 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
924 io
.ntcreatex
.in
.flags
= 0;
925 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
926 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
927 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
928 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
929 io
.ntcreatex
.in
.alloc_size
= 0;
930 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
931 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
932 io
.ntcreatex
.in
.security_flags
= 0;
933 io
.ntcreatex
.in
.fname
= BASEDIR
;
935 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
936 CHECK_STATUS(status
, NT_STATUS_OK
);
937 fnum
= io
.ntcreatex
.out
.file
.fnum
;
939 /* ask for a change notify,
940 on file or directory name changes */
941 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
942 notify
.nttrans
.in
.buffer_size
= 1000;
943 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
944 notify
.nttrans
.in
.file
.fnum
= fnum
;
945 notify
.nttrans
.in
.recursive
= true;
947 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
949 status
= smb_raw_exit(cli
->session
);
950 CHECK_STATUS(status
, NT_STATUS_OK
);
952 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
953 CHECK_STATUS(status
, NT_STATUS_OK
);
954 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
957 torture_close_connection(cli
);
962 basic testing of change notifies followed by a ulogoff
964 static bool test_notify_ulogoff(struct torture_context
*tctx
)
968 union smb_notify notify
;
971 struct smbcli_request
*req
;
972 struct smbcli_state
*cli
= NULL
;
974 printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
976 if (!torture_open_connection(&cli
, tctx
, 0)) {
981 get a handle on the directory
983 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
984 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
985 io
.ntcreatex
.in
.flags
= 0;
986 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
987 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
988 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
989 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
990 io
.ntcreatex
.in
.alloc_size
= 0;
991 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
992 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
993 io
.ntcreatex
.in
.security_flags
= 0;
994 io
.ntcreatex
.in
.fname
= BASEDIR
;
996 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
997 CHECK_STATUS(status
, NT_STATUS_OK
);
998 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1000 /* ask for a change notify,
1001 on file or directory name changes */
1002 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1003 notify
.nttrans
.in
.buffer_size
= 1000;
1004 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1005 notify
.nttrans
.in
.file
.fnum
= fnum
;
1006 notify
.nttrans
.in
.recursive
= true;
1008 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1010 status
= smb_raw_ulogoff(cli
->session
);
1011 CHECK_STATUS(status
, NT_STATUS_OK
);
1013 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1014 CHECK_STATUS(status
, NT_STATUS_OK
);
1015 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
1018 torture_close_connection(cli
);
1022 static void tcp_dis_handler(struct smbcli_transport
*t
, void *p
)
1024 struct smbcli_state
*cli
= (struct smbcli_state
*)p
;
1025 smbcli_transport_dead(cli
->transport
, NT_STATUS_LOCAL_DISCONNECT
);
1026 cli
->transport
= NULL
;
1030 basic testing of change notifies followed by tcp disconnect
1032 static bool test_notify_tcp_dis(struct torture_context
*tctx
)
1036 union smb_notify notify
;
1039 struct smbcli_request
*req
;
1040 struct smbcli_state
*cli
= NULL
;
1042 printf("TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT\n");
1044 if (!torture_open_connection(&cli
, tctx
, 0)) {
1049 get a handle on the directory
1051 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1052 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1053 io
.ntcreatex
.in
.flags
= 0;
1054 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1055 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1056 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1057 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1058 io
.ntcreatex
.in
.alloc_size
= 0;
1059 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1060 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1061 io
.ntcreatex
.in
.security_flags
= 0;
1062 io
.ntcreatex
.in
.fname
= BASEDIR
;
1064 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1065 CHECK_STATUS(status
, NT_STATUS_OK
);
1066 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1068 /* ask for a change notify,
1069 on file or directory name changes */
1070 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1071 notify
.nttrans
.in
.buffer_size
= 1000;
1072 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1073 notify
.nttrans
.in
.file
.fnum
= fnum
;
1074 notify
.nttrans
.in
.recursive
= true;
1076 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1078 smbcli_transport_idle_handler(cli
->transport
, tcp_dis_handler
, 250, cli
);
1080 status
= smb_raw_changenotify_recv(req
, tctx
, ¬ify
);
1081 CHECK_STATUS(status
, NT_STATUS_LOCAL_DISCONNECT
);
1084 torture_close_connection(cli
);
1089 test setting up two change notify requests on one handle
1091 static bool test_notify_double(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
1095 union smb_notify notify
;
1098 struct smbcli_request
*req1
, *req2
;
1100 printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
1103 get a handle on the directory
1105 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1106 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1107 io
.ntcreatex
.in
.flags
= 0;
1108 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1109 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1110 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1111 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1112 io
.ntcreatex
.in
.alloc_size
= 0;
1113 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1114 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1115 io
.ntcreatex
.in
.security_flags
= 0;
1116 io
.ntcreatex
.in
.fname
= BASEDIR
;
1118 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1119 CHECK_STATUS(status
, NT_STATUS_OK
);
1120 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1122 /* ask for a change notify,
1123 on file or directory name changes */
1124 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1125 notify
.nttrans
.in
.buffer_size
= 1000;
1126 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1127 notify
.nttrans
.in
.file
.fnum
= fnum
;
1128 notify
.nttrans
.in
.recursive
= true;
1130 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1131 req2
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1133 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1135 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1136 CHECK_STATUS(status
, NT_STATUS_OK
);
1137 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1138 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1140 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name2");
1142 status
= smb_raw_changenotify_recv(req2
, mem_ctx
, ¬ify
);
1143 CHECK_STATUS(status
, NT_STATUS_OK
);
1144 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1145 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name2", STR_UNICODE
);
1148 smb_raw_exit(cli
->session
);
1154 test multiple change notifies at different depths and with/without recursion
1156 static bool test_notify_tree(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
1159 union smb_notify notify
;
1161 struct smbcli_request
*req
;
1171 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 30 },
1172 {BASEDIR
"\\zqy", true, FILE_NOTIFY_CHANGE_NAME
, 8 },
1173 {BASEDIR
"\\atsy", true, FILE_NOTIFY_CHANGE_NAME
, 4 },
1174 {BASEDIR
"\\abc\\foo", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1175 {BASEDIR
"\\abc\\blah", true, FILE_NOTIFY_CHANGE_NAME
, 13 },
1176 {BASEDIR
"\\abc\\blah", false, FILE_NOTIFY_CHANGE_NAME
, 7 },
1177 {BASEDIR
"\\abc\\blah\\a", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1178 {BASEDIR
"\\abc\\blah\\b", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1179 {BASEDIR
"\\abc\\blah\\c", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1180 {BASEDIR
"\\abc\\fooblah", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1181 {BASEDIR
"\\zqy\\xx", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1182 {BASEDIR
"\\zqy\\yyy", true, FILE_NOTIFY_CHANGE_NAME
, 2 },
1183 {BASEDIR
"\\zqy\\..", true, FILE_NOTIFY_CHANGE_NAME
, 40 },
1184 {BASEDIR
, true, FILE_NOTIFY_CHANGE_NAME
, 40 },
1185 {BASEDIR
, false,FILE_NOTIFY_CHANGE_NAME
, 6 },
1186 {BASEDIR
"\\atsy", false,FILE_NOTIFY_CHANGE_NAME
, 4 },
1187 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 24 },
1188 {BASEDIR
"\\abc", false,FILE_NOTIFY_CHANGE_FILE_NAME
, 0 },
1189 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_FILE_NAME
, 0 },
1190 {BASEDIR
"\\abc", true, FILE_NOTIFY_CHANGE_NAME
, 24 },
1194 bool all_done
= false;
1196 printf("TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS\n");
1198 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1199 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1200 io
.ntcreatex
.in
.flags
= 0;
1201 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1202 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1203 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1204 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1205 io
.ntcreatex
.in
.alloc_size
= 0;
1206 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
1207 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1208 io
.ntcreatex
.in
.security_flags
= 0;
1210 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1211 notify
.nttrans
.in
.buffer_size
= 20000;
1214 setup the directory tree, and the notify buffer on each directory
1216 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1217 io
.ntcreatex
.in
.fname
= dirs
[i
].path
;
1218 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1219 CHECK_STATUS(status
, NT_STATUS_OK
);
1220 dirs
[i
].fnum
= io
.ntcreatex
.out
.file
.fnum
;
1222 notify
.nttrans
.in
.completion_filter
= dirs
[i
].filter
;
1223 notify
.nttrans
.in
.file
.fnum
= dirs
[i
].fnum
;
1224 notify
.nttrans
.in
.recursive
= dirs
[i
].recursive
;
1225 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1226 smb_raw_ntcancel(req
);
1227 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
1228 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
1231 /* trigger 2 events in each dir */
1232 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1233 char *path
= talloc_asprintf(mem_ctx
, "%s\\test.dir", dirs
[i
].path
);
1234 smbcli_mkdir(cli
->tree
, path
);
1235 smbcli_rmdir(cli
->tree
, path
);
1239 /* give a bit of time for the events to propogate */
1240 tv
= timeval_current();
1243 /* count events that have happened in each dir */
1244 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1245 notify
.nttrans
.in
.file
.fnum
= dirs
[i
].fnum
;
1246 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1247 smb_raw_ntcancel(req
);
1248 notify
.nttrans
.out
.num_changes
= 0;
1249 status
= smb_raw_changenotify_recv(req
, mem_ctx
, ¬ify
);
1250 dirs
[i
].counted
+= notify
.nttrans
.out
.num_changes
;
1255 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1256 if (dirs
[i
].counted
!= dirs
[i
].expected
) {
1260 } while (!all_done
&& timeval_elapsed(&tv
) < 20);
1262 printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv
));
1264 for (i
=0;i
<ARRAY_SIZE(dirs
);i
++) {
1265 if (dirs
[i
].counted
!= dirs
[i
].expected
) {
1266 printf("ERROR: i=%d expected %d got %d for '%s'\n",
1267 i
, dirs
[i
].expected
, dirs
[i
].counted
, dirs
[i
].path
);
1273 run from the back, closing and deleting
1275 for (i
=ARRAY_SIZE(dirs
)-1;i
>=0;i
--) {
1276 smbcli_close(cli
->tree
, dirs
[i
].fnum
);
1277 smbcli_rmdir(cli
->tree
, dirs
[i
].path
);
1281 smb_raw_exit(cli
->session
);
1286 Test response when cached server events exceed single NT NOTFIY response
1289 static bool test_notify_overflow(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
1293 union smb_notify notify
;
1297 struct smbcli_request
*req1
;
1300 printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
1302 /* get a handle on the directory */
1303 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1304 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1305 io
.ntcreatex
.in
.flags
= 0;
1306 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1307 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1308 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1309 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1310 NTCREATEX_SHARE_ACCESS_WRITE
;
1311 io
.ntcreatex
.in
.alloc_size
= 0;
1312 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1313 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1314 io
.ntcreatex
.in
.security_flags
= 0;
1315 io
.ntcreatex
.in
.fname
= BASEDIR
;
1317 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1318 CHECK_STATUS(status
, NT_STATUS_OK
);
1319 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1321 /* ask for a change notify, on name changes. */
1322 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1323 notify
.nttrans
.in
.buffer_size
= 1000;
1324 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1325 notify
.nttrans
.in
.file
.fnum
= fnum
;
1327 notify
.nttrans
.in
.recursive
= true;
1328 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1330 /* cancel initial requests so the buffer is setup */
1331 smb_raw_ntcancel(req1
);
1332 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1333 CHECK_STATUS(status
, NT_STATUS_CANCELLED
);
1335 /* open a lot of files, filling up the server side notify buffer */
1336 printf("Testing overflowed buffer notify on create of %d files\n",
1338 for (i
=0;i
<count
;i
++) {
1339 char *fname
= talloc_asprintf(cli
, BASEDIR
"\\test%d.txt", i
);
1340 int fnum2
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
,
1343 printf("Failed to create %s - %s\n",
1344 fname
, smbcli_errstr(cli
->tree
));
1349 smbcli_close(cli
->tree
, fnum2
);
1352 /* expect that 0 events will be returned with NT_STATUS_OK */
1353 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1354 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1355 CHECK_STATUS(status
, NT_STATUS_OK
);
1356 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 0);
1359 smb_raw_exit(cli
->session
);
1364 Test if notifications are returned for changes to the base directory.
1367 static bool test_notify_basedir(struct smbcli_state
*cli
, TALLOC_CTX
*mem_ctx
)
1371 union smb_notify notify
;
1374 struct smbcli_request
*req1
;
1376 printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
1378 /* get a handle on the directory */
1379 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1380 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1381 io
.ntcreatex
.in
.flags
= 0;
1382 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1383 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1384 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1385 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1386 NTCREATEX_SHARE_ACCESS_WRITE
;
1387 io
.ntcreatex
.in
.alloc_size
= 0;
1388 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1389 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1390 io
.ntcreatex
.in
.security_flags
= 0;
1391 io
.ntcreatex
.in
.fname
= BASEDIR
;
1393 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1394 CHECK_STATUS(status
, NT_STATUS_OK
);
1395 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1397 /* create a test file that will also be modified */
1398 smbcli_close(cli
->tree
, smbcli_open(cli
->tree
, BASEDIR
"\\tname1",
1401 /* ask for a change notify, on attribute changes. */
1402 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1403 notify
.nttrans
.in
.buffer_size
= 1000;
1404 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
1405 notify
.nttrans
.in
.file
.fnum
= fnum
;
1406 notify
.nttrans
.in
.recursive
= true;
1408 req1
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1410 /* set attribute on the base dir */
1411 smbcli_setatr(cli
->tree
, BASEDIR
, FILE_ATTRIBUTE_HIDDEN
, 0);
1413 /* set attribute on a file to assure we receive a notification */
1414 smbcli_setatr(cli
->tree
, BASEDIR
"\\tname1", FILE_ATTRIBUTE_HIDDEN
, 0);
1417 /* check how many responses were given, expect only 1 for the file */
1418 status
= smb_raw_changenotify_recv(req1
, mem_ctx
, ¬ify
);
1419 CHECK_STATUS(status
, NT_STATUS_OK
);
1420 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1421 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_MODIFIED
);
1422 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "tname1", STR_UNICODE
);
1425 smb_raw_exit(cli
->session
);
1431 create a secondary tree connect - used to test for a bug in Samba3 messaging
1434 static struct smbcli_tree
*secondary_tcon(struct smbcli_state
*cli
,
1435 struct torture_context
*tctx
)
1438 const char *share
, *host
;
1439 struct smbcli_tree
*tree
;
1440 union smb_tcon tcon
;
1442 share
= torture_setting_string(tctx
, "share", NULL
);
1443 host
= torture_setting_string(tctx
, "host", NULL
);
1445 printf("create a second tree context on the same session\n");
1446 tree
= smbcli_tree_init(cli
->session
, tctx
, false);
1448 tcon
.generic
.level
= RAW_TCON_TCONX
;
1449 tcon
.tconx
.in
.flags
= 0;
1450 tcon
.tconx
.in
.password
= data_blob(NULL
, 0);
1451 tcon
.tconx
.in
.path
= talloc_asprintf(tctx
, "\\\\%s\\%s", host
, share
);
1452 tcon
.tconx
.in
.device
= "A:";
1453 status
= smb_raw_tcon(tree
, tctx
, &tcon
);
1454 if (!NT_STATUS_IS_OK(status
)) {
1456 printf("Failed to create secondary tree\n");
1460 tree
->tid
= tcon
.tconx
.out
.tid
;
1461 printf("tid1=%d tid2=%d\n", cli
->tree
->tid
, tree
->tid
);
1468 very simple change notify test
1470 static bool test_notify_tcon(struct smbcli_state
*cli
, struct torture_context
*torture
)
1474 union smb_notify notify
;
1477 struct smbcli_request
*req
;
1478 extern int torture_numops
;
1479 struct smbcli_tree
*tree
= NULL
;
1481 printf("TESTING SIMPLE CHANGE NOTIFY\n");
1484 get a handle on the directory
1486 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1487 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1488 io
.ntcreatex
.in
.flags
= 0;
1489 io
.ntcreatex
.in
.access_mask
= SEC_FILE_ALL
;
1490 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1491 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1492 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1493 io
.ntcreatex
.in
.alloc_size
= 0;
1494 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1495 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1496 io
.ntcreatex
.in
.security_flags
= 0;
1497 io
.ntcreatex
.in
.fname
= BASEDIR
;
1499 status
= smb_raw_open(cli
->tree
, torture
, &io
);
1500 CHECK_STATUS(status
, NT_STATUS_OK
);
1501 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1503 status
= smb_raw_open(cli
->tree
, torture
, &io
);
1504 CHECK_STATUS(status
, NT_STATUS_OK
);
1505 fnum2
= io
.ntcreatex
.out
.file
.fnum
;
1507 /* ask for a change notify,
1508 on file or directory name changes */
1509 notify
.nttrans
.level
= RAW_NOTIFY_NTTRANS
;
1510 notify
.nttrans
.in
.buffer_size
= 1000;
1511 notify
.nttrans
.in
.completion_filter
= FILE_NOTIFY_CHANGE_NAME
;
1512 notify
.nttrans
.in
.file
.fnum
= fnum
;
1513 notify
.nttrans
.in
.recursive
= true;
1515 printf("Testing notify mkdir\n");
1516 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1517 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1519 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1520 CHECK_STATUS(status
, NT_STATUS_OK
);
1522 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1523 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1524 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1526 printf("Testing notify rmdir\n");
1527 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1528 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1530 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1531 CHECK_STATUS(status
, NT_STATUS_OK
);
1532 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1533 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1534 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1536 printf("SIMPLE CHANGE NOTIFY OK\n");
1538 printf("TESTING WITH SECONDARY TCON\n");
1539 tree
= secondary_tcon(cli
, torture
);
1541 printf("Testing notify mkdir\n");
1542 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1543 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1545 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1546 CHECK_STATUS(status
, NT_STATUS_OK
);
1548 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1549 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1550 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1552 printf("Testing notify rmdir\n");
1553 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1554 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1556 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1557 CHECK_STATUS(status
, NT_STATUS_OK
);
1558 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1559 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1560 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1562 printf("CHANGE NOTIFY WITH TCON OK\n");
1564 printf("Disconnecting secondary tree\n");
1565 status
= smb_tree_disconnect(tree
);
1566 CHECK_STATUS(status
, NT_STATUS_OK
);
1569 printf("Testing notify mkdir\n");
1570 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1571 smbcli_mkdir(cli
->tree
, BASEDIR
"\\subdir-name");
1573 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1574 CHECK_STATUS(status
, NT_STATUS_OK
);
1576 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1577 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_ADDED
);
1578 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1580 printf("Testing notify rmdir\n");
1581 req
= smb_raw_changenotify_send(cli
->tree
, ¬ify
);
1582 smbcli_rmdir(cli
->tree
, BASEDIR
"\\subdir-name");
1584 status
= smb_raw_changenotify_recv(req
, torture
, ¬ify
);
1585 CHECK_STATUS(status
, NT_STATUS_OK
);
1586 CHECK_VAL(notify
.nttrans
.out
.num_changes
, 1);
1587 CHECK_VAL(notify
.nttrans
.out
.changes
[0].action
, NOTIFY_ACTION_REMOVED
);
1588 CHECK_WSTR(notify
.nttrans
.out
.changes
[0].name
, "subdir-name", STR_UNICODE
);
1590 printf("CHANGE NOTIFY WITH TDIS OK\n");
1592 smb_raw_exit(cli
->session
);
1598 basic testing of change notify
1600 bool torture_raw_notify(struct torture_context
*torture
,
1601 struct smbcli_state
*cli
,
1602 struct smbcli_state
*cli2
)
1606 if (!torture_setup_dir(cli
, BASEDIR
)) {
1610 ret
&= test_notify_tcon(cli
, torture
);
1611 ret
&= test_notify_dir(cli
, cli2
, torture
);
1612 ret
&= test_notify_mask(cli
, torture
);
1613 ret
&= test_notify_recursive(cli
, torture
);
1614 ret
&= test_notify_mask_change(cli
, torture
);
1615 ret
&= test_notify_file(cli
, torture
);
1616 ret
&= test_notify_tdis(torture
);
1617 ret
&= test_notify_exit(torture
);
1618 ret
&= test_notify_ulogoff(torture
);
1619 ret
&= test_notify_tcp_dis(torture
);
1620 ret
&= test_notify_double(cli
, torture
);
1621 ret
&= test_notify_tree(cli
, torture
);
1622 ret
&= test_notify_overflow(cli
, torture
);
1623 ret
&= test_notify_basedir(cli
, torture
);
1625 smb_raw_exit(cli
->session
);
1626 smbcli_deltree(cli
->tree
, BASEDIR
);