smbd: Make fsp->fh->gen_id unique per process
authorVolker Lendecke <vl@samba.org>
Mon, 16 Sep 2019 10:54:32 +0000 (03:54 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 17 Sep 2019 22:49:35 +0000 (22:49 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/durable.c
source3/smbd/files.c
source3/smbd/proto.h

index a42c201b81b74d42fd6674d801d250e1a77bc3ec..2863b41b354c3849edb01f33cff9073f4a5b93cc 100644 (file)
@@ -657,7 +657,6 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        }
 
        fsp->fh->private_options = e->private_options;
-       fsp->fh->gen_id = smbXsrv_open_hash(op);
        fsp->file_id = file_id;
        fsp->file_pid = smb1req->smbpid;
        fsp->vuid = smb1req->vuid;
@@ -666,6 +665,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        fsp->can_read = ((fsp->access_mask & (FILE_READ_DATA)) != 0);
        fsp->can_write = ((fsp->access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) != 0);
        fsp->fnum = op->local_id;
+       fsp_set_gen_id(fsp);
 
        /*
         * TODO:
index e8fbb57c88b7a1f513597e89c1cf27a36d12abdb..e0ec601c56fadf6aef24fda3fbc2d4bec002726d 100644 (file)
@@ -83,6 +83,17 @@ fail:
        return status;
 }
 
+void fsp_set_gen_id(files_struct *fsp)
+{
+       static uint64_t gen_id = 1;
+
+       /*
+        * A billion of 64-bit increments per second gives us
+        * more than 500 years of runtime without wrap.
+        */
+       fsp->fh->gen_id = gen_id++;
+}
+
 /****************************************************************************
  Find first available file slot.
 ****************************************************************************/
@@ -116,12 +127,13 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                fsp->op = op;
                op->compat = fsp;
                fsp->fnum = op->local_id;
-               fsp->fh->gen_id = smbXsrv_open_hash(op);
        } else {
                DEBUG(10, ("%s: req==NULL, INTERNAL_OPEN_ONLY, smbXsrv_open "
                           "allocated\n", __func__));
        }
 
+       fsp_set_gen_id(fsp);
+
        /*
         * Create an smb_filename with "" for the base_name.  There are very
         * few NULL checks, so make sure it's initialized with something. to
index 5ebee0486e727e2c053567146d4cdbe93e7e4f01..f1c374f652bc0fc8894dab51dc2858c98cbe277c 100644 (file)
@@ -368,6 +368,7 @@ NTSTATUS filename_convert_with_privilege(TALLOC_CTX *mem_ctx,
 
 NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
                 files_struct **result);
+void fsp_set_gen_id(files_struct *fsp);
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result);
 void file_close_conn(connection_struct *conn);