2 Unix SMB/CIFS implementation.
3 SMB client oplock functions
4 Copyright (C) Andrew Tridgell 2001
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "../lib/util/tevent_ntstatus.h"
22 #include "async_smb.h"
23 #include "libsmb/libsmb.h"
24 #include "../libcli/smb/smbXcli_base.h"
26 struct cli_smb_oplock_break_waiter_state
{
31 static void cli_smb_oplock_break_waiter_done(struct tevent_req
*subreq
);
33 struct tevent_req
*cli_smb_oplock_break_waiter_send(TALLOC_CTX
*mem_ctx
,
34 struct tevent_context
*ev
,
35 struct cli_state
*cli
)
37 struct tevent_req
*req
, *subreq
;
38 struct cli_smb_oplock_break_waiter_state
*state
;
40 req
= tevent_req_create(mem_ctx
, &state
,
41 struct cli_smb_oplock_break_waiter_state
);
47 * Create a fake SMB request that we will never send out. This is only
48 * used to be set into the pending queue with the right mid.
50 subreq
= smb1cli_req_create(mem_ctx
, ev
, cli
->conn
, 0, 0, 0, 0, 0, 0,
51 0, NULL
, NULL
, 0, NULL
, 0, NULL
);
52 if (tevent_req_nomem(subreq
, req
)) {
53 return tevent_req_post(req
, ev
);
55 smb1cli_req_set_mid(subreq
, 0xffff);
57 if (!smbXcli_req_set_pending(subreq
)) {
59 return tevent_req_post(req
, ev
);
61 tevent_req_set_callback(subreq
, cli_smb_oplock_break_waiter_done
, req
);
65 static void cli_smb_oplock_break_waiter_done(struct tevent_req
*subreq
)
67 struct tevent_req
*req
= tevent_req_callback_data(
68 subreq
, struct tevent_req
);
69 struct cli_smb_oplock_break_waiter_state
*state
= tevent_req_data(
70 req
, struct cli_smb_oplock_break_waiter_state
);
76 status
= smb1cli_req_recv(subreq
, state
,
81 NULL
, /* pvwv_offset */
82 NULL
, /* pnum_bytes */
84 NULL
, /* pbytes_offset */
86 NULL
, 0); /* expected */
88 if (tevent_req_nterror(req
, status
)) {
92 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
95 state
->fnum
= SVAL(vwv
+2, 0);
96 state
->level
= CVAL(vwv
+3, 1);
100 NTSTATUS
cli_smb_oplock_break_waiter_recv(struct tevent_req
*req
,
104 struct cli_smb_oplock_break_waiter_state
*state
= tevent_req_data(
105 req
, struct cli_smb_oplock_break_waiter_state
);
108 if (tevent_req_is_nterror(req
, &status
)) {
111 *pfnum
= state
->fnum
;
112 *plevel
= state
->level
;
116 /****************************************************************************
117 send an ack for an oplock break request
118 ****************************************************************************/
120 struct cli_oplock_ack_state
{
124 static void cli_oplock_ack_done(struct tevent_req
*subreq
);
126 struct tevent_req
*cli_oplock_ack_send(TALLOC_CTX
*mem_ctx
,
127 struct tevent_context
*ev
,
128 struct cli_state
*cli
,
129 uint16_t fnum
, uint8_t level
)
131 struct tevent_req
*req
, *subreq
;
132 struct cli_oplock_ack_state
*state
;
134 req
= tevent_req_create(mem_ctx
, &state
, struct cli_oplock_ack_state
);
139 subreq
= cli_lockingx_send(
141 ev
, /* tevent_context */
144 LOCKING_ANDX_OPLOCK_RELEASE
, /* typeoflock */
145 level
, /* newoplocklevel */
152 if (tevent_req_nomem(subreq
, req
)) {
153 return tevent_req_post(req
, ev
);
155 tevent_req_set_callback(subreq
, cli_oplock_ack_done
, req
);
159 static void cli_oplock_ack_done(struct tevent_req
*subreq
)
161 NTSTATUS status
= cli_lockingx_recv(subreq
);
162 tevent_req_simple_finish_ntstatus(subreq
, status
);
165 NTSTATUS
cli_oplock_ack_recv(struct tevent_req
*req
)
167 return tevent_req_simple_recv_ntstatus(req
);