From: Volker Lendecke Date: Thu, 5 Dec 2024 16:20:41 +0000 (+0100) Subject: smbd: Simplify rmdir_internals() X-Git-Tag: tdb-1.4.13~291 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=663f03996ca10bd2dd73bef10ea21fd3947fe129;p=thirdparty%2Fsamba.git smbd: Simplify rmdir_internals() Remove a "copy" of can_delete_directory_hnd() Signed-off-by: Volker Lendecke Reviewed-by: Pavel Filipenský --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 0c1b395ed33..9e08a3c987c 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -1192,147 +1192,8 @@ static NTSTATUS rmdir_internals(TALLOC_CTX *ctx, struct files_struct *fsp) dirfsp = dir_hnd_fetch_fsp(dir_hnd); - while ((dname = ReadDirName(dir_hnd, &talloced)) != NULL) { - struct smb_filename *smb_dname_full = NULL; - struct smb_filename *direntry_fname = NULL; - char *fullname = NULL; - int retval; - - if (ISDOT(dname) || ISDOTDOT(dname)) { - TALLOC_FREE(talloced); - continue; - } - if (IS_VETO_PATH(conn, dname)) { - TALLOC_FREE(talloced); - continue; - } - - fullname = talloc_asprintf(talloc_tos(), - "%s/%s", - smb_dname->base_name, - dname); - - if (fullname == NULL) { - TALLOC_FREE(talloced); - status = NT_STATUS_NO_MEMORY; - goto err; - } - - smb_dname_full = synthetic_smb_fname(talloc_tos(), - fullname, - NULL, - NULL, - smb_dname->twrp, - smb_dname->flags); - if (smb_dname_full == NULL) { - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - status = NT_STATUS_NO_MEMORY; - goto err; - } - - retval = SMB_VFS_LSTAT(conn, smb_dname_full); - if (retval != 0) { - status = map_nt_error_from_unix(errno); - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - goto err; - } - - if (S_ISLNK(smb_dname_full->st.st_ex_mode)) { - /* Could it be an msdfs link ? */ - if (lp_host_msdfs() && - lp_msdfs_root(SNUM(conn))) { - struct smb_filename *smb_atname; - smb_atname = synthetic_smb_fname(talloc_tos(), - dname, - NULL, - &smb_dname_full->st, - fsp->fsp_name->twrp, - fsp->fsp_name->flags); - if (smb_atname == NULL) { - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - status = NT_STATUS_NO_MEMORY; - goto err; - } - if (is_msdfs_link(fsp, smb_atname)) { - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - TALLOC_FREE(smb_atname); - DBG_DEBUG("got msdfs link name %s " - "- can't delete directory %s\n", - dname, - fsp_str_dbg(fsp)); - status = NT_STATUS_DIRECTORY_NOT_EMPTY; - goto err; - } - TALLOC_FREE(smb_atname); - } - - /* Not a DFS link - could it be a dangling symlink ? */ - retval = SMB_VFS_STAT(conn, smb_dname_full); - if (retval == -1 && (errno == ENOENT || errno == ELOOP)) { - /* - * Dangling symlink. - * Allow delete as "delete veto files = yes" - */ - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - continue; - } - - DBG_DEBUG("got symlink name %s - " - "can't delete directory %s\n", - dname, - fsp_str_dbg(fsp)); - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - status = NT_STATUS_DIRECTORY_NOT_EMPTY; - goto err; - } - - /* Not a symlink, get a pathref. */ - status = synthetic_pathref(talloc_tos(), - dirfsp, - dname, - NULL, - &smb_dname_full->st, - smb_dname->twrp, - smb_dname->flags, - &direntry_fname); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - goto err; - } - - if (!is_visible_fsp(direntry_fname->fsp)) { - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - TALLOC_FREE(direntry_fname); - continue; - } - - /* - * We found a client visible name. - * We cannot delete this directory. - */ - DBG_DEBUG("got name %s - " - "can't delete directory %s\n", - dname, - fsp_str_dbg(fsp)); - TALLOC_FREE(talloced); - TALLOC_FREE(fullname); - TALLOC_FREE(smb_dname_full); - TALLOC_FREE(direntry_fname); + status = can_delete_directory_hnd(dir_hnd); + if (!NT_STATUS_IS_OK(status)) { status = NT_STATUS_DIRECTORY_NOT_EMPTY; goto err; }