2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "smbd/globals.h"
23 #include "../source4/libcli/smb2/smb2_constants.h"
25 static NTSTATUS smbd_smb2_flush(struct smbd_smb2_request *req,
26 uint64_t in_file_id_volatile);
28 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req)
31 const uint8_t *inbody;
32 int i = req->current_idx;
34 size_t expected_body_size = 0x18;
36 uint64_t in_file_id_persistent;
37 uint64_t in_file_id_volatile;
40 inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
41 if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
42 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
45 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
47 body_size = SVAL(inbody, 0x00);
48 if (body_size != expected_body_size) {
49 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
52 in_file_id_persistent = BVAL(inbody, 0x08);
53 in_file_id_volatile = BVAL(inbody, 0x10);
55 if (in_file_id_persistent != 0) {
56 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
59 status = smbd_smb2_flush(req,
61 if (!NT_STATUS_IS_OK(status)) {
62 return smbd_smb2_request_error(req, status);
65 outbody = data_blob_talloc(req->out.vector, NULL, 0x10);
66 if (outbody.data == NULL) {
67 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
70 SSVAL(outbody.data, 0x00, 0x04); /* struct size */
71 SSVAL(outbody.data, 0x02, 0); /* reserved */
73 return smbd_smb2_request_done(req, outbody, NULL);
76 static NTSTATUS smbd_smb2_flush(struct smbd_smb2_request *req,
77 uint64_t in_file_id_volatile)
80 struct smb_request *smbreq;
81 connection_struct *conn = req->tcon->compat_conn;
84 DEBUG(10,("smbd_smb2_flush: file_id[0x%016llX]\n",
85 (unsigned long long)in_file_id_volatile));
87 smbreq = smbd_smb2_fake_smb_request(req);
89 return NT_STATUS_NO_MEMORY;
92 /* If it's an IPC, pass off the pipe handler. */
94 return NT_STATUS_NOT_IMPLEMENTED;
97 fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
99 return NT_STATUS_FILE_CLOSED;
101 if (conn != fsp->conn) {
102 return NT_STATUS_FILE_CLOSED;
104 if (req->session->vuid != fsp->vuid) {
105 return NT_STATUS_FILE_CLOSED;
108 if (!CHECK_WRITE(fsp)) {
109 return NT_STATUS_ACCESS_DENIED;
112 status = sync_file(conn, fsp, true);
113 if (!NT_STATUS_IS_OK(status)) {
114 DEBUG(5,("smbd_smb2_flush: sync_file for %s returned %s\n",
115 fsp->fsp_name, nt_errstr(status)));