summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYi Zhao <yi.zhao@windriver.com>2021-06-23 17:15:04 +0800
committerArmin Kuster <akuster808@gmail.com>2021-07-10 05:16:52 -0700
commitcab0c7d343fd28345fe005df08c4d25b46b1a28e (patch)
treecff2c9ca58bf63c58d4ccc88e02f6fc02c472acc
parent366bd7026fe5a6d4d8465b87118948de97f2310f (diff)
downloadmeta-security-cab0c7d343fd28345fe005df08c4d25b46b1a28e.tar.gz
apparmor: use its own initscript and service files
Use initscript and service files provided by apparmor. Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
-rw-r--r--recipes-mac/AppArmor/apparmor_3.0.1.bb33
-rw-r--r--recipes-mac/AppArmor/files/0001-Makefile-fix-hardcoded-installation-directories.patch51
-rw-r--r--recipes-mac/AppArmor/files/0001-rc.apparmor.debian-add-missing-functions.patch57
-rw-r--r--recipes-mac/AppArmor/files/apparmor226
-rw-r--r--recipes-mac/AppArmor/files/apparmor.rc98
-rw-r--r--recipes-mac/AppArmor/files/apparmor.service22
-rw-r--r--recipes-mac/AppArmor/files/functions271
7 files changed, 118 insertions, 640 deletions
diff --git a/recipes-mac/AppArmor/apparmor_3.0.1.bb b/recipes-mac/AppArmor/apparmor_3.0.1.bb
index 6377683..ff5b39b 100644
--- a/recipes-mac/AppArmor/apparmor_3.0.1.bb
+++ b/recipes-mac/AppArmor/apparmor_3.0.1.bb
@@ -15,15 +15,13 @@ DEPENDS = "bison-native apr gettext-native coreutils-native swig-native"
15 15
16SRC_URI = " \ 16SRC_URI = " \
17 git://gitlab.com/apparmor/apparmor.git;protocol=https;branch=apparmor-3.0 \ 17 git://gitlab.com/apparmor/apparmor.git;protocol=https;branch=apparmor-3.0 \
18 file://run-ptest \
18 file://disable_perl_h_check.patch \ 19 file://disable_perl_h_check.patch \
19 file://crosscompile_perl_bindings.patch \ 20 file://crosscompile_perl_bindings.patch \
20 file://apparmor.rc \
21 file://functions \
22 file://apparmor \
23 file://apparmor.service \
24 file://0001-Makefile.am-suppress-perllocal.pod.patch \ 21 file://0001-Makefile.am-suppress-perllocal.pod.patch \
25 file://run-ptest \
26 file://0001-Revert-profiles-Update-make-check-to-select-tools-ba.patch \ 22 file://0001-Revert-profiles-Update-make-check-to-select-tools-ba.patch \
23 file://0001-Makefile-fix-hardcoded-installation-directories.patch \
24 file://0001-rc.apparmor.debian-add-missing-functions.patch \
27 " 25 "
28 26
29SRCREV = "b0f08aa9d678197b8e3477c2fbff790f50a1de5e" 27SRCREV = "b0f08aa9d678197b8e3477c2fbff790f50a1de5e"
@@ -79,8 +77,6 @@ do_compile () {
79} 77}
80 78
81do_install () { 79do_install () {
82 install -d ${D}/${INIT_D_DIR}
83 install -d ${D}/lib/apparmor
84 oe_runmake -C ${B}/libraries/libapparmor DESTDIR="${D}" install 80 oe_runmake -C ${B}/libraries/libapparmor DESTDIR="${D}" install
85 oe_runmake -C ${B}/binutils DESTDIR="${D}" install 81 oe_runmake -C ${B}/binutils DESTDIR="${D}" install
86 oe_runmake -C ${B}/utils DESTDIR="${D}" install 82 oe_runmake -C ${B}/utils DESTDIR="${D}" install
@@ -96,16 +92,16 @@ do_install () {
96 fi 92 fi
97 93
98 if ${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'true', 'false', d)}; then 94 if ${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'true', 'false', d)}; then
99 install -d ${D}/lib/security
100 oe_runmake -C ${B}/changehat/pam_apparmor DESTDIR="${D}" install 95 oe_runmake -C ${B}/changehat/pam_apparmor DESTDIR="${D}" install
101 fi 96 fi
102 97
103 install -m 755 ${WORKDIR}/apparmor ${D}/${INIT_D_DIR}/apparmor 98 if ${@bb.utils.contains('DISTRO_FEATURES','sysvinit','true','false',d)}; then
104 install -m 755 ${WORKDIR}/functions ${D}/lib/apparmor 99 install -d ${D}${sysconfdir}/init.d
100 install -m 755 ${B}/parser/rc.apparmor.debian ${D}${sysconfdir}/init.d/apparmor
101 fi
105 102
106 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then 103 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
107 install -d ${D}${systemd_system_unitdir} 104 oe_runmake -C ${B}/parser DESTDIR="${D}" install-systemd
108 install -m 0644 ${WORKDIR}/apparmor.service ${D}${systemd_system_unitdir}
109 fi 105 fi
110} 106}
111 107
@@ -152,15 +148,6 @@ do_install_ptest_arm() {
152 : 148 :
153} 149}
154 150
155pkg_postinst_ontarget_${PN} () {
156if [ ! -d /etc/apparmor.d/cache ] ; then
157 mkdir /etc/apparmor.d/cache
158fi
159}
160
161# We need the init script so don't rm it
162RMINITDIR_class-target_remove = " rm_sysvinit_initddir"
163
164INITSCRIPT_PACKAGES = "${PN}" 151INITSCRIPT_PACKAGES = "${PN}"
165INITSCRIPT_NAME = "apparmor" 152INITSCRIPT_NAME = "apparmor"
166INITSCRIPT_PARAMS = "start 16 2 3 4 5 . stop 35 0 1 6 ." 153INITSCRIPT_PARAMS = "start 16 2 3 4 5 . stop 35 0 1 6 ."
@@ -171,9 +158,9 @@ SYSTEMD_AUTO_ENABLE ?= "enable"
171 158
172PACKAGES += "mod-${PN}" 159PACKAGES += "mod-${PN}"
173 160
174FILES_${PN} += "/lib/apparmor/ /lib/security/ ${sysconfdir}/apparmor ${nonarch_libdir}/${PYTHON_DIR}/site-packages" 161FILES_${PN} += "${nonarch_base_libdir}/apparmor/ ${base_libdir}/security/ ${sysconfdir}/apparmor ${nonarch_libdir}/${PYTHON_DIR}/site-packages"
175FILES_mod-${PN} = "${libdir}/apache2/modules/*" 162FILES_mod-${PN} = "${libdir}/apache2/modules/*"
176FILES_${PN}-dbg += "/lib/security/" 163FILES_${PN}-dbg += "${base_libdir}/security/.debug"
177 164
178DEPENDS_append_libc-musl = " fts " 165DEPENDS_append_libc-musl = " fts "
179RDEPENDS_${PN}_libc-musl += "musl-utils" 166RDEPENDS_${PN}_libc-musl += "musl-utils"
diff --git a/recipes-mac/AppArmor/files/0001-Makefile-fix-hardcoded-installation-directories.patch b/recipes-mac/AppArmor/files/0001-Makefile-fix-hardcoded-installation-directories.patch
new file mode 100644
index 0000000..f10acb1
--- /dev/null
+++ b/recipes-mac/AppArmor/files/0001-Makefile-fix-hardcoded-installation-directories.patch
@@ -0,0 +1,51 @@
1From 363114dcd72abf1c0dcd637c66037227b8be229b Mon Sep 17 00:00:00 2001
2From: Yi Zhao <yi.zhao@windriver.com>
3Date: Mon, 21 Jun 2021 14:18:30 +0800
4Subject: [PATCH 1/2] Makefile: fix hardcoded installation directories
5
6Update the installation directories to fix the do_install error for
7multilib and usrmerge.
8
9Upstream-Status: Inappropriate [configuration]
10
11Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
12---
13 changehat/pam_apparmor/Makefile | 2 +-
14 parser/Makefile | 8 ++++----
15 2 files changed, 5 insertions(+), 5 deletions(-)
16
17diff --git a/changehat/pam_apparmor/Makefile b/changehat/pam_apparmor/Makefile
18index f6ece2d1..0143ae9f 100644
19--- a/changehat/pam_apparmor/Makefile
20+++ b/changehat/pam_apparmor/Makefile
21@@ -77,7 +77,7 @@ $(NAME).so: ${OBJECTS}
22
23 # need some better way of determining this
24 DESTDIR=/
25-SECDIR ?= ${DESTDIR}/lib/security
26+SECDIR ?= ${DESTDIR}/${base_libdir}/security
27
28 .PHONY: install
29 install: $(NAME).so
30diff --git a/parser/Makefile b/parser/Makefile
31index 8250ac45..cf18bc11 100644
32--- a/parser/Makefile
33+++ b/parser/Makefile
34@@ -23,10 +23,10 @@ COMMONDIR=../common/
35 include $(COMMONDIR)/Make.rules
36
37 DESTDIR=/
38-APPARMOR_BIN_PREFIX=${DESTDIR}/lib/apparmor
39-SBINDIR=${DESTDIR}/sbin
40-USR_SBINDIR=${DESTDIR}/usr/sbin
41-SYSTEMD_UNIT_DIR=${DESTDIR}/usr/lib/systemd/system
42+APPARMOR_BIN_PREFIX=${DESTDIR}/${nonarch_base_libdir}/apparmor
43+SBINDIR=${DESTDIR}/${base_sbindir}
44+USR_SBINDIR=${DESTDIR}/${sbindir}
45+SYSTEMD_UNIT_DIR=${DESTDIR}/${systemd_system_unitdir}
46 CONFDIR=/etc/apparmor
47 INSTALL_CONFDIR=${DESTDIR}${CONFDIR}
48 LOCALEDIR=/usr/share/locale
49--
502.17.1
51
diff --git a/recipes-mac/AppArmor/files/0001-rc.apparmor.debian-add-missing-functions.patch b/recipes-mac/AppArmor/files/0001-rc.apparmor.debian-add-missing-functions.patch
new file mode 100644
index 0000000..53bdde8
--- /dev/null
+++ b/recipes-mac/AppArmor/files/0001-rc.apparmor.debian-add-missing-functions.patch
@@ -0,0 +1,57 @@
1From a737c95ac0f887c365fe8f16583ea95da79de1e9 Mon Sep 17 00:00:00 2001
2From: Yi Zhao <yi.zhao@windriver.com>
3Date: Mon, 21 Jun 2021 16:53:39 +0800
4Subject: [PATCH] rc.apparmor.debian: add missing functions
5
6Add missing functions:
7 aa_log_action_start
8 aa_log_action_end
9 aa_log_daemon_msg
10 aa_log_end_msg
11
12Fixes:
13$ /etc/init.d/apparmor start
14/lib/apparmor/rc.apparmor.functions: line 294: aa_log_daemon_msg: command not found
15/lib/apparmor/rc.apparmor.functions: line 214: aa_log_action_start: command not found
16
17Upstream-Status: Pending
18
19Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
20---
21 parser/rc.apparmor.debian | 20 ++++++++++++++++++++
22 1 file changed, 20 insertions(+)
23
24diff --git a/parser/rc.apparmor.debian b/parser/rc.apparmor.debian
25index 8efd4400..f35124e8 100644
26--- a/parser/rc.apparmor.debian
27+++ b/parser/rc.apparmor.debian
28@@ -70,6 +70,26 @@ aa_log_skipped_msg() {
29 echo ": Skipped."
30 }
31
32+aa_log_action_start()
33+{
34+ echo "$@"
35+}
36+
37+aa_log_action_end()
38+{
39+ printf ""
40+}
41+
42+aa_log_daemon_msg()
43+{
44+ echo "$@"
45+}
46+
47+aa_log_end_msg()
48+{
49+ printf ""
50+}
51+
52 usage() {
53 echo "Usage: $0 {start|stop|restart|try-restart|reload|force-reload|status|kill}"
54 }
55--
562.17.1
57
diff --git a/recipes-mac/AppArmor/files/apparmor b/recipes-mac/AppArmor/files/apparmor
deleted file mode 100644
index 604e48d..0000000
--- a/recipes-mac/AppArmor/files/apparmor
+++ /dev/null
@@ -1,226 +0,0 @@
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, 2009 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# Steve Beattie <steve.beattie@canonical.com>
21# Kees Cook <kees@ubuntu.com>
22#
23# /etc/init.d/apparmor
24#
25### BEGIN INIT INFO
26# Provides: apparmor
27# Required-Start: $local_fs
28# Required-Stop: umountfs
29# Default-Start: S
30# Default-Stop:
31# Short-Description: AppArmor initialization
32# Description: AppArmor init script. This script loads all AppArmor profiles.
33### END INIT INFO
34
35log_daemon_msg() {
36 echo $*
37}
38
39log_end_msg () {
40 retval=$1
41 if [ $retval -eq 0 ]; then
42 echo "."
43 else
44 echo " failed!"
45 fi
46 return $retval
47}
48
49. /lib/apparmor/functions
50
51usage() {
52 echo "Usage: $0 {start|stop|restart|reload|force-reload|status|recache}"
53}
54
55test -x ${PARSER} || exit 0 # by debian policy
56# LSM is built-in, so it is either there or not enabled for this boot
57test -d /sys/module/apparmor || exit 0
58
59securityfs() {
60 # Need securityfs for any mode
61 if [ ! -d "${AA_SFS}" ]; then
62 if cut -d" " -f2,3 /proc/mounts | grep -q "^${SECURITYFS} securityfs"'$' ; then
63 log_daemon_msg "AppArmor not available as kernel LSM."
64 log_end_msg 1
65 exit 1
66 else
67 log_daemon_msg "Mounting securityfs on ${SECURITYFS}"
68 if ! mount -t securityfs none "${SECURITYFS}"; then
69 log_end_msg 1
70 exit 1
71 fi
72 fi
73 fi
74 if [ ! -w "$AA_SFS"/.load ]; then
75 log_daemon_msg "Insufficient privileges to change profiles."
76 log_end_msg 1
77 exit 1
78 fi
79}
80
81handle_system_policy_package_updates() {
82 apparmor_was_updated=0
83
84 if ! compare_previous_version ; then
85 # On snappy flavors, if the current and previous versions are
86 # different then clear the system cache. snappy will handle
87 # "$PROFILES_CACHE_VAR" itself (on Touch flavors
88 # compare_previous_version always returns '0' since snappy
89 # isn't available).
90 clear_cache_system
91 apparmor_was_updated=1
92 elif ! compare_and_save_debsums apparmor ; then
93 # If the system policy has been updated since the last time we
94 # ran, clear the cache to prevent potentially stale binary
95 # cache files after an Ubuntu image based upgrade (LP:
96 # #1350673). This can be removed once all system image flavors
97 # move to snappy (on snappy systems compare_and_save_debsums
98 # always returns '0' since /var/lib/dpkg doesn't exist).
99 clear_cache
100 apparmor_was_updated=1
101 fi
102
103 if [ -x /usr/bin/aa-clickhook ] || [ -x /usr/bin/aa-profile-hook ] ; then
104 # If packages for system policy that affect click packages have
105 # been updated since the last time we ran, run aa-clickhook -f
106 force_clickhook=0
107 force_profile_hook=0
108 if ! compare_and_save_debsums apparmor-easyprof-ubuntu ; then
109 force_clickhook=1
110 fi
111 if ! compare_and_save_debsums apparmor-easyprof-ubuntu-snappy ; then
112 force_clickhook=1
113 fi
114 if ! compare_and_save_debsums click-apparmor ; then
115 force_clickhook=1
116 force_profile_hook=1
117 fi
118 if [ -x /usr/bin/aa-clickhook ] && ([ $force_clickhook -eq 1 ] || [ $apparmor_was_updated -eq 1 ]) ; then
119 aa-clickhook -f
120 fi
121 if [ -x /usr/bin/aa-profile-hook ] && ([ $force_profile_hook -eq 1 ] || [ $apparmor_was_updated -eq 1 ]) ; then
122 aa-profile-hook -f
123 fi
124 fi
125}
126
127# Allow "recache" even when running on the liveCD
128if [ "$1" = "recache" ]; then
129 log_daemon_msg "Recaching AppArmor profiles"
130 recache_profiles
131 rc=$?
132 log_end_msg "$rc"
133 exit $rc
134fi
135
136# do not perform start/stop/reload actions when running from liveCD
137test -d /rofs/etc/apparmor.d && exit 0
138
139rc=255
140case "$1" in
141 start)
142 if test -x /sbin/systemd-detect-virt && \
143 systemd-detect-virt --quiet --container && \
144 ! is_container_with_internal_policy; then
145 log_daemon_msg "Not starting AppArmor in container"
146 log_end_msg 0
147 exit 0
148 fi
149 log_daemon_msg "Starting AppArmor profiles"
150 securityfs
151 # That is only useful for click, snappy and system images,
152 # i.e. not in Debian. And it reads and writes to /var, that
153 # can be remote-mounted, so it would prevent us from using
154 # Before=sysinit.target without possibly introducing dependency
155 # loops.
156 handle_system_policy_package_updates
157 load_configured_profiles
158 rc=$?
159 log_end_msg "$rc"
160 ;;
161 stop)
162 log_daemon_msg "Clearing AppArmor profiles cache"
163 clear_cache
164 rc=$?
165 log_end_msg "$rc"
166 cat >&2 <<EOM
167All profile caches have been cleared, but no profiles have been unloaded.
168Unloading profiles will leave already running processes permanently
169unconfined, which can lead to unexpected situations.
170
171To set a process to complain mode, use the command line tool
172'aa-complain'. To really tear down all profiles, run the init script
173with the 'teardown' option."
174EOM
175 ;;
176 teardown)
177 if test -x /sbin/systemd-detect-virt && \
178 systemd-detect-virt --quiet --container && \
179 ! is_container_with_internal_policy; then
180 log_daemon_msg "Not tearing down AppArmor in container"
181 log_end_msg 0
182 exit 0
183 fi
184 log_daemon_msg "Unloading AppArmor profiles"
185 securityfs
186 running_profile_names | while read profile; do
187 if ! unload_profile "$profile" ; then
188 log_end_msg 1
189 exit 1
190 fi
191 done
192 rc=0
193 log_end_msg $rc
194 ;;
195 restart|reload|force-reload)
196 if test -x /sbin/systemd-detect-virt && \
197 systemd-detect-virt --quiet --container && \
198 ! is_container_with_internal_policy; then
199 log_daemon_msg "Not reloading AppArmor in container"
200 log_end_msg 0
201 exit 0
202 fi
203 log_daemon_msg "Reloading AppArmor profiles"
204 securityfs
205 clear_cache
206 load_configured_profiles
207 rc=$?
208 unload_obsolete_profiles
209
210 log_end_msg "$rc"
211 ;;
212 status)
213 securityfs
214 if [ -x /usr/sbin/aa-status ]; then
215 aa-status --verbose
216 else
217 cat "$AA_SFS"/profiles
218 fi
219 rc=$?
220 ;;
221 *)
222 usage
223 rc=1
224 ;;
225 esac
226exit $rc
diff --git a/recipes-mac/AppArmor/files/apparmor.rc b/recipes-mac/AppArmor/files/apparmor.rc
deleted file mode 100644
index 1507d7b..0000000
--- a/recipes-mac/AppArmor/files/apparmor.rc
+++ /dev/null
@@ -1,98 +0,0 @@
1description "Pre-cache and pre-load apparmor profiles"
2author "Dimitri John Ledkov <xnox@ubuntu.com> and Jamie Strandboge <jamie@ubuntu.com>"
3
4task
5
6start on starting rc-sysinit
7
8script
9 [ -d /rofs/etc/apparmor.d ] && exit 0 # do not load on liveCD
10 [ -d /sys/module/apparmor ] || exit 0 # do not load without AppArmor
11 [ -x /sbin/apparmor_parser ] || exit 0 # do not load without parser
12
13 . /lib/apparmor/functions
14
15 systemd-detect-virt --quiet --container && ! is_container_with_internal_policy && exit 0 || true
16
17 # Need securityfs for any mode
18 if [ ! -d /sys/kernel/security/apparmor ]; then
19 if cut -d" " -f2,3 /proc/mounts | grep -q "^/sys/kernel/security securityfs"'$' ; then
20 exit 0
21 else
22 mount -t securityfs none /sys/kernel/security || exit 0
23 fi
24 fi
25
26 [ -w /sys/kernel/security/apparmor/.load ] || exit 0
27
28 apparmor_was_updated=0
29 if ! compare_previous_version ; then
30 # On snappy flavors, if the current and previous versions are
31 # different then clear the system cache. snappy will handle
32 # "$PROFILES_CACHE_VAR" itself (on Touch flavors
33 # compare_previous_version always returns '0' since snappy
34 # isn't available).
35 clear_cache_system
36 apparmor_was_updated=1
37 elif ! compare_and_save_debsums apparmor ; then
38 # If the system policy has been updated since the last time we
39 # ran, clear the cache to prevent potentially stale binary
40 # cache files after an Ubuntu image based upgrade (LP:
41 # #1350673). This can be removed once all system image flavors
42 # move to snappy (on snappy systems compare_and_save_debsums
43 # always returns '0' since /var/lib/dpkg doesn't exist).
44 clear_cache
45 apparmor_was_updated=1
46 fi
47
48 if [ -x /usr/bin/aa-clickhook ] || [ -x /usr/bin/aa-profile-hook ] ; then
49 # If packages for system policy that affect click packages have
50 # been updated since the last time we ran, run aa-clickhook -f
51 force_clickhook=0
52 force_profile_hook=0
53 if ! compare_and_save_debsums apparmor-easyprof-ubuntu ; then
54 force_clickhook=1
55 fi
56 if ! compare_and_save_debsums apparmor-easyprof-ubuntu-snappy ; then
57 force_clickhook=1
58 fi
59 if ! compare_and_save_debsums click-apparmor ; then
60 force_clickhook=1
61 force_profile_hook=1
62 fi
63 if [ -x /usr/bin/aa-clickhook ] && ([ $force_clickhook -eq 1 ] || [ $apparmor_was_updated -eq 1 ]) ; then
64 aa-clickhook -f
65 fi
66 if [ -x /usr/bin/aa-profile-hook ] && ([ $force_profile_hook -eq 1 ] || [ $apparmor_was_updated -eq 1 ]) ; then
67 aa-profile-hook -f
68 fi
69 fi
70
71 if [ "$ACTION" = "teardown" ]; then
72 running_profile_names | while read profile; do
73 unload_profile "$profile"
74 done
75 exit 0
76 fi
77
78 if [ "$ACTION" = "clear" ]; then
79 clear_cache
80 exit 0
81 fi
82
83 if [ "$ACTION" = "reload" ] || [ "$ACTION" = "force-reload" ]; then
84 clear_cache
85 load_configured_profiles
86 unload_obsolete_profiles
87 exit 0
88 fi
89
90 # Note: if apparmor-easyprof-ubuntu md5sums didn't match up above,
91 # aa-clickhook will have already compiled the policy, generated the cache
92 # files and loaded them into the kernel by this point, so reloading click
93 # policy from cache, while fairly fast (<2 seconds for 250 profiles on
94 # armhf), is redundant. Fixing this would complicate the logic quite a bit
95 # and it wouldn't improve the (by far) common case (ie, when
96 # 'aa-clickhook -f' is not run).
97 load_configured_profiles
98end script
diff --git a/recipes-mac/AppArmor/files/apparmor.service b/recipes-mac/AppArmor/files/apparmor.service
deleted file mode 100644
index e66afe4..0000000
--- a/recipes-mac/AppArmor/files/apparmor.service
+++ /dev/null
@@ -1,22 +0,0 @@
1[Unit]
2Description=AppArmor initialization
3After=local-fs.target
4Before=sysinit.target
5AssertPathIsReadWrite=/sys/kernel/security/apparmor/.load
6ConditionSecurity=apparmor
7DefaultDependencies=no
8Documentation=man:apparmor(7)
9Documentation=http://wiki.apparmor.net/
10
11# Don't start this unit on the Ubuntu Live CD
12ConditionPathExists=!/rofs/etc/apparmor.d
13
14[Service]
15Type=oneshot
16RemainAfterExit=yes
17ExecStart=/etc/init.d/apparmor start
18ExecStop=/etc/init.d/apparmor stop
19ExecReload=/etc/init.d/apparmor reload
20
21[Install]
22WantedBy=sysinit.target
diff --git a/recipes-mac/AppArmor/files/functions b/recipes-mac/AppArmor/files/functions
deleted file mode 100644
index e9e2bbf..0000000
--- a/recipes-mac/AppArmor/files/functions
+++ /dev/null
@@ -1,271 +0,0 @@
1# /lib/apparmor/functions for Debian -*- shell-script -*-
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
22PROFILES="/etc/apparmor.d"
23PROFILES_CACHE="$PROFILES/cache"
24PROFILES_VAR="/var/lib/apparmor/profiles"
25PROFILES_SNAPPY="/var/lib/snapd/apparmor/profiles"
26PROFILES_CACHE_VAR="/var/cache/apparmor"
27PARSER="/sbin/apparmor_parser"
28SECURITYFS="/sys/kernel/security"
29export AA_SFS="$SECURITYFS/apparmor"
30
31# Suppress warnings when booting in quiet mode
32quiet_arg=""
33[ "${QUIET:-no}" = yes ] && quiet_arg="-q"
34[ "${quiet:-n}" = y ] && quiet_arg="-q"
35
36foreach_configured_profile() {
37 rc_all="0"
38 for pdir in "$PROFILES" "$PROFILES_VAR" "$PROFILES_SNAPPY" ; do
39 if [ ! -d "$pdir" ]; then
40 continue
41 fi
42 num=`find "$pdir" -type f ! -name '*.md5sums' | wc -l`
43 if [ "$num" = "0" ]; then
44 continue
45 fi
46
47 cache_dir="$PROFILES_CACHE"
48 if [ -d "$PROFILES_CACHE_VAR" ] && [ "$pdir" = "$PROFILES_VAR" ] || [ "$pdir" = "$PROFILES_SNAPPY" ]; then
49 cache_dir="$PROFILES_CACHE_VAR"
50 fi
51 cache_args="--cache-loc=$cache_dir"
52 if [ ! -d "$cache_dir" ]; then
53 cache_args=
54 fi
55
56 # LP: #1383858 - expr tree simplification is too slow for
57 # Touch policy on ARM, so disable it for now
58 cache_extra_args=
59 if [ -d "$PROFILES_CACHE_VAR" ] && [ "$pdir" = "$PROFILES_VAR" ] || [ "$pdir" = "$PROFILES_SNAPPY" ]; then
60 cache_extra_args="-O no-expr-simplify"
61 fi
62
63 # If need to compile everything, then use -n1 with xargs to
64 # take advantage of -P. When cache files are in use, omit -n1
65 # since it is considerably faster on moderately sized profile
66 # sets to give the parser all the profiles to load at once
67 n1_args=
68 num=`find "$cache_dir" -type f ! -name '.features' | wc -l`
69 if [ "$num" = "0" ]; then
70 n1_args="-n1"
71 fi
72
73 (ls -1 "$pdir" | egrep -v '(\.dpkg-(new|old|dist|bak)|~)$' | \
74 while read profile; do
75 if [ -f "$pdir"/"$profile" ]; then
76 echo "$pdir"/"$profile"
77 fi
78 done) | \
79 xargs $n1_args -d"\n" -P$(getconf _NPROCESSORS_ONLN) "$PARSER" "$@" $cache_args $cache_extra_args -- || {
80 rc_all="$?"
81 # FIXME: when the parser properly handles broken
82 # profiles (LP: #1377338), remove this if statement.
83 # For now, if the xargs returns with error, just run
84 # through everything with -n1. (This could be broken
85 # out and refactored, but this is temporary so make it
86 # easy to understand and revert)
87 if [ "$rc_all" != "0" ]; then
88 (ls -1 "$pdir" | \
89 egrep -v '(\.dpkg-(new|old|dist|bak)|~)$' | \
90 while read profile; do
91 if [ -f "$pdir"/"$profile" ]; then
92 echo "$pdir"/"$profile"
93 fi
94 done) | \
95 xargs -n1 -d"\n" -P$(getconf _NPROCESSORS_ONLN) "$PARSER" "$@" $cache_args $cache_extra_args -- || {
96 rc_all="$?"
97 }
98 fi
99 }
100 done
101 return $rc_all
102}
103
104load_configured_profiles() {
105 clear_cache_if_outdated
106 foreach_configured_profile $quiet_arg --write-cache --replace
107}
108
109load_configured_profiles_without_caching() {
110 foreach_configured_profile $quiet_arg --replace
111}
112
113recache_profiles() {
114 clear_cache
115 foreach_configured_profile $quiet_arg --write-cache --skip-kernel-load
116}
117
118configured_profile_names() {
119 foreach_configured_profile $quiet_arg -N 2>/dev/null | LC_COLLATE=C sort | grep -v '//'
120}
121
122running_profile_names() {
123 # Output a sorted list of loaded profiles, skipping libvirt's
124 # dynamically generated files
125 cat "$AA_SFS"/profiles | sed -e "s/ (\(enforce\|complain\))$//" | egrep -v '^libvirt-[0-9a-f\-]+$' | LC_COLLATE=C sort | grep -v '//'
126}
127
128unload_profile() {
129 echo -n "$1" > "$AA_SFS"/.remove
130}
131
132clear_cache() {
133 clear_cache_system
134 clear_cache_var
135}
136
137clear_cache_system() {
138 find "$PROFILES_CACHE" -maxdepth 1 -type f -print0 | xargs -0 rm -f --
139}
140
141clear_cache_var() {
142 find "$PROFILES_CACHE_VAR" -maxdepth 1 -type f -print0 | xargs -0 rm -f --
143}
144
145read_features_dir()
146{
147 for f in `ls -A "$1"` ; do
148 if [ -f "$1/$f" ] ; then
149 read -r KF < "$1/$f" || true
150 echo -n "$f {$KF } "
151 elif [ -d "$1/$f" ] ; then
152 echo -n "$f {"
153 KF=`read_features_dir "$1/$f"` || true
154 echo -n "$KF} "
155 fi
156 done
157}
158
159clear_cache_if_outdated() {
160 if [ -r "$PROFILES_CACHE"/.features ]; then
161 if [ -d "$AA_SFS"/features ]; then
162 KERN_FEATURES=`read_features_dir "$AA_SFS"/features`
163 else
164 read -r KERN_FEATURES < "$AA_SFS"/features
165 fi
166 CACHE_FEATURES=`tr '\n' ' ' < "$PROFILES_CACHE"/.features`
167 if [ "$KERN_FEATURES" != "$CACHE_FEATURES" ]; then
168 clear_cache
169 fi
170 fi
171}
172
173unload_obsolete_profiles() {
174 # Currently we must re-parse all the profiles to get policy names. :(
175 aa_configured=$(mktemp -t aa-XXXXXX)
176 configured_profile_names > "$aa_configured" || true
177 aa_loaded=$(mktemp -t aa-XXXXXX)
178 running_profile_names > "$aa_loaded" || true
179 LC_COLLATE=C comm -2 -3 "$aa_loaded" "$aa_configured" | while read profile ; do
180 unload_profile "$profile"
181 done
182 rm -f "$aa_configured" "$aa_loaded"
183}
184
185# If the system debsum differs from the saved debsum, the new system debsum is
186# saved and non-zero is returned. Returns 0 if the two debsums matched or if
187# the system debsum file does not exist. This can be removed when system image
188# flavors all move to snappy.
189compare_and_save_debsums() {
190 pkg="$1"
191
192 if [ -n $pkg ] && [ -d "$PROFILES_VAR" ]; then
193 sums="/var/lib/dpkg/info/${pkg}.md5sums"
194 # store saved md5sums in /var/lib/apparmor/profiles since
195 # /var/cache/apparmor might be cleared by apparmor
196 saved_sums="${PROFILES_VAR}/.${pkg}.md5sums"
197
198 if [ -f "$sums" ] && \
199 ! diff -q "$sums" "$saved_sums" 2>&1 >/dev/null ; then
200 cp -f "$sums" "$saved_sums"
201 return 1
202 fi
203 fi
204
205 return 0
206}
207
208compare_previous_version() {
209 installed="/usr/share/snappy/security-policy-version"
210 previous="/var/lib/snappy/security-policy-version"
211
212 # When just $previous doesn't exist, assume this is a new system with
213 # no cache and don't do anything special.
214 if [ -f "$installed" ] && [ -f "$previous" ]; then
215 pv=`grep '^apparmor/' "$previous" | cut -d ' ' -f 2`
216 iv=`grep '^apparmor/' "$installed" | cut -d ' ' -f 2`
217 if [ -n "$iv" ] && [ -n "$pv" ] && [ "$iv" != "$pv" ]; then
218 # snappy updates $previous elsewhere, so just return
219 return 1
220 fi
221 fi
222
223 return 0
224}
225
226# Checks to see if the current container is capable of having internal AppArmor
227# profiles that should be loaded. Callers of this function should have already
228# verified that they're running inside of a container environment with
229# something like `systemd-detect-virt --container`.
230#
231# The only known container environments capable of supporting internal policy
232# are LXD and LXC environment.
233#
234# Returns 0 if the container environment is capable of having its own internal
235# policy and non-zero otherwise.
236#
237# IMPORTANT: This function will return 0 in the case of a non-LXD/non-LXC
238# system container technology being nested inside of a LXD/LXC container that
239# utilized an AppArmor namespace and profile stacking. The reason 0 will be
240# returned is because .ns_stacked will be "yes" and .ns_name will still match
241# "lx[dc]-*" since the nested system container technology will not have set up
242# a new AppArmor profile namespace. This will result in the nested system
243# container's boot process to experience failed policy loads but the boot
244# process should continue without any loss of functionality. This is an
245# unsupported configuration that cannot be properly handled by this function.
246is_container_with_internal_policy() {
247 local ns_stacked_path="${AA_SFS}/.ns_stacked"
248 local ns_name_path="${AA_SFS}/.ns_name"
249 local ns_stacked
250 local ns_name
251
252 if ! [ -f "$ns_stacked_path" ] || ! [ -f "$ns_name_path" ]; then
253 return 1
254 fi
255
256 read -r ns_stacked < "$ns_stacked_path"
257 if [ "$ns_stacked" != "yes" ]; then
258 return 1
259 fi
260
261 # LXD and LXC set up AppArmor namespaces starting with "lxd-" and
262 # "lxc-", respectively. Return non-zero for all other namespace
263 # identifiers.
264 read -r ns_name < "$ns_name_path"
265 if [ "${ns_name#lxd-*}" = "$ns_name" ] && \
266 [ "${ns_name#lxc-*}" = "$ns_name" ]; then
267 return 1
268 fi
269
270 return 0
271}