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 "../libcli/smb/smb_common.h"
25 static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
26 struct tevent_context *ev,
27 struct smbd_smb2_request *smb2req,
28 uint8_t in_oplock_level,
29 uint64_t in_file_id_volatile);
30 static NTSTATUS smbd_smb2_oplock_break_recv(struct tevent_req *req,
31 uint8_t *out_oplock_level);
33 static void smbd_smb2_request_oplock_break_done(struct tevent_req *subreq);
34 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req)
37 const uint8_t *inbody;
38 int i = req->current_idx;
39 size_t expected_body_size = 0x18;
41 uint8_t in_oplock_level;
42 uint64_t in_file_id_persistent;
43 uint64_t in_file_id_volatile;
44 struct tevent_req *subreq;
46 inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
47 if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
48 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
51 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
53 body_size = SVAL(inbody, 0x00);
54 if (body_size != expected_body_size) {
55 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
58 in_oplock_level = CVAL(inbody, 0x02);
59 /* 0x03 1 bytes reserved */
60 /* 0x04 4 bytes reserved */
61 in_file_id_persistent = BVAL(inbody, 0x08);
62 in_file_id_volatile = BVAL(inbody, 0x10);
64 if (req->compat_chain_fsp) {
66 } else if (in_file_id_persistent != 0) {
67 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
70 subreq = smbd_smb2_oplock_break_send(req,
71 req->sconn->smb2.event_ctx,
76 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
78 tevent_req_set_callback(subreq, smbd_smb2_request_oplock_break_done, req);
80 if (tevent_req_is_in_progress(subreq)) {
81 return smbd_smb2_request_pending_queue(req);
87 static void smbd_smb2_request_oplock_break_done(struct tevent_req *subreq)
89 struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
90 struct smbd_smb2_request);
91 const uint8_t *inbody;
92 int i = req->current_idx;
93 uint64_t in_file_id_persistent;
94 uint64_t in_file_id_volatile;
95 uint8_t out_oplock_level = 0;
98 NTSTATUS error; /* transport error */
100 status = smbd_smb2_oplock_break_recv(subreq, &out_oplock_level);
102 if (!NT_STATUS_IS_OK(status)) {
103 error = smbd_smb2_request_error(req, status);
104 if (!NT_STATUS_IS_OK(error)) {
105 smbd_server_connection_terminate(req->sconn,
112 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
114 in_file_id_persistent = BVAL(inbody, 0x08);
115 in_file_id_volatile = BVAL(inbody, 0x10);
117 outbody = data_blob_talloc(req->out.vector, NULL, 0x18);
118 if (outbody.data == NULL) {
119 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
120 if (!NT_STATUS_IS_OK(error)) {
121 smbd_server_connection_terminate(req->sconn,
128 SSVAL(outbody.data, 0x00, 0x18); /* struct size */
129 SCVAL(outbody.data, 0x02,
130 out_oplock_level); /* oplock level */
131 SCVAL(outbody.data, 0x03, 0); /* reserved */
132 SIVAL(outbody.data, 0x04, 0); /* reserved */
133 SBVAL(outbody.data, 0x08,
134 in_file_id_persistent); /* file id (persistent) */
135 SBVAL(outbody.data, 0x10,
136 in_file_id_volatile); /* file id (volatile) */
138 error = smbd_smb2_request_done(req, outbody, NULL);
139 if (!NT_STATUS_IS_OK(error)) {
140 smbd_server_connection_terminate(req->sconn,
146 struct smbd_smb2_oplock_break_state {
147 struct smbd_smb2_request *smb2req;
148 uint8_t out_oplock_level;
151 static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
152 struct tevent_context *ev,
153 struct smbd_smb2_request *smb2req,
154 uint8_t in_oplock_level,
155 uint64_t in_file_id_volatile)
157 struct tevent_req *req;
158 struct smbd_smb2_oplock_break_state *state;
159 struct smb_request *smbreq;
160 connection_struct *conn = smb2req->tcon->compat_conn;
163 req = tevent_req_create(mem_ctx, &state,
164 struct smbd_smb2_oplock_break_state);
168 state->smb2req = smb2req;
169 state->out_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
171 DEBUG(10,("smbd_smb2_oplock_break_send: file_id[0x%016llX]\n",
172 (unsigned long long)in_file_id_volatile));
174 smbreq = smbd_smb2_fake_smb_request(smb2req);
175 if (tevent_req_nomem(smbreq, req)) {
176 return tevent_req_post(req, ev);
179 fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
181 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
182 return tevent_req_post(req, ev);
184 if (conn != fsp->conn) {
185 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
186 return tevent_req_post(req, ev);
188 if (smb2req->session->vuid != fsp->vuid) {
189 tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
190 return tevent_req_post(req, ev);
193 tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
194 return tevent_req_post(req, ev);
197 static NTSTATUS smbd_smb2_oplock_break_recv(struct tevent_req *req,
198 uint8_t *out_oplock_level)
201 struct smbd_smb2_oplock_break_state *state =
203 struct smbd_smb2_oplock_break_state);
205 if (tevent_req_is_nterror(req, &status)) {
206 tevent_req_received(req);
210 *out_oplock_level = state->out_oplock_level;
212 tevent_req_received(req);