mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
s3: smbd: Fix logic in can_delete_directory_fsp() to cope with dangling symlinks.
Remove knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14879 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> (cherry picked from commite9ef970eee
) (backported from commit5023dbc04b
) [pfilipen@redhat.com: can_delete_directory_fsp() got refactored in 4.15]
This commit is contained in:
parent
7034f9b765
commit
b61fb49a7a
@ -1 +0,0 @@
|
||||
^samba3.blackbox.test_dangle_rmdir.rmdir can delete directory containing dangling symlink\(fileserver\)
|
@ -1876,6 +1876,8 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp)
|
||||
char *talloced = NULL;
|
||||
SMB_STRUCT_STAT st;
|
||||
struct connection_struct *conn = fsp->conn;
|
||||
struct smb_filename *smb_dname = fsp->fsp_name;
|
||||
int ret;
|
||||
struct smb_Dir *dir_hnd = OpenDir(talloc_tos(),
|
||||
conn,
|
||||
fsp->fsp_name,
|
||||
@ -1887,6 +1889,9 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp)
|
||||
}
|
||||
|
||||
while ((dname = ReadDirName(dir_hnd, &dirpos, &st, &talloced))) {
|
||||
struct smb_filename *smb_dname_full = NULL;
|
||||
char *fullname = NULL;
|
||||
|
||||
if (ISDOT(dname) || (ISDOTDOT(dname))) {
|
||||
TALLOC_FREE(talloced);
|
||||
continue;
|
||||
@ -1901,6 +1906,98 @@ NTSTATUS can_delete_directory_fsp(files_struct *fsp)
|
||||
continue;
|
||||
}
|
||||
|
||||
fullname = talloc_asprintf(talloc_tos(),
|
||||
"%s/%s",
|
||||
smb_dname->base_name,
|
||||
dname);
|
||||
|
||||
if (fullname == NULL) {
|
||||
TALLOC_FREE(dir_hnd);
|
||||
TALLOC_FREE(talloced);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
smb_dname_full = synthetic_smb_fname(talloc_tos(),
|
||||
fullname,
|
||||
NULL,
|
||||
NULL,
|
||||
smb_dname->twrp,
|
||||
smb_dname->flags);
|
||||
if (smb_dname_full == NULL) {
|
||||
TALLOC_FREE(dir_hnd);
|
||||
TALLOC_FREE(talloced);
|
||||
TALLOC_FREE(fullname);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
ret = SMB_VFS_LSTAT(conn, smb_dname_full);
|
||||
if (ret != 0) {
|
||||
TALLOC_FREE(dir_hnd);
|
||||
TALLOC_FREE(talloced);
|
||||
TALLOC_FREE(fullname);
|
||||
TALLOC_FREE(smb_dname_full);
|
||||
return map_nt_error_from_unix(errno);
|
||||
}
|
||||
|
||||
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(dir_hnd);
|
||||
TALLOC_FREE(talloced);
|
||||
TALLOC_FREE(fullname);
|
||||
TALLOC_FREE(smb_dname_full);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
if (is_msdfs_link(conn, smb_atname)) {
|
||||
TALLOC_FREE(dir_hnd);
|
||||
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));
|
||||
return NT_STATUS_DIRECTORY_NOT_EMPTY;
|
||||
}
|
||||
TALLOC_FREE(smb_atname);
|
||||
}
|
||||
|
||||
/* Not a DFS link - could it be a dangling symlink ? */
|
||||
ret = SMB_VFS_STAT(conn, smb_dname_full);
|
||||
if (ret == -1 && (errno == ENOENT || errno == ELOOP)) {
|
||||
/*
|
||||
* Dangling symlink.
|
||||
* Allow if "delete veto files = yes"
|
||||
*/
|
||||
if (lp_delete_veto_files(SNUM(conn))) {
|
||||
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(dir_hnd);
|
||||
TALLOC_FREE(talloced);
|
||||
TALLOC_FREE(fullname);
|
||||
TALLOC_FREE(smb_dname_full);
|
||||
return NT_STATUS_DIRECTORY_NOT_EMPTY;
|
||||
}
|
||||
|
||||
DEBUG(10,("got name %s - can't delete\n",
|
||||
dname ));
|
||||
status = NT_STATUS_DIRECTORY_NOT_EMPTY;
|
||||
|
Loading…
Reference in New Issue
Block a user