2 Unix SMB/CIFS implementation.
3 Lease utility functions
5 Copyright (C) Jeremy Allison 2017.
6 Copyright (C) Stefan (metze) Metzmacher 2017.
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.
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.
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/>.
22 #define DBGC_CLASS DBGC_LOCKING
24 #include "../librpc/gen_ndr/open_files.h"
25 #include "locking/proto.h"
26 #include "smbd/globals.h"
27 #include "locking/leases_db.h"
29 uint32_t map_oplock_to_lease_type(uint16_t op_type
)
35 case BATCH_OPLOCK
|EXCLUSIVE_OPLOCK
:
36 ret
= SMB2_LEASE_READ
|SMB2_LEASE_WRITE
|SMB2_LEASE_HANDLE
;
38 case EXCLUSIVE_OPLOCK
:
39 ret
= SMB2_LEASE_READ
|SMB2_LEASE_WRITE
;
42 ret
= SMB2_LEASE_READ
;
45 ret
= SMB2_LEASE_NONE
;
51 uint32_t fsp_lease_type(struct files_struct
*fsp
)
55 if (fsp
->oplock_type
!= LEASE_OPLOCK
) {
56 uint32_t type
= map_oplock_to_lease_type(fsp
->oplock_type
);
60 status
= leases_db_get_current_state(
62 &fsp
->lease
->lease
.lease_key
,
63 &fsp
->leases_db_seqnum
,
65 if (!NT_STATUS_IS_OK(status
)) {
66 DBG_DEBUG("leases_db_get_current_state failed: %s\n",
68 fsp
->lease_type
= 0; /* no lease */
71 return fsp
->lease_type
;
74 const struct GUID
*fsp_client_guid(const files_struct
*fsp
)
76 return &fsp
->conn
->sconn
->client
->global
->client_guid
;