From: Ralph Boehme Date: Thu, 26 Sep 2019 17:31:51 +0000 (-0700) Subject: s3:smbd: use is_named_stream() in a a few places X-Git-Tag: talloc-2.3.1~522 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=993d327f5d24305d96781afeb11855487323975d;p=thirdparty%2Fsamba.git s3:smbd: use is_named_stream() in a a few places This simplifies (and corrects) things in the VFS as there the caller is only interested in whether a name is pointing to a real named stream most of the times. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 5f789604b23..a863f47fe1e 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1613,7 +1613,7 @@ static int fruit_open(vfs_handle_struct *handle, DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname)); - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode); } @@ -1696,7 +1696,7 @@ static int fruit_close(vfs_handle_struct *handle, DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(fsp->fsp_name), fd); - if (!is_ntfs_stream_smb_fname(fsp->fsp_name)) { + if (!is_named_stream(fsp->fsp_name)) { return SMB_VFS_NEXT_CLOSE(handle, fsp); } @@ -1993,7 +1993,7 @@ static int fruit_unlink_internal(vfs_handle_struct *handle, dirfsp, smb_fname, false); - } else if (is_ntfs_stream_smb_fname(smb_fname)) { + } else if (is_named_stream(smb_fname)) { return SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, smb_fname, @@ -3202,8 +3202,7 @@ static int fruit_stat(vfs_handle_struct *handle, DEBUG(10, ("fruit_stat called for %s\n", smb_fname_str_dbg(smb_fname))); - if (!is_ntfs_stream_smb_fname(smb_fname) - || is_ntfs_default_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { rc = SMB_VFS_NEXT_STAT(handle, smb_fname); if (rc == 0) { update_btime(handle, smb_fname); @@ -3244,8 +3243,7 @@ static int fruit_lstat(vfs_handle_struct *handle, DEBUG(10, ("fruit_lstat called for %s\n", smb_fname_str_dbg(smb_fname))); - if (!is_ntfs_stream_smb_fname(smb_fname) - || is_ntfs_default_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { rc = SMB_VFS_NEXT_LSTAT(handle, smb_fname); if (rc == 0) { update_btime(handle, smb_fname); @@ -4117,8 +4115,7 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle, if (global_fruit_config.nego_aapl && create_disposition == FILE_OPEN && smb_fname->st.st_ex_size == 0 && - is_ntfs_stream_smb_fname(smb_fname) && - !(is_ntfs_default_stream_smb_fname(smb_fname))) + is_named_stream(smb_fname)) { status = NT_STATUS_OBJECT_NAME_NOT_FOUND; goto fail; @@ -4129,7 +4126,7 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle, fio->created = true; } - if (is_ntfs_stream_smb_fname(smb_fname) + if (is_named_stream(smb_fname) || fsp->is_directory) { return status; } diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c index d8e9a3231bf..b17a0fdd6c6 100644 --- a/source3/modules/vfs_gpfs.c +++ b/source3/modules/vfs_gpfs.c @@ -149,8 +149,7 @@ static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, * fd, so lacking a distinct fd for the stream we have to skip * kernel_flock and set_gpfs_sharemode for stream. */ - if (is_ntfs_stream_smb_fname(fsp->fsp_name) && - !is_ntfs_default_stream_smb_fname(fsp->fsp_name)) { + if (is_named_stream(fsp->fsp_name)) { DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp))); return 0; } diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c index 4d6978d19f7..e0cfac2d990 100644 --- a/source3/modules/vfs_streams_depot.c +++ b/source3/modules/vfs_streams_depot.c @@ -537,28 +537,6 @@ static NTSTATUS walk_streams(vfs_handle_struct *handle, return NT_STATUS_OK; } -/** - * Helper to stat/lstat the base file of an smb_fname. This will actually - * fills in the stat struct in smb_filename. - */ -static int streams_depot_stat_base(vfs_handle_struct *handle, - struct smb_filename *smb_fname, - bool follow_links) -{ - char *tmp_stream_name; - int result; - - tmp_stream_name = smb_fname->stream_name; - smb_fname->stream_name = NULL; - if (follow_links) { - result = SMB_VFS_NEXT_STAT(handle, smb_fname); - } else { - result = SMB_VFS_NEXT_LSTAT(handle, smb_fname); - } - smb_fname->stream_name = tmp_stream_name; - return result; -} - static int streams_depot_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname) { @@ -569,15 +547,10 @@ static int streams_depot_stat(vfs_handle_struct *handle, DEBUG(10, ("streams_depot_stat called for [%s]\n", smb_fname_str_dbg(smb_fname))); - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_STAT(handle, smb_fname); } - /* If the default stream is requested, just stat the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - return streams_depot_stat_base(handle, smb_fname, true); - } - /* Stat the actual stream now. */ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, false); @@ -608,15 +581,10 @@ static int streams_depot_lstat(vfs_handle_struct *handle, DEBUG(10, ("streams_depot_lstat called for [%s]\n", smb_fname_str_dbg(smb_fname))); - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_LSTAT(handle, smb_fname); } - /* If the default stream is requested, just stat the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - return streams_depot_stat_base(handle, smb_fname, false); - } - /* Stat the actual stream now. */ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, false); @@ -642,22 +610,10 @@ static int streams_depot_open(vfs_handle_struct *handle, NTSTATUS status; int ret = -1; - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode); } - /* If the default stream is requested, just open the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - char *tmp_stream_name; - - tmp_stream_name = smb_fname->stream_name; - smb_fname->stream_name = NULL; - ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode); - smb_fname->stream_name = tmp_stream_name; - - return ret; - } - /* Ensure the base file still exists. */ smb_fname_base = synthetic_smb_fname(talloc_tos(), smb_fname->base_name, @@ -703,8 +659,7 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle, smb_fname_str_dbg(smb_fname))); /* If there is a valid stream, just unlink the stream and return. */ - if (is_ntfs_stream_smb_fname(smb_fname) && - !is_ntfs_default_stream_smb_fname(smb_fname)) { + if (is_named_stream(smb_fname)) { struct smb_filename *smb_fname_stream = NULL; NTSTATUS status; diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 341fae4da42..fa54fe26435 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -264,20 +264,15 @@ static int streams_xattr_stat(vfs_handle_struct *handle, int result = -1; char *xattr_name = NULL; - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_STAT(handle, smb_fname); } /* Note if lp_posix_paths() is true, we can never - * get here as is_ntfs_stream_smb_fname() is + * get here as is_named_stream() is * always false. So we never need worry about * not following links here. */ - /* If the default stream is requested, just stat the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - return streams_xattr_stat_base(handle, smb_fname, true); - } - /* Populate the stat struct with info from the base file. */ if (streams_xattr_stat_base(handle, smb_fname, true) == -1) { return -1; @@ -322,15 +317,10 @@ static int streams_xattr_lstat(vfs_handle_struct *handle, int result = -1; char *xattr_name = NULL; - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_LSTAT(handle, smb_fname); } - /* If the default stream is requested, just stat the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - return streams_xattr_stat_base(handle, smb_fname, false); - } - /* Populate the stat struct with info from the base file. */ if (streams_xattr_stat_base(handle, smb_fname, false) == -1) { return -1; @@ -388,24 +378,10 @@ static int streams_xattr_open(vfs_handle_struct *handle, DEBUG(10, ("streams_xattr_open called for %s with flags 0x%x\n", smb_fname_str_dbg(smb_fname), flags)); - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode); } - /* If the default stream is requested, just open the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - char *tmp_stream_name; - - tmp_stream_name = smb_fname->stream_name; - smb_fname->stream_name = NULL; - - ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode); - - smb_fname->stream_name = tmp_stream_name; - - return ret; - } - status = streams_xattr_get_name(handle, talloc_tos(), smb_fname->stream_name, &xattr_name); if (!NT_STATUS_IS_OK(status)) { @@ -532,11 +508,7 @@ static int streams_xattr_close(vfs_handle_struct *handle, DBG_DEBUG("streams_xattr_close called [%s] fd [%d]\n", smb_fname_str_dbg(fsp->fsp_name), fd); - if (!is_ntfs_stream_smb_fname(fsp->fsp_name)) { - return SMB_VFS_NEXT_CLOSE(handle, fsp); - } - - if (is_ntfs_default_stream_smb_fname(fsp->fsp_name)) { + if (!is_named_stream(fsp->fsp_name)) { return SMB_VFS_NEXT_CLOSE(handle, fsp); } @@ -555,32 +527,13 @@ static int streams_xattr_unlink_internal(vfs_handle_struct *handle, int ret = -1; char *xattr_name = NULL; - if (!is_ntfs_stream_smb_fname(smb_fname)) { + if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, smb_fname, flags); } - /* If the default stream is requested, just open the base file. */ - if (is_ntfs_default_stream_smb_fname(smb_fname)) { - struct smb_filename *smb_fname_base = NULL; - - smb_fname_base = cp_smb_filename(talloc_tos(), smb_fname); - if (smb_fname_base == NULL) { - errno = ENOMEM; - return -1; - } - - ret = SMB_VFS_NEXT_UNLINKAT(handle, - dirfsp, - smb_fname_base, - flags); - - TALLOC_FREE(smb_fname_base); - return ret; - } - status = streams_xattr_get_name(handle, talloc_tos(), smb_fname->stream_name, &xattr_name); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/modules/vfs_virusfilter.c b/source3/modules/vfs_virusfilter.c index 828fd166eed..a243a5ad6ef 100644 --- a/source3/modules/vfs_virusfilter.c +++ b/source3/modules/vfs_virusfilter.c @@ -1152,7 +1152,7 @@ static int virusfilter_vfs_open( size_t test_suffix; int rename_trap_count = 0; int ret; - bool ok1, ok2; + bool ok1; char *sret = NULL; SMB_VFS_HANDLE_GET_DATA(handle, config, @@ -1172,9 +1172,7 @@ static int virusfilter_vfs_open( rename_trap_count++; } - ok1 = is_ntfs_stream_smb_fname(smb_fname); - ok2 = is_ntfs_default_stream_smb_fname(smb_fname); - if (ok1 && !ok2) { + if (is_named_stream(smb_fname)) { DBG_INFO("Not scanned: only file backed streams can be scanned:" " %s/%s\n", cwd_fname, fname); goto virusfilter_vfs_open_next; @@ -1318,7 +1316,6 @@ static int virusfilter_vfs_close( int close_errno = 0; virusfilter_result scan_result; int scan_errno = 0; - bool ok1, ok2; SMB_VFS_HANDLE_GET_DATA(handle, config, struct virusfilter_config, return -1); @@ -1352,9 +1349,7 @@ static int virusfilter_vfs_close( return close_result; } - ok1 = is_ntfs_stream_smb_fname(fsp->fsp_name); - ok2 = is_ntfs_default_stream_smb_fname(fsp->fsp_name); - if (ok1 && !ok2) { + if (is_named_stream(fsp->fsp_name)) { if (config->scan_on_open && fsp->modified) { if (config->cache) { DBG_DEBUG("Removing cache entry (if existent)" diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 32a01c271c6..38d34623336 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -736,14 +736,9 @@ static uint32_t dos_mode_post(uint32_t dosmode, * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 */ - if (is_ntfs_stream_smb_fname(smb_fname)) { + if (is_named_stream(smb_fname)) { /* is_ntfs_stream_smb_fname() returns false for a POSIX path. */ - if (!is_ntfs_default_stream_smb_fname(smb_fname)) { - /* - * Non-default stream name, not a posix path. - */ - dosmode &= ~(FILE_ATTRIBUTE_DIRECTORY); - } + dosmode &= ~(FILE_ATTRIBUTE_DIRECTORY); } if (conn->fs_capabilities & FILE_FILE_COMPRESSION) {