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 0 : bool run_nttrans_fsctl(int dummy)
27 : {
28 0 : struct cli_state *cli = NULL;
29 : NTSTATUS status;
30 0 : bool ret = false;
31 0 : const char *fname = "fsctltest";
32 : uint16_t fnum;
33 : uint16_t setup[4];
34 0 : uint8_t *object_data = NULL;
35 0 : uint8_t *ranges = NULL;
36 : uint8_t range_data[16];
37 0 : uint8_t *param_data = NULL;
38 0 : uint8_t data[1] = { 0x1 };
39 : uint32_t rdata_size;
40 : uint32_t rparam_size;
41 :
42 0 : printf("Starting NTTRANS_FSCTL\n");
43 :
44 0 : if (!torture_open_connection(&cli, 0)) {
45 0 : printf("torture_open_connection failed\n");
46 0 : goto fail;
47 : }
48 :
49 0 : 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 0 : 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 0 : status = cli_nt_delete_on_close(cli, fnum, true);
62 0 : 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 0 : SIVAL(setup, 0, FSCTL_SET_SPARSE); /* returns value */
70 0 : SSVAL(setup, 4, fnum);
71 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
72 0 : SCVAL(setup, 7, 0x0);
73 :
74 0 : 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 0 : 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 0 : printf("FSCTL_SET_SPARSE returned correct status \n");
91 :
92 : /* Fill in for FSCTL_CREATE_OR_GET_OBJECT_ID and call cli_trans ... */
93 0 : SIVAL(setup, 0, FSCTL_CREATE_OR_GET_OBJECT_ID); /* returns value */
94 0 : SSVAL(setup, 4, fnum);
95 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
96 0 : SCVAL(setup, 7, 0x0);
97 :
98 0 : 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 0 : 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 0 : TALLOC_FREE(object_data);
115 0 : TALLOC_FREE(param_data);
116 :
117 0 : 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 0 : SIVAL(setup, 0, FSCTL_GET_REPARSE_POINT); /* returns NOT A REPARSE POINT */
121 0 : SSVAL(setup, 4, fnum);
122 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
123 0 : SCVAL(setup, 7, 0x0);
124 :
125 0 : 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 0 : 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 0 : printf("FSCTL_GET_REPARSE_POINT returned correct status \n");
142 :
143 : /* Fill in for FSCTL_SET_REPARSE_POINT and call cli_trans ... */
144 0 : SIVAL(setup, 0, FSCTL_SET_REPARSE_POINT); /* returns NOT A REPARSE POINT */
145 0 : SSVAL(setup, 4, fnum);
146 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
147 0 : SCVAL(setup, 7, 0x0);
148 :
149 0 : 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 0 : if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_REPARSE_POINT)) {
160 0 : d_fprintf(stderr, "cli_trans of FSCTL_SET_REPARSE_POINT returned %s instead of NT_STATUS_NOT_A_REPARSE_POINT\n",
161 : nt_errstr(status));
162 0 : goto fail;
163 : }
164 :
165 0 : printf("FSCTL_SET_REPARSE_POINT returned correct status \n");
166 :
167 : /*
168 : * Fill in for FSCTL_GET_SHADOW_COPY_DATA and call cli_trans ... what
169 : * we do is send an invalid data length to provoke an INVALID PARAMETER
170 : * response.
171 : */
172 0 : SIVAL(setup, 0, FSCTL_GET_SHADOW_COPY_DATA); /* Should return IVN VAL */
173 0 : SSVAL(setup, 4, fnum);
174 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
175 0 : SCVAL(setup, 7, 0x0);
176 :
177 0 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
178 :
179 0 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
180 : NULL, fnum,
181 : NT_TRANSACT_IOCTL, 0,
182 : setup, 4, 4,
183 : NULL, 0, 0, /* param, param_num, max_param */
184 : NULL, 0, 8, /* data, data_len, max_data */
185 : NULL, /* recv_flags2 */
186 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
187 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
188 : &ranges, 0, &rdata_size); /* rdata, ... */
189 0 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
190 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
191 : nt_errstr(status));
192 0 : goto fail;
193 : }
194 :
195 0 : TALLOC_FREE(ranges);
196 :
197 0 : printf("FSCTL_GET_SHADOW_COPY_DATA returned correct status \n");
198 : /*
199 : * Fill in for FSCTL_FIND_FILES_BY and call cli_trans ... here we are
200 : * only probing for its existence by provoking an INVALID PARAM
201 : * response with a short and invalid SID in range_data
202 : */
203 0 : SIVAL(setup, 0, FSCTL_FIND_FILES_BY_SID); /* Should return 16 bytes */
204 0 : SSVAL(setup, 4, fnum);
205 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
206 0 : SCVAL(setup, 7, 0x0);
207 :
208 0 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
209 :
210 0 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
211 : NULL, fnum,
212 : NT_TRANSACT_IOCTL, 0,
213 : setup, 4, 4,
214 : NULL, 0, 0, /* param, param_num, max_param */
215 : range_data, 4, 16, /* data, data_len, max_data */
216 : NULL, /* recv_flags2 */
217 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
218 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
219 : &ranges, 0, &rdata_size); /* rdata, ... */
220 0 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
221 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
222 : nt_errstr(status));
223 0 : goto fail;
224 : }
225 :
226 0 : printf("FSCTL_FIND_FILES_BY_SID returned correct status \n");
227 :
228 : /* Fill in for FSCTL_QUERY_ALLOCATED_RANGES and call cli_trans ... */
229 0 : SIVAL(setup, 0, FSCTL_QUERY_ALLOCATED_RANGES); /* Should return 16 bytes */
230 0 : SSVAL(setup, 4, fnum);
231 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
232 0 : SCVAL(setup, 7, 0x0);
233 :
234 0 : memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
235 :
236 0 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
237 : NULL, fnum,
238 : NT_TRANSACT_IOCTL, 0,
239 : setup, 4, 4,
240 : NULL, 0, 0, /* param, param_num, max_param */
241 : range_data, 16, 16, /* data, data_len, max_data */
242 : NULL, /* recv_flags2 */
243 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
244 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
245 : &ranges, 0, &rdata_size); /* rdata, ... */
246 0 : if (!NT_STATUS_IS_OK(status)) {
247 0 : d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_OK\n",
248 : nt_errstr(status));
249 0 : goto fail;
250 : }
251 :
252 0 : TALLOC_FREE(ranges);
253 :
254 0 : printf("FSCTL_QUERY_ALLOCATED_RANGES returned correct status \n");
255 :
256 : /* Fill in for FSCTL_IS_VOLUME_DIRTY and call cli_trans ... */
257 0 : SIVAL(setup, 0, FSCTL_IS_VOLUME_DIRTY); /* Should return INVAL PARAM */
258 0 : SSVAL(setup, 4, fnum);
259 0 : SCVAL(setup, 6, 0x1); /* It is an fsctl */
260 0 : SCVAL(setup, 7, 0x0);
261 :
262 0 : status = cli_trans(talloc_tos(), cli, SMBnttrans,
263 : NULL, fnum,
264 : NT_TRANSACT_IOCTL, 0,
265 : setup, 4, 4,
266 : NULL, 0, 0, /* param, param_num, max_param */
267 : NULL, 0, 0, /* data, data_len, max_data */
268 : NULL, /* recv_flags2 */
269 : NULL, 0, NULL, /* rsetup, min_rsetup, num_rsetup */
270 : NULL, 0, NULL, /* rparam, min_rparam, num_rparam */
271 : NULL, 0, NULL); /* rdata, ... */
272 0 : if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
273 0 : d_fprintf(stderr, "cli_trans of FSCTL_IS_VOLUME_DIRTY returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
274 : nt_errstr(status));
275 0 : goto fail;
276 : }
277 :
278 0 : printf("FSCTL_IS_VOLUME_DIRTY returned correct status \n");
279 :
280 0 : ret = true;
281 0 : fail:
282 0 : if (cli != NULL) {
283 0 : torture_close_connection(cli);
284 : }
285 0 : return ret;
286 : }
|