From: Ralph Boehme Date: Thu, 9 Oct 2025 13:27:31 +0000 (+0200) Subject: smbd: use op->global->open_global_id for the share_mode_entry.share_file_id X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3df388b8f148c00a3ef331d393cea976fb9340b3;p=thirdparty%2Fsamba.git smbd: use op->global->open_global_id for the share_mode_entry.share_file_id open_global_id is an uint32_t, share_file_id is an uint64_t. For internal opens that don't have an smbXsrv_open_global.tdb entry, continue to use a generation counter starting at UINT32_MAX + 1. We don't expose internal opens via srvsrc, which imposes the requirement for using an uint32_t, so we can use larger ids for the internal opens as srvsvc never sees them (as they're not in smbXsrv_open_global.tdb and srvsvc as any other component listing open files like smbstatus lists smbXsrv_open_global.tdb). Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Fri Oct 10 11:43:16 UTC 2025 on atb-devel-224 --- diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c index ce5ef40e370..66a7c1b6c04 100644 --- a/source3/locking/share_mode_lock.c +++ b/source3/locking/share_mode_lock.c @@ -2739,7 +2739,7 @@ bool mark_share_mode_disconnected(struct share_mode_lock *lck, ok = reset_share_mode_entry( lck, messaging_server_id(fsp->conn->sconn->msg_ctx), - fh_get_gen_id(fsp->fh), + fsp->op->global->open_persistent_id, disconnected_pid, UINT64_MAX, fsp->op->global->open_persistent_id); diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c index c13c8382f0f..57416e506eb 100644 --- a/source3/smbd/durable.c +++ b/source3/smbd/durable.c @@ -887,7 +887,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn, state.fsp->file_pid = smb1req->smbpid; state.fsp->vuid = smb1req->vuid; state.fsp->fnum = op->local_id; - fsp_set_gen_id(state.fsp); + fh_set_gen_id(state.fsp->fh, op->global->open_global_id); status = fsp_set_smb_fname(state.fsp, smb_fname); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 779d1f3c611..cce1dc3790a 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -92,13 +92,16 @@ fail: void fsp_set_gen_id(files_struct *fsp) { - static uint64_t gen_id = 1; + static uint64_t gen_id = UINT32_MAX; /* - * A billion of 64-bit increments per second gives us - * more than 500 years of runtime without wrap. + * These ids are only used for internal opens, which gives us 4 billion + * opens until we wrap. */ gen_id++; + if (gen_id == 0) { + gen_id = UINT32_MAX; + } fh_set_gen_id(fsp->fh, gen_id); } @@ -112,10 +115,9 @@ NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req) NTTIME now; NTSTATUS status; - fsp_set_gen_id(fsp); - if (req == NULL) { DBG_DEBUG("INTERNAL_OPEN_ONLY, skipping smbXsrv_open\n"); + fsp_set_gen_id(fsp); return NT_STATUS_OK; } @@ -131,6 +133,7 @@ NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req) } fsp->op = op; op->compat = fsp; + fh_set_gen_id(fsp->fh, fsp->op->global->open_global_id); fsp->fnum = op->local_id; fsp->mid = req->mid;