]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify rmdir_internals()
authorVolker Lendecke <vl@samba.org>
Thu, 5 Dec 2024 16:20:41 +0000 (17:20 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 17 Dec 2024 12:30:31 +0000 (12:30 +0000)
Remove a "copy" of can_delete_directory_hnd()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
source3/smbd/close.c

index 0c1b395ed33726898dc67624c1d6ef0b8625e680..9e08a3c987cf75fc6465c18e695b2078ff98cde5 100644 (file)
@@ -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;
        }