2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
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 "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/smb/smb_common.h"
25 #include "../lib/util/tevent_ntstatus.h"
26 #include "rpc_server/srv_pipe_hnd.h"
27 #include "include/ntioctl.h"
28 #include "../librpc/ndr/libndr.h"
30 static struct tevent_req
*smbd_smb2_ioctl_send(TALLOC_CTX
*mem_ctx
,
31 struct tevent_context
*ev
,
32 struct smbd_smb2_request
*smb2req
,
33 struct files_struct
*in_fsp
,
36 uint32_t in_max_output
,
38 static NTSTATUS
smbd_smb2_ioctl_recv(struct tevent_req
*req
,
40 DATA_BLOB
*out_output
,
43 static void smbd_smb2_request_ioctl_done(struct tevent_req
*subreq
);
44 NTSTATUS
smbd_smb2_request_process_ioctl(struct smbd_smb2_request
*req
)
47 const uint8_t *inbody
;
48 int i
= req
->current_idx
;
49 uint32_t min_buffer_offset
;
50 uint32_t max_buffer_offset
;
51 uint32_t min_output_offset
;
52 uint32_t allowed_length_in
;
53 uint32_t allowed_length_out
;
55 uint64_t in_file_id_persistent
;
56 uint64_t in_file_id_volatile
;
57 struct files_struct
*in_fsp
= NULL
;
58 uint32_t in_input_offset
;
59 uint32_t in_input_length
;
60 DATA_BLOB in_input_buffer
= data_blob_null
;
61 uint32_t in_max_input_length
;
62 uint32_t in_output_offset
;
63 uint32_t in_output_length
;
64 DATA_BLOB in_output_buffer
= data_blob_null
;
65 uint32_t in_max_output_length
;
67 uint32_t data_length_in
;
68 uint32_t data_length_out
;
69 uint32_t data_length_tmp
;
70 uint32_t data_length_max
;
71 struct tevent_req
*subreq
;
73 status
= smbd_smb2_request_verify_sizes(req
, 0x39);
74 if (!NT_STATUS_IS_OK(status
)) {
75 return smbd_smb2_request_error(req
, status
);
77 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
79 in_ctl_code
= IVAL(inbody
, 0x04);
80 in_file_id_persistent
= BVAL(inbody
, 0x08);
81 in_file_id_volatile
= BVAL(inbody
, 0x10);
82 in_input_offset
= IVAL(inbody
, 0x18);
83 in_input_length
= IVAL(inbody
, 0x1C);
84 in_max_input_length
= IVAL(inbody
, 0x20);
85 in_output_offset
= IVAL(inbody
, 0x24);
86 in_output_length
= IVAL(inbody
, 0x28);
87 in_max_output_length
= IVAL(inbody
, 0x2C);
88 in_flags
= IVAL(inbody
, 0x30);
90 min_buffer_offset
= SMB2_HDR_BODY
+ req
->in
.vector
[i
+1].iov_len
;
91 max_buffer_offset
= min_buffer_offset
+ req
->in
.vector
[i
+2].iov_len
;
92 min_output_offset
= min_buffer_offset
;
95 * InputOffset (4 bytes): The offset, in bytes, from the beginning of
96 * the SMB2 header to the input data buffer. If no input data is
97 * required for the FSCTL/IOCTL command being issued, the client SHOULD
98 * set this value to 0.<49>
99 * <49> If no input data is required for the FSCTL/IOCTL command being
100 * issued, Windows-based clients set this field to any value.
102 allowed_length_in
= 0;
103 if ((in_input_offset
> 0) && (in_input_length
> 0)) {
106 if (in_input_offset
< min_buffer_offset
) {
107 return smbd_smb2_request_error(req
,
108 NT_STATUS_INVALID_PARAMETER
);
110 if (in_input_offset
> max_buffer_offset
) {
111 return smbd_smb2_request_error(req
,
112 NT_STATUS_INVALID_PARAMETER
);
114 allowed_length_in
= max_buffer_offset
- in_input_offset
;
116 tmp_ofs
= in_input_offset
- min_buffer_offset
;
117 in_input_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
118 in_input_buffer
.data
+= tmp_ofs
;
119 in_input_buffer
.length
= in_input_length
;
120 min_output_offset
+= tmp_ofs
;
121 min_output_offset
+= in_input_length
;
124 if (in_input_length
> allowed_length_in
) {
125 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
128 allowed_length_out
= 0;
129 if (in_output_offset
> 0) {
130 if (in_output_offset
< min_buffer_offset
) {
131 return smbd_smb2_request_error(req
,
132 NT_STATUS_INVALID_PARAMETER
);
134 if (in_output_offset
> max_buffer_offset
) {
135 return smbd_smb2_request_error(req
,
136 NT_STATUS_INVALID_PARAMETER
);
138 allowed_length_out
= max_buffer_offset
- in_output_offset
;
141 if (in_output_length
> allowed_length_out
) {
142 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
145 if (in_output_length
> 0) {
148 if (in_output_offset
< min_output_offset
) {
149 return smbd_smb2_request_error(req
,
150 NT_STATUS_INVALID_PARAMETER
);
153 tmp_ofs
= in_output_offset
- min_buffer_offset
;
154 in_output_buffer
.data
= (uint8_t *)req
->in
.vector
[i
+2].iov_base
;
155 in_output_buffer
.data
+= tmp_ofs
;
156 in_output_buffer
.length
= in_output_length
;
160 * verify the credits and avoid overflows
161 * in_input_buffer.length and in_output_buffer.length
162 * are already verified.
164 data_length_in
= in_input_buffer
.length
+ in_output_buffer
.length
;
166 data_length_out
= in_max_input_length
;
167 data_length_tmp
= UINT32_MAX
- data_length_out
;
168 if (data_length_tmp
< in_max_output_length
) {
169 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
171 data_length_out
+= in_max_output_length
;
173 data_length_max
= MAX(data_length_in
, data_length_out
);
175 status
= smbd_smb2_request_verify_creditcharge(req
, data_length_max
);
176 if (!NT_STATUS_IS_OK(status
)) {
177 return smbd_smb2_request_error(req
, status
);
181 * If the Flags field of the request is not SMB2_0_IOCTL_IS_FSCTL the
182 * server MUST fail the request with STATUS_NOT_SUPPORTED.
184 if (in_flags
!= SMB2_IOCTL_FLAG_IS_FSCTL
) {
185 return smbd_smb2_request_error(req
, NT_STATUS_NOT_SUPPORTED
);
188 switch (in_ctl_code
) {
189 case FSCTL_DFS_GET_REFERRALS
:
190 case FSCTL_DFS_GET_REFERRALS_EX
:
191 case FSCTL_PIPE_WAIT
:
192 case FSCTL_VALIDATE_NEGOTIATE_INFO_224
:
193 case FSCTL_VALIDATE_NEGOTIATE_INFO
:
194 case FSCTL_QUERY_NETWORK_INTERFACE_INFO
:
196 * Some SMB2 specific CtlCodes like FSCTL_DFS_GET_REFERRALS or
197 * FSCTL_PIPE_WAIT does not take a file handle.
199 * If FileId in the SMB2 Header of the request is not
200 * 0xFFFFFFFFFFFFFFFF, then the server MUST fail the request
201 * with STATUS_INVALID_PARAMETER.
203 if (in_file_id_persistent
!= UINT64_MAX
||
204 in_file_id_volatile
!= UINT64_MAX
) {
205 return smbd_smb2_request_error(req
,
206 NT_STATUS_INVALID_PARAMETER
);
210 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
,
211 in_file_id_volatile
);
212 if (in_fsp
== NULL
) {
213 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
218 subreq
= smbd_smb2_ioctl_send(req
, req
->sconn
->ev_ctx
,
222 in_max_output_length
,
224 if (subreq
== NULL
) {
225 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
227 tevent_req_set_callback(subreq
, smbd_smb2_request_ioctl_done
, req
);
229 return smbd_smb2_request_pending_queue(req
, subreq
, 1000);
232 static void smbd_smb2_request_ioctl_done(struct tevent_req
*subreq
)
234 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
235 struct smbd_smb2_request
);
236 const uint8_t *inbody
;
237 int i
= req
->current_idx
;
240 uint32_t in_ctl_code
;
241 uint64_t in_file_id_persistent
;
242 uint64_t in_file_id_volatile
;
243 uint32_t out_input_offset
;
244 uint32_t out_output_offset
;
245 DATA_BLOB out_output_buffer
= data_blob_null
;
247 NTSTATUS error
; /* transport error */
248 bool disconnect
= false;
250 status
= smbd_smb2_ioctl_recv(subreq
, req
,
254 DEBUG(10,("smbd_smb2_request_ioctl_done: smbd_smb2_ioctl_recv returned "
256 (unsigned int)out_output_buffer
.length
,
257 nt_errstr(status
) ));
262 smbd_server_connection_terminate(req
->sconn
,
267 if (NT_STATUS_EQUAL(status
, STATUS_BUFFER_OVERFLOW
)) {
269 } else if (!NT_STATUS_IS_OK(status
)) {
270 error
= smbd_smb2_request_error(req
, status
);
271 if (!NT_STATUS_IS_OK(error
)) {
272 smbd_server_connection_terminate(req
->sconn
,
279 out_input_offset
= SMB2_HDR_BODY
+ 0x30;
280 out_output_offset
= SMB2_HDR_BODY
+ 0x30;
282 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
284 in_ctl_code
= IVAL(inbody
, 0x04);
285 in_file_id_persistent
= BVAL(inbody
, 0x08);
286 in_file_id_volatile
= BVAL(inbody
, 0x10);
288 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x30);
289 if (outbody
.data
== NULL
) {
290 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
291 if (!NT_STATUS_IS_OK(error
)) {
292 smbd_server_connection_terminate(req
->sconn
,
299 SSVAL(outbody
.data
, 0x00, 0x30 + 1); /* struct size */
300 SSVAL(outbody
.data
, 0x02, 0); /* reserved */
301 SIVAL(outbody
.data
, 0x04,
302 in_ctl_code
); /* ctl code */
303 SBVAL(outbody
.data
, 0x08,
304 in_file_id_persistent
); /* file id (persistent) */
305 SBVAL(outbody
.data
, 0x10,
306 in_file_id_volatile
); /* file id (volatile) */
307 SIVAL(outbody
.data
, 0x18,
308 out_input_offset
); /* input offset */
309 SIVAL(outbody
.data
, 0x1C, 0); /* input count */
310 SIVAL(outbody
.data
, 0x20,
311 out_output_offset
); /* output offset */
312 SIVAL(outbody
.data
, 0x24,
313 out_output_buffer
.length
); /* output count */
314 SIVAL(outbody
.data
, 0x28, 0); /* flags */
315 SIVAL(outbody
.data
, 0x2C, 0); /* reserved */
318 * Note: Windows Vista and 2008 send back also the
319 * input from the request. But it was fixed in
322 outdyn
= out_output_buffer
;
324 error
= smbd_smb2_request_done_ex(req
, status
, outbody
, &outdyn
,
326 if (!NT_STATUS_IS_OK(error
)) {
327 smbd_server_connection_terminate(req
->sconn
,
333 struct smbd_smb2_ioctl_state
{
334 struct smbd_smb2_request
*smb2req
;
335 struct smb_request
*smbreq
;
338 uint32_t in_max_output
;
339 DATA_BLOB out_output
;
343 static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req
*subreq
);
344 static void smbd_smb2_ioctl_pipe_read_done(struct tevent_req
*subreq
);
346 static struct tevent_req
*smbd_smb2_ioctl_send(TALLOC_CTX
*mem_ctx
,
347 struct tevent_context
*ev
,
348 struct smbd_smb2_request
*smb2req
,
349 struct files_struct
*fsp
,
350 uint32_t in_ctl_code
,
352 uint32_t in_max_output
,
355 struct tevent_req
*req
;
356 struct smbd_smb2_ioctl_state
*state
;
357 struct smb_request
*smbreq
;
358 struct tevent_req
*subreq
;
360 req
= tevent_req_create(mem_ctx
, &state
,
361 struct smbd_smb2_ioctl_state
);
365 state
->smb2req
= smb2req
;
366 state
->smbreq
= NULL
;
368 state
->in_input
= in_input
;
369 state
->in_max_output
= in_max_output
;
370 state
->out_output
= data_blob_null
;
372 DEBUG(10, ("smbd_smb2_ioctl: ctl_code[0x%08x] %s, %s\n",
373 (unsigned)in_ctl_code
,
374 fsp
? fsp_str_dbg(fsp
) : "<no handle>",
377 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
378 if (tevent_req_nomem(smbreq
, req
)) {
379 return tevent_req_post(req
, ev
);
381 state
->smbreq
= smbreq
;
383 switch (in_ctl_code
) {
384 case 0x00060194: /* FSCTL_DFS_GET_REFERRALS */
386 uint16_t in_max_referral_level
;
387 DATA_BLOB in_file_name_buffer
;
388 char *in_file_name_string
;
389 size_t in_file_name_string_size
;
391 bool overflow
= false;
394 char *dfs_data
= NULL
;
396 if (!IS_IPC(smbreq
->conn
)) {
397 tevent_req_nterror(req
, NT_STATUS_INVALID_DEVICE_REQUEST
);
398 return tevent_req_post(req
, ev
);
401 if (!lp_host_msdfs()) {
402 tevent_req_nterror(req
, NT_STATUS_FS_DRIVER_REQUIRED
);
403 return tevent_req_post(req
, ev
);
406 if (in_input
.length
< (2 + 2)) {
407 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
408 return tevent_req_post(req
, ev
);
411 in_max_referral_level
= SVAL(in_input
.data
, 0);
412 in_file_name_buffer
.data
= in_input
.data
+ 2;
413 in_file_name_buffer
.length
= in_input
.length
- 2;
415 ok
= convert_string_talloc(state
, CH_UTF16
, CH_UNIX
,
416 in_file_name_buffer
.data
,
417 in_file_name_buffer
.length
,
418 &in_file_name_string
,
419 &in_file_name_string_size
);
421 tevent_req_nterror(req
, NT_STATUS_ILLEGAL_CHARACTER
);
422 return tevent_req_post(req
, ev
);
425 dfs_size
= setup_dfs_referral(smbreq
->conn
,
427 in_max_referral_level
,
430 tevent_req_nterror(req
, status
);
431 return tevent_req_post(req
, ev
);
434 if (dfs_size
> in_max_output
) {
436 * TODO: we need a testsuite for this
439 dfs_size
= in_max_output
;
442 state
->out_output
= data_blob_talloc(state
,
447 tevent_req_nomem(state
->out_output
.data
, req
)) {
448 return tevent_req_post(req
, ev
);
452 tevent_req_nterror(req
, STATUS_BUFFER_OVERFLOW
);
454 tevent_req_done(req
);
456 return tevent_req_post(req
, ev
);
458 case 0x0011C017: /* FSCTL_PIPE_TRANSCEIVE */
460 if (!IS_IPC(smbreq
->conn
)) {
461 tevent_req_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
462 return tevent_req_post(req
, ev
);
466 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
467 return tevent_req_post(req
, ev
);
470 if (!fsp_is_np(fsp
)) {
471 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
472 return tevent_req_post(req
, ev
);
475 DEBUG(10,("smbd_smb2_ioctl_send: np_write_send of size %u\n",
476 (unsigned int)in_input
.length
));
478 subreq
= np_write_send(state
, ev
,
479 fsp
->fake_file_handle
,
482 if (tevent_req_nomem(subreq
, req
)) {
483 return tevent_req_post(req
, ev
);
485 tevent_req_set_callback(subreq
,
486 smbd_smb2_ioctl_pipe_write_done
,
490 case FSCTL_VALIDATE_NEGOTIATE_INFO_224
:
492 struct smbXsrv_connection
*conn
= smbreq
->sconn
->conn
;
493 uint32_t in_capabilities
;
494 DATA_BLOB in_guid_blob
;
496 uint16_t in_security_mode
;
497 uint16_t in_max_dialect
;
498 uint16_t max_dialect
;
499 DATA_BLOB out_guid_blob
;
502 if (in_input
.length
!= 0x18) {
503 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
504 return tevent_req_post(req
, ev
);
507 if (in_max_output
< 0x18) {
508 tevent_req_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
509 return tevent_req_post(req
, ev
);
512 in_capabilities
= IVAL(in_input
.data
, 0x00);
513 in_guid_blob
= data_blob_const(in_input
.data
+ 0x04, 16);
514 in_security_mode
= SVAL(in_input
.data
, 0x14);
515 in_max_dialect
= SVAL(in_input
.data
, 0x16);
517 status
= GUID_from_ndr_blob(&in_guid_blob
, &in_guid
);
518 if (tevent_req_nterror(req
, status
)) {
519 return tevent_req_post(req
, ev
);
522 max_dialect
= conn
->smb2
.client
.dialects
[conn
->smb2
.client
.num_dialects
-1];
523 if (in_max_dialect
!= max_dialect
) {
524 state
->disconnect
= true;
525 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
526 return tevent_req_post(req
, ev
);
529 if (!GUID_compare(&in_guid
, &conn
->smb2
.client
.guid
)) {
530 state
->disconnect
= true;
531 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
532 return tevent_req_post(req
, ev
);
535 if (in_security_mode
!= conn
->smb2
.client
.security_mode
) {
536 state
->disconnect
= true;
537 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
538 return tevent_req_post(req
, ev
);
541 if (in_capabilities
!= conn
->smb2
.client
.capabilities
) {
542 state
->disconnect
= true;
543 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
544 return tevent_req_post(req
, ev
);
547 status
= GUID_to_ndr_blob(&conn
->smb2
.server
.guid
, state
,
549 if (tevent_req_nterror(req
, status
)) {
550 return tevent_req_post(req
, ev
);
553 state
->out_output
= data_blob_talloc(state
, NULL
, 0x18);
554 if (tevent_req_nomem(state
->out_output
.data
, req
)) {
555 return tevent_req_post(req
, ev
);
558 SIVAL(state
->out_output
.data
, 0x00, conn
->smb2
.server
.capabilities
);
559 memcpy(state
->out_output
.data
+0x04, out_guid_blob
.data
, 16);
560 SIVAL(state
->out_output
.data
, 0x14, conn
->smb2
.server
.security_mode
);
561 SIVAL(state
->out_output
.data
, 0x16, conn
->smb2
.server
.dialect
);
563 tevent_req_done(req
);
564 return tevent_req_post(req
, ev
);
567 case FSCTL_VALIDATE_NEGOTIATE_INFO
:
569 struct smbXsrv_connection
*conn
= smbreq
->sconn
->conn
;
570 uint32_t in_capabilities
;
571 DATA_BLOB in_guid_blob
;
573 uint16_t in_security_mode
;
574 uint16_t in_num_dialects
;
576 DATA_BLOB out_guid_blob
;
579 if (in_input
.length
< 0x18) {
580 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
581 return tevent_req_post(req
, ev
);
584 in_capabilities
= IVAL(in_input
.data
, 0x00);
585 in_guid_blob
= data_blob_const(in_input
.data
+ 0x04, 16);
586 in_security_mode
= SVAL(in_input
.data
, 0x14);
587 in_num_dialects
= SVAL(in_input
.data
, 0x16);
589 if (in_input
.length
!= (0x18 + in_num_dialects
*2)) {
590 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
591 return tevent_req_post(req
, ev
);
594 if (in_max_output
< 0x18) {
595 tevent_req_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
596 return tevent_req_post(req
, ev
);
599 status
= GUID_from_ndr_blob(&in_guid_blob
, &in_guid
);
600 if (tevent_req_nterror(req
, status
)) {
601 return tevent_req_post(req
, ev
);
604 if (in_num_dialects
!= conn
->smb2
.client
.num_dialects
) {
605 state
->disconnect
= true;
606 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
607 return tevent_req_post(req
, ev
);
610 for (i
=0; i
< in_num_dialects
; i
++) {
611 uint16_t v
= SVAL(in_input
.data
, 0x18 + i
*2);
613 if (conn
->smb2
.client
.dialects
[i
] != v
) {
614 state
->disconnect
= true;
615 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
616 return tevent_req_post(req
, ev
);
620 if (!GUID_compare(&in_guid
, &conn
->smb2
.client
.guid
)) {
621 state
->disconnect
= true;
622 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
623 return tevent_req_post(req
, ev
);
626 if (in_security_mode
!= conn
->smb2
.client
.security_mode
) {
627 state
->disconnect
= true;
628 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
629 return tevent_req_post(req
, ev
);
632 if (in_capabilities
!= conn
->smb2
.client
.capabilities
) {
633 state
->disconnect
= true;
634 tevent_req_nterror(req
, NT_STATUS_ACCESS_DENIED
);
635 return tevent_req_post(req
, ev
);
638 status
= GUID_to_ndr_blob(&conn
->smb2
.server
.guid
, state
,
640 if (tevent_req_nterror(req
, status
)) {
641 return tevent_req_post(req
, ev
);
644 state
->out_output
= data_blob_talloc(state
, NULL
, 0x18);
645 if (tevent_req_nomem(state
->out_output
.data
, req
)) {
646 return tevent_req_post(req
, ev
);
649 SIVAL(state
->out_output
.data
, 0x00, conn
->smb2
.server
.capabilities
);
650 memcpy(state
->out_output
.data
+0x04, out_guid_blob
.data
, 16);
651 SIVAL(state
->out_output
.data
, 0x14, conn
->smb2
.server
.security_mode
);
652 SIVAL(state
->out_output
.data
, 0x16, conn
->smb2
.server
.dialect
);
654 tevent_req_done(req
);
655 return tevent_req_post(req
, ev
);
659 uint8_t *out_data
= NULL
;
660 uint32_t out_data_len
= 0;
664 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
665 return tevent_req_post(req
, ev
);
668 status
= SMB_VFS_FSCTL(fsp
,
677 state
->out_output
= data_blob_const(out_data
, out_data_len
);
678 if (NT_STATUS_IS_OK(status
)) {
679 tevent_req_done(req
);
680 return tevent_req_post(req
, ev
);
683 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
684 if (IS_IPC(smbreq
->conn
)) {
685 status
= NT_STATUS_FS_DRIVER_REQUIRED
;
687 status
= NT_STATUS_INVALID_DEVICE_REQUEST
;
691 tevent_req_nterror(req
, status
);
692 return tevent_req_post(req
, ev
);
696 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
697 return tevent_req_post(req
, ev
);
700 static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req
*subreq
)
702 struct tevent_req
*req
= tevent_req_callback_data(subreq
,
704 struct smbd_smb2_ioctl_state
*state
= tevent_req_data(req
,
705 struct smbd_smb2_ioctl_state
);
707 ssize_t nwritten
= -1;
709 status
= np_write_recv(subreq
, &nwritten
);
711 DEBUG(10,("smbd_smb2_ioctl_pipe_write_done: received %ld\n",
712 (long int)nwritten
));
715 if (!NT_STATUS_IS_OK(status
)) {
716 NTSTATUS old
= status
;
717 status
= nt_status_np_pipe(old
);
718 tevent_req_nterror(req
, status
);
722 if (nwritten
!= state
->in_input
.length
) {
723 tevent_req_nterror(req
, NT_STATUS_PIPE_NOT_AVAILABLE
);
727 state
->out_output
= data_blob_talloc(state
, NULL
, state
->in_max_output
);
728 if (state
->in_max_output
> 0 &&
729 tevent_req_nomem(state
->out_output
.data
, req
)) {
733 DEBUG(10,("smbd_smb2_ioctl_pipe_write_done: issuing np_read_send "
735 (unsigned int)state
->out_output
.length
));
738 subreq
= np_read_send(state
->smbreq
->conn
,
739 state
->smb2req
->sconn
->ev_ctx
,
740 state
->fsp
->fake_file_handle
,
741 state
->out_output
.data
,
742 state
->out_output
.length
);
743 if (tevent_req_nomem(subreq
, req
)) {
746 tevent_req_set_callback(subreq
, smbd_smb2_ioctl_pipe_read_done
, req
);
749 static void smbd_smb2_ioctl_pipe_read_done(struct tevent_req
*subreq
)
751 struct tevent_req
*req
= tevent_req_callback_data(subreq
,
753 struct smbd_smb2_ioctl_state
*state
= tevent_req_data(req
,
754 struct smbd_smb2_ioctl_state
);
758 bool is_data_outstanding
= false;
760 status
= np_read_recv(subreq
, &nread
, &is_data_outstanding
);
764 status
= nt_status_np_pipe(old
);
766 DEBUG(10,("smbd_smb2_ioctl_pipe_read_done: np_read_recv nread = %d "
767 "is_data_outstanding = %d, status = %s%s%s\n",
769 (int)is_data_outstanding
,
771 NT_STATUS_EQUAL(old
, status
)?"":" => ",
772 NT_STATUS_EQUAL(old
, status
)?"":nt_errstr(status
)));
774 if (!NT_STATUS_IS_OK(status
)) {
775 tevent_req_nterror(req
, status
);
779 state
->out_output
.length
= nread
;
781 if (is_data_outstanding
) {
782 tevent_req_nterror(req
, STATUS_BUFFER_OVERFLOW
);
786 tevent_req_done(req
);
789 static NTSTATUS
smbd_smb2_ioctl_recv(struct tevent_req
*req
,
791 DATA_BLOB
*out_output
,
794 NTSTATUS status
= NT_STATUS_OK
;
795 struct smbd_smb2_ioctl_state
*state
= tevent_req_data(req
,
796 struct smbd_smb2_ioctl_state
);
798 *disconnect
= state
->disconnect
;
800 if (tevent_req_is_nterror(req
, &status
)) {
801 if (!NT_STATUS_EQUAL(status
, STATUS_BUFFER_OVERFLOW
)) {
802 tevent_req_received(req
);
807 *out_output
= state
->out_output
;
808 talloc_steal(mem_ctx
, out_output
->data
);
810 tevent_req_received(req
);