2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) David Disseldorp 2013
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 "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
26 #include "../libcli/security/security.h"
27 #include "../lib/util/tevent_ntstatus.h"
28 #include "rpc_server/srv_pipe_hnd.h"
29 #include "include/ntioctl.h"
30 #include "../librpc/ndr/libndr.h"
31 #include "librpc/gen_ndr/ndr_ioctl.h"
32 #include "smb2_ioctl_private.h"
34 static NTSTATUS
fsctl_get_cmprn(TALLOC_CTX
*mem_ctx
,
35 struct tevent_context
*ev
,
36 struct files_struct
*fsp
,
38 DATA_BLOB
*out_output
)
40 struct compression_state cmpr_state
;
41 enum ndr_err_code ndr_ret
;
46 return NT_STATUS_FILE_CLOSED
;
49 /* Windows doesn't check for SEC_FILE_READ_ATTRIBUTE permission here */
51 if ((fsp
->conn
->fs_capabilities
& FILE_FILE_COMPRESSION
) == 0) {
52 DEBUG(4, ("FS does not advertise compression support\n"));
53 return NT_STATUS_NOT_SUPPORTED
;
56 ZERO_STRUCT(cmpr_state
);
57 status
= SMB_VFS_GET_COMPRESSION(fsp
->conn
,
62 if (!NT_STATUS_IS_OK(status
)) {
66 ndr_ret
= ndr_push_struct_blob(&output
, mem_ctx
,
68 (ndr_push_flags_fn_t
)ndr_push_compression_state
);
69 if (ndr_ret
!= NDR_ERR_SUCCESS
) {
70 return NT_STATUS_INTERNAL_ERROR
;
73 if (in_max_output
< output
.length
) {
74 DEBUG(1, ("max output %u too small for compression state %ld\n",
75 (unsigned int)in_max_output
, (long int)output
.length
));
76 return NT_STATUS_INVALID_USER_BUFFER
;
83 static NTSTATUS
fsctl_set_cmprn(TALLOC_CTX
*mem_ctx
,
84 struct tevent_context
*ev
,
85 struct files_struct
*fsp
,
88 struct compression_state cmpr_state
;
89 enum ndr_err_code ndr_ret
;
93 return NT_STATUS_FILE_CLOSED
;
96 /* WRITE_DATA permission is required, WRITE_ATTRIBUTES is not */
97 status
= check_access(fsp
->conn
, fsp
, NULL
,
99 if (!NT_STATUS_IS_OK(status
)) {
103 if ((fsp
->conn
->fs_capabilities
& FILE_FILE_COMPRESSION
) == 0) {
104 DEBUG(4, ("FS does not advertise compression support\n"));
105 return NT_STATUS_NOT_SUPPORTED
;
108 ndr_ret
= ndr_pull_struct_blob(in_input
, mem_ctx
, &cmpr_state
,
109 (ndr_pull_flags_fn_t
)ndr_pull_compression_state
);
110 if (ndr_ret
!= NDR_ERR_SUCCESS
) {
111 DEBUG(0, ("failed to unmarshall set compression req\n"));
112 return NT_STATUS_INVALID_PARAMETER
;
115 status
= SMB_VFS_SET_COMPRESSION(fsp
->conn
,
119 if (!NT_STATUS_IS_OK(status
)) {
126 struct tevent_req
*smb2_ioctl_filesys(uint32_t ctl_code
,
127 struct tevent_context
*ev
,
128 struct tevent_req
*req
,
129 struct smbd_smb2_ioctl_state
*state
)
134 case FSCTL_GET_COMPRESSION
:
135 status
= fsctl_get_cmprn(state
, ev
, state
->fsp
,
136 state
->in_max_output
,
138 if (!tevent_req_nterror(req
, status
)) {
139 tevent_req_done(req
);
141 return tevent_req_post(req
, ev
);
143 case FSCTL_SET_COMPRESSION
:
144 status
= fsctl_set_cmprn(state
, ev
, state
->fsp
,
146 if (!tevent_req_nterror(req
, status
)) {
147 tevent_req_done(req
);
149 return tevent_req_post(req
, ev
);
152 uint8_t *out_data
= NULL
;
153 uint32_t out_data_len
= 0;
155 if (state
->fsp
== NULL
) {
156 status
= NT_STATUS_NOT_SUPPORTED
;
158 status
= SMB_VFS_FSCTL(state
->fsp
,
161 state
->smbreq
->flags2
,
162 state
->in_input
.data
,
163 state
->in_input
.length
,
165 state
->in_max_output
,
167 state
->out_output
= data_blob_const(out_data
, out_data_len
);
168 if (NT_STATUS_IS_OK(status
)) {
169 tevent_req_done(req
);
170 return tevent_req_post(req
, ev
);
174 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
175 if (IS_IPC(state
->smbreq
->conn
)) {
176 status
= NT_STATUS_FS_DRIVER_REQUIRED
;
178 status
= NT_STATUS_INVALID_DEVICE_REQUEST
;
182 tevent_req_nterror(req
, status
);
183 return tevent_req_post(req
, ev
);
188 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
189 return tevent_req_post(req
, ev
);