summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2019-08-15 12:10:52 +0200
committerJeremy Allison <jra@samba.org>2019-09-17 22:49:36 +0000
commitd12421ace457d1fdca0d97e2c680e90edf556967 (patch)
treef4dc1134ef2dd04db79d68b424a4e9f9289e2300 /source3/locking
parentcc2e5b41646f6c18288ffb4b0ea16f4ea2cb4874 (diff)
downloadsamba-d12421ace457d1fdca0d97e2c680e90edf556967.tar.gz
smbd: Let fsp_lease_type() look at leases.tdb
The same lease can be used via different TCP connections (yes, we have tests for this!). At the end of downgrade_lease() we update all fsp's with fsps_lease_update() that link to the lease that just was changed. However, this is only in the local process, this is not cross-smbd. So other smbds using the same lease can use stale information and for example get the mandatory locking wrong. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/leases_util.c26
-rw-r--r--source3/locking/proto.h4
2 files changed, 23 insertions, 7 deletions
diff --git a/source3/locking/leases_util.c b/source3/locking/leases_util.c
index da094069941..d307f420c7c 100644
--- a/source3/locking/leases_util.c
+++ b/source3/locking/leases_util.c
@@ -24,6 +24,7 @@
#include "../librpc/gen_ndr/open_files.h"
#include "locking/proto.h"
#include "smbd/globals.h"
+#include "locking/leases_db.h"
uint32_t map_oplock_to_lease_type(uint16_t op_type)
{
@@ -47,12 +48,27 @@ uint32_t map_oplock_to_lease_type(uint16_t op_type)
return ret;
}
-uint32_t fsp_lease_type(const struct files_struct *fsp)
+uint32_t fsp_lease_type(struct files_struct *fsp)
{
- if (fsp->oplock_type == LEASE_OPLOCK) {
- return fsp->lease->lease.lease_state;
+ NTSTATUS status;
+
+ if (fsp->oplock_type != LEASE_OPLOCK) {
+ uint32_t type = map_oplock_to_lease_type(fsp->oplock_type);
+ return type;
+ }
+
+ status = leases_db_get_current_state(
+ fsp_client_guid(fsp),
+ &fsp->lease->lease.lease_key,
+ &fsp->leases_db_seqnum,
+ &fsp->lease_type);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_DEBUG("leases_db_get_current_state failed: %s\n",
+ nt_errstr(status));
+ fsp->lease_type = 0; /* no lease */
}
- return map_oplock_to_lease_type(fsp->oplock_type);
+
+ return fsp->lease_type;
}
static uint32_t lease_type_is_exclusive(uint32_t lease_type)
@@ -65,7 +81,7 @@ static uint32_t lease_type_is_exclusive(uint32_t lease_type)
return false;
}
-bool fsp_lease_type_is_exclusive(const struct files_struct *fsp)
+bool fsp_lease_type_is_exclusive(struct files_struct *fsp)
{
uint32_t lease_type = fsp_lease_type(fsp);
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index 9094cc02651..7d2d28f4172 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -263,8 +263,8 @@ bool release_posix_lock_posix_flavour(files_struct *fsp,
/* The following definitions come from locking/leases_util.c */
uint32_t map_oplock_to_lease_type(uint16_t op_type);
-uint32_t fsp_lease_type(const struct files_struct *fsp);
-bool fsp_lease_type_is_exclusive(const struct files_struct *fsp);
+uint32_t fsp_lease_type(struct files_struct *fsp);
+bool fsp_lease_type_is_exclusive(struct files_struct *fsp);
const struct GUID *fsp_client_guid(const files_struct *fsp);
#endif /* _LOCKING_PROTO_H_ */