]> git.samba.org - gd/samba-autobuild/.git/blob - source4/torture/raw/notify.c
2a5a0ca074a9fc451458d6977df7a88a4c89de69
[gd/samba-autobuild/.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 "librpc/gen_ndr/ndr_security.h"
23
24 #define BASEDIR "\\test_notify"
25
26 #define CHECK_STATUS(status, correct) do { \
27         if (!NT_STATUS_EQUAL(status, correct)) { \
28                 printf("(%d) Incorrect status %s - should be %s\n", \
29                        __LINE__, nt_errstr(status), nt_errstr(correct)); \
30                 ret = False; \
31                 goto done; \
32         }} while (0)
33
34
35 #define CHECK_VAL(v, correct) do { \
36         if ((v) != (correct)) { \
37                 printf("(%d) wrong value for %s  0x%x - 0x%x\n", \
38                        __LINE__, #v, (int)v, (int)correct); \
39                 ret = False; \
40                 goto done; \
41         }} while (0)
42
43 #define CHECK_WSTR(field, value, flags) do { \
44         if (!field.s || strcmp(field.s, value) || wire_bad_flags(&field, flags, cli)) { \
45                 printf("(%d) %s [%s] != %s\n",  __LINE__, #field, field.s, value); \
46                         ret = False; \
47                 goto done; \
48         }} while (0)
49
50
51 /* 
52    basic testing of change notify
53 */
54 BOOL torture_raw_notify(void)
55 {
56         struct smbcli_state *cli;
57         BOOL ret = True;
58         TALLOC_CTX *mem_ctx;
59         NTSTATUS status;
60         struct smb_notify notify;
61         union smb_open io;
62         int fnum = -1;
63         struct smbcli_request *req;
64                 
65         if (!torture_open_connection(&cli)) {
66                 return False;
67         }
68
69         mem_ctx = talloc_init("torture_raw_notify");
70
71         if (!torture_setup_dir(cli, BASEDIR)) {
72                 return False;
73         }
74
75         /*
76           get a handle on the directory
77         */
78         io.generic.level = RAW_OPEN_NTCREATEX;
79         io.ntcreatex.in.root_fid = 0;
80         io.ntcreatex.in.flags = 0;
81         io.ntcreatex.in.access_mask = SEC_FILE_ALL;
82         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
83         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
84         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
85         io.ntcreatex.in.alloc_size = 0;
86         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
87         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
88         io.ntcreatex.in.security_flags = 0;
89         io.ntcreatex.in.fname = BASEDIR;
90
91         status = smb_raw_open(cli->tree, mem_ctx, &io);
92         CHECK_STATUS(status, NT_STATUS_OK);
93         fnum = io.ntcreatex.out.fnum;
94
95         /* ask for a change notify */
96         notify.in.buffer_size = 4096;
97         notify.in.completion_filter = 0xFF;
98         notify.in.fnum = fnum;
99         notify.in.recursive = True;
100
101         printf("testing notify mkdir\n");
102
103         req = smb_raw_changenotify_send(cli->tree, &notify);
104         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
105
106         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
107         CHECK_STATUS(status, NT_STATUS_OK);
108
109         CHECK_VAL(notify.out.num_changes, 1);
110         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_ADDED);
111         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
112
113         printf("testing notify rmdir\n");
114
115         req = smb_raw_changenotify_send(cli->tree, &notify);
116         smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
117
118         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
119         CHECK_STATUS(status, NT_STATUS_OK);
120         CHECK_VAL(notify.out.num_changes, 1);
121         CHECK_VAL(notify.out.changes[0].action, NOTIFY_ACTION_REMOVED);
122         CHECK_WSTR(notify.out.changes[0].name, "subdir-name", STR_UNICODE);
123
124         printf("testing notify cancel\n");
125
126         req = smb_raw_changenotify_send(cli->tree, &notify);
127         smb_raw_ntcancel(req);
128         smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
129         status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
130         CHECK_STATUS(status, NT_STATUS_CANCELLED);
131
132 done:
133         smb_raw_exit(cli->session);
134         smbcli_deltree(cli->tree, BASEDIR);
135         torture_close_connection(cli);
136         talloc_destroy(mem_ctx);
137         return ret;
138 }