selnx01.at 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Process this file with autom4te to create testsuite. -*- Autotest -*-
  2. #
  3. # Test suite for GNU tar.
  4. # Copyright 2012-2023 Free Software Foundation, Inc.
  5. # This file is part of GNU tar.
  6. # GNU tar is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. # GNU tar is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # Test description:
  18. #
  19. # This is basic test for selinux support (store & restore).
  20. AT_SETUP([selinux: basic store/restore])
  21. AT_KEYWORDS([xattrs selinux selnx01])
  22. AT_TAR_CHECK([
  23. AT_XATTRS_UTILS_PREREQ
  24. AT_SELINUX_PREREQ
  25. mkdir dir
  26. genfile --file dir/file
  27. ln -s file dir/link
  28. getfattr -h -d -msecurity.selinux dir dir/file dir/link > start
  29. restorecon -R dir
  30. chcon -h --user=system_u dir
  31. chcon -h --user=unconfined_u dir/file
  32. chcon -h --user=system_u dir/link
  33. # archive whole directory including selinux contexts
  34. tar --selinux -cf archive.tar dir
  35. # clear the directory
  36. rm -rf dir
  37. # ================================================
  38. # check if selinux contexts are correctly restored
  39. tar --selinux -xf archive.tar
  40. # archive for later debugging
  41. cp archive.tar archive_origin.tar
  42. # check if selinux contexts were restored
  43. getfattr -h -d dir dir/file dir/link -msecurity.selinux | \
  44. grep -v -e '^#' -e ^$ | cut -d: -f1
  45. # ===========================================================================
  46. # check if selinux contexts are not restored when --selinux option is missing
  47. getfattr -h -d -msecurity.selinux dir dir/file dir/link > with_selinux
  48. rm -rf dir
  49. tar -xf archive.tar
  50. getfattr -h -d -msecurity.selinux dir dir/file dir/link > without_selinux
  51. diff with_selinux without_selinux > diff_with_without
  52. if test "$?" -eq "0"; then
  53. echo "selinux contexts probably restored while --selinux is off"
  54. fi
  55. # =================================================================
  56. # check if selinux is not archived when --selinux option is missing
  57. tar -cf archive.tar dir
  58. # clear the directory
  59. rm -rf dir
  60. # restore (with --selinux)
  61. tar --selinux -xf archive.tar dir
  62. getfattr -h -d -msecurity.selinux dir dir/file dir/link > final
  63. diff start final > final_diff
  64. if test "$?" -ne "0"; then
  65. echo "bad result"
  66. fi
  67. ],
  68. [0],
  69. [security.selinux="system_u
  70. security.selinux="unconfined_u
  71. security.selinux="system_u
  72. ])
  73. AT_CLEANUP