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
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.
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.
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/>.
22 #include "torture/proto.h"
23 #include "libsmb/libsmb.h"
24 #include "libcli/security/security.h"
27 bool run_nttrans_fsctl(int dummy
)
29 struct cli_state
*cli
= NULL
;
32 const char *fname
= "fsctltest";
35 uint8_t *object_data
= NULL
;
36 uint8_t *ranges
= NULL
;
37 uint8_t range_data
[16];
38 uint8_t *param_data
= NULL
;
39 uint8_t data
[1] = { 0x1 };
43 printf("Starting NTTRANS_FSCTL\n");
45 if (!torture_open_connection(&cli
, 0)) {
46 printf("torture_open_connection failed\n");
50 status
= cli_nttrans_create(
51 cli
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
|
53 FILE_ATTRIBUTE_NORMAL
,
54 FILE_SHARE_READ
|FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
55 FILE_CREATE
, 0, 0, NULL
, NULL
, 0, &fnum
);
56 if (!NT_STATUS_IS_OK(status
)) {
57 d_fprintf(stderr
, "cli_nttrans_create returned %s\n",
62 status
= cli_nt_delete_on_close(cli
, fnum
, true);
63 if (!NT_STATUS_IS_OK(status
)) {
64 d_fprintf(stderr
, "cli_nt_delete_on_close returned %s\n",
69 /* Fill in for FSCTL_SET_SPARSE and call cli_trans ... */
70 SIVAL(setup
, 0, FSCTL_SET_SPARSE
); /* returns value */
71 SSVAL(setup
, 4, fnum
);
72 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
75 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
79 NULL
, 0, 0, /* param, param_num, max_param */
80 data
, 1, 1, /* data, data_len, max_data */
81 NULL
, /* recv_flags2 */
82 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
83 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
84 NULL
, 0, NULL
); /* rdata, ... */
85 if (!NT_STATUS_IS_OK(status
)) {
86 d_fprintf(stderr
, "cli_trans of FSCTL_SET_SPARSE returned %s instead of NT_STATUS_OK\n",
91 printf("FSCTL_SET_SPARSE returned correct status \n");
93 /* Fill in for FSCTL_CREATE_OR_GET_OBJECT_ID and call cli_trans ... */
94 SIVAL(setup
, 0, FSCTL_CREATE_OR_GET_OBJECT_ID
); /* returns value */
95 SSVAL(setup
, 4, fnum
);
96 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
99 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
101 NT_TRANSACT_IOCTL
, 0,
103 NULL
, 0, 0, /* param, param_num, max_param */
104 NULL
, 0, 64, /* data, data_len, max_data */
105 NULL
, /* recv_flags2 */
106 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
107 ¶m_data
, 0, &rparam_size
, /* rparam, min_rparam, num_rparam */
108 &object_data
, 0, &rdata_size
); /* rdata, ... */
109 if (!NT_STATUS_IS_OK(status
)) {
110 d_fprintf(stderr
, "cli_trans of FSCTL_CREATE_OR_GET_OBJECT_ID returned %s instead of NT_STATUS_OK\n",
115 TALLOC_FREE(object_data
);
116 TALLOC_FREE(param_data
);
118 printf("FSCTL_CREATE_OR_GET_OBJECT_ID returned correct status \n");
120 /* Fill in for FSCTL_GET_REPARSE_POINT and call cli_trans ... */
121 SIVAL(setup
, 0, FSCTL_GET_REPARSE_POINT
); /* returns NOT A REPARSE POINT */
122 SSVAL(setup
, 4, fnum
);
123 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
124 SCVAL(setup
, 7, 0x0);
126 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
128 NT_TRANSACT_IOCTL
, 0,
130 NULL
, 0, 0, /* param, param_num, max_param */
131 NULL
, 0, 0, /* data, data_len, max_data */
132 NULL
, /* recv_flags2 */
133 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
134 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
135 NULL
, 0, NULL
); /* rdata, ... */
136 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_A_REPARSE_POINT
)) {
137 d_fprintf(stderr
, "cli_trans of FSCTL_GET_REPARSE_POINT returned %s instead of NT_STATUS_NOT_A_REPARSE_POINT\n",
142 printf("FSCTL_GET_REPARSE_POINT returned correct status \n");
144 /* Fill in for FSCTL_SET_REPARSE_POINT and call cli_trans ... */
145 SIVAL(setup
, 0, FSCTL_SET_REPARSE_POINT
); /* returns NOT A REPARSE POINT */
146 SSVAL(setup
, 4, fnum
);
147 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
148 SCVAL(setup
, 7, 0x0);
150 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
152 NT_TRANSACT_IOCTL
, 0,
154 NULL
, 0, 0, /* param, param_num, max_param */
155 NULL
, 0, 0, /* data, data_len, max_data */
156 NULL
, /* recv_flags2 */
157 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
158 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
159 NULL
, 0, NULL
); /* rdata, ... */
160 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_A_REPARSE_POINT
)) {
161 d_fprintf(stderr
, "cli_trans of FSCTL_SET_REPARSE_POINT returned %s instead of NT_STATUS_NOT_A_REPARSE_POINT\n",
166 printf("FSCTL_SET_REPARSE_POINT returned correct status \n");
169 * Fill in for FSCTL_GET_SHADOW_COPY_DATA and call cli_trans ... what
170 * we do is send an invalid data length to provoke an INVALID PARAMETER
173 SIVAL(setup
, 0, FSCTL_GET_SHADOW_COPY_DATA
); /* Should return IVN VAL */
174 SSVAL(setup
, 4, fnum
);
175 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
176 SCVAL(setup
, 7, 0x0);
178 memset(range_data
, 0, sizeof(range_data
)); /* 0 and 0 */
180 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
182 NT_TRANSACT_IOCTL
, 0,
184 NULL
, 0, 0, /* param, param_num, max_param */
185 NULL
, 0, 8, /* data, data_len, max_data */
186 NULL
, /* recv_flags2 */
187 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
188 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
189 &ranges
, 0, &rdata_size
); /* rdata, ... */
190 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
191 d_fprintf(stderr
, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
198 printf("FSCTL_GET_SHADOW_COPY_DATA returned correct status \n");
200 * Fill in for FSCTL_FIND_FILES_BY and call cli_trans ... here we are
201 * only probing for its existence by provoking an INVALID PARAM
202 * response with a short and invalid SID in range_data
204 SIVAL(setup
, 0, FSCTL_FIND_FILES_BY_SID
); /* Should return 16 bytes */
205 SSVAL(setup
, 4, fnum
);
206 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
207 SCVAL(setup
, 7, 0x0);
209 memset(range_data
, 0, sizeof(range_data
)); /* 0 and 0 */
211 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
213 NT_TRANSACT_IOCTL
, 0,
215 NULL
, 0, 0, /* param, param_num, max_param */
216 range_data
, 4, 16, /* data, data_len, max_data */
217 NULL
, /* recv_flags2 */
218 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
219 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
220 &ranges
, 0, &rdata_size
); /* rdata, ... */
221 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
222 d_fprintf(stderr
, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
227 printf("FSCTL_FIND_FILES_BY_SID returned correct status \n");
229 /* Fill in for FSCTL_QUERY_ALLOCATED_RANGES and call cli_trans ... */
230 SIVAL(setup
, 0, FSCTL_QUERY_ALLOCATED_RANGES
); /* Should return 16 bytes */
231 SSVAL(setup
, 4, fnum
);
232 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
233 SCVAL(setup
, 7, 0x0);
235 memset(range_data
, 0, sizeof(range_data
)); /* 0 and 0 */
237 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
239 NT_TRANSACT_IOCTL
, 0,
241 NULL
, 0, 0, /* param, param_num, max_param */
242 range_data
, 16, 16, /* data, data_len, max_data */
243 NULL
, /* recv_flags2 */
244 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
245 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
246 &ranges
, 0, &rdata_size
); /* rdata, ... */
247 if (!NT_STATUS_IS_OK(status
)) {
248 d_fprintf(stderr
, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_OK\n",
255 printf("FSCTL_QUERY_ALLOCATED_RANGES returned correct status \n");
257 /* Fill in for FSCTL_IS_VOLUME_DIRTY and call cli_trans ... */
258 SIVAL(setup
, 0, FSCTL_IS_VOLUME_DIRTY
); /* Should return INVAL PARAM */
259 SSVAL(setup
, 4, fnum
);
260 SCVAL(setup
, 6, 0x1); /* It is an fsctl */
261 SCVAL(setup
, 7, 0x0);
263 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
265 NT_TRANSACT_IOCTL
, 0,
267 NULL
, 0, 0, /* param, param_num, max_param */
268 NULL
, 0, 0, /* data, data_len, max_data */
269 NULL
, /* recv_flags2 */
270 NULL
, 0, NULL
, /* rsetup, min_rsetup, num_rsetup */
271 NULL
, 0, NULL
, /* rparam, min_rparam, num_rparam */
272 NULL
, 0, NULL
); /* rdata, ... */
273 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
274 d_fprintf(stderr
, "cli_trans of FSCTL_IS_VOLUME_DIRTY returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
279 printf("FSCTL_IS_VOLUME_DIRTY returned correct status \n");
284 torture_close_connection(cli
);