From: Ralph Boehme Date: Sun, 13 Oct 2024 15:44:18 +0000 (+0200) Subject: smbd: consolidate "have_file_open_below" logic in have_file_open_below() X-Git-Tag: tdb-1.4.13~724 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac3a74b459338da1b129549cdacfd8925f5a8359;p=thirdparty%2Fsamba.git smbd: consolidate "have_file_open_below" logic in have_file_open_below() Let have_file_open_below() be the single function to check if "have_file_open_below" and let it check internally whether to just search the fsp list in the process or traversing locking.tdb based on the setting of "strict rename". BUG: https://bugzilla.samba.org/show_bug.cgi?id=15608 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 35aa3687b4b..64a747f294f 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1286,22 +1286,31 @@ static int have_file_open_below_fn(const struct share_mode_data *data, return -1; } -bool have_file_open_below(connection_struct *conn, - const struct smb_filename *name) +bool have_file_open_below(struct files_struct *fsp) { struct have_file_open_below_state state = { .found_one = false, }; int ret; - if (!VALID_STAT(name->st)) { + if (!lp_strict_rename(SNUM(fsp->conn))) { + if (file_find_subpath(fsp)) { + return true; + } return false; } - if (!S_ISDIR(name->st.st_ex_mode)) { + + if (!VALID_STAT(fsp->fsp_name->st)) { + return false; + } + if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { return false; } - ret = opens_below_forall_read(conn, name, have_file_open_below_fn, &state); + ret = opens_below_forall_read(fsp->conn, + fsp->fsp_name, + have_file_open_below_fn, + &state); if (ret == -1) { return false; } @@ -1659,9 +1668,7 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp) return status; } - if (lp_strict_rename(SNUM(conn)) && - have_file_open_below(fsp->conn, fsp->fsp_name)) - { + if (have_file_open_below(fsp)) { return NT_STATUS_ACCESS_DENIED; } diff --git a/source3/smbd/dir.h b/source3/smbd/dir.h index c6272652c0d..21e4632eb63 100644 --- a/source3/smbd/dir.h +++ b/source3/smbd/dir.h @@ -47,8 +47,7 @@ char *dptr_ReadDirName(TALLOC_CTX *ctx, struct dptr_struct *dptr); void dptr_RewindDir(struct dptr_struct *dptr); void dptr_set_priv(struct dptr_struct *dptr); const char *dptr_wcard(struct smbd_server_connection *sconn, int key); -bool have_file_open_below(connection_struct *conn, - const struct smb_filename *name); +bool have_file_open_below(struct files_struct *fsp); bool opens_below_forall(struct connection_struct *conn, const struct smb_filename *dir_name, int (*fn)(struct share_mode_data *data, diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index d829e691ad2..1ac214041f2 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -1169,17 +1169,7 @@ static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp, /* If no pathnames are open below this directory, allow the rename. */ - if (lp_strict_rename(SNUM(conn))) { - /* - * Strict rename, check open file db. - */ - if (have_file_open_below(fsp->conn, fsp->fsp_name)) { - return NT_STATUS_ACCESS_DENIED; - } - } else if (file_find_subpath(fsp)) { - /* - * No strict rename, just look in local process. - */ + if (have_file_open_below(fsp)) { return NT_STATUS_ACCESS_DENIED; } return NT_STATUS_OK;