profile-load 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. # profile-load
  3. #
  4. # ----------------------------------------------------------------------
  5. # Copyright (c) 2010-2015 Canonical, Ltd.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of version 2 of the GNU General Public
  9. # License published by the Free Software Foundation.
  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, contact Canonical, Ltd.
  18. # ----------------------------------------------------------------------
  19. #
  20. # Helper for loading an AppArmor profile in pre-start scripts.
  21. [ -z "$1" ] && exit 1 # require a profile name
  22. . /lib/apparmor/rc.apparmor.functions
  23. # do not load in a container
  24. [ -x /usr/bin/systemd-detect-virt ] && systemd-detect-virt --quiet --container && ! is_container_with_internal_policy && exit 0 || true
  25. [ -d /rofs/etc/apparmor.d ] && exit 0 # do not load if running liveCD
  26. profile=/etc/apparmor.d/"$1"
  27. [ -e "$profile" ] || exit 0 # skip when missing profile
  28. module=/sys/module/apparmor
  29. [ -d $module ] || exit 0 # do not load without AppArmor in kernel
  30. [ -x /sbin/apparmor_parser ] || exit 0 # do not load without parser
  31. aafs=/sys/kernel/security/apparmor
  32. [ -d $aafs ] || exit 0 # do not load if unmounted
  33. [ -w $aafs/.load ] || exit 1 # fail if cannot load profiles
  34. params=$module/parameters
  35. [ -r $params/enabled ] || exit 0 # do not load if missing
  36. read enabled < $params/enabled || exit 1 # if this fails, something went wrong
  37. [ "$enabled" = "Y" ] || exit 0 # do not load if disabled
  38. /sbin/apparmor_parser -r -W "$profile" || exit 0 # LP: #1058356