From: Ralph Boehme Date: Mon, 25 Jan 2021 10:46:30 +0000 (+0100) Subject: vfs_error_inject: add unlinkat hook X-Git-Tag: tevent-0.11.0~1981 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c44dad3ac2eb36fc5eb5a9f80a9ef97183be26ef;p=thirdparty%2Fsamba.git vfs_error_inject: add unlinkat hook Note that a failure is only injected if the owner of the parent directory is not the same as the current user. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14617 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/modules/vfs_error_inject.c b/source3/modules/vfs_error_inject.c index 2230b8a2991..31257cc1d00 100644 --- a/source3/modules/vfs_error_inject.c +++ b/source3/modules/vfs_error_inject.c @@ -30,6 +30,7 @@ struct unix_error_map { { "ESTALE", ESTALE }, { "EBADF", EBADF }, { "EINTR", EINTR }, + { "EACCES", EACCES }, }; static int find_unix_error_from_string(const char *err_str) @@ -123,10 +124,53 @@ static int vfs_error_inject_openat(struct vfs_handle_struct *handle, return SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode); } +static int vfs_error_inject_unlinkat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + int flags) +{ + struct smb_filename *full_fname = NULL; + struct smb_filename *parent_fname = NULL; + int error = inject_unix_error("unlinkat", handle); + int ret; + bool ok; + + if (error == 0) { + return SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, smb_fname, flags); + } + + full_fname = full_path_from_dirfsp_atname(talloc_tos(), + dirfsp, + smb_fname); + if (full_fname == NULL) { + return -1; + } + + ok = parent_smb_fname(full_fname, full_fname, &parent_fname, NULL); + if (!ok) { + TALLOC_FREE(full_fname); + return -1; + } + + ret = SMB_VFS_STAT(handle->conn, parent_fname); + if (ret != 0) { + TALLOC_FREE(full_fname); + return -1; + } + + if (parent_fname->st.st_ex_uid == get_current_uid(dirfsp->conn)) { + return SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, smb_fname, flags); + } + + errno = error; + return -1; +} + static struct vfs_fn_pointers vfs_error_inject_fns = { .chdir_fn = vfs_error_inject_chdir, .pwrite_fn = vfs_error_inject_pwrite, .openat_fn = vfs_error_inject_openat, + .unlinkat_fn = vfs_error_inject_unlinkat, }; static_decl_vfs;