2 Unix SMB/CIFS implementation.
4 SMB2 getinfo test suite
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
34 union smb_fileinfo finfo
;
35 union smb_fileinfo dinfo
;
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
) },
53 { LEVEL(RAW_FILEINFO_SMB2_ALL_EAS
) },
55 { LEVEL(RAW_FILEINFO_SMB2_ALL_INFORMATION
) },
56 { LEVEL(RAW_FILEINFO_SEC_DESC
) }
63 union smb_fsinfo info
;
65 { LEVEL(RAW_QFS_VOLUME_INFORMATION
) },
66 { LEVEL(RAW_QFS_SIZE_INFORMATION
) },
67 { LEVEL(RAW_QFS_DEVICE_INFORMATION
) },
68 { LEVEL(RAW_QFS_ATTRIBUTE_INFORMATION
) },
69 { LEVEL(RAW_QFS_QUOTA_INFORMATION
) },
70 { LEVEL(RAW_QFS_FULL_SIZE_INFORMATION
) },
71 { LEVEL(RAW_QFS_OBJECTID_INFORMATION
) }
74 #define FNAME "testsmb2_file.dat"
75 #define DNAME "testsmb2_dir"
80 static bool torture_smb2_fileinfo(struct torture_context
*tctx
, struct smb2_tree
*tree
)
82 struct smb2_handle hfile
, hdir
;
86 status
= torture_smb2_testfile(tree
, FNAME
, &hfile
);
87 torture_assert_ntstatus_ok(tctx
, status
, "Unable to create test file "
90 status
= torture_smb2_testdir(tree
, DNAME
, &hdir
);
91 torture_assert_ntstatus_ok(tctx
, status
, "Unable to create test dir "
94 printf("Testing file info levels\n");
95 torture_smb2_all_info(tree
, hfile
);
96 torture_smb2_all_info(tree
, hdir
);
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
.in
.secinfo_flags
= 0x7;
101 file_levels
[i
].dinfo
.query_secdesc
.in
.secinfo_flags
= 0x7;
103 if (file_levels
[i
].level
== RAW_FILEINFO_SMB2_ALL_EAS
) {
104 file_levels
[i
].finfo
.all_eas
.in
.continue_flags
=
105 SMB2_CONTINUE_FLAG_RESTART
;
106 file_levels
[i
].dinfo
.all_eas
.in
.continue_flags
=
107 SMB2_CONTINUE_FLAG_RESTART
;
109 file_levels
[i
].finfo
.generic
.level
= file_levels
[i
].level
;
110 file_levels
[i
].finfo
.generic
.in
.file
.handle
= hfile
;
111 file_levels
[i
].fstatus
= smb2_getinfo_file(tree
, tree
, &file_levels
[i
].finfo
);
112 torture_assert_ntstatus_ok(tctx
, file_levels
[i
].fstatus
,
113 talloc_asprintf(tctx
, "%s on file",
114 file_levels
[i
].name
));
115 file_levels
[i
].dinfo
.generic
.level
= file_levels
[i
].level
;
116 file_levels
[i
].dinfo
.generic
.in
.file
.handle
= hdir
;
117 file_levels
[i
].dstatus
= smb2_getinfo_file(tree
, tree
, &file_levels
[i
].dinfo
);
118 torture_assert_ntstatus_ok(tctx
, file_levels
[i
].dstatus
,
119 talloc_asprintf(tctx
, "%s on dir",
120 file_levels
[i
].name
));
130 static bool torture_smb2_fsinfo(struct torture_context
*tctx
)
133 struct smb2_tree
*tree
;
136 struct smb2_handle handle
;
138 printf("Testing fsinfo levels\n");
140 ret
= torture_smb2_connection(tctx
, &tree
);
141 torture_assert(tctx
, ret
, "connection failed");
143 status
= smb2_util_roothandle(tree
, &handle
);
144 torture_assert_ntstatus_ok(tctx
, status
, "Unable to create root handle");
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 torture_assert_ntstatus_ok(tctx
, fs_levels
[i
].status
,
159 test for buffer size handling
161 static bool torture_smb2_buffercheck(struct torture_context
*tctx
)
164 struct smb2_tree
*tree
;
166 struct smb2_handle handle
;
167 struct smb2_getinfo b
;
169 printf("Testing buffer size handling\n");
171 ret
= torture_smb2_connection(tctx
, &tree
);
172 torture_assert(tctx
, ret
, "connection failed");
174 status
= smb2_util_roothandle(tree
, &handle
);
175 torture_assert_ntstatus_ok(tctx
, status
, "Unable to create root handle");
178 b
.in
.info_type
= SMB2_GETINFO_FS
;
180 b
.in
.output_buffer_length
= 0x1;
181 b
.in
.input_buffer_length
= 0;
182 b
.in
.file
.handle
= handle
;
184 status
= smb2_getinfo(tree
, tree
, &b
);
185 torture_assert_ntstatus_equal(tctx
, status
,
186 NT_STATUS_INFO_LENGTH_MISMATCH
,
187 "Wrong error code for small buffer");
192 /* basic testing of all SMB2 getinfo levels
194 static bool torture_smb2_getinfo(struct torture_context
*torture
)
196 struct smb2_tree
*tree
;
200 ret
= torture_smb2_connection(torture
, &tree
);
201 torture_assert(torture
, ret
, "connection failed");
203 smb2_deltree(tree
, FNAME
);
204 smb2_deltree(tree
, DNAME
);
206 status
= torture_setup_complex_file(tree
, FNAME
);
207 torture_assert_ntstatus_ok(torture
, status
,
208 "setup complex file " FNAME
);
210 status
= torture_setup_complex_file(tree
, FNAME
":streamtwo");
211 torture_assert_ntstatus_ok(torture
, status
,
212 "setup complex file " FNAME
":streamtwo");
214 status
= torture_setup_complex_dir(tree
, DNAME
);
215 torture_assert_ntstatus_ok(torture
, status
,
216 "setup complex dir " DNAME
);
218 status
= torture_setup_complex_file(tree
, DNAME
":streamtwo");
219 torture_assert_ntstatus_ok(torture
, status
,
220 "setup complex dir " DNAME
":streamtwo");
222 ret
&= torture_smb2_fileinfo(torture
, tree
);
227 struct torture_suite
*torture_smb2_getinfo_init(void)
229 struct torture_suite
*suite
= torture_suite_create(
230 talloc_autofree_context(), "getinfo");
232 torture_suite_add_simple_test(suite
, "complex", torture_smb2_getinfo
);
233 torture_suite_add_simple_test(suite
, "fsinfo", torture_smb2_fsinfo
);
234 torture_suite_add_simple_test(suite
, "buffercheck",
235 torture_smb2_buffercheck
);