source: vendor/3.6.0/source3/libsmb/clioplock.c

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 3.8 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 SMB client oplock functions
4 Copyright (C) Andrew Tridgell 2001
5
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.
10
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.
15
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/>.
18*/
19
20#include "includes.h"
21#include "../lib/util/tevent_ntstatus.h"
22#include "async_smb.h"
23#include "libsmb/libsmb.h"
24
25/****************************************************************************
26send an ack for an oplock break request
27****************************************************************************/
28
29struct cli_oplock_ack_state {
30 uint16_t vwv[8];
31};
32
33static void cli_oplock_ack_done(struct tevent_req *subreq);
34
35struct tevent_req *cli_oplock_ack_send(TALLOC_CTX *mem_ctx,
36 struct tevent_context *ev,
37 struct cli_state *cli,
38 uint16_t fnum, uint8_t level)
39{
40 struct tevent_req *req, *subreq;
41 struct cli_oplock_ack_state *state;
42
43 req = tevent_req_create(mem_ctx, &state, struct cli_oplock_ack_state);
44 if (req == NULL) {
45 return NULL;
46 }
47 SCVAL(state->vwv+0, 0, 0xff);
48 SCVAL(state->vwv+0, 1, 0);
49 SSVAL(state->vwv+1, 0, 0);
50 SSVAL(state->vwv+2, 0, fnum);
51 SCVAL(state->vwv+3, 0, LOCKING_ANDX_OPLOCK_RELEASE);
52 SCVAL(state->vwv+3, 1, level);
53 SIVAL(state->vwv+4, 0, 0); /* timeout */
54 SSVAL(state->vwv+6, 0, 0); /* unlockcount */
55 SSVAL(state->vwv+7, 0, 0); /* lockcount */
56
57 subreq = cli_smb_send(state, ev, cli, SMBlockingX, 0, 8, state->vwv,
58 0, NULL);
59 if (tevent_req_nomem(subreq, req)) {
60 return tevent_req_post(req, ev);
61 }
62 tevent_req_set_callback(subreq, cli_oplock_ack_done, req);
63 return req;
64}
65
66static void cli_oplock_ack_done(struct tevent_req *subreq)
67{
68 struct tevent_req *req = tevent_req_callback_data(
69 subreq, struct tevent_req);
70 NTSTATUS status;
71
72 status = cli_smb_recv(subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
73 TALLOC_FREE(subreq);
74 if (!NT_STATUS_IS_OK(status)) {
75 tevent_req_nterror(req, status);
76 return;
77 }
78 tevent_req_done(req);
79}
80
81NTSTATUS cli_oplock_ack_recv(struct tevent_req *req)
82{
83 return tevent_req_simple_recv_ntstatus(req);
84}
85
86NTSTATUS cli_oplock_ack(struct cli_state *cli, uint16_t fnum, unsigned char level)
87{
88 TALLOC_CTX *frame = talloc_stackframe();
89 struct event_context *ev;
90 struct tevent_req *req;
91 NTSTATUS status = NT_STATUS_OK;
92
93 if (cli_has_async_calls(cli)) {
94 /*
95 * Can't use sync call while an async call is in flight
96 */
97 status = NT_STATUS_INVALID_PARAMETER;
98 goto fail;
99 }
100
101 ev = event_context_init(frame);
102 if (ev == NULL) {
103 status = NT_STATUS_NO_MEMORY;
104 goto fail;
105 }
106
107 req = cli_oplock_ack_send(frame, ev, cli, fnum, level);
108 if (req == NULL) {
109 status = NT_STATUS_NO_MEMORY;
110 goto fail;
111 }
112
113 if (!tevent_req_poll(req, ev)) {
114 status = map_nt_error_from_unix(errno);
115 goto fail;
116 }
117
118 status = cli_oplock_ack_recv(req);
119 fail:
120 TALLOC_FREE(frame);
121 if (!NT_STATUS_IS_OK(status)) {
122 cli_set_error(cli, status);
123 }
124 return status;
125}
126
127/****************************************************************************
128set the oplock handler for a connection
129****************************************************************************/
130
131void cli_oplock_handler(struct cli_state *cli,
132 NTSTATUS (*handler)(struct cli_state *, uint16_t, unsigned char))
133{
134 cli->oplock_handler = handler;
135}
Note: See TracBrowser for help on using the repository browser.