]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: use op->global->open_global_id for the share_mode_entry.share_file_id
authorRalph Boehme <slow@samba.org>
Thu, 9 Oct 2025 13:27:31 +0000 (15:27 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 10 Oct 2025 11:43:16 +0000 (11:43 +0000)
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 <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Oct 10 11:43:16 UTC 2025 on atb-devel-224

source3/locking/share_mode_lock.c
source3/smbd/durable.c
source3/smbd/files.c

index ce5ef40e370a15bc152fe64eb667bcb72b5ab8a1..66a7c1b6c0487719fc2316314adfd1353f323688 100644 (file)
@@ -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);
index c13c8382f0f303e679714754e76ec6ece08002ee..57416e506ebbde8a04f0514745c407378d22777e 100644 (file)
@@ -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)) {
index 779d1f3c611327dc8cf65f4077f2a5d51df3cf24..cce1dc3790aaf13ebdc31464324eb4c23f13d0f0 100644 (file)
@@ -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;