r23792: convert Samba4 to GPLv3
[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 static struct {
30         const char *name;
31         uint16_t level;
32         NTSTATUS fstatus;
33         NTSTATUS dstatus;
34         union smb_fileinfo finfo;
35         union smb_fileinfo dinfo;
36 } file_levels[] = {
37 #define LEVEL(x) #x, x
38  { LEVEL(RAW_FILEINFO_BASIC_INFORMATION) },
39  { LEVEL(RAW_FILEINFO_STANDARD_INFORMATION) },
40  { LEVEL(RAW_FILEINFO_INTERNAL_INFORMATION) },
41  { LEVEL(RAW_FILEINFO_EA_INFORMATION) },
42  { LEVEL(RAW_FILEINFO_ACCESS_INFORMATION) },
43  { LEVEL(RAW_FILEINFO_POSITION_INFORMATION) },
44  { LEVEL(RAW_FILEINFO_MODE_INFORMATION) },
45  { LEVEL(RAW_FILEINFO_ALIGNMENT_INFORMATION) },
46  { LEVEL(RAW_FILEINFO_ALL_INFORMATION) },
47  { LEVEL(RAW_FILEINFO_ALT_NAME_INFORMATION) },
48  { LEVEL(RAW_FILEINFO_STREAM_INFORMATION) },
49  { LEVEL(RAW_FILEINFO_COMPRESSION_INFORMATION) },
50  { LEVEL(RAW_FILEINFO_NETWORK_OPEN_INFORMATION) },
51  { LEVEL(RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION) },
52  { LEVEL(RAW_FILEINFO_SMB2_ALL_EAS) },
53  { LEVEL(RAW_FILEINFO_SMB2_ALL_INFORMATION) },
54  { LEVEL(RAW_FILEINFO_SEC_DESC) }
55 };
56
57 static struct {
58         const char *name;
59         uint16_t level;
60         NTSTATUS status;
61         union smb_fsinfo info;
62 } fs_levels[] = {
63  { LEVEL(RAW_QFS_VOLUME_INFORMATION) },
64  { LEVEL(RAW_QFS_SIZE_INFORMATION) },
65  { LEVEL(RAW_QFS_DEVICE_INFORMATION) },
66  { LEVEL(RAW_QFS_ATTRIBUTE_INFORMATION) },
67  { LEVEL(RAW_QFS_QUOTA_INFORMATION) },
68  { LEVEL(RAW_QFS_FULL_SIZE_INFORMATION) },
69  { LEVEL(RAW_QFS_OBJECTID_INFORMATION) }
70 };
71
72 #define FNAME "testsmb2_file.dat"
73 #define DNAME "testsmb2_dir"
74
75 /*
76   test fileinfo levels
77 */
78 static BOOL torture_smb2_fileinfo(struct smb2_tree *tree)
79 {
80         struct smb2_handle hfile, hdir;
81         NTSTATUS status;
82         int i;
83
84         status = torture_smb2_testfile(tree, FNAME, &hfile);
85         if (!NT_STATUS_IS_OK(status)) {
86                 printf("Unable to create test file '%s' - %s\n", FNAME, nt_errstr(status));
87                 goto failed;
88         }
89
90         status = torture_smb2_testdir(tree, DNAME, &hdir);
91         if (!NT_STATUS_IS_OK(status)) {
92                 printf("Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
93                 goto failed;
94         }
95
96         printf("Testing file info levels\n");
97         torture_smb2_all_info(tree, hfile);
98         torture_smb2_all_info(tree, hdir);
99
100         for (i=0;i<ARRAY_SIZE(file_levels);i++) {
101                 if (file_levels[i].level == RAW_FILEINFO_SEC_DESC) {
102                         file_levels[i].finfo.query_secdesc.in.secinfo_flags = 0x7;
103                         file_levels[i].dinfo.query_secdesc.in.secinfo_flags = 0x7;
104                 }
105                 if (file_levels[i].level == RAW_FILEINFO_SMB2_ALL_EAS) {
106                         if (lp_parm_bool(-1, "torture", "samba4", False)) {
107                                 continue;
108                         }
109                         file_levels[i].finfo.all_eas.in.continue_flags = 
110                                 SMB2_CONTINUE_FLAG_RESTART;
111                         file_levels[i].dinfo.all_eas.in.continue_flags = 
112                                 SMB2_CONTINUE_FLAG_RESTART;
113                 }
114                 file_levels[i].finfo.generic.level = file_levels[i].level;
115                 file_levels[i].finfo.generic.in.file.handle = hfile;
116                 file_levels[i].fstatus = smb2_getinfo_file(tree, tree, &file_levels[i].finfo);
117                 if (!NT_STATUS_IS_OK(file_levels[i].fstatus)) {
118                         printf("(%s) %s failed on file - %s\n", __location__,
119                                 file_levels[i].name, nt_errstr(file_levels[i].fstatus));
120                         goto failed;
121                 }
122                 file_levels[i].dinfo.generic.level = file_levels[i].level;
123                 file_levels[i].dinfo.generic.in.file.handle = hdir;
124                 file_levels[i].dstatus = smb2_getinfo_file(tree, tree, &file_levels[i].dinfo);
125                 if (!NT_STATUS_IS_OK(file_levels[i].dstatus)) {
126                         printf("(%s) %s failed on dir - %s\n", __location__,
127                                 file_levels[i].name, nt_errstr(file_levels[i].dstatus));
128                         goto failed;
129                 }
130         }
131
132         return True;
133
134 failed:
135         return False;
136 }
137
138
139 /*
140   test fsinfo levels
141 */
142 static BOOL torture_smb2_fsinfo(struct smb2_tree *tree)
143 {
144         int i;
145         NTSTATUS status;
146         struct smb2_handle handle;
147
148         printf("Testing fsinfo levels\n");
149         status = smb2_util_roothandle(tree, &handle);
150         if (!NT_STATUS_IS_OK(status)) {
151                 printf("Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
152                 return False;
153         }
154
155         for (i=0;i<ARRAY_SIZE(fs_levels);i++) {
156                 fs_levels[i].info.generic.level = fs_levels[i].level;
157                 fs_levels[i].info.generic.handle = handle;
158                 fs_levels[i].status = smb2_getinfo_fs(tree, tree, &fs_levels[i].info);
159                 if (!NT_STATUS_IS_OK(fs_levels[i].status)) {
160                         printf("%s failed - %s\n", fs_levels[i].name, nt_errstr(fs_levels[i].status));
161                         return False;
162                 }
163         }
164
165         return True;
166 }
167
168
169 /* basic testing of all SMB2 getinfo levels
170 */
171 BOOL torture_smb2_getinfo(struct torture_context *torture)
172 {
173         TALLOC_CTX *mem_ctx = talloc_new(NULL);
174         struct smb2_tree *tree;
175         BOOL ret = True;
176         NTSTATUS status;
177
178         if (!torture_smb2_connection(mem_ctx, &tree)) {
179                 return False;
180         }
181
182         status = torture_setup_complex_file(tree, FNAME);
183         if (!NT_STATUS_IS_OK(status)) {
184                 return False;
185         }
186         torture_setup_complex_file(tree, FNAME ":streamtwo");
187         status = torture_setup_complex_dir(tree, DNAME);
188         if (!NT_STATUS_IS_OK(status)) {
189                 return False;
190         }
191         torture_setup_complex_file(tree, DNAME ":streamtwo");
192
193         ret &= torture_smb2_fileinfo(tree);
194         ret &= torture_smb2_fsinfo(tree);
195
196         talloc_free(mem_ctx);
197
198         return ret;
199 }