Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Basic test for NTTRANS FSCTL requests (copied from NTTRANS CREATE)
4 : Copyright (C) Richard Sharpe 2011
5 : Copyright (C) Volker Lendecke 2011
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "includes.h"
22 : #include "torture/proto.h"
23 : #include "libsmb/libsmb.h"
24 : #include "libcli/security/security.h"
25 :
26 4 : bool run_nttrans_fsctl(int dummy)
27 : {
28 4 : struct cli_state *cli = NULL;
29 0 : NTSTATUS status;
30 4 : bool ret = false;
31 4 : const char *fname = "fsctltest";
32 0 : uint16_t fnum;
33 0 : uint16_t setup[4];
34 4 : uint8_t *object_data = NULL;
35 4 : uint8_t *ranges = NULL;
36 0 : uint8_t range_data[16];
37 4 : uint8_t *param_data = NULL;
38 4 : uint8_t data[1] = { 0x1 };
39 0 : uint32_t rdata_size;
40 0 : uint32_t rparam_size;
41 :
42 4 : printf("Starting NTTRANS_FSCTL\n");
43 :
44 4 : if (!torture_open_connection(&cli, 0)) {
45 0 : printf("torture_open_connection failed\n");
46 0 : goto fail;
47 : }
48 :
49 4 : status = cli_nttrans_create(
50 : cli, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS|
51 : READ_CONTROL_ACCESS,
52 : FILE_ATTRIBUTE_NORMAL,
53 : FILE_SHARE_READ|FILE_SHARE_WRITE| FILE_SHARE_DELETE,
54 : FILE_CREATE, 0, 0, NULL, NULL, 0, &fnum, NULL);
55 4 : if (!NT_STATUS_IS_OK(status)) {
56 0 : d_fprintf(stderr, "cli_nttrans_create returned %s\n",
57 : nt_errstr(status));
58 0 : goto fail;
59 : }
60 :
61 4 : status = cli_nt_delete_on_close(cli, fnum, true);
62 4 : if (!NT_STATUS_IS_OK(status)) {
63 0 : d_fprintf(stderr, "cli_nt_delete_on_close returned %s\n",
64 : nt_errstr(status));
65 0 : goto fail;
66 : }
67 :
68 : /* Fill in for FSCTL_SET_SPARSE and call cli_trans ... */
69 4 : SIVAL(setup, 0, FSCTL_SET_SPARSE); /* returns value */
70 4 : SSVAL(setup, 4, fnum);
71 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
72 4 : SCVAL(setup, 7, 0x0);
73 :
74 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
75 : NULL, fnum,
76 : NT_TRANSACT_IOCTL, 0,
77 : setup, 4, 4,
78 : NULL, 0, 0, /* param, param_num, max_param */
79 : data, 1, 1, /* data, data_len, max_data */
80 : NULL, /* recv_flags2 */
81 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
82 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
83 : NULL, 0, NULL); /* rdata, ... */
84 4 : if (!NT_STATUS_IS_OK(status)) {
85 0 : d_fprintf(stderr, "cli_trans of FSCTL_SET_SPARSE returned %s instead of NT_STATUS_OK\n",
86 : nt_errstr(status));
87 0 : goto fail;
88 : }
89 :
90 4 : printf("FSCTL_SET_SPARSE returned correct status \n");
91 :
92 : /* Fill in for FSCTL_CREATE_OR_GET_OBJECT_ID and call cli_trans ... */
93 4 : SIVAL(setup, 0, FSCTL_CREATE_OR_GET_OBJECT_ID); /* returns value */
94 4 : SSVAL(setup, 4, fnum);
95 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
96 4 : SCVAL(setup, 7, 0x0);
97 :
98 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
99 : NULL, fnum,
100 : NT_TRANSACT_IOCTL, 0,
101 : setup, 4, 4,
102 : NULL, 0, 0, /* param, param_num, max_param */
103 : NULL, 0, 64, /* data, data_len, max_data */
104 : NULL, /* recv_flags2 */
105 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
106 : ¶m_data, 0, &rparam_size, /* rparam, min_rparam, num_rparam */
107 : &object_data, 0, &rdata_size); /* rdata, ... */
108 4 : if (!NT_STATUS_IS_OK(status)) {
109 0 : d_fprintf(stderr, "cli_trans of FSCTL_CREATE_OR_GET_OBJECT_ID returned %s instead of NT_STATUS_OK\n",
110 : nt_errstr(status));
111 0 : goto fail;
112 : }
113 :
114 4 : TALLOC_FREE(object_data);
115 4 : TALLOC_FREE(param_data);
116 :
117 4 : printf("FSCTL_CREATE_OR_GET_OBJECT_ID returned correct status \n");
118 :
119 : /* Fill in for FSCTL_GET_REPARSE_POINT and call cli_trans ... */
120 4 : SIVAL(setup, 0, FSCTL_GET_REPARSE_POINT); /* returns NOT A REPARSE POINT */
121 4 : SSVAL(setup, 4, fnum);
122 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
123 4 : SCVAL(setup, 7, 0x0);
124 :
125 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
126 : NULL, fnum,
127 : NT_TRANSACT_IOCTL, 0,
128 : setup, 4, 4,
129 : NULL, 0, 0, /* param, param_num, max_param */
130 : NULL, 0, 0, /* data, data_len, max_data */
131 : NULL, /* recv_flags2 */
132 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
133 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
134 : NULL, 0, NULL); /* rdata, ... */
135 4 : if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_REPARSE_POINT)) {
136 0 : d_fprintf(stderr, "cli_trans of FSCTL_GET_REPARSE_POINT returned %s instead of NT_STATUS_NOT_A_REPARSE_POINT\n",
137 : nt_errstr(status));
138 0 : goto fail;
139 : }
140 :
141 4 : printf("FSCTL_GET_REPARSE_POINT returned correct status \n");
142 :
143 : /* Fill in for FSCTL_SET_REPARSE_POINT and call cli_trans ... */
144 4 : SIVAL(setup, 0, FSCTL_SET_REPARSE_POINT); /* returns INVALID_BUFFER_SIZE */
145 4 : SSVAL(setup, 4, fnum);
146 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
147 4 : SCVAL(setup, 7, 0x0);
148 :
149 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
150 : NULL, fnum,
151 : NT_TRANSACT_IOCTL, 0,
152 : setup, 4, 4,
153 : NULL, 0, 0, /* param, param_num, max_param */
154 : NULL, 0, 0, /* data, data_len, max_data */
155 : NULL, /* recv_flags2 */
156 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
157 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
158 : NULL, 0, NULL); /* rdata, ... */
159 4 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_BUFFER_SIZE)) {
160 0 : d_fprintf(stderr,
161 : "cli_trans of FSCTL_SET_REPARSE_POINT returned %s "
162 : "instead of NT_STATUS_INVALID_BUFFER_SIZE\n",
163 : nt_errstr(status));
164 0 : goto fail;
165 : }
166 :
167 4 : printf("FSCTL_SET_REPARSE_POINT returned correct status \n");
168 :
169 : /*
170 : * Fill in for FSCTL_GET_SHADOW_COPY_DATA and call cli_trans ... what
171 : * we do is send an invalid data length to provoke an INVALID PARAMETER
172 : * response.
173 : */
174 4 : SIVAL(setup, 0, FSCTL_GET_SHADOW_COPY_DATA); /* Should return IVN VAL */
175 4 : SSVAL(setup, 4, fnum);
176 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
177 4 : SCVAL(setup, 7, 0x0);
178 :
179 4 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
180 :
181 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
182 : NULL, fnum,
183 : NT_TRANSACT_IOCTL, 0,
184 : setup, 4, 4,
185 : NULL, 0, 0, /* param, param_num, max_param */
186 : NULL, 0, 8, /* data, data_len, max_data */
187 : NULL, /* recv_flags2 */
188 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
189 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
190 : &ranges, 0, &rdata_size); /* rdata, ... */
191 4 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
192 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
193 : nt_errstr(status));
194 0 : goto fail;
195 : }
196 :
197 4 : TALLOC_FREE(ranges);
198 :
199 4 : printf("FSCTL_GET_SHADOW_COPY_DATA returned correct status \n");
200 : /*
201 : * Fill in for FSCTL_FIND_FILES_BY and call cli_trans ... here we are
202 : * only probing for its existence by provoking an INVALID PARAM
203 : * response with a short and invalid SID in range_data
204 : */
205 4 : SIVAL(setup, 0, FSCTL_FIND_FILES_BY_SID); /* Should return 16 bytes */
206 4 : SSVAL(setup, 4, fnum);
207 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
208 4 : SCVAL(setup, 7, 0x0);
209 :
210 4 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
211 :
212 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
213 : NULL, fnum,
214 : NT_TRANSACT_IOCTL, 0,
215 : setup, 4, 4,
216 : NULL, 0, 0, /* param, param_num, max_param */
217 : range_data, 4, 16, /* data, data_len, max_data */
218 : NULL, /* recv_flags2 */
219 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
220 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
221 : &ranges, 0, &rdata_size); /* rdata, ... */
222 4 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
223 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
224 : nt_errstr(status));
225 0 : goto fail;
226 : }
227 :
228 4 : printf("FSCTL_FIND_FILES_BY_SID returned correct status \n");
229 :
230 : /* Fill in for FSCTL_QUERY_ALLOCATED_RANGES and call cli_trans ... */
231 4 : SIVAL(setup, 0, FSCTL_QUERY_ALLOCATED_RANGES); /* Should return 16 bytes */
232 4 : SSVAL(setup, 4, fnum);
233 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
234 4 : SCVAL(setup, 7, 0x0);
235 :
236 4 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
237 :
238 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
239 : NULL, fnum,
240 : NT_TRANSACT_IOCTL, 0,
241 : setup, 4, 4,
242 : NULL, 0, 0, /* param, param_num, max_param */
243 : range_data, 16, 16, /* data, data_len, max_data */
244 : NULL, /* recv_flags2 */
245 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
246 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
247 : &ranges, 0, &rdata_size); /* rdata, ... */
248 4 : if (!NT_STATUS_IS_OK(status)) {
249 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_OK\n",
250 : nt_errstr(status));
251 0 : goto fail;
252 : }
253 :
254 4 : TALLOC_FREE(ranges);
255 :
256 4 : printf("FSCTL_QUERY_ALLOCATED_RANGES returned correct status \n");
257 :
258 : /* Fill in for FSCTL_IS_VOLUME_DIRTY and call cli_trans ... */
259 4 : SIVAL(setup, 0, FSCTL_IS_VOLUME_DIRTY); /* Should return INVAL PARAM */
260 4 : SSVAL(setup, 4, fnum);
261 4 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
262 4 : SCVAL(setup, 7, 0x0);
263 :
264 4 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
265 : NULL, fnum,
266 : NT_TRANSACT_IOCTL, 0,
267 : setup, 4, 4,
268 : NULL, 0, 0, /* param, param_num, max_param */
269 : NULL, 0, 0, /* data, data_len, max_data */
270 : NULL, /* recv_flags2 */
271 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
272 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
273 : NULL, 0, NULL); /* rdata, ... */
274 4 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
275 0 : d_fprintf(stderr, "cli_trans of FSCTL_IS_VOLUME_DIRTY returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
276 : nt_errstr(status));
277 0 : goto fail;
278 : }
279 :
280 4 : printf("FSCTL_IS_VOLUME_DIRTY returned correct status \n");
281 :
282 4 : ret = true;
283 4 : fail:
284 4 : if (cli != NULL) {
285 4 : torture_close_connection(cli);
286 : }
287 4 : return ret;
288 : }
|