From 22a0fdd4cdb0622decd6b70bafc1710c8368db98 Mon Sep 17 00:00:00 2001 From: Noel Kuntze Date: Sun, 8 Aug 2021 02:44:39 +0200 Subject: [PATCH] main/samba: Fix the broken btrfs_fget_compression function This unbreaks btrfs support in samba by restructuring the function to avoid calling ioctl() on fd=-1 --- ...-Fix-function-btrfs_fget_compression.patch | 114 ++++++++++++++++++ main/samba/APKBUILD | 4 +- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 main/samba/0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch diff --git a/main/samba/0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch b/main/samba/0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch new file mode 100644 index 0000000000..b8b500cbe8 --- /dev/null +++ b/main/samba/0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch @@ -0,0 +1,114 @@ +From 00a303202cf013b1bb47a6b24b616c7c8b7c9d92 Mon Sep 17 00:00:00 2001 +From: Noel Kuntze +Date: Sun, 8 Aug 2021 02:13:24 +0200 +Subject: [PATCH] s3: vfs_btrfs: Fix function btrfs_fget_compression + +--- + source3/modules/vfs_btrfs.c | 73 ++++++++++++++++++------------------- + 1 file changed, 36 insertions(+), 37 deletions(-) + +diff --git a/source3/modules/vfs_btrfs.c b/source3/modules/vfs_btrfs.c +index 789bc6d6e8a..1d43fcb2104 100644 +--- a/source3/modules/vfs_btrfs.c ++++ b/source3/modules/vfs_btrfs.c +@@ -460,61 +460,60 @@ static NTSTATUS btrfs_fget_compression(struct vfs_handle_struct *handle, + const char *p = NULL; + int ret; + long flags = 0; +- int fd = -1; ++ int fd = fd = fsp_get_pathref_fd(fsp); + NTSTATUS status; + +- if (!fsp->fsp_flags.is_pathref) { +- ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); +- if (ret < 0) { +- DBG_WARNING("FS_IOC_GETFLAGS failed: %s, fd %lld\n", +- strerror(errno), (long long)fd); +- return map_nt_error_from_unix(errno); ++ if (fsp->fsp_flags.is_pathref) { ++ if (!fsp->fsp_flags.have_proc_fds) { ++ return NT_STATUS_NOT_IMPLEMENTED; + } +- if (flags & FS_COMPR_FL) { +- *_compression_fmt = COMPRESSION_FORMAT_LZNT1; +- } else { +- *_compression_fmt = COMPRESSION_FORMAT_NONE; ++ ++ fd = fsp_get_pathref_fd(fsp); ++ ++ p = sys_proc_fd_path(fd, buf, sizeof(buf)); ++ if (p == NULL) { ++ return NT_STATUS_NO_MEMORY; + } +- return NT_STATUS_OK; +- } + +- if (!fsp->fsp_flags.have_proc_fds) { +- return NT_STATUS_NOT_IMPLEMENTED; +- } ++ fd = open(p, O_RDONLY); ++ if (fd == -1) { ++ DBG_ERR("/proc open of %s failed: %s\n", p, strerror(errno)); ++ return map_nt_error_from_unix(errno); ++ } + +- fd = fsp_get_pathref_fd(fsp); ++ ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); ++ if (ret < 0) { ++ DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %lld\n", ++ strerror(errno), (long long)fd)); ++ status = map_nt_error_from_unix(errno); ++ } else { ++ if (flags & FS_COMPR_FL) { ++ *_compression_fmt = COMPRESSION_FORMAT_LZNT1; ++ } else { ++ *_compression_fmt = COMPRESSION_FORMAT_NONE; ++ } ++ status = NT_STATUS_OK; ++ } + +- p = sys_proc_fd_path(fd, buf, sizeof(buf)); +- if (p == NULL) { +- return NT_STATUS_NO_MEMORY; +- } ++ if (fd != -1) { ++ close(fd); ++ } + +- fd = open(p, O_RDONLY); +- if (fd == -1) { +- DBG_ERR("/proc open of %s failed: %s\n", p, strerror(errno)); +- return map_nt_error_from_unix(errno); ++ return status; + } + + ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); + if (ret < 0) { +- DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %lld\n", +- strerror(errno), (long long)fd)); +- status = map_nt_error_from_unix(errno); +- goto err_close; ++ DBG_WARNING("FS_IOC_GETFLAGS failed: %s, fd %lld\n", ++ strerror(errno), (long long)fd); ++ return map_nt_error_from_unix(errno); + } + if (flags & FS_COMPR_FL) { + *_compression_fmt = COMPRESSION_FORMAT_LZNT1; + } else { + *_compression_fmt = COMPRESSION_FORMAT_NONE; + } +- status = NT_STATUS_OK; +- +-err_close: +- if (fd != -1) { +- close(fd); +- } +- +- return status; ++ return NT_STATUS_OK; + } + + static NTSTATUS btrfs_set_compression(struct vfs_handle_struct *handle, +-- +2.32.0 + diff --git a/main/samba/APKBUILD b/main/samba/APKBUILD index da943c08d6..2432b98c13 100644 --- a/main/samba/APKBUILD +++ b/main/samba/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: Natanael Copa pkgname=samba pkgver=4.14.5 -pkgrel=0 +pkgrel=1 pkgdesc="Tools to access a server's filespace and printers via SMB" url="https://www.samba.org/" arch="all" @@ -88,6 +88,7 @@ source=" musl_rm_unistd_incl.patch add_missing___compar_fn_t.patch pidl.patch + 0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch $pkgname.initd $pkgname.confd $pkgname.logrotate @@ -611,6 +612,7 @@ c0afe8b1dfddc5290c9aa611163d20adc3a546f54bba0081f739cda4255829f1a72bae422b6cb049 9bf4bbc8b03d9ea17d2f8ffeaf3a83541b171936a90bb8d75b08cc5afbdbaaec545c1b3782c90ae2ffc4568ab4e6f15fb21899d80c654a796301e16429c93b65 musl_rm_unistd_incl.patch bc2df70e327fea5dfbd923600225f1448815d842c37d6937dd74eab7f7699d7f52cd7a8e28a61233974649cf86661a0107dce5019d33b71205e4b41bac73f4e2 add_missing___compar_fn_t.patch c0bbe1186b150a9bb2a0b741a8cfbd7a5109e5fed1eaa07aaa38cf026ebe054d38cc01e2496f0cab7b40f743e1b7ecfbf8a4d5820810226c4152021df65f36dc pidl.patch +946bb10ce6ac333c8339cd5d94ef0f0e8df32e531115fb3253fb84fd162bbda1306b400690bdf9106b1f7534a90d74473209f8b910f1d1b454bca366a536a122 0001-s3-vfs_btrfs-Fix-function-btrfs_fget_compression.patch 96070e2461370437f48571e7de550c13a332fef869480cfe92e7cac73a998f6c2ee85d2580df58211953bebd0e577691aa710c8edddf3ea0f30e9d47d0a2fd44 samba.initd e2b49cb394e758447ca97de155a61b4276499983a0a5c00b44ae621c5559b759a766f8d1c8d3ee98ad5560f4064a847a7a20cfa2e14f85c061bec8b80fd649eb samba.confd 3458a4e1f8a8b44c966afb339b2dca51615be049f594c14911fc4d8203623deee416b6fe881436e246fc7d49c97a2b3bf9c5f33ba774302b24190a1103d6b67d samba.logrotate -- 2.32.0