2 Unix SMB/CIFS implementation.
4 SMB2 setinfo individual 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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "system/time.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
28 #include "torture/smb2/proto.h"
32 /* basic testing of all SMB2 setinfo calls
33 for each call we test that it succeeds, and where possible test
34 for consistency between the calls.
36 BOOL torture_smb2_setinfo(void)
38 struct smb2_tree *tree;
40 TALLOC_CTX *mem_ctx = talloc_new(NULL);
41 struct smb2_handle handle;
44 union smb_fileinfo finfo2;
45 union smb_setfileinfo sfinfo;
46 NTSTATUS status, status2;
47 const char *call_name;
48 time_t basetime = (time(NULL) - 86400) & ~1;
49 int n = time(NULL) % 100;
53 fname = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_%d.txt", n);
54 fname_new = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_new_%d.txt", n);
56 if (!torture_smb2_connection(mem_ctx, &tree)) {
60 #define RECREATE_FILE(fname) do { \
61 smb2_util_close(tree, handle); \
62 status = smb2_create_complex_file(tree, fname, &handle); \
63 if (!NT_STATUS_IS_OK(status)) { \
64 printf("(%s) ERROR: open of %s failed (%s)\n", \
65 __location__, fname, nt_errstr(status)); \
70 #define RECREATE_BOTH do { \
71 RECREATE_FILE(fname); \
76 #define CHECK_CALL(call, rightstatus) do { \
78 sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
79 sfinfo.generic.file.handle = handle; \
80 status = smb2_setinfo_file(tree, &sfinfo); \
81 if (!NT_STATUS_EQUAL(status, rightstatus)) { \
82 printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
83 nt_errstr(status), nt_errstr(rightstatus)); \
88 #define CHECK1(call) \
89 do { if (NT_STATUS_IS_OK(status)) { \
90 finfo2.generic.level = RAW_FILEINFO_ ## call; \
91 finfo2.generic.in.handle = handle; \
92 status2 = smb2_getinfo_file(tree, mem_ctx, &finfo2); \
93 if (!NT_STATUS_IS_OK(status2)) { \
94 printf("%s - %s\n", #call, nt_errstr(status2)); \
98 #define CHECK_VALUE(call, stype, field, value) do { \
100 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
101 printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
102 call_name, #stype, #field, \
103 (uint_t)value, (uint_t)finfo2.stype.out.field); \
104 torture_smb2_all_info(tree, handle); \
107 #define CHECK_TIME(call, stype, field, value) do { \
109 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
110 printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
111 call_name, #stype, #field, \
113 (uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
114 printf("\t%s", timestring(mem_ctx, value)); \
115 printf("\t%s\n", nt_time_string(mem_ctx, finfo2.stype.out.field)); \
116 torture_smb2_all_info(tree, handle); \
119 #define CHECK_STR(call, stype, field, value) do { \
121 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && strcmp(finfo2.stype.out.field, value) != 0) { \
122 printf("(%s) %s - %s/%s should be '%s' - '%s'\n", __location__, \
123 call_name, #stype, #field, \
125 finfo2.stype.out.field); \
126 torture_smb2_all_info(tree, handle); \
129 #define CHECK_STATUS(status, correct) do { \
130 if (!NT_STATUS_EQUAL(status, correct)) { \
131 printf("(%s) Incorrect status %s - should be %s\n", \
132 __location__, nt_errstr(status), nt_errstr(correct)); \
138 torture_smb2_all_info(tree, handle);
140 printf("test basic_information level\n");
142 unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
143 unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
144 unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300);
145 unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
146 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
147 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
148 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
149 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
150 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
151 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
152 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_READONLY);
154 printf("a zero time means don't change\n");
155 unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
156 unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
157 unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
158 unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
159 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
160 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
161 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
162 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
163 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
164 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
165 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
167 printf("change the attribute\n");
168 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
169 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
170 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
172 printf("zero attrib means don't change\n");
173 sfinfo.basic_info.in.attrib = 0;
174 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
175 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
177 printf("restore attribute\n");
178 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
179 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
180 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
182 printf("test disposition_information level\n");
183 sfinfo.disposition_info.in.delete_on_close = 1;
184 CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
185 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 1);
186 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 0);
188 sfinfo.disposition_info.in.delete_on_close = 0;
189 CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
190 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 0);
191 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 1);
193 printf("test allocation_information level\n");
194 sfinfo.allocation_info.in.alloc_size = 0;
195 CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
196 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
197 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 0);
199 sfinfo.allocation_info.in.alloc_size = 4096;
200 CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
201 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 4096);
202 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
204 printf("test end_of_file_info level\n");
205 sfinfo.end_of_file_info.in.size = 37;
206 CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
207 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 37);
209 sfinfo.end_of_file_info.in.size = 7;
210 CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
211 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 7);
213 printf("test position_information level\n");
214 sfinfo.position_information.in.position = 123456;
215 CHECK_CALL(POSITION_INFORMATION, NT_STATUS_OK);
216 CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456);
217 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, position, 123456);
219 printf("test mode_information level\n");
220 sfinfo.mode_information.in.mode = 2;
221 CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
222 CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2);
223 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, mode, 2);
225 sfinfo.mode_information.in.mode = 1;
226 CHECK_CALL(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER);
228 sfinfo.mode_information.in.mode = 0;
229 CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
230 CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
233 status = smb2_util_close(tree, handle);
234 if (NT_STATUS_IS_ERR(status)) {
235 printf("Failed to delete %s - %s\n", fname, nt_errstr(status));
237 smb2_util_unlink(tree, fname);
239 talloc_free(mem_ctx);