selnx01.at 2.6 KB

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