summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2022-07-27 18:40:21 +0200
committerVolker Lendecke <vl@samba.org>2022-08-10 16:32:35 +0000
commitfc45fcfde51b0b0bdcd524c82a0f9eabf7273045 (patch)
treefb04b098c364523fb9644b68258ebdf79e2d12f9
parent51243e3849736acbbf1d8f52cc02cdec5995fde4 (diff)
downloadsamba-fc45fcfde51b0b0bdcd524c82a0f9eabf7273045.tar.gz
vfs_default: assert all passed in fsp's and names are non-stream type
Enforce fsp is a non-stream one in as many VFS operations as possible in vfs_default. We really need an assert here instead of returning an error, as otherwise he can have very hard to diagnose bugs. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15126 MR: https://gitlab.com/samba-team/samba/-/merge_requests/2643 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Aug 10 16:32:35 UTC 2022 on sn-devel-184
-rw-r--r--source3/modules/vfs_default.c92
1 files changed, 58 insertions, 34 deletions
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 9cf70fd84ce..dee8ff50df4 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -707,11 +707,7 @@ static int vfswrap_openat(vfs_handle_struct *handle,
goto out;
}
- if (is_named_stream(smb_fname)) {
- errno = ENOENT;
- result = -1;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname));
#ifdef O_PATH
have_opath = true;
@@ -1258,17 +1254,14 @@ static int vfswrap_renameat(vfs_handle_struct *handle,
START_PROFILE(syscall_renameat);
- if (is_named_stream(smb_fname_src) || is_named_stream(smb_fname_dst)) {
- errno = ENOENT;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname_src));
+ SMB_ASSERT(!is_named_stream(smb_fname_dst));
result = renameat(fsp_get_pathref_fd(srcfsp),
smb_fname_src->base_name,
fsp_get_pathref_fd(dstfsp),
smb_fname_dst->base_name);
- out:
END_PROFILE(syscall_renameat);
return result;
}
@@ -1280,14 +1273,11 @@ static int vfswrap_stat(vfs_handle_struct *handle,
START_PROFILE(syscall_stat);
- if (is_named_stream(smb_fname)) {
- errno = ENOENT;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname));
result = sys_stat(smb_fname->base_name, &smb_fname->st,
lp_fake_directory_create_times(SNUM(handle->conn)));
- out:
+
END_PROFILE(syscall_stat);
return result;
}
@@ -1310,14 +1300,11 @@ static int vfswrap_lstat(vfs_handle_struct *handle,
START_PROFILE(syscall_lstat);
- if (is_named_stream(smb_fname)) {
- errno = ENOENT;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname));
result = sys_lstat(smb_fname->base_name, &smb_fname->st,
lp_fake_directory_create_times(SNUM(handle->conn)));
- out:
+
END_PROFILE(syscall_lstat);
return result;
}
@@ -1333,10 +1320,7 @@ static int vfswrap_fstatat(
START_PROFILE(syscall_fstatat);
- if (is_named_stream(smb_fname)) {
- errno = ENOENT;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname));
result = sys_fstatat(
fsp_get_pathref_fd(dirfsp),
@@ -1344,7 +1328,7 @@ static int vfswrap_fstatat(
sbuf,
flags,
lp_fake_directory_create_times(SNUM(handle->conn)));
- out:
+
END_PROFILE(syscall_fstatat);
return result;
}
@@ -1441,6 +1425,8 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
char **out_data = (char **)_out_data;
NTSTATUS status;
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
switch (function) {
case FSCTL_SET_SPARSE:
{
@@ -1805,6 +1791,8 @@ static struct tevent_req *vfswrap_get_dos_attributes_send(
struct tevent_req *subreq = NULL;
struct vfswrap_get_dos_attributes_state *state = NULL;
+ SMB_ASSERT(!is_named_stream(smb_fname));
+
req = tevent_req_create(mem_ctx, &state,
struct vfswrap_get_dos_attributes_state);
if (req == NULL) {
@@ -1961,6 +1949,8 @@ static NTSTATUS vfswrap_fget_dos_attributes(struct vfs_handle_struct *handle,
{
bool offline;
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
offline = vfswrap_is_offline(handle->conn, fsp->fsp_name);
if (offline) {
*dosmode |= FILE_ATTRIBUTE_OFFLINE;
@@ -1973,6 +1963,8 @@ static NTSTATUS vfswrap_fset_dos_attributes(struct vfs_handle_struct *handle,
struct files_struct *fsp,
uint32_t dosmode)
{
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
return set_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode);
}
@@ -2649,15 +2641,12 @@ static int vfswrap_unlinkat(vfs_handle_struct *handle,
START_PROFILE(syscall_unlinkat);
- if (is_named_stream(smb_fname)) {
- errno = ENOENT;
- goto out;
- }
+ SMB_ASSERT(!is_named_stream(smb_fname));
+
result = unlinkat(fsp_get_pathref_fd(dirfsp),
smb_fname->base_name,
flags);
- out:
END_PROFILE(syscall_unlinkat);
return result;
}
@@ -3142,6 +3131,8 @@ static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
START_PROFILE(syscall_linux_setlease);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
#ifdef HAVE_KERNEL_OPLOCKS_LINUX
result = linux_setlease(fsp_get_io_fd(fsp), leasetype);
#else
@@ -3160,6 +3151,8 @@ static int vfswrap_symlinkat(vfs_handle_struct *handle,
START_PROFILE(syscall_symlinkat);
+ SMB_ASSERT(!is_named_stream(new_smb_fname));
+
result = symlinkat(link_target->base_name,
fsp_get_pathref_fd(dirfsp),
new_smb_fname->base_name);
@@ -3177,6 +3170,8 @@ static int vfswrap_readlinkat(vfs_handle_struct *handle,
START_PROFILE(syscall_readlinkat);
+ SMB_ASSERT(!is_named_stream(smb_fname));
+
result = readlinkat(fsp_get_pathref_fd(dirfsp),
smb_fname->base_name,
buf,
@@ -3197,6 +3192,9 @@ static int vfswrap_linkat(vfs_handle_struct *handle,
START_PROFILE(syscall_linkat);
+ SMB_ASSERT(!is_named_stream(old_smb_fname));
+ SMB_ASSERT(!is_named_stream(new_smb_fname));
+
result = linkat(fsp_get_pathref_fd(srcfsp),
old_smb_fname->base_name,
fsp_get_pathref_fd(dstfsp),
@@ -3217,6 +3215,8 @@ static int vfswrap_mknodat(vfs_handle_struct *handle,
START_PROFILE(syscall_mknodat);
+ SMB_ASSERT(!is_named_stream(smb_fname));
+
result = sys_mknodat(fsp_get_pathref_fd(dirfsp),
smb_fname->base_name,
mode,
@@ -3255,6 +3255,8 @@ static int vfswrap_fchflags(vfs_handle_struct *handle,
#ifdef HAVE_FCHFLAGS
int fd = fsp_get_pathref_fd(fsp);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (!fsp->fsp_flags.is_pathref) {
return fchflags(fd, flags);
}
@@ -3326,6 +3328,8 @@ static NTSTATUS vfswrap_fstreaminfo(vfs_handle_struct *handle,
struct stream_struct *streams = *pstreams;
NTSTATUS status;
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (fsp->fsp_flags.is_directory) {
/*
* No default streams on directories
@@ -3426,6 +3430,9 @@ static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
NTSTATUS result;
START_PROFILE(fget_nt_acl);
+
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
result = posix_fget_nt_acl(fsp, security_info,
mem_ctx, ppdesc);
END_PROFILE(fget_nt_acl);
@@ -3437,6 +3444,9 @@ static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp
NTSTATUS result;
START_PROFILE(fset_nt_acl);
+
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
result = set_nt_acl(fsp, security_info_sent, psd);
END_PROFILE(fset_nt_acl);
return result;
@@ -3456,6 +3466,8 @@ static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle,
SMB_ACL_TYPE_T type,
TALLOC_CTX *mem_ctx)
{
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
return sys_acl_get_fd(handle, fsp, type, mem_ctx);
}
@@ -3464,12 +3476,16 @@ static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle,
SMB_ACL_TYPE_T type,
SMB_ACL_T theacl)
{
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
return sys_acl_set_fd(handle, fsp, type, theacl);
}
static int vfswrap_sys_acl_delete_def_fd(vfs_handle_struct *handle,
files_struct *fsp)
{
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
return sys_acl_delete_def_fd(handle, fsp);
}
@@ -3485,6 +3501,8 @@ static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle,
{
int fd = fsp_get_pathref_fd(fsp);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (!fsp->fsp_flags.is_pathref) {
return fgetxattr(fd, name, value, size);
}
@@ -3555,6 +3573,8 @@ static struct tevent_req *vfswrap_getxattrat_send(
bool have_per_thread_creds = false;
bool do_async = false;
+ SMB_ASSERT(!is_named_stream(smb_fname));
+
req = tevent_req_create(mem_ctx, &state,
struct vfswrap_getxattrat_state);
if (req == NULL) {
@@ -3661,10 +3681,9 @@ static void vfswrap_getxattrat_do_sync(struct tevent_req *req)
{
struct vfswrap_getxattrat_state *state = tevent_req_data(
req, struct vfswrap_getxattrat_state);
- struct files_struct *fsp = metadata_fsp(state->smb_fname->fsp);
state->xattr_size = vfswrap_fgetxattr(state->handle,
- fsp,
+ state->smb_fname->fsp,
state->xattr_name,
state->xattr_value,
talloc_array_length(state->xattr_value));
@@ -3684,7 +3703,6 @@ static void vfswrap_getxattrat_do_async(void *private_data)
struct timespec start_time;
struct timespec end_time;
int ret;
- struct files_struct *fsp = metadata_fsp(state->smb_fname->fsp);
PROFILE_TIMESTAMP(&start_time);
SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
@@ -3708,7 +3726,7 @@ static void vfswrap_getxattrat_do_async(void *private_data)
}
state->xattr_size = vfswrap_fgetxattr(state->handle,
- fsp,
+ state->smb_fname->fsp,
state->xattr_name,
state->xattr_value,
talloc_array_length(state->xattr_value));
@@ -3809,6 +3827,8 @@ static ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files
{
int fd = fsp_get_pathref_fd(fsp);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (!fsp->fsp_flags.is_pathref) {
return flistxattr(fd, list, size);
}
@@ -3835,6 +3855,8 @@ static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_s
{
int fd = fsp_get_pathref_fd(fsp);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (!fsp->fsp_flags.is_pathref) {
return fremovexattr(fd, name);
}
@@ -3861,6 +3883,8 @@ static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_stru
{
int fd = fsp_get_pathref_fd(fsp);
+ SMB_ASSERT(!fsp_is_alternate_stream(fsp));
+
if (!fsp->fsp_flags.is_pathref) {
return fsetxattr(fd, name, value, size, flags);
}