lib: talloc: Allow destructors to reparent the object they're called on.
[Samba.git] / source3 / torture / test_nttrans_fsctl.c
blobc2d8e6848518ce58230b867ce092b24c84e18af5
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
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/>.
21 #include "includes.h"
22 #include "torture/proto.h"
23 #include "libsmb/libsmb.h"
24 #include "libcli/security/security.h"
26 bool run_nttrans_fsctl(int dummy)
28 struct cli_state *cli = NULL;
29 NTSTATUS status;
30 bool ret = false;
31 const char *fname = "fsctltest";
32 uint16_t fnum;
33 uint16_t setup[4];
34 uint8_t *object_data = NULL;
35 uint8_t *ranges = NULL;
36 uint8_t range_data[16];
37 uint8_t *param_data = NULL;
38 uint8_t data[1] = { 0x1 };
39 uint32_t rdata_size;
40 uint32_t rparam_size;
42 printf("Starting NTTRANS_FSCTL\n");
44 if (!torture_open_connection(&cli, 0)) {
45 printf("torture_open_connection failed\n");
46 goto fail;
49 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 if (!NT_STATUS_IS_OK(status)) {
56 d_fprintf(stderr, "cli_nttrans_create returned %s\n",
57 nt_errstr(status));
58 goto fail;
61 status = cli_nt_delete_on_close(cli, fnum, true);
62 if (!NT_STATUS_IS_OK(status)) {
63 d_fprintf(stderr, "cli_nt_delete_on_close returned %s\n",
64 nt_errstr(status));
65 goto fail;
68 /* Fill in for FSCTL_SET_SPARSE and call cli_trans ... */
69 SIVAL(setup, 0, FSCTL_SET_SPARSE); /* returns value */
70 SSVAL(setup, 4, fnum);
71 SCVAL(setup, 6, 0x1); /* It is an fsctl */
72 SCVAL(setup, 7, 0x0);
74 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 if (!NT_STATUS_IS_OK(status)) {
85 d_fprintf(stderr, "cli_trans of FSCTL_SET_SPARSE returned %s instead of NT_STATUS_OK\n",
86 nt_errstr(status));
87 goto fail;
90 printf("FSCTL_SET_SPARSE returned correct status \n");
92 /* Fill in for FSCTL_CREATE_OR_GET_OBJECT_ID and call cli_trans ... */
93 SIVAL(setup, 0, FSCTL_CREATE_OR_GET_OBJECT_ID); /* returns value */
94 SSVAL(setup, 4, fnum);
95 SCVAL(setup, 6, 0x1); /* It is an fsctl */
96 SCVAL(setup, 7, 0x0);
98 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 &param_data, 0, &rparam_size, /* rparam, min_rparam, num_rparam */
107 &object_data, 0, &rdata_size); /* rdata, ... */
108 if (!NT_STATUS_IS_OK(status)) {
109 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 goto fail;
114 TALLOC_FREE(object_data);
115 TALLOC_FREE(param_data);
117 printf("FSCTL_CREATE_OR_GET_OBJECT_ID returned correct status \n");
119 /* Fill in for FSCTL_GET_REPARSE_POINT and call cli_trans ... */
120 SIVAL(setup, 0, FSCTL_GET_REPARSE_POINT); /* returns NOT A REPARSE POINT */
121 SSVAL(setup, 4, fnum);
122 SCVAL(setup, 6, 0x1); /* It is an fsctl */
123 SCVAL(setup, 7, 0x0);
125 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 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_REPARSE_POINT)) {
136 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 goto fail;
141 printf("FSCTL_GET_REPARSE_POINT returned correct status \n");
143 /* Fill in for FSCTL_SET_REPARSE_POINT and call cli_trans ... */
144 SIVAL(setup, 0, FSCTL_SET_REPARSE_POINT); /* returns NOT A REPARSE POINT */
145 SSVAL(setup, 4, fnum);
146 SCVAL(setup, 6, 0x1); /* It is an fsctl */
147 SCVAL(setup, 7, 0x0);
149 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 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_REPARSE_POINT)) {
160 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 goto fail;
165 printf("FSCTL_SET_REPARSE_POINT returned correct status \n");
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.
172 SIVAL(setup, 0, FSCTL_GET_SHADOW_COPY_DATA); /* Should return IVN VAL */
173 SSVAL(setup, 4, fnum);
174 SCVAL(setup, 6, 0x1); /* It is an fsctl */
175 SCVAL(setup, 7, 0x0);
177 memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
179 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 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
190 d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
191 nt_errstr(status));
192 goto fail;
195 TALLOC_FREE(ranges);
197 printf("FSCTL_GET_SHADOW_COPY_DATA returned correct status \n");
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
203 SIVAL(setup, 0, FSCTL_FIND_FILES_BY_SID); /* Should return 16 bytes */
204 SSVAL(setup, 4, fnum);
205 SCVAL(setup, 6, 0x1); /* It is an fsctl */
206 SCVAL(setup, 7, 0x0);
208 memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
210 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 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
221 d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
222 nt_errstr(status));
223 goto fail;
226 printf("FSCTL_FIND_FILES_BY_SID returned correct status \n");
228 /* Fill in for FSCTL_QUERY_ALLOCATED_RANGES and call cli_trans ... */
229 SIVAL(setup, 0, FSCTL_QUERY_ALLOCATED_RANGES); /* Should return 16 bytes */
230 SSVAL(setup, 4, fnum);
231 SCVAL(setup, 6, 0x1); /* It is an fsctl */
232 SCVAL(setup, 7, 0x0);
234 memset(range_data, 0, sizeof(range_data)); /* 0 and 0 */
236 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 if (!NT_STATUS_IS_OK(status)) {
247 d_fprintf(stderr, "cli_trans of FSCTL_QUERY_ALLOCATED_RANGES returned %s instead of NT_STATUS_OK\n",
248 nt_errstr(status));
249 goto fail;
252 TALLOC_FREE(ranges);
254 printf("FSCTL_QUERY_ALLOCATED_RANGES returned correct status \n");
256 /* Fill in for FSCTL_IS_VOLUME_DIRTY and call cli_trans ... */
257 SIVAL(setup, 0, FSCTL_IS_VOLUME_DIRTY); /* Should return INVAL PARAM */
258 SSVAL(setup, 4, fnum);
259 SCVAL(setup, 6, 0x1); /* It is an fsctl */
260 SCVAL(setup, 7, 0x0);
262 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 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
273 d_fprintf(stderr, "cli_trans of FSCTL_IS_VOLUME_DIRTY returned %s instead of NT_STATUS_INVALID_PARAMETER\n",
274 nt_errstr(status));
275 goto fail;
278 printf("FSCTL_IS_VOLUME_DIRTY returned correct status \n");
280 ret = true;
281 fail:
282 if (cli != NULL) {
283 torture_close_connection(cli);
285 return ret;