install-Z-selinux.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # test 'install -Z -D' and 'install -Z -d'
  3. # based on tests/mkdir/restorecon.sh
  4. # Copyright (C) 2013-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  16. print_ver_ ginstall
  17. require_selinux_
  18. mkdir subdir || framework_failure_
  19. ctx='root:object_r:tmp_t'
  20. mls_enabled_ && ctx="$ctx:s0"
  21. chcon "$ctx" subdir || skip_ "Failed to set context: $ctx"
  22. cd subdir
  23. # Since in a tmp_t dir, dirs can be created as user_tmp_t ...
  24. touch standard || framework_failure_
  25. mkdir restored || framework_failure_
  26. if restorecon restored 2>/dev/null; then
  27. # ... but when restored can be set to user_home_t
  28. # So ensure the type for these mkdir -Z cases matches
  29. # the directory type as set by restorecon.
  30. ginstall -Z standard single || fail=1
  31. ginstall -Z -d single_d || fail=1
  32. # Run these as separate processes in case global context
  33. # set for an arg, impacts on another arg
  34. # TODO: Have the defaultcon() vary over these directories
  35. for dst in single_d/existing/file multi/ple/file; do
  36. ginstall -Z -D standard "$dst" || fail=1
  37. done
  38. restored_type=$(get_selinux_type 'restored')
  39. test "$(get_selinux_type 'single')" = "$restored_type" || fail=1
  40. test "$(get_selinux_type 'single_d')" = "$restored_type" || fail=1
  41. test "$(get_selinux_type 'single_d/existing')" = "$restored_type" || fail=1
  42. test "$(get_selinux_type 'multi')" = "$restored_type" || fail=1
  43. test "$(get_selinux_type 'multi/ple')" = "$restored_type" || fail=1
  44. fi
  45. if test "$fail" = '1'; then
  46. ls -UZd standard restored
  47. ls -UZd single single_d single_d/existing multi multi/ple
  48. fi
  49. Exit $fail