From: Ralph Boehme Date: Mon, 19 May 2025 10:59:24 +0000 (+0200) Subject: smbd: add and fill CreateGuid in struct smbd_smb2_request X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50a1c44bc14574aacf3069f5c6f2de6e6edc00f1;p=thirdparty%2Fsamba.git smbd: add and fill CreateGuid in struct smbd_smb2_request This will get stored in the share_mode_entry and is used as part of Persistent Handle reconnect. Signed-off-by: Ralph Boehme Reviewed-by: Anoop C S --- diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c index 7047fdf97bf..70400f9e98b 100644 --- a/source3/locking/share_mode_lock.c +++ b/source3/locking/share_mode_lock.c @@ -2075,6 +2075,7 @@ bool set_share_mode(struct share_mode_lock *lck, uint64_t mid, uint16_t op_type, const struct smb2_lease_key *lease_key, + const struct GUID *create_guid, uint32_t share_access, uint32_t access_mask) { @@ -2136,6 +2137,8 @@ bool set_share_mode(struct share_mode_lock *lck, if (e.flags & SHARE_ENTRY_FLAG_PERSISTENT_OPEN) { d->num_persistent++; d->modified = true; + SMB_ASSERT(create_guid != NULL); + e.create_guid = *create_guid; } ok = share_mode_entry_put(&e, &e_buf); diff --git a/source3/locking/share_mode_lock.h b/source3/locking/share_mode_lock.h index b4f2848d81b..a3c66d74f31 100644 --- a/source3/locking/share_mode_lock.h +++ b/source3/locking/share_mode_lock.h @@ -49,6 +49,7 @@ bool remove_share_oplock(struct share_mode_lock *lck, struct files_struct *fsp); bool file_has_read_lease(struct files_struct *fsp); +struct GUID; bool set_share_mode( struct share_mode_lock *lck, struct files_struct *fsp, @@ -56,6 +57,7 @@ bool set_share_mode( uint64_t mid, uint16_t op_type, const struct smb2_lease_key *lease_key, + const struct GUID *create_guid, uint32_t share_access, uint32_t access_mask); bool reset_share_mode_entry( diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index c7d67e2ed9d..ff4ea716128 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -666,6 +666,13 @@ struct smbd_smb2_request { bool request_counters_updated; uint64_t channel_generation; + /* + * The client provided CreateGuid from a + * SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 if any. + */ + struct GUID _create_guid; + struct GUID *create_guid; + /* * The sub request for async backend calls. * This is used for SMB2 Cancel. diff --git a/source3/smbd/open.c b/source3/smbd/open.c index bdf243dcaf4..c4b7daf787e 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -3224,6 +3224,7 @@ static NTSTATUS check_and_store_share_mode( uint32_t granted_lease = 0; const struct smb2_lease_key *lease_key = NULL; struct blocker_debug_state *blocker_debug_state = NULL; + const struct GUID *create_guid = NULL; bool delete_on_close; bool ok; @@ -3263,12 +3264,17 @@ static NTSTATUS check_and_store_share_mode( share_mode_flags_restrict(lck, access_mask, share_access, 0); + if (req != NULL && req->smb2req != NULL) { + create_guid = req->smb2req->create_guid; + } + ok = set_share_mode(lck, fsp, get_current_uid(fsp->conn), req ? req->mid : 0, oplock_type, lease_key, + create_guid, share_access, access_mask); if (!ok) { diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c index a3a1edb00ba..c79c8970e1e 100644 --- a/source3/smbd/smb2_create.c +++ b/source3/smbd/smb2_create.c @@ -1412,6 +1412,13 @@ static void smbd_smb2_cc_before_exec_dhc2q(struct tevent_req *req) return; } state->create_guid = &state->_create_guid; + /* + * Make the CreateGuid available to the FSA and VFS layers via + * the "req" argument to SMB_VFS_CREATE_FILE(): + * req->smb2req->create_guid. + */ + smb2req->_create_guid = state->_create_guid; + smb2req->create_guid = &smb2req->_create_guid; /* * we need to store the create_guid later