Testing recording and extraction of ACLs and xattr if available

This commit is contained in:
Thomas Schmitt 2011-08-18 15:23:32 +00:00
parent 932496694d
commit 934e9db6ca

View File

@ -6,6 +6,8 @@
# Test the correct handling of hardlinks by xorriso options # Test the correct handling of hardlinks by xorriso options
# -update_r , -hardlinks perform_update , and -extract # -update_r , -hardlinks perform_update , and -extract
# If there is support for ACLs or xattr in xorriso and on the local system,
# then test recording and restoring of these features.
not_in_releng_exit() { not_in_releng_exit() {
printf "\nPlease execute the tests from releng directory.\n\n" printf "\nPlease execute the tests from releng directory.\n\n"
@ -67,6 +69,7 @@ then
exit 3 exit 3
fi fi
# All must be set at this point # All must be set at this point
printf "\n${SELF}: Setting up $on_disk with several hardlinks\n" >&2 printf "\n${SELF}: Setting up $on_disk with several hardlinks\n" >&2
echo test_content >"$on_disk"/file_1 || exit 1 echo test_content >"$on_disk"/file_1 || exit 1
@ -74,7 +77,6 @@ echo test_content >"$on_disk"/file_2 || exit 1
ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1 ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1
ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1 ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1
ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1 ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
ls -l "$on_disk"/*
# trivial ISO 9660 image validation routine # trivial ISO 9660 image validation routine
is_valid_iso9660() { is_valid_iso9660() {
@ -92,6 +94,73 @@ is_valid_iso9660() {
fi fi
} }
# Create test file and find out whether ACLs and/or xattr are available.
# Users known on GNU/Linux and FreeBSD: root games daemon man
# Groups : daemon games bin sshd sys
acl_xattr_test_file="$on_disk"/acl_xattr_test_file
echo echo hello world >"$acl_xattr_test_file" || exit 1
sys=$(uname -s)
acls=no
if ( setfacl -m u::rwx,u:root:rwx,g:sys:rwx,u:daemon:r,mask::rwx \
"$acl_xattr_test_file" ) >/dev/null 2>&1
then
if ( getfacl "$acl_xattr_test_file" ) >/dev/null 2>&1
then
acls=yes
fi
fi
xattrs=no
extattrs=no
if ( setfattr -n user.test_xattr -v test_value "$acl_xattr_test_file" ) \
>/dev/null 2>&1
then
if ( getfattr "$acl_xattr_test_file" ) >/dev/null 2>&1
then
xattrs=yes
setfattr -n user.long_data -v 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
setfattr -n user.more_data -v 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
fi
fi
if test "$xattrs" = no
then
# >>> Try FreeBSD style setextattr
dummy=dummy
fi
echo
echo "${SELF}: Detected sys='$sys' , acls=$acls , xattrs=$xattrs , extattrs=$extattrs"
# Examine capabilities of xorriso
xorriso_acls=no
xorriso_xattrs=no
extras=$("$xorriso" -list_extras all 2>/dev/null)
if test "$?" = 0
then
if echo "$extras" | fgrep 'Local ACL : yes' >/dev/null 2>&1
then
xorriso_acls=yes
fi
if echo "$extras" | fgrep 'Local xattr : yes' >/dev/null 2>&1
then
xorriso_xattrs=yes
fi
fi
if test "$xorriso_acls" = no
then
acls=no
fi
if test "$xorriso_xattrs" = no
then
xattrs=no
fi
echo "${SELF}: Detected xorriso_acls=$xorriso_acls , xorriso_xattrs=$xorriso_xattrs"
echo
ls -l "$on_disk"/*
echo -e "\n${SELF}: Producing simple image via -o" >&2 echo -e "\n${SELF}: Producing simple image via -o" >&2
"$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso "$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso
is_valid_iso9660 "$workdir"/image_minus_o.iso is_valid_iso9660 "$workdir"/image_minus_o.iso
@ -115,9 +184,8 @@ echo -e "\n${SELF}: Producing simple image with for_backup/update_r/hardlinks" >
ret=$? ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32 if test "$ret" -gt 0 -a "$ret" -lt 32
then then
printf "\n${SELF}: xorriso write run failed\n\n" >&2 printf "\nFAIL : ${SELF} : xorriso write run failed\n\n"
cleanup cleanup
printf "${SELF}: FAILED\n"
exit 1 exit 1
fi fi
is_valid_iso9660 "$image_file" is_valid_iso9660 "$image_file"
@ -141,7 +209,7 @@ then
failure=1 failure=1
echo >&2 echo >&2
echo "$msg" >&2 echo "$msg" >&2
printf "\nFAIL : ${SELF} : -assert_volid test not properly performed\n\n" >&2 printf "\nFAIL : ${SELF} : -assert_volid test not properly performed\n\n"
else else
failure=1 failure=1
printf "\nFAIL : ${SELF} : -assert_volid did not snap\n\n" >&2 printf "\nFAIL : ${SELF} : -assert_volid did not snap\n\n" >&2
@ -159,9 +227,8 @@ echo -e "\n${SELF}: Copying from image to temporary disk tree" >&2
ret=$? ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32 if test "$ret" -gt 0 -a "$ret" -lt 32
then then
printf "\n${SELF}: xorriso file extraction run failed\n\n" >&2 printf "\nFAIL : ${SELF} : xorriso file extraction run failed\n\n"
cleanup cleanup
printf "${SELF}: FAILED\n"
exit 1 exit 1
fi fi
@ -187,10 +254,10 @@ fi
printf "\n${SELF}: Checking for hardlinks being siblings...\n" printf "\n${SELF}: Checking for hardlinks being siblings...\n"
ls -l "$copy_on_disk"/* ls -l "$copy_on_disk"/*
x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}')) x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}'))
expected="3 3 3 2 2" expected="1 3 3 3 2 2"
if test x"$x" = x"$expected" if test x"$x" = x"$expected"
then then
printf "\n${SELF}: Checking for hardlinks being siblings. Done. OK.\n" >&2 printf "${SELF}: Checking for hardlinks being siblings done: ok.\n" >&2
else else
printf "\nFAIL : ${SELF} : Link count of extracted files is not as expected." >&2 printf "\nFAIL : ${SELF} : Link count of extracted files is not as expected." >&2
printf "\n${SELF}: Expected: $expected" >&2 printf "\n${SELF}: Expected: $expected" >&2
@ -198,7 +265,50 @@ else
failure=1 failure=1
fi fi
if test "$acls" = yes
then
printf "\n${SELF}: Checking ACLs ...\n" >&2
acl_on_disk=$(getfacl "$acl_xattr_test_file" | grep -v '^# file:' | sort)
acl_in_copy=$(getfacl "$copy_on_disk"/acl_xattr_test_file |
grep -v '^# file:' | sort)
if test "$acl_on_disk" = "$acl_in_copy"
then
printf "${SELF}: Checking ACLs done: ok.\n" >&2
else
printf "\nFAIL : ${SELF} : ACL mismatch between original and extracted copy\n"
printf "\nOriginal:\n${acl_on_disk}\n"
printf "\nCopy:\n${acl_in_copy}\n"
failure=1
fi
fi
if test "$xattrs" = yes
then
printf "\n${SELF}: Checking xattr via getfattr ...\n" >&2
xattr_on_disk=$(getfattr "$acl_xattr_test_file" | \
grep -v '^# file:' | grep -v '^$' | \sort)
xattr_in_copy=$(getfattr "$copy_on_disk"/acl_xattr_test_file |
grep -v '^# file:' | grep -v '^$' | sort)
if test "$xattr_on_disk" = "$xattr_in_copy"
then
num_xattr=$(echo "$xattr_on_disk" | wc -l)
printf "${SELF}: Checking xattr done: $num_xattr attributes, ok.\n" >&2
else
printf "\nFAIL : ${SELF} : xattr mismatch between original and extracted copy\n"
printf "\nOriginal:\n${xattr_on_disk}\n"
printf "\nCopy:\n${xattr_in_copy}\n"
failure=1
fi
elif test "$extattr" = yes
then
# >>> Compare xattr of "$acl_xattr_test_file" by getextattr
dummy=dummy
fi
# #
echo
cleanup cleanup
# Report result # Report result