s4:samba_kcc: Use 'dburl' passed from command line rather than lp.samdb_url()
[Samba.git] / source3 / smbd / smb2_ioctl_filesys.c
blob92bf63a9e24b1115dc6702ef459d420e95960bfc
1 /*
2 Unix SMB/CIFS implementation.
3 Core SMB2 server
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/>.
22 #include "includes.h"
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,
37 size_t in_max_output,
38 DATA_BLOB *out_output)
40 struct compression_state cmpr_state;
41 enum ndr_err_code ndr_ret;
42 DATA_BLOB output;
43 NTSTATUS status;
45 if (fsp == NULL) {
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,
58 mem_ctx,
59 fsp,
60 NULL,
61 &cmpr_state.format);
62 if (!NT_STATUS_IS_OK(status)) {
63 return status;
66 ndr_ret = ndr_push_struct_blob(&output, mem_ctx,
67 &cmpr_state,
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;
78 *out_output = output;
80 return NT_STATUS_OK;
83 static NTSTATUS fsctl_set_cmprn(TALLOC_CTX *mem_ctx,
84 struct tevent_context *ev,
85 struct files_struct *fsp,
86 DATA_BLOB *in_input)
88 struct compression_state cmpr_state;
89 enum ndr_err_code ndr_ret;
90 NTSTATUS status;
92 if (fsp == NULL) {
93 return NT_STATUS_FILE_CLOSED;
96 /* WRITE_DATA permission is required, WRITE_ATTRIBUTES is not */
97 status = check_access(fsp->conn, fsp, NULL,
98 FILE_WRITE_DATA);
99 if (!NT_STATUS_IS_OK(status)) {
100 return 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,
116 mem_ctx,
117 fsp,
118 cmpr_state.format);
119 if (!NT_STATUS_IS_OK(status)) {
120 return status;
123 return NT_STATUS_OK;
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)
131 NTSTATUS status;
133 switch (ctl_code) {
134 case FSCTL_GET_COMPRESSION:
135 status = fsctl_get_cmprn(state, ev, state->fsp,
136 state->in_max_output,
137 &state->out_output);
138 if (!tevent_req_nterror(req, status)) {
139 tevent_req_done(req);
141 return tevent_req_post(req, ev);
142 break;
143 case FSCTL_SET_COMPRESSION:
144 status = fsctl_set_cmprn(state, ev, state->fsp,
145 &state->in_input);
146 if (!tevent_req_nterror(req, status)) {
147 tevent_req_done(req);
149 return tevent_req_post(req, ev);
150 break;
151 default: {
152 uint8_t *out_data = NULL;
153 uint32_t out_data_len = 0;
155 if (state->fsp == NULL) {
156 status = NT_STATUS_NOT_SUPPORTED;
157 } else {
158 status = SMB_VFS_FSCTL(state->fsp,
159 state,
160 ctl_code,
161 state->smbreq->flags2,
162 state->in_input.data,
163 state->in_input.length,
164 &out_data,
165 state->in_max_output,
166 &out_data_len);
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;
177 } else {
178 status = NT_STATUS_INVALID_DEVICE_REQUEST;
182 tevent_req_nterror(req, status);
183 return tevent_req_post(req, ev);
184 break;
188 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
189 return tevent_req_post(req, ev);