r14794: added a test to see what happens when you send a notify request on a
[abartlet/samba.git/.git] / source4 / torture / raw / notify.c
1 /* 
2    Unix SMB/CIFS implementation.
3    basic raw test suite for change notify
4    Copyright (C) Andrew Tridgell 2003
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
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.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/libcli.h"
25 #include "system/filesys.h"
26 #include "torture/util.h"
27
28 #define BASEDIR "\\test_notify"
29
30 #define CHECK_STATUS(status, correct) do { \
31         if (!NT_STATUS_EQUAL(status, correct)) { \
32                 printf("(%d) Incorrect status %s - should be %s\n", \
33                        __LINE__, nt_errstr(status), nt_errstr(correct)); \
34                 ret = False; \
35                 goto done; \
36         }} while (0)
37
38
39 #define CHECK_VAL(v, correct) do { \
40         if ((v) != (correct)) { \
41                 printf("(%d) wrong value for %s  0x%x should be 0x%x\n", \
42                        __LINE__, #v, (int)v, (int)correct); \
43                 ret = False; \
44                 goto done; \
45         }} while (0)
46
47 #define CHECK_WSTR(field, value, flags) do { \
48         if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli)) { \
49                 printf("(%d) %s [%s] != %s\n",  __LINE__, #field, field.s, value); \
50                         ret = False; \
51                 goto done; \
52         }} while (0)
53
54
55 /* 
56    basic testing of change notify on directories
57 */
58 static BOOL test_notify_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
59 {
60         BOOL ret = True;
61         NTSTATUS status;
62         struct smb_notify notify;
63         union smb_open io;
64         union smb_close cl;
65         int i, count, fnum, fnum2;
66         struct smbcli_request *req, *req2;
67         extern int torture_numops;
68
69         printf("TESTING CHANGE NOTIFY ON DIRECTRIES\n");
70                 
71         /*
72           get a handle on the directory
73         */
74         io.generic.level = RAW_OPEN_NTCREATEX;
75         io.ntcreatex.in.root_fid = 0;
76         io.ntcreatex.in.flags = 0;
77         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
78         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
79         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
80         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
81         io.ntcreatex.in.alloc_size = 0;
82         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
83         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
84         io.ntcreatex.in.security_flags = 0;
85         io.ntcreatex.in.fname = BASEDIR;
86
87         status = smb_raw_open(cli->tree, mem_ctx, &io);
88         CHECK_STATUS(status, NT_STATUS_OK);
89         fnum = io.ntcreatex.out.file.fnum;
90
91         status = smb_raw_open(cli->tree, mem_ctx, &io);
92         CHECK_STATUS(status, NT_STATUS_OK);
93         fnum2 = io.ntcreatex.out.file.fnum;
94
95         /* ask for a change notify,
96            on file or directory name changes */
97         notify.in.buffer_size = 1000;
98         notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
99         notify.in.file.fnum = fnum;
100         notify.in.recursive = True;
101
102         printf("testing notify cancel\n");
103
104         req = smb_raw_changenotify_send(cli->tree, &notify);
105         smb_raw_ntcancel(req);
106         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
107         CHECK_STATUS(status, NT_STATUS_CANCELLED);
108
109         printf("testing notify mkdir\n");
110
111         req = smb_raw_changenotify_send(cli->tree, &notify);
112         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
113
114         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
115         CHECK_STATUS(status, NT_STATUS_OK);
116
117         CHECK_VAL(notify.out.num_changes, 1);
118         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
119         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
120
121         printf("testing notify rmdir\n");
122
123         req = smb_raw_changenotify_send(cli->tree, &notify);
124         smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
125
126         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
127         CHECK_STATUS(status, NT_STATUS_OK);
128         CHECK_VAL(notify.out.num_changes, 1);
129         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
130         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
131
132         printf("testing notify mkdir - rmdir - mkdir - rmdir\n");
133
134         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
135         smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
136         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
137         smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
138         req = smb_raw_changenotify_send(cli->tree, &notify);
139         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
140         CHECK_STATUS(status, NT_STATUS_OK);
141         CHECK_VAL(notify.out.num_changes, 4);
142         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
143         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
144         CHECK_VAL(notify.out.changes[1].action, NOTIFY_ACTION_REMOVED);
145         CHECK_WSTR(notify.out.changes[1].name, "subdir-name", STR_UNICODE);
146         CHECK_VAL(notify.out.changes[2].action, NOTIFY_ACTION_ADDED);
147         CHECK_WSTR(notify.out.changes[2].name, "subdir-name", STR_UNICODE);
148         CHECK_VAL(notify.out.changes[3].action, NOTIFY_ACTION_REMOVED);
149         CHECK_WSTR(notify.out.changes[3].name, "subdir-name", STR_UNICODE);
150
151         count = torture_numops;
152         printf("testing buffered notify on create of %d files\n", count);
153         for (i=0;i<count;i++) {
154                 char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
155                 int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
156                 if (fnum3 == -1) {
157                         printf("Failed to create %s - %s\n", 
158                                fname, smbcli_errstr(cli->tree));
159                         ret = False;
160                         goto done;
161                 }
162                 talloc_free(fname);
163                 smbcli_close(cli->tree, fnum3);
164         }
165
166         /* (1st notify) setup a new notify on a different directory handle.
167            This new notify won't see the events above. */
168         notify.in.file.fnum = fnum2;
169         req2 = smb_raw_changenotify_send(cli->tree, &notify);
170
171         /* (2nd notify) whereas this notify will see the above buffered events,
172            and it directly returns the buffered events */
173         notify.in.file.fnum = fnum;
174         req = smb_raw_changenotify_send(cli->tree, &notify);
175
176         /* (1st unlink) as the 2nd notify directly returns,
177            this unlink is only seen by the 1st notify and 
178            the 3rd notify (later) */
179         printf("testing notify on unlink for the first file\n");
180         status = smbcli_unlink(cli->tree, BASEDIR "\\test0.txt");
181         CHECK_STATUS(status, NT_STATUS_OK);
182
183         /* receive the reply from the 2nd notify */
184         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
185         CHECK_STATUS(status, NT_STATUS_OK);
186
187         CHECK_VAL(notify.out.num_changes, count);
188         for (i=1;i<notify.out.num_changes;i++) {
189                 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_ADDED);
190         }
191         CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
192
193         /* and now from the 1st notify */
194         status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);
195         CHECK_STATUS(status, NT_STATUS_OK);
196         CHECK_VAL(notify.out.num_changes, 1);
197         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
198         CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
199
200         /* (3rd notify) this notify will only see the 1st unlink */
201         req = smb_raw_changenotify_send(cli->tree, &notify);
202
203         printf("testing notify on wildcard unlink for %d files\n", count-1);
204         /* (2nd unlink) do a wildcard unlink */
205         status = smbcli_unlink(cli->tree, BASEDIR "\\test*.txt");
206         CHECK_STATUS(status, NT_STATUS_OK);
207
208         /* recev the 3rd notify */
209         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
210         CHECK_STATUS(status, NT_STATUS_OK);
211         CHECK_VAL(notify.out.num_changes, 1);
212         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
213         CHECK_WSTR(notify.out.changes[0].name, "test0.txt", STR_UNICODE);
214
215         /* and we now see the rest of the unlink calls on both directory handles */
216         notify.in.file.fnum = fnum;
217         req = smb_raw_changenotify_send(cli->tree, &notify);
218         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
219         CHECK_STATUS(status, NT_STATUS_OK);
220         CHECK_VAL(notify.out.num_changes, count-1);
221         for (i=0;i<notify.out.num_changes;i++) {
222                 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_REMOVED);
223         }
224         notify.in.file.fnum = fnum2;
225         req = smb_raw_changenotify_send(cli->tree, &notify);
226         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
227         CHECK_STATUS(status, NT_STATUS_OK);
228         CHECK_VAL(notify.out.num_changes, count-1);
229         for (i=0;i<notify.out.num_changes;i++) {
230                 CHECK_VAL(notify.out.changes[i].action, NOTIFY_ACTION_REMOVED);
231         }
232
233         printf("testing if a close() on the dir handle triggers the notify reply\n");
234
235         notify.in.file.fnum = fnum;
236         req = smb_raw_changenotify_send(cli->tree, &notify);
237
238         cl.close.level = RAW_CLOSE_CLOSE;
239         cl.close.in.file.fnum = fnum;
240         cl.close.in.write_time = 0;
241         status = smb_raw_close(cli->tree, &cl);
242         CHECK_STATUS(status, NT_STATUS_OK);
243
244         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
245         CHECK_STATUS(status, NT_STATUS_OK);
246         CHECK_VAL(notify.out.num_changes, 0);
247
248 done:
249         smb_raw_exit(cli->session);
250         return ret;
251 }
252
253 /*
254   basic testing of change notify on files
255 */
256 static BOOL test_notify_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
257 {
258         NTSTATUS status;
259         BOOL ret = True;
260         union smb_open io;
261         union smb_close cl;
262         struct smb_notify notify;
263         struct smbcli_request *req;
264         int fnum;
265         const char *fname = BASEDIR "\\file.txt";
266
267         printf("TESTING CHANGE NOTIFY ON FILES\n");
268
269         io.generic.level = RAW_OPEN_NTCREATEX;
270         io.ntcreatex.in.root_fid = 0;
271         io.ntcreatex.in.flags = 0;
272         io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
273         io.ntcreatex.in.create_options = 0;
274         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
275         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
276         io.ntcreatex.in.alloc_size = 0;
277         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
278         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
279         io.ntcreatex.in.security_flags = 0;
280         io.ntcreatex.in.fname = fname;
281         status = smb_raw_open(cli->tree, mem_ctx, &io);
282         CHECK_STATUS(status, NT_STATUS_OK);
283         fnum = io.ntcreatex.out.file.fnum;
284
285         /* ask for a change notify,
286            on file or directory name changes */
287         notify.in.file.fnum = fnum;
288         notify.in.buffer_size = 1000;
289         notify.in.completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME;
290         notify.in.recursive = False;
291
292         printf("testing if notifies on file handles are invalid (should be)\n");
293
294         req = smb_raw_changenotify_send(cli->tree, &notify);
295         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
296         CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
297
298         cl.close.level = RAW_CLOSE_CLOSE;
299         cl.close.in.file.fnum = fnum;
300         cl.close.in.write_time = 0;
301         status = smb_raw_close(cli->tree, &cl);
302         CHECK_STATUS(status, NT_STATUS_OK);
303
304         status = smbcli_unlink(cli->tree, fname);
305         CHECK_STATUS(status, NT_STATUS_OK);
306
307 done:
308         smb_raw_exit(cli->session);
309         return ret;
310 }
311
312 /*
313   basic testing of change notifies followed by a tdis
314 */
315 static BOOL test_notify_tdis(TALLOC_CTX *mem_ctx)
316 {
317         BOOL ret = True;
318         NTSTATUS status;
319         struct smb_notify notify;
320         union smb_open io;
321         int fnum;
322         struct smbcli_request *req;
323         struct smbcli_state *cli = NULL;
324
325         printf("TESTING CHANGE NOTIFY FOLLOWED BY TDIS\n");
326
327         if (!torture_open_connection(&cli)) {
328                 return False;
329         }
330
331         /*
332           get a handle on the directory
333         */
334         io.generic.level = RAW_OPEN_NTCREATEX;
335         io.ntcreatex.in.root_fid = 0;
336         io.ntcreatex.in.flags = 0;
337         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
338         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
339         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
340         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
341         io.ntcreatex.in.alloc_size = 0;
342         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
343         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
344         io.ntcreatex.in.security_flags = 0;
345         io.ntcreatex.in.fname = BASEDIR;
346
347         status = smb_raw_open(cli->tree, mem_ctx, &io);
348         CHECK_STATUS(status, NT_STATUS_OK);
349         fnum = io.ntcreatex.out.file.fnum;
350
351         /* ask for a change notify,
352            on file or directory name changes */
353         notify.in.buffer_size = 1000;
354         notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
355         notify.in.file.fnum = fnum;
356         notify.in.recursive = True;
357
358         req = smb_raw_changenotify_send(cli->tree, &notify);
359
360         status = smbcli_tdis(cli);
361         CHECK_STATUS(status, NT_STATUS_OK);
362
363         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
364         CHECK_STATUS(status, NT_STATUS_OK);
365         CHECK_VAL(notify.out.num_changes, 0);
366
367 done:
368         torture_close_connection(cli);
369         return ret;
370 }
371
372 /*
373   basic testing of change notifies followed by a exit
374 */
375 static BOOL test_notify_exit(TALLOC_CTX *mem_ctx)
376 {
377         BOOL ret = True;
378         NTSTATUS status;
379         struct smb_notify notify;
380         union smb_open io;
381         int fnum;
382         struct smbcli_request *req;
383         struct smbcli_state *cli = NULL;
384
385         printf("TESTING CHANGE NOTIFY FOLLOWED BY EXIT\n");
386
387         if (!torture_open_connection(&cli)) {
388                 return False;
389         }
390
391         /*
392           get a handle on the directory
393         */
394         io.generic.level = RAW_OPEN_NTCREATEX;
395         io.ntcreatex.in.root_fid = 0;
396         io.ntcreatex.in.flags = 0;
397         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
398         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
399         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
400         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
401         io.ntcreatex.in.alloc_size = 0;
402         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
403         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
404         io.ntcreatex.in.security_flags = 0;
405         io.ntcreatex.in.fname = BASEDIR;
406
407         status = smb_raw_open(cli->tree, mem_ctx, &io);
408         CHECK_STATUS(status, NT_STATUS_OK);
409         fnum = io.ntcreatex.out.file.fnum;
410
411         /* ask for a change notify,
412            on file or directory name changes */
413         notify.in.buffer_size = 1000;
414         notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
415         notify.in.file.fnum = fnum;
416         notify.in.recursive = True;
417
418         req = smb_raw_changenotify_send(cli->tree, &notify);
419
420         status = smb_raw_exit(cli->session);
421         CHECK_STATUS(status, NT_STATUS_OK);
422
423         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
424         CHECK_STATUS(status, NT_STATUS_OK);
425         CHECK_VAL(notify.out.num_changes, 0);
426
427 done:
428         torture_close_connection(cli);
429         return ret;
430 }
431
432 /*
433   basic testing of change notifies followed by a ulogoff
434 */
435 static BOOL test_notify_ulogoff(TALLOC_CTX *mem_ctx)
436 {
437         BOOL ret = True;
438         NTSTATUS status;
439         struct smb_notify notify;
440         union smb_open io;
441         int fnum;
442         struct smbcli_request *req;
443         struct smbcli_state *cli = NULL;
444
445         printf("TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF\n");
446
447         if (!torture_open_connection(&cli)) {
448                 return False;
449         }
450
451         /*
452           get a handle on the directory
453         */
454         io.generic.level = RAW_OPEN_NTCREATEX;
455         io.ntcreatex.in.root_fid = 0;
456         io.ntcreatex.in.flags = 0;
457         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
458         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
459         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
460         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
461         io.ntcreatex.in.alloc_size = 0;
462         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
463         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
464         io.ntcreatex.in.security_flags = 0;
465         io.ntcreatex.in.fname = BASEDIR;
466
467         status = smb_raw_open(cli->tree, mem_ctx, &io);
468         CHECK_STATUS(status, NT_STATUS_OK);
469         fnum = io.ntcreatex.out.file.fnum;
470
471         /* ask for a change notify,
472            on file or directory name changes */
473         notify.in.buffer_size = 1000;
474         notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
475         notify.in.file.fnum = fnum;
476         notify.in.recursive = True;
477
478         req = smb_raw_changenotify_send(cli->tree, &notify);
479
480         status = smb_raw_ulogoff(cli->session);
481         CHECK_STATUS(status, NT_STATUS_OK);
482
483         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
484         CHECK_STATUS(status, NT_STATUS_OK);
485         CHECK_VAL(notify.out.num_changes, 0);
486
487 done:
488         torture_close_connection(cli);
489         return ret;
490 }
491
492
493 /* 
494    test setting up two change notify requests on one handle
495 */
496 static BOOL test_notify_double(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
497 {
498         BOOL ret = True;
499         NTSTATUS status;
500         struct smb_notify notify;
501         union smb_open io;
502         int fnum;
503         struct smbcli_request *req1, *req2;
504
505         printf("TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY\n");
506                 
507         /*
508           get a handle on the directory
509         */
510         io.generic.level = RAW_OPEN_NTCREATEX;
511         io.ntcreatex.in.root_fid = 0;
512         io.ntcreatex.in.flags = 0;
513         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
514         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
515         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
516         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
517         io.ntcreatex.in.alloc_size = 0;
518         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
519         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
520         io.ntcreatex.in.security_flags = 0;
521         io.ntcreatex.in.fname = BASEDIR;
522
523         status = smb_raw_open(cli->tree, mem_ctx, &io);
524         CHECK_STATUS(status, NT_STATUS_OK);
525         fnum = io.ntcreatex.out.file.fnum;
526
527         /* ask for a change notify,
528            on file or directory name changes */
529         notify.in.buffer_size = 1000;
530         notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
531         notify.in.file.fnum = fnum;
532         notify.in.recursive = True;
533
534         req1 = smb_raw_changenotify_send(cli->tree, &notify);
535         req2 = smb_raw_changenotify_send(cli->tree, &notify);
536
537         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
538
539         status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
540         CHECK_STATUS(status, NT_STATUS_OK);
541         CHECK_VAL(notify.out.num_changes, 1);
542         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
543
544         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name2");
545
546         status = smb_raw_changenotify_recv(req2, mem_ctx, &notify);
547         CHECK_STATUS(status, NT_STATUS_OK);
548         CHECK_VAL(notify.out.num_changes, 1);
549         CHECK_WSTR(notify.out.changes[0].name, "subdir-name2", STR_UNICODE);
550
551
552 done:
553         smb_raw_exit(cli->session);
554         return ret;
555 }
556
557 /* 
558    basic testing of change notify
559 */
560 BOOL torture_raw_notify(struct torture_context *torture)
561 {
562         struct smbcli_state *cli;
563         BOOL ret = True;
564         TALLOC_CTX *mem_ctx;
565                 
566         if (!torture_open_connection(&cli)) {
567                 return False;
568         }
569
570         mem_ctx = talloc_init("torture_raw_notify");
571
572         if (!torture_setup_dir(cli, BASEDIR)) {
573                 return False;
574         }
575
576         ret &= test_notify_dir(cli, mem_ctx);
577         ret &= test_notify_file(cli, mem_ctx);
578         ret &= test_notify_tdis(mem_ctx);
579         ret &= test_notify_exit(mem_ctx);
580         ret &= test_notify_ulogoff(mem_ctx);
581         ret &= test_notify_double(cli, mem_ctx);
582
583         smb_raw_exit(cli->session);
584         smbcli_deltree(cli->tree, BASEDIR);
585         torture_close_connection(cli);
586         talloc_free(mem_ctx);
587         return ret;
588 }