From cf69a9ef142098704ab358f01abf5e0e79652973 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Dec 2024 17:17:59 +0100 Subject: [PATCH] smbd: Factor out can_delete_directory_hnd() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To be used in close.c next Signed-off-by: Volker Lendecke Reviewed-by: Pavel Filipenský --- source3/smbd/dir.c | 30 +++++++++++++++++------------- source3/smbd/dir.h | 1 + 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 7cf79222c2f..afc9c74dfdd 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1539,21 +1539,14 @@ bool opens_below_forall(struct connection_struct *conn, Is this directory empty ? *****************************************************************/ -NTSTATUS can_delete_directory_fsp(files_struct *fsp) +NTSTATUS can_delete_directory_hnd(struct smb_Dir *dir_hnd) { NTSTATUS status = NT_STATUS_OK; const char *dname = NULL; char *talloced = NULL; - struct connection_struct *conn = fsp->conn; + struct files_struct *dirfsp = dir_hnd_fetch_fsp(dir_hnd); + struct connection_struct *conn = dirfsp->conn; bool delete_veto = lp_delete_veto_files(SNUM(conn)); - struct smb_Dir *dir_hnd = NULL; - struct files_struct *dirfsp = NULL; - - status = OpenDir_from_pathref(talloc_tos(), fsp, NULL, 0, &dir_hnd); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - dirfsp = dir_hnd_fetch_fsp(dir_hnd); while ((dname = ReadDirName(dir_hnd, &talloced))) { struct smb_filename *direntry_fname = NULL; @@ -1658,15 +1651,26 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp) } if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(dir_hnd); return status; } if (have_file_open_below(dirfsp)) { - TALLOC_FREE(dir_hnd); return NT_STATUS_ACCESS_DENIED; } - TALLOC_FREE(dir_hnd); return NT_STATUS_OK; } + +NTSTATUS can_delete_directory_fsp(files_struct *fsp) +{ + struct smb_Dir *dir_hnd = NULL; + NTSTATUS status; + + status = OpenDir_from_pathref(talloc_tos(), fsp, NULL, 0, &dir_hnd); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + status = can_delete_directory_hnd(dir_hnd); + TALLOC_FREE(dir_hnd); + return status; +} diff --git a/source3/smbd/dir.h b/source3/smbd/dir.h index 21e4632eb63..5cfe9e37f13 100644 --- a/source3/smbd/dir.h +++ b/source3/smbd/dir.h @@ -23,6 +23,7 @@ struct smb_Dir; struct dptr_struct; +NTSTATUS can_delete_directory_hnd(struct smb_Dir *dir_hnd); NTSTATUS can_delete_directory_fsp(files_struct *fsp); struct files_struct *dir_hnd_fetch_fsp(struct smb_Dir *dir_hnd); uint16_t dptr_attr(struct smbd_server_connection *sconn, int key);