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"
28 /* basic testing of all SMB2 setinfo calls
29 for each call we test that it succeeds, and where possible test
30 for consistency between the calls.
32 BOOL torture_smb2_setinfo(void)
34 struct smb2_tree *tree;
36 TALLOC_CTX *mem_ctx = talloc_new(NULL);
37 struct smb2_handle handle;
40 union smb_fileinfo finfo2;
41 union smb_setfileinfo sfinfo;
42 NTSTATUS status, status2;
43 const char *call_name;
44 time_t basetime = (time(NULL) - 86400) & ~1;
45 int n = time(NULL) % 100;
47 fname = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_%d.txt", n);
48 fname_new = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_new_%d.txt", n);
50 if (!torture_smb2_connection(mem_ctx, &tree)) {
54 #define RECREATE_FILE(fname) do { \
55 smb2_util_close(tree, handle); \
56 status = smb2_create_complex_file(tree, fname, &handle); \
57 if (!NT_STATUS_IS_OK(status)) { \
58 printf("(%s) ERROR: open of %s failed (%s)\n", \
59 __location__, fname, nt_errstr(status)); \
64 #define RECREATE_BOTH do { \
65 RECREATE_FILE(fname); \
70 #define CHECK_CALL(call, rightstatus) do { \
72 sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
73 sfinfo.generic.file.handle = handle; \
74 status = smb2_setinfo_file(tree, &sfinfo); \
75 if (!NT_STATUS_EQUAL(status, rightstatus)) { \
76 printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
77 nt_errstr(status), nt_errstr(rightstatus)); \
82 #define CHECK1(call) \
83 do { if (NT_STATUS_IS_OK(status)) { \
84 finfo2.generic.level = RAW_FILEINFO_ ## call; \
85 finfo2.generic.in.handle = handle; \
86 status2 = smb2_getinfo_file(tree, mem_ctx, &finfo2); \
87 if (!NT_STATUS_IS_OK(status2)) { \
88 printf("%s - %s\n", #call, nt_errstr(status2)); \
92 #define CHECK_VALUE(call, stype, field, value) do { \
94 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
95 printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
96 call_name, #stype, #field, \
97 (uint_t)value, (uint_t)finfo2.stype.out.field); \
98 torture_smb2_all_info(tree, handle); \
101 #define CHECK_TIME(call, stype, field, value) do { \
103 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
104 printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
105 call_name, #stype, #field, \
107 (uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
108 printf("\t%s", timestring(mem_ctx, value)); \
109 printf("\t%s\n", nt_time_string(mem_ctx, finfo2.stype.out.field)); \
110 torture_smb2_all_info(tree, handle); \
113 #define CHECK_STR(call, stype, field, value) do { \
115 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && strcmp(finfo2.stype.out.field, value) != 0) { \
116 printf("(%s) %s - %s/%s should be '%s' - '%s'\n", __location__, \
117 call_name, #stype, #field, \
119 finfo2.stype.out.field); \
120 torture_smb2_all_info(tree, handle); \
123 #define CHECK_STATUS(status, correct) do { \
124 if (!NT_STATUS_EQUAL(status, correct)) { \
125 printf("(%s) Incorrect status %s - should be %s\n", \
126 __location__, nt_errstr(status), nt_errstr(correct)); \
132 torture_smb2_all_info(tree, handle);
134 printf("test basic_information level\n");
136 unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
137 unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
138 unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300);
139 unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
140 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
141 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
142 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
143 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
144 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
145 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
146 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_READONLY);
148 printf("a zero time means don't change\n");
149 unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
150 unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
151 unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
152 unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
153 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
154 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
155 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
156 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
157 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
158 CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
159 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
161 printf("change the attribute\n");
162 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
163 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
164 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
166 printf("zero attrib means don't change\n");
167 sfinfo.basic_info.in.attrib = 0;
168 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
169 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
171 printf("restore attribute\n");
172 sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
173 CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
174 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
176 printf("test disposition_information level\n");
177 sfinfo.disposition_info.in.delete_on_close = 1;
178 CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
179 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 1);
180 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 0);
182 sfinfo.disposition_info.in.delete_on_close = 0;
183 CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
184 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 0);
185 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 1);
187 printf("test allocation_information level\n");
188 sfinfo.allocation_info.in.alloc_size = 0;
189 CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
190 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
191 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 0);
193 sfinfo.allocation_info.in.alloc_size = 4096;
194 CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
195 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 4096);
196 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
198 printf("test end_of_file_info level\n");
199 sfinfo.end_of_file_info.in.size = 37;
200 CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
201 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 37);
203 sfinfo.end_of_file_info.in.size = 7;
204 CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
205 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 7);
207 printf("test position_information level\n");
208 sfinfo.position_information.in.position = 123456;
209 CHECK_CALL(POSITION_INFORMATION, NT_STATUS_OK);
210 CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456);
211 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, position, 123456);
213 printf("test mode_information level\n");
214 sfinfo.mode_information.in.mode = 2;
215 CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
216 CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2);
217 CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, mode, 2);
219 sfinfo.mode_information.in.mode = 1;
220 CHECK_CALL(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER);
222 sfinfo.mode_information.in.mode = 0;
223 CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
224 CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
227 status = smb2_util_close(tree, handle);
228 if (NT_STATUS_IS_ERR(status)) {
229 printf("Failed to delete %s - %s\n", fname, nt_errstr(status));
231 smb2_util_unlink(tree, fname);
233 talloc_free(mem_ctx);