From: Stefan Metzmacher Date: Tue, 30 Aug 2022 06:11:12 +0000 (+0200) Subject: s3:smbd: let update_write_time_on_close() use share_mode_do_locked_vfs_denied() X-Git-Tag: talloc-2.4.0~866 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b80bc6307cf4ec7d54284e1b940ce9f7430e6716;p=thirdparty%2Fsamba.git s3:smbd: let update_write_time_on_close() use share_mode_do_locked_vfs_denied() BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index d50d34229b7..b1db60bac77 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -564,11 +564,33 @@ void set_close_write_time(struct files_struct *fsp, struct timespec ts) fsp->close_write_time = ts; } +static void update_write_time_on_close_share_mode_fn(struct share_mode_lock *lck, + void *private_data) +{ + struct files_struct *fsp = + talloc_get_type_abort(private_data, + struct files_struct); + NTTIME share_mtime = share_mode_changed_write_time(lck); + + /* + * On close if we're changing the real file time we + * must update it in the open file db too. + */ + share_mode_set_old_write_time(lck, fsp->close_write_time); + + /* + * Close write times overwrite sticky write times + * so we must replace any sticky write time here. + */ + if (!null_nttime(share_mtime)) { + share_mode_set_changed_write_time(lck, fsp->close_write_time); + } +} + static NTSTATUS update_write_time_on_close(struct files_struct *fsp) { struct smb_file_time ft; NTSTATUS status; - struct share_mode_lock *lck = NULL; init_smb_file_time(&ft); @@ -592,31 +614,14 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp) } /* - * get_existing_share_mode_lock() isn't really the right - * call here, as we're being called after - * close_remove_share_mode() inside close_normal_file() - * so it's quite normal to not have an existing share - * mode here. However, get_share_mode_lock() doesn't - * work because that will create a new share mode if - * one doesn't exist - so stick with this call (just - * ignore any error we get if the share mode doesn't - * exist. + * We're being called after close_remove_share_mode() inside + * close_normal_file() so it's quite normal to not have an + * existing share. So just ignore the result of + * share_mode_do_locked_vfs_denied()... */ - - lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id); - if (lck) { - NTTIME share_mtime = share_mode_changed_write_time(lck); - /* On close if we're changing the real file time we - * must update it in the open file db too. */ - share_mode_set_old_write_time(lck, fsp->close_write_time); - - /* Close write times overwrite sticky write times - so we must replace any sticky write time here. */ - if (!null_nttime(share_mtime)) { - share_mode_set_changed_write_time(lck, fsp->close_write_time); - } - TALLOC_FREE(lck); - } + share_mode_do_locked_vfs_denied(fsp->file_id, + update_write_time_on_close_share_mode_fn, + fsp); ft.mtime = fsp->close_write_time; /* As this is a close based update, we are not directly changing the