summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-01-08 14:47:27 -0500
committerTavian Barnes <tavianator@tavianator.com>2020-01-08 15:11:36 -0500
commit2215f7a5d902764755673cc15a317982f0f15592 (patch)
treec164da27ad2bfbaa3e45439abd5c3c623f348250
parent82dd2eb052aea282de099c2a26fd36f94649a5ae (diff)
downloadbfs-2215f7a5d902764755673cc15a317982f0f15592.tar.xz
fsade: Support checking for xattrs (extattrs) on FreeBSD
-rw-r--r--fsade.c14
-rw-r--r--fsade.h2
-rwxr-xr-xtests.sh56
-rw-r--r--util.h4
4 files changed, 50 insertions, 26 deletions
diff --git a/fsade.c b/fsade.c
index 84c6978..668f586 100644
--- a/fsade.c
+++ b/fsade.c
@@ -30,7 +30,9 @@
# include <sys/capability.h>
#endif
-#if BFS_CAN_CHECK_XATTRS
+#if BFS_HAS_SYS_EXTATTR
+# include <sys/extattr.h>
+#elif BFS_HAS_SYS_XATTR
# include <sys/xattr.h>
#endif
@@ -281,7 +283,15 @@ int bfs_check_xattrs(const struct BFTW *ftwbuf) {
const char *path = fake_at(ftwbuf);
ssize_t len;
-#if __APPLE__
+#if BFS_HAS_SYS_EXTATTR
+ ssize_t (*extattr_list)(const char *, int, void*, size_t) =
+ ftwbuf->typeflag == BFTW_LNK ? extattr_list_link : extattr_list_file;
+
+ len = extattr_list(path, EXTATTR_NAMESPACE_SYSTEM, NULL, 0);
+ if (len <= 0) {
+ len = extattr_list(path, EXTATTR_NAMESPACE_USER, NULL, 0);
+ }
+#elif __APPLE__
int options = ftwbuf->typeflag == BFTW_LNK ? XATTR_NOFOLLOW : 0;
len = listxattr(path, NULL, 0, options);
#else
diff --git a/fsade.h b/fsade.h
index c9dcfc9..7a4faa6 100644
--- a/fsade.h
+++ b/fsade.h
@@ -35,7 +35,7 @@
# endif
#endif
-#define BFS_CAN_CHECK_XATTRS BFS_HAS_SYS_XATTR
+#define BFS_CAN_CHECK_XATTRS (BFS_HAS_SYS_EXTATTR || BFS_HAS_SYS_XATTR)
/**
* Check if a file has a non-trvial Access Control List.
diff --git a/tests.sh b/tests.sh
index 9d18f83..bf0a65e 100755
--- a/tests.sh
+++ b/tests.sh
@@ -652,9 +652,6 @@ sudo_tests=(
test_capable
test_L_capable
- test_xattr
- test_L_xattr
-
test_mount
test_L_mount
test_xdev
@@ -666,6 +663,18 @@ sudo_tests=(
test_xtype_bind_mount
)
+if [ "$UNAME" = "Linux" ]; then
+ sudo_tests+=(
+ test_xattr
+ test_L_xattr
+ )
+else
+ bsd_tests+=(
+ test_xattr
+ test_L_xattr
+ )
+fi
+
if [ "$DEFAULT" ]; then
POSIX=yes
BSD=yes
@@ -2462,6 +2471,25 @@ function test_L_capable() {
bfs_diff -L scratch -capable
}
+function set_xattr() {
+ case "$UNAME" in
+ Darwin)
+ xattr -w bfs_test true "$1"
+ xattr -s -w bfs_test true "$2"
+ ;;
+ FreeBSD)
+ setextattr user bfs_test true "$1"
+ setextattr -h user bfs_test true "$2"
+ ;;
+ *)
+ # Linux tmpfs doesn't support the user.* namespace, so we use the security.*
+ # namespace, which is writable by root and readable by others
+ sudo setfattr -n security.bfs_test "$1"
+ sudo setfattr -h -n security.bfs_test "$2"
+ ;;
+ esac
+}
+
function test_xattr() {
rm -rf scratch/*
@@ -2472,16 +2500,7 @@ function test_xattr() {
touch scratch/{normal,xattr}
ln -s xattr scratch/link
ln -s normal scratch/xattr_link
-
- if [ "$(uname)" = "Darwin" ]; then
- xattr -w bfs_test true scratch/xattr
- xattr -s -w bfs_test true scratch/xattr_link
- else
- # Linux tmpfs doesn't support the user.* namespace, so we use the security.*
- # namespace, which is writable by root and readable by others
- sudo setfattr -n security.bfs_test scratch/xattr
- sudo setfattr -h -n security.bfs_test scratch/xattr_link
- fi
+ set_xattr scratch/xattr scratch/xattr_link
bfs_diff scratch -xattr
}
@@ -2496,16 +2515,7 @@ function test_L_xattr() {
touch scratch/{normal,xattr}
ln -s xattr scratch/link
ln -s normal scratch/xattr_link
-
- if [ "$(uname)" = "Darwin" ]; then
- xattr -w bfs_test true scratch/xattr
- xattr -s -w bfs_test true scratch/xattr_link
- else
- # Linux tmpfs doesn't support the user.* namespace, so we use the security.*
- # namespace, which is writable by root and readable by others
- sudo setfattr -n security.bfs_test scratch/xattr
- sudo setfattr -h -n security.bfs_test scratch/xattr_link
- fi
+ set_xattr scratch/xattr scratch/xattr_link
bfs_diff -L scratch -xattr
}
diff --git a/util.h b/util.h
index 73258b9..5a6dec4 100644
--- a/util.h
+++ b/util.h
@@ -55,6 +55,10 @@
# define BFS_HAS_SYS_CAPABILITY BFS_HAS_INCLUDE(<sys/capability.h>, __linux__)
#endif
+#ifndef BFS_HAS_SYS_EXTATTR
+# define BFS_HAS_SYS_EXTATTR BFS_HAS_INCLUDE(<sys/extattr.h>, __FreeBSD__)
+#endif
+
#ifndef BFS_HAS_SYS_MKDEV
# define BFS_HAS_SYS_MKDEV BFS_HAS_INCLUDE(<sys/mkdev.h>, false)
#endif