2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) Jeremy Allison 2010
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"
28 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
29 struct tevent_context *ev,
30 struct smbd_smb2_request *smb2req,
32 uint8_t in_file_info_class,
33 DATA_BLOB in_input_buffer,
34 uint32_t in_additional_information,
35 uint64_t in_file_id_volatile);
36 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req);
38 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq);
39 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req)
42 const uint8_t *inbody;
43 int i = req->current_idx;
44 size_t expected_body_size = 0x21;
47 uint8_t in_file_info_class;
48 uint16_t in_input_buffer_offset;
49 uint32_t in_input_buffer_length;
50 DATA_BLOB in_input_buffer;
51 uint32_t in_additional_information;
52 uint64_t in_file_id_persistent;
53 uint64_t in_file_id_volatile;
54 struct tevent_req *subreq;
56 inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
57 if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
58 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
61 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
63 body_size = SVAL(inbody, 0x00);
64 if (body_size != expected_body_size) {
65 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
68 in_info_type = CVAL(inbody, 0x02);
69 in_file_info_class = CVAL(inbody, 0x03);
70 in_input_buffer_length = IVAL(inbody, 0x04);
71 in_input_buffer_offset = SVAL(inbody, 0x08);
72 /* 0x0A 2 bytes reserved */
73 in_additional_information = IVAL(inbody, 0x0C);
74 in_file_id_persistent = BVAL(inbody, 0x10);
75 in_file_id_volatile = BVAL(inbody, 0x18);
77 if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
79 } else if (in_input_buffer_offset !=
80 (SMB2_HDR_BODY + (body_size & 0xFFFFFFFE))) {
81 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
84 if (in_input_buffer_length > req->in.vector[i+2].iov_len) {
85 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
88 in_input_buffer.data = (uint8_t *)req->in.vector[i+2].iov_base;
89 in_input_buffer.length = in_input_buffer_length;
91 if (req->compat_chain_fsp) {
93 } else if (in_file_id_persistent != in_file_id_volatile) {
94 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
97 subreq = smbd_smb2_setinfo_send(req,
98 req->sconn->smb2.event_ctx,
103 in_additional_information,
104 in_file_id_volatile);
105 if (subreq == NULL) {
106 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
108 tevent_req_set_callback(subreq, smbd_smb2_request_setinfo_done, req);
110 return smbd_smb2_request_pending_queue(req, subreq);
113 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq)
115 struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
116 struct smbd_smb2_request);
119 NTSTATUS error; /* transport error */
121 status = smbd_smb2_setinfo_recv(subreq);
123 if (!NT_STATUS_IS_OK(status)) {
124 error = smbd_smb2_request_error(req, status);
125 if (!NT_STATUS_IS_OK(error)) {
126 smbd_server_connection_terminate(req->sconn,
133 outbody = data_blob_talloc(req->out.vector, NULL, 0x02);
134 if (outbody.data == NULL) {
135 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
136 if (!NT_STATUS_IS_OK(error)) {
137 smbd_server_connection_terminate(req->sconn,
144 SSVAL(outbody.data, 0x00, 0x02); /* struct size */
146 error = smbd_smb2_request_done(req, outbody, NULL);
147 if (!NT_STATUS_IS_OK(error)) {
148 smbd_server_connection_terminate(req->sconn,
154 struct smbd_smb2_setinfo_state {
155 struct smbd_smb2_request *smb2req;
158 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
159 struct tevent_context *ev,
160 struct smbd_smb2_request *smb2req,
161 uint8_t in_info_type,
162 uint8_t in_file_info_class,
163 DATA_BLOB in_input_buffer,
164 uint32_t in_additional_information,
165 uint64_t in_file_id_volatile)
167 struct tevent_req *req = NULL;
168 struct smbd_smb2_setinfo_state *state = NULL;
169 struct smb_request *smbreq = NULL;
170 connection_struct *conn = smb2req->tcon->compat_conn;
171 files_struct *fsp = NULL;
174 req = tevent_req_create(mem_ctx, &state,
175 struct smbd_smb2_setinfo_state);
179 state->smb2req = smb2req;
181 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
182 (unsigned long long)in_file_id_volatile));
184 smbreq = smbd_smb2_fake_smb_request(smb2req);
185 if (tevent_req_nomem(smbreq, req)) {
186 return tevent_req_post(req, ev);
189 fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
191 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
192 return tevent_req_post(req, ev);
194 if (conn != fsp->conn) {
195 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
196 return tevent_req_post(req, ev);
198 if (smb2req->session->vuid != fsp->vuid) {
199 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
200 return tevent_req_post(req, ev);
204 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
205 return tevent_req_post(req, ev);
208 switch (in_info_type) {
209 case 0x01:/* SMB2_SETINFO_FILE */
211 uint16_t file_info_level;
217 file_info_level = in_file_info_class + 1000;
218 if (file_info_level == SMB_FILE_RENAME_INFORMATION) {
219 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
220 file_info_level = SMB2_FILE_RENAME_INFORMATION_INTERNAL;
221 if (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK &&
222 fsp->oplock_type != NO_OPLOCK) {
223 /* No break, but error. */
224 tevent_req_nterror(req, NT_STATUS_SHARING_VIOLATION);
225 return tevent_req_post(req, ev);
229 if (fsp->fh->fd == -1) {
231 * This is actually a SETFILEINFO on a directory
232 * handle (returned from an NT SMB). NT5.0 seems
233 * to do this call. JRA.
235 if (INFO_LEVEL_IS_UNIX(file_info_level)) {
236 /* Always do lstat for UNIX calls. */
237 if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) {
238 DEBUG(3,("smbd_smb2_setinfo_send: "
239 "SMB_VFS_LSTAT of %s failed "
240 "(%s)\n", fsp_str_dbg(fsp),
242 status = map_nt_error_from_unix(errno);
243 tevent_req_nterror(req, status);
244 return tevent_req_post(req, ev);
247 if (SMB_VFS_STAT(conn, fsp->fsp_name) != 0) {
248 DEBUG(3,("smbd_smb2_setinfo_send: "
249 "fileinfo of %s failed (%s)\n",
252 status = map_nt_error_from_unix(errno);
253 tevent_req_nterror(req, status);
254 return tevent_req_post(req, ev);
257 } else if (fsp->print_file) {
259 * Doing a DELETE_ON_CLOSE should cancel a print job.
261 if ((file_info_level == SMB_SET_FILE_DISPOSITION_INFO)
262 && in_input_buffer.length >= 1
263 && CVAL(in_input_buffer.data,0)) {
264 fsp->fh->private_options |= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE;
266 DEBUG(3,("smbd_smb2_setinfo_send: "
267 "Cancelling print job (%s)\n",
270 tevent_req_done(req);
271 return tevent_req_post(req, ev);
273 tevent_req_nterror(req,
274 NT_STATUS_OBJECT_PATH_INVALID);
275 return tevent_req_post(req, ev);
279 * Original code - this is an open file.
282 if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
283 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
284 "of fnum %d failed (%s)\n", fsp->fnum,
286 status = map_nt_error_from_unix(errno);
287 tevent_req_nterror(req, status);
288 return tevent_req_post(req, ev);
293 data_size = in_input_buffer.length;
295 data = (char *)SMB_MALLOC_ARRAY(char, data_size);
296 if (tevent_req_nomem(data, req)) {
297 return tevent_req_post(req, ev);
299 memcpy(data, in_input_buffer.data, data_size);
302 status = smbd_do_setfilepathinfo(conn, smbreq, state,
310 if (!NT_STATUS_IS_OK(status)) {
311 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
312 status = NT_STATUS_INVALID_INFO_CLASS;
314 tevent_req_nterror(req, status);
315 return tevent_req_post(req, ev);
320 case 0x03:/* SMB2_SETINFO_SECURITY */
322 if (!CAN_WRITE(conn)) {
323 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
324 return tevent_req_post(req, ev);
328 in_input_buffer.data,
329 in_input_buffer.length,
330 in_additional_information);
331 if (!NT_STATUS_IS_OK(status)) {
332 tevent_req_nterror(req, status);
333 return tevent_req_post(req, ev);
339 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
340 return tevent_req_post(req, ev);
343 tevent_req_done(req);
344 return tevent_req_post(req, ev);
347 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req)
351 if (tevent_req_is_nterror(req, &status)) {
352 tevent_req_received(req);
356 tevent_req_received(req);