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 return smbd_smb2_request_pending_queue(req
, subreq
);
83 static void smbd_smb2_request_oplock_break_done(struct tevent_req
*subreq
)
85 struct smbd_smb2_request
*req
= tevent_req_callback_data(subreq
,
86 struct smbd_smb2_request
);
87 const uint8_t *inbody
;
88 int i
= req
->current_idx
;
89 uint64_t in_file_id_persistent
;
90 uint64_t in_file_id_volatile
;
91 uint8_t out_oplock_level
= 0;
94 NTSTATUS error
; /* transport error */
96 status
= smbd_smb2_oplock_break_recv(subreq
, &out_oplock_level
);
98 if (!NT_STATUS_IS_OK(status
)) {
99 error
= smbd_smb2_request_error(req
, status
);
100 if (!NT_STATUS_IS_OK(error
)) {
101 smbd_server_connection_terminate(req
->sconn
,
108 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
110 in_file_id_persistent
= BVAL(inbody
, 0x08);
111 in_file_id_volatile
= BVAL(inbody
, 0x10);
113 outbody
= data_blob_talloc(req
->out
.vector
, NULL
, 0x18);
114 if (outbody
.data
== NULL
) {
115 error
= smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
116 if (!NT_STATUS_IS_OK(error
)) {
117 smbd_server_connection_terminate(req
->sconn
,
124 SSVAL(outbody
.data
, 0x00, 0x18); /* struct size */
125 SCVAL(outbody
.data
, 0x02,
126 out_oplock_level
); /* oplock level */
127 SCVAL(outbody
.data
, 0x03, 0); /* reserved */
128 SIVAL(outbody
.data
, 0x04, 0); /* reserved */
129 SBVAL(outbody
.data
, 0x08,
130 in_file_id_persistent
); /* file id (persistent) */
131 SBVAL(outbody
.data
, 0x10,
132 in_file_id_volatile
); /* file id (volatile) */
134 error
= smbd_smb2_request_done(req
, outbody
, NULL
);
135 if (!NT_STATUS_IS_OK(error
)) {
136 smbd_server_connection_terminate(req
->sconn
,
142 struct smbd_smb2_oplock_break_state
{
143 struct smbd_smb2_request
*smb2req
;
144 uint8_t out_oplock_level
;
147 static struct tevent_req
*smbd_smb2_oplock_break_send(TALLOC_CTX
*mem_ctx
,
148 struct tevent_context
*ev
,
149 struct smbd_smb2_request
*smb2req
,
150 uint8_t in_oplock_level
,
151 uint64_t in_file_id_volatile
)
153 struct tevent_req
*req
;
154 struct smbd_smb2_oplock_break_state
*state
;
155 struct smb_request
*smbreq
;
156 connection_struct
*conn
= smb2req
->tcon
->compat_conn
;
159 req
= tevent_req_create(mem_ctx
, &state
,
160 struct smbd_smb2_oplock_break_state
);
164 state
->smb2req
= smb2req
;
165 state
->out_oplock_level
= SMB2_OPLOCK_LEVEL_NONE
;
167 DEBUG(10,("smbd_smb2_oplock_break_send: file_id[0x%016llX]\n",
168 (unsigned long long)in_file_id_volatile
));
170 smbreq
= smbd_smb2_fake_smb_request(smb2req
);
171 if (tevent_req_nomem(smbreq
, req
)) {
172 return tevent_req_post(req
, ev
);
175 fsp
= file_fsp(smbreq
, (uint16_t)in_file_id_volatile
);
177 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
178 return tevent_req_post(req
, ev
);
180 if (conn
!= fsp
->conn
) {
181 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
182 return tevent_req_post(req
, ev
);
184 if (smb2req
->session
->vuid
!= fsp
->vuid
) {
185 tevent_req_nterror(req
, NT_STATUS_FILE_CLOSED
);
186 return tevent_req_post(req
, ev
);
189 tevent_req_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
190 return tevent_req_post(req
, ev
);
193 static NTSTATUS
smbd_smb2_oplock_break_recv(struct tevent_req
*req
,
194 uint8_t *out_oplock_level
)
197 struct smbd_smb2_oplock_break_state
*state
=
199 struct smbd_smb2_oplock_break_state
);
201 if (tevent_req_is_nterror(req
, &status
)) {
202 tevent_req_received(req
);
206 *out_oplock_level
= state
->out_oplock_level
;
208 tevent_req_received(req
);