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/globals.h"
24 #include "../libcli/smb/smb_common.h"
27 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
28 struct tevent_context *ev,
29 struct smbd_smb2_request *smb2req,
31 uint8_t in_file_info_class,
32 DATA_BLOB in_input_buffer,
33 uint32_t in_additional_information,
34 uint64_t in_file_id_volatile);
35 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req);
37 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq);
38 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req)
41 const uint8_t *inbody;
42 int i = req->current_idx;
43 size_t expected_body_size = 0x21;
46 uint8_t in_file_info_class;
47 uint16_t in_input_buffer_offset;
48 uint32_t in_input_buffer_length;
49 DATA_BLOB in_input_buffer;
50 uint32_t in_additional_information;
51 uint64_t in_file_id_persistent;
52 uint64_t in_file_id_volatile;
53 struct tevent_req *subreq;
55 inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
56 if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
57 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
60 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
62 body_size = SVAL(inbody, 0x00);
63 if (body_size != expected_body_size) {
64 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
67 in_info_type = CVAL(inbody, 0x02);
68 in_file_info_class = CVAL(inbody, 0x03);
69 in_input_buffer_length = IVAL(inbody, 0x04);
70 in_input_buffer_offset = SVAL(inbody, 0x08);
71 /* 0x0A 2 bytes reserved */
72 in_additional_information = IVAL(inbody, 0x0C);
73 in_file_id_persistent = BVAL(inbody, 0x10);
74 in_file_id_volatile = BVAL(inbody, 0x18);
76 if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
78 } else if (in_input_buffer_offset !=
79 (SMB2_HDR_BODY + (body_size & 0xFFFFFFFE))) {
80 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
83 if (in_input_buffer_length > req->in.vector[i+2].iov_len) {
84 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
87 in_input_buffer.data = (uint8_t *)req->in.vector[i+2].iov_base;
88 in_input_buffer.length = in_input_buffer_length;
90 if (req->compat_chain_fsp) {
92 } else if (in_file_id_persistent != in_file_id_volatile) {
93 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
96 subreq = smbd_smb2_setinfo_send(req,
97 req->sconn->smb2.event_ctx,
102 in_additional_information,
103 in_file_id_volatile);
104 if (subreq == NULL) {
105 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
107 tevent_req_set_callback(subreq, smbd_smb2_request_setinfo_done, req);
109 return smbd_smb2_request_pending_queue(req, subreq);
112 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq)
114 struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
115 struct smbd_smb2_request);
118 NTSTATUS error; /* transport error */
120 status = smbd_smb2_setinfo_recv(subreq);
122 if (!NT_STATUS_IS_OK(status)) {
123 error = smbd_smb2_request_error(req, status);
124 if (!NT_STATUS_IS_OK(error)) {
125 smbd_server_connection_terminate(req->sconn,
132 outbody = data_blob_talloc(req->out.vector, NULL, 0x02);
133 if (outbody.data == NULL) {
134 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
135 if (!NT_STATUS_IS_OK(error)) {
136 smbd_server_connection_terminate(req->sconn,
143 SSVAL(outbody.data, 0x00, 0x02); /* struct size */
145 error = smbd_smb2_request_done(req, outbody, NULL);
146 if (!NT_STATUS_IS_OK(error)) {
147 smbd_server_connection_terminate(req->sconn,
153 struct smbd_smb2_setinfo_state {
154 struct smbd_smb2_request *smb2req;
157 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
158 struct tevent_context *ev,
159 struct smbd_smb2_request *smb2req,
160 uint8_t in_info_type,
161 uint8_t in_file_info_class,
162 DATA_BLOB in_input_buffer,
163 uint32_t in_additional_information,
164 uint64_t in_file_id_volatile)
166 struct tevent_req *req = NULL;
167 struct smbd_smb2_setinfo_state *state = NULL;
168 struct smb_request *smbreq = NULL;
169 connection_struct *conn = smb2req->tcon->compat_conn;
170 files_struct *fsp = NULL;
173 req = tevent_req_create(mem_ctx, &state,
174 struct smbd_smb2_setinfo_state);
178 state->smb2req = smb2req;
180 DEBUG(10,("smbd_smb2_setinfo_send: file_id[0x%016llX]\n",
181 (unsigned long long)in_file_id_volatile));
183 smbreq = smbd_smb2_fake_smb_request(smb2req);
184 if (tevent_req_nomem(smbreq, req)) {
185 return tevent_req_post(req, ev);
188 fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
190 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
191 return tevent_req_post(req, ev);
193 if (conn != fsp->conn) {
194 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
195 return tevent_req_post(req, ev);
197 if (smb2req->session->vuid != fsp->vuid) {
198 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
199 return tevent_req_post(req, ev);
203 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
204 return tevent_req_post(req, ev);
207 switch (in_info_type) {
208 case 0x01:/* SMB2_SETINFO_FILE */
210 uint16_t file_info_level;
216 file_info_level = in_file_info_class + 1000;
217 if (file_info_level == SMB_FILE_RENAME_INFORMATION) {
218 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
219 file_info_level = SMB2_FILE_RENAME_INFORMATION_INTERNAL;
220 if (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK &&
221 fsp->oplock_type != NO_OPLOCK) {
222 /* No break, but error. */
223 tevent_req_nterror(req, NT_STATUS_SHARING_VIOLATION);
224 return tevent_req_post(req, ev);
228 if (fsp->fh->fd == -1) {
230 * This is actually a SETFILEINFO on a directory
231 * handle (returned from an NT SMB). NT5.0 seems
232 * to do this call. JRA.
234 if (INFO_LEVEL_IS_UNIX(file_info_level)) {
235 /* Always do lstat for UNIX calls. */
236 if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) {
237 DEBUG(3,("smbd_smb2_setinfo_send: "
238 "SMB_VFS_LSTAT of %s failed "
239 "(%s)\n", fsp_str_dbg(fsp),
241 status = map_nt_error_from_unix(errno);
242 tevent_req_nterror(req, status);
243 return tevent_req_post(req, ev);
246 if (SMB_VFS_STAT(conn, fsp->fsp_name) != 0) {
247 DEBUG(3,("smbd_smb2_setinfo_send: "
248 "fileinfo of %s failed (%s)\n",
251 status = map_nt_error_from_unix(errno);
252 tevent_req_nterror(req, status);
253 return tevent_req_post(req, ev);
256 } else if (fsp->print_file) {
258 * Doing a DELETE_ON_CLOSE should cancel a print job.
260 if ((file_info_level == SMB_SET_FILE_DISPOSITION_INFO)
261 && in_input_buffer.length >= 1
262 && CVAL(in_input_buffer.data,0)) {
263 fsp->fh->private_options |= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE;
265 DEBUG(3,("smbd_smb2_setinfo_send: "
266 "Cancelling print job (%s)\n",
269 tevent_req_done(req);
270 return tevent_req_post(req, ev);
272 tevent_req_nterror(req,
273 NT_STATUS_OBJECT_PATH_INVALID);
274 return tevent_req_post(req, ev);
278 * Original code - this is an open file.
281 if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
282 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
283 "of fnum %d failed (%s)\n", fsp->fnum,
285 status = map_nt_error_from_unix(errno);
286 tevent_req_nterror(req, status);
287 return tevent_req_post(req, ev);
292 data_size = in_input_buffer.length;
294 data = (char *)SMB_MALLOC_ARRAY(char, data_size);
295 if (tevent_req_nomem(data, req)) {
296 return tevent_req_post(req, ev);
298 memcpy(data, in_input_buffer.data, data_size);
301 status = smbd_do_setfilepathinfo(conn, smbreq, state,
309 if (!NT_STATUS_IS_OK(status)) {
310 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
311 status = NT_STATUS_INVALID_INFO_CLASS;
313 tevent_req_nterror(req, status);
314 return tevent_req_post(req, ev);
319 case 0x03:/* SMB2_SETINFO_SECURITY */
321 if (!CAN_WRITE(conn)) {
322 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
323 return tevent_req_post(req, ev);
327 in_input_buffer.data,
328 in_input_buffer.length,
329 in_additional_information);
330 if (!NT_STATUS_IS_OK(status)) {
331 tevent_req_nterror(req, status);
332 return tevent_req_post(req, ev);
338 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
339 return tevent_req_post(req, ev);
342 tevent_req_done(req);
343 return tevent_req_post(req, ev);
346 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req)
350 if (tevent_req_is_nterror(req, &status)) {
351 tevent_req_received(req);
355 tevent_req_received(req);