Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-test
[kai/samba.git] / source4 / torture / smb2 / getinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 getinfo test suite
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28
29 #include "param/param.h"
30
31 static struct {
32         const char *name;
33         uint16_t level;
34         NTSTATUS fstatus;
35         NTSTATUS dstatus;
36         union smb_fileinfo finfo;
37         union smb_fileinfo dinfo;
38 } file_levels[] = {
39 #define LEVEL(x) #x, x
40  { LEVEL(RAW_FILEINFO_BASIC_INFORMATION) },
41  { LEVEL(RAW_FILEINFO_STANDARD_INFORMATION) },
42  { LEVEL(RAW_FILEINFO_INTERNAL_INFORMATION) },
43  { LEVEL(RAW_FILEINFO_EA_INFORMATION) },
44  { LEVEL(RAW_FILEINFO_ACCESS_INFORMATION) },
45  { LEVEL(RAW_FILEINFO_POSITION_INFORMATION) },
46  { LEVEL(RAW_FILEINFO_MODE_INFORMATION) },
47  { LEVEL(RAW_FILEINFO_ALIGNMENT_INFORMATION) },
48  { LEVEL(RAW_FILEINFO_ALL_INFORMATION) },
49  { LEVEL(RAW_FILEINFO_ALT_NAME_INFORMATION) },
50  { LEVEL(RAW_FILEINFO_STREAM_INFORMATION) },
51  { LEVEL(RAW_FILEINFO_COMPRESSION_INFORMATION) },
52  { LEVEL(RAW_FILEINFO_NETWORK_OPEN_INFORMATION) },
53  { LEVEL(RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION) },
54 /*
55  { LEVEL(RAW_FILEINFO_SMB2_ALL_EAS) },
56 */
57  { LEVEL(RAW_FILEINFO_SMB2_ALL_INFORMATION) },
58  { LEVEL(RAW_FILEINFO_SEC_DESC) }
59 };
60
61 static struct {
62         const char *name;
63         uint16_t level;
64         NTSTATUS status;
65         union smb_fsinfo info;
66 } fs_levels[] = {
67  { LEVEL(RAW_QFS_VOLUME_INFORMATION) },
68  { LEVEL(RAW_QFS_SIZE_INFORMATION) },
69  { LEVEL(RAW_QFS_DEVICE_INFORMATION) },
70  { LEVEL(RAW_QFS_ATTRIBUTE_INFORMATION) },
71  { LEVEL(RAW_QFS_QUOTA_INFORMATION) },
72  { LEVEL(RAW_QFS_FULL_SIZE_INFORMATION) },
73  { LEVEL(RAW_QFS_OBJECTID_INFORMATION) }
74 };
75
76 #define FNAME "testsmb2_file.dat"
77 #define DNAME "testsmb2_dir"
78
79 /*
80   test fileinfo levels
81 */
82 static bool torture_smb2_fileinfo(struct torture_context *tctx, struct smb2_tree *tree)
83 {
84         struct smb2_handle hfile, hdir;
85         NTSTATUS status;
86         int i;
87
88         status = torture_smb2_testfile(tree, FNAME, &hfile);
89         if (!NT_STATUS_IS_OK(status)) {
90                 printf(__location__ " Unable to create test file '%s' - %s\n", FNAME, nt_errstr(status));
91                 goto failed;
92         }
93
94         status = torture_smb2_testdir(tree, DNAME, &hdir);
95         if (!NT_STATUS_IS_OK(status)) {
96                 printf(__location__ " Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
97                 goto failed;
98         }
99
100         printf("Testing file info levels\n");
101         torture_smb2_all_info(tree, hfile);
102         torture_smb2_all_info(tree, hdir);
103
104         for (i=0;i<ARRAY_SIZE(file_levels);i++) {
105                 if (file_levels[i].level == RAW_FILEINFO_SEC_DESC) {
106                         file_levels[i].finfo.query_secdesc.in.secinfo_flags = 0x7;
107                         file_levels[i].dinfo.query_secdesc.in.secinfo_flags = 0x7;
108                 }
109                 if (file_levels[i].level == RAW_FILEINFO_SMB2_ALL_EAS) {
110                         file_levels[i].finfo.all_eas.in.continue_flags = 
111                                 SMB2_CONTINUE_FLAG_RESTART;
112                         file_levels[i].dinfo.all_eas.in.continue_flags = 
113                                 SMB2_CONTINUE_FLAG_RESTART;
114                 }
115                 file_levels[i].finfo.generic.level = file_levels[i].level;
116                 file_levels[i].finfo.generic.in.file.handle = hfile;
117                 file_levels[i].fstatus = smb2_getinfo_file(tree, tree, &file_levels[i].finfo);
118                 if (!NT_STATUS_IS_OK(file_levels[i].fstatus)) {
119                         printf("(%s) %s failed on file - %s\n", __location__,
120                                 file_levels[i].name, nt_errstr(file_levels[i].fstatus));
121                         goto failed;
122                 }
123                 file_levels[i].dinfo.generic.level = file_levels[i].level;
124                 file_levels[i].dinfo.generic.in.file.handle = hdir;
125                 file_levels[i].dstatus = smb2_getinfo_file(tree, tree, &file_levels[i].dinfo);
126                 if (!NT_STATUS_IS_OK(file_levels[i].dstatus)) {
127                         printf("(%s) %s failed on dir - %s\n", __location__,
128                                 file_levels[i].name, nt_errstr(file_levels[i].dstatus));
129                         goto failed;
130                 }
131         }
132
133         return true;
134
135 failed:
136         return false;
137 }
138
139
140 /*
141   test fsinfo levels
142 */
143 static bool torture_smb2_fsinfo(struct smb2_tree *tree)
144 {
145         int i;
146         NTSTATUS status;
147         struct smb2_handle handle;
148
149         printf("Testing fsinfo levels\n");
150         status = smb2_util_roothandle(tree, &handle);
151         if (!NT_STATUS_IS_OK(status)) {
152                 printf(__location__ " Unable to create root handle - %s\n", nt_errstr(status));
153                 return false;
154         }
155
156         for (i=0;i<ARRAY_SIZE(fs_levels);i++) {
157                 fs_levels[i].info.generic.level = fs_levels[i].level;
158                 fs_levels[i].info.generic.handle = handle;
159                 fs_levels[i].status = smb2_getinfo_fs(tree, tree, &fs_levels[i].info);
160                 if (!NT_STATUS_IS_OK(fs_levels[i].status)) {
161                         printf("%s failed - %s\n", fs_levels[i].name, nt_errstr(fs_levels[i].status));
162                         return false;
163                 }
164         }
165
166         return true;
167 }
168
169
170 /*
171   test for buffer size handling
172 */
173 static bool torture_smb2_buffercheck(struct smb2_tree *tree)
174 {
175         NTSTATUS status;
176         struct smb2_handle handle;
177         struct smb2_getinfo b;
178
179         printf("Testing buffer size handling\n");
180         status = smb2_util_roothandle(tree, &handle);
181         if (!NT_STATUS_IS_OK(status)) {
182                 printf(__location__ " Unable to create root handle - %s\n", nt_errstr(status));
183                 return false;
184         }
185
186         ZERO_STRUCT(b);
187         b.in.info_type            = SMB2_GETINFO_FS;
188         b.in.info_class           = 1;
189         b.in.output_buffer_length = 0x1;
190         b.in.input_buffer_length  = 0;
191         b.in.file.handle          = handle;
192
193         status = smb2_getinfo(tree, tree, &b);
194         if (!NT_STATUS_EQUAL(status, NT_STATUS_INFO_LENGTH_MISMATCH)) {
195                 printf(__location__ " Wrong error code for small buffer %s\n",
196                        nt_errstr(status));
197                 return false;
198         }
199
200         return true;
201 }
202
203
204 /* basic testing of all SMB2 getinfo levels
205 */
206 bool torture_smb2_getinfo(struct torture_context *torture)
207 {
208         TALLOC_CTX *mem_ctx = talloc_new(NULL);
209         struct smb2_tree *tree;
210         bool ret = true;
211         NTSTATUS status;
212
213         if (!torture_smb2_connection(torture, &tree)) {
214                 return false;
215         }
216
217         smb2_deltree(tree, FNAME);
218         smb2_deltree(tree, DNAME);
219
220         status = torture_setup_complex_file(tree, FNAME);
221         if (!NT_STATUS_IS_OK(status)) {
222                 return false;
223         }
224         torture_setup_complex_file(tree, FNAME ":streamtwo");
225         status = torture_setup_complex_dir(tree, DNAME);
226         if (!NT_STATUS_IS_OK(status)) {
227                 return false;
228         }
229         torture_setup_complex_file(tree, DNAME ":streamtwo");
230
231         ret &= torture_smb2_fileinfo(torture, tree);
232         ret &= torture_smb2_fsinfo(tree);
233         ret &= torture_smb2_buffercheck(tree);
234
235         talloc_free(mem_ctx);
236
237         return ret;
238 }