2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "librpc/gen_ndr/ioctl.h"
30 struct smb2_request
*smb2_ioctl_send(struct smb2_tree
*tree
, struct smb2_ioctl
*io
)
33 struct smb2_request
*req
;
35 req
= smb2_request_init_tree(tree
, SMB2_OP_IOCTL
, 0x38, true,
36 io
->in
.in
.length
+io
->in
.out
.length
);
37 if (req
== NULL
) return NULL
;
39 SSVAL(req
->out
.body
, 0x02, 0); /* pad */
40 SIVAL(req
->out
.body
, 0x04, io
->in
.function
);
41 smb2_push_handle(req
->out
.body
+0x08, &io
->in
.file
.handle
);
43 status
= smb2_push_o32s32_blob(&req
->out
, 0x18, io
->in
.out
);
44 if (!NT_STATUS_IS_OK(status
)) {
49 SIVAL(req
->out
.body
, 0x20, io
->in
.unknown2
);
51 status
= smb2_push_o32s32_blob(&req
->out
, 0x24, io
->in
.in
);
52 if (!NT_STATUS_IS_OK(status
)) {
57 SIVAL(req
->out
.body
, 0x2C, io
->in
.max_response_size
);
58 SBVAL(req
->out
.body
, 0x30, io
->in
.flags
);
60 smb2_transport_send(req
);
66 * 3.3.4.4 Sending an Error Response
68 static bool smb2_ioctl_is_failure(uint32_t ctl_code
, NTSTATUS status
,
71 if (NT_STATUS_IS_OK(status
)) {
75 if (NT_STATUS_EQUAL(status
, STATUS_BUFFER_OVERFLOW
)
76 && ((ctl_code
== FSCTL_PIPE_TRANSCEIVE
)
77 || (ctl_code
== FSCTL_PIPE_PEEK
)
78 || (ctl_code
== FSCTL_DFS_GET_REFERRALS
))) {
82 if (((ctl_code
== FSCTL_SRV_COPYCHUNK
)
83 || (ctl_code
== FSCTL_SRV_COPYCHUNK_WRITE
))
84 && (data_size
== sizeof(struct srv_copychunk_rsp
))) {
86 * copychunk responses may come with copychunk data or error
87 * response data, independent of status.
98 NTSTATUS
smb2_ioctl_recv(struct smb2_request
*req
,
99 TALLOC_CTX
*mem_ctx
, struct smb2_ioctl
*io
)
103 if (!smb2_request_receive(req
) ||
104 smb2_ioctl_is_failure(io
->in
.function
, req
->status
,
105 req
->in
.bufinfo
.data_size
)) {
106 return smb2_request_destroy(req
);
109 SMB2_CHECK_PACKET_RECV(req
, 0x30, true);
111 io
->out
._pad
= SVAL(req
->in
.body
, 0x02);
112 io
->out
.function
= IVAL(req
->in
.body
, 0x04);
113 smb2_pull_handle(req
->in
.body
+0x08, &io
->out
.file
.handle
);
115 status
= smb2_pull_o32s32_blob(&req
->in
, mem_ctx
, req
->in
.body
+0x18, &io
->out
.in
);
116 if (!NT_STATUS_IS_OK(status
)) {
117 smb2_request_destroy(req
);
121 status
= smb2_pull_o32s32_blob(&req
->in
, mem_ctx
, req
->in
.body
+0x20, &io
->out
.out
);
122 if (!NT_STATUS_IS_OK(status
)) {
123 smb2_request_destroy(req
);
127 io
->out
.unknown2
= IVAL(req
->in
.body
, 0x28);
128 io
->out
.unknown3
= IVAL(req
->in
.body
, 0x2C);
130 return smb2_request_destroy(req
);
136 NTSTATUS
smb2_ioctl(struct smb2_tree
*tree
, TALLOC_CTX
*mem_ctx
, struct smb2_ioctl
*io
)
138 struct smb2_request
*req
= smb2_ioctl_send(tree
, io
);
139 return smb2_ioctl_recv(req
, mem_ctx
, io
);