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