/apparmor/functions

http://github.com/brinkman83/bashrc · Shell · 82 lines · 48 code · 11 blank · 23 comment · 7 complexity · bf1e4af791814a179a468687cb43b3f2 MD5 · raw file

  1. #!/bin/sh
  2. # ----------------------------------------------------------------------
  3. # Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  4. # NOVELL (All rights reserved)
  5. # Copyright (c) 2008-2010 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 Novell, Inc.
  18. # ----------------------------------------------------------------------
  19. # Authors:
  20. # Kees Cook <kees@ubuntu.com>
  21. #
  22. # /etc/apparmor/functions
  23. PROFILES="/etc/apparmor.d"
  24. PARSER="/sbin/apparmor_parser"
  25. SECURITYFS="/sys/kernel/security"
  26. export AA_SFS="$SECURITYFS/apparmor"
  27. # Suppress warnings when booting in quiet mode
  28. quiet_arg=""
  29. [ "${QUIET:-no}" = yes ] && quiet_arg="-q"
  30. [ "${quiet:-n}" = y ] && quiet_arg="-q"
  31. foreach_configured_profile() {
  32. (ls -1 "$PROFILES" | egrep -v '(\.dpkg-(new|old|dist|bak)|~)$' | \
  33. while read profile; do
  34. if [ -f "$PROFILES"/"$profile" ]; then
  35. echo "$PROFILES"/"$profile"
  36. fi
  37. done) | \
  38. xargs -n1 "$PARSER" "$@" --
  39. }
  40. load_configured_profiles() {
  41. clear_cache_if_outdated
  42. foreach_configured_profile $quiet_arg --write-cache --replace
  43. }
  44. load_configured_profiles_without_caching() {
  45. foreach_configured_profile $quiet_arg --replace
  46. }
  47. recache_profiles() {
  48. clear_cache
  49. foreach_configured_profile $quiet_arg --write-cache --skip-kernel-load
  50. }
  51. configured_profile_names() {
  52. foreach_configured_profile $quiet_arg -N 2>/dev/null | sort | grep -v '\^'
  53. }
  54. running_profile_names() {
  55. cat "$AA_SFS"/profiles | sed -e "s/ (\(enforce\|complain\))$//" | sort
  56. }
  57. unload_profile() {
  58. echo -n "$1" > "$AA_SFS"/.remove
  59. }
  60. clear_cache() {
  61. find "$PROFILES"/cache -maxdepth 1 -type f -print0 | xargs -0 rm -f --
  62. }
  63. clear_cache_if_outdated() {
  64. if [ -r "$PROFILES"/cache/.features ]; then
  65. read CACHE_FEATURES < "$PROFILES"/cache/.features
  66. read KERN_FEATURES < "$AA_SFS"/features
  67. if [ "$KERN_FEATURES" != "$CACHE_FEATURES" ]; then
  68. clear_cache
  69. fi
  70. fi
  71. }