Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Lease utility functions
4 :
5 : Copyright (C) Jeremy Allison 2017.
6 : Copyright (C) Stefan (metze) Metzmacher 2017.
7 :
8 : This program is free software; you can redistribute it and/or modify
9 : it under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3 of the License, or
11 : (at your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : GNU General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program. If not, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : #define DBGC_CLASS DBGC_LOCKING
23 : #include "includes.h"
24 : #include "../librpc/gen_ndr/open_files.h"
25 : #include "locking/proto.h"
26 : #include "smbd/globals.h"
27 : #include "locking/leases_db.h"
28 :
29 766857 : uint32_t map_oplock_to_lease_type(uint16_t op_type)
30 : {
31 : uint32_t ret;
32 :
33 766077 : switch(op_type) {
34 2743 : case BATCH_OPLOCK:
35 : case BATCH_OPLOCK|EXCLUSIVE_OPLOCK:
36 2743 : ret = SMB2_LEASE_READ|SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE;
37 2743 : break;
38 464 : case EXCLUSIVE_OPLOCK:
39 464 : ret = SMB2_LEASE_READ|SMB2_LEASE_WRITE;
40 464 : break;
41 640 : case LEVEL_II_OPLOCK:
42 640 : ret = SMB2_LEASE_READ;
43 640 : break;
44 762230 : default:
45 762230 : ret = SMB2_LEASE_NONE;
46 762230 : break;
47 : }
48 766857 : return ret;
49 : }
50 :
51 363068 : uint32_t fsp_lease_type(struct files_struct *fsp)
52 : {
53 : NTSTATUS status;
54 :
55 363068 : if (fsp->oplock_type != LEASE_OPLOCK) {
56 362342 : uint32_t type = map_oplock_to_lease_type(fsp->oplock_type);
57 362342 : return type;
58 : }
59 :
60 1452 : status = leases_db_get_current_state(
61 : fsp_client_guid(fsp),
62 726 : &fsp->lease->lease.lease_key,
63 : &fsp->leases_db_seqnum,
64 : &fsp->lease_type);
65 726 : if (!NT_STATUS_IS_OK(status)) {
66 0 : DBG_DEBUG("leases_db_get_current_state failed: %s\n",
67 : nt_errstr(status));
68 0 : fsp->lease_type = 0; /* no lease */
69 : }
70 :
71 726 : return fsp->lease_type;
72 : }
73 :
74 175869 : static uint32_t lease_type_is_exclusive(uint32_t lease_type)
75 : {
76 175985 : if ((lease_type & (SMB2_LEASE_READ | SMB2_LEASE_WRITE)) ==
77 : (SMB2_LEASE_READ | SMB2_LEASE_WRITE)) {
78 178 : return true;
79 : }
80 :
81 175691 : return false;
82 : }
83 :
84 175985 : bool fsp_lease_type_is_exclusive(struct files_struct *fsp)
85 : {
86 175985 : uint32_t lease_type = fsp_lease_type(fsp);
87 :
88 175985 : return lease_type_is_exclusive(lease_type);
89 : }
90 :
91 5338 : const struct GUID *fsp_client_guid(const files_struct *fsp)
92 : {
93 5338 : return &fsp->conn->sconn->client->global->client_guid;
94 : }
|