2006-04-11 21:52:54 +00:00
# ------------------------------------------------------------------
#
2010-08-05 15:10:33 -05:00
# Copyright (C) 2002-2009 Novell/SUSE
2016-12-10 10:25:31 -08:00
# Copyright (C) 2010-2016 Canonical Ltd.
2006-04-11 21:52:54 +00:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
2006-06-05 16:39:29 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
2006-04-11 21:52:54 +00:00
# ------------------------------------------------------------------
2010-08-05 15:10:33 -05:00
# Makefile for LSM-based AppArmor profiles
2006-04-11 21:52:54 +00:00
NAME = apparmor-profiles
2016-12-10 10:25:31 -08:00
all : local docs
2006-04-12 20:35:41 +00:00
COMMONDIR = ../common/
2006-04-11 21:52:54 +00:00
2015-01-23 15:52:09 -08:00
i n c l u d e $( COMMONDIR ) / M a k e . r u l e s
2006-04-11 21:52:54 +00:00
DESTDIR = /
2007-05-16 18:51:46 +00:00
PROFILES_DEST = ${ DESTDIR } /etc/apparmor.d
2012-09-27 23:57:21 +02:00
EXTRAS_DEST = ${ DESTDIR } /usr/share/apparmor/extra-profiles/
2007-05-16 18:51:46 +00:00
PROFILES_SOURCE = ./apparmor.d
2018-10-13 15:41:15 +03:00
ABSTRACTIONS_SOURCE = ./apparmor.d/abstractions
2007-05-16 18:51:46 +00:00
EXTRAS_SOURCE = ./apparmor/profiles/extras/
2012-11-21 07:39:40 -08:00
SUBDIRS = $( shell find ${ PROFILES_SOURCE } -type d -print)
TOPLEVEL_PROFILES = $( filter-out ${ SUBDIRS } , $( wildcard ${ PROFILES_SOURCE } /*) )
2006-04-11 21:52:54 +00:00
2020-07-09 17:17:29 -07:00
i f d e f U S E _ S Y S T E M
PYTHONPATH =
PARSER?= apparmor_parser
LOGPROF?= aa-logprof
e l s e
# PYTHON_DIST_BUILD_PATH based on libapparmor/swig/python/test/Makefile.am
PYTHON_DIST_BUILD_PATH = ../libraries/libapparmor/swig/python/build/$$ ( $( PYTHON) -c "import distutils.util; import platform; print(\"lib.%s-%s\" %(distutils.util.get_platform(), platform.python_version()[:3]))" )
2020-07-23 19:14:34 -07:00
LIBAPPARMOR_PATH = ../libraries/libapparmor/src/.libs/
LD_LIBRARY_PATH = $( LIBAPPARMOR_PATH) :$( PYTHON_DIST_BUILD_PATH)
2020-07-09 17:17:29 -07:00
PYTHONPATH = ../utils/:$( PYTHON_DIST_BUILD_PATH)
PARSER?= ../parser/apparmor_parser
# use ../utils logprof
2020-10-25 15:53:29 +01:00
LOGPROF?= LD_LIBRARY_PATH = $( LD_LIBRARY_PATH) PYTHONPATH = $( PYTHONPATH) $( PYTHON) ../utils/aa-logprof --configdir ../utils/test/
2020-07-09 17:17:29 -07:00
e n d i f
2018-03-18 17:13:18 +01:00
# $(PWD) is wrong when using "make -C profiles" - explicitely set it here to get the right value
PWD = $( shell pwd )
2020-07-23 18:57:53 -07:00
.PHONY : test -dependencies
2020-07-23 19:08:41 -07:00
test-dependencies : __parser __libapparmor
2020-07-09 17:17:29 -07:00
2020-07-23 19:08:41 -07:00
.PHONY : __parser __libapparmor
2020-07-09 17:17:29 -07:00
__parser :
i f n d e f U S E _ S Y S T E M
@if [ ! -f $( PARSER) ] ; then \
echo " error: $( PARSER) is missing. Pick one of these possible solutions: " 1>& 2; \
echo " 1) Test using the in-tree parser by building it first and then trying again. See the top-level README for help." 1>& 2; \
echo " 2) Test using the system parser by adding USE_SYSTEM=1 to your make command." 1>& 2; \
exit 1; \
fi
e n d i f
2020-07-23 19:08:41 -07:00
__libapparmor :
i f n d e f U S E _ S Y S T E M
2020-07-23 19:14:34 -07:00
@if [ ! -f $( LIBAPPARMOR_PATH) libapparmor.so ] ; then \
echo " error: $( LIBAPPARMOR_PATH) libapparmor.so is missing. Pick one of these possible solutions: " 1>& 2; \
2020-07-23 19:08:41 -07:00
echo " 1) Build against the in-tree libapparmor by building it first and then trying again. See the top-level README for help." 1>& 2; \
echo " 2) Build against the system libapparmor by adding USE_SYSTEM=1 to your make command." 1>& 2; \
exit 1; \
fi
e n d i f
2020-07-23 18:57:53 -07:00
local :
2012-11-21 07:39:40 -08:00
for profile in ${ TOPLEVEL_PROFILES } ; do \
2010-08-05 15:10:33 -05:00
fn = $$ ( basename $$ profile) ; \
echo " # Site-specific additions and overrides for ' $$ fn' " > ${ PROFILES_SOURCE } /local/$$ fn; \
2020-04-28 22:28:12 +02:00
grep " include[[:space:]]\\+if[[:space:]]\\+exists[[:space:]]\\+<local/ $$ fn> " " $$ profile " >/dev/null || { echo " $$ profile doesn't contain include if exists <local/ $$ fn> " ; exit 1; } ; \
2010-08-05 15:10:33 -05:00
done ; \
2006-04-11 21:52:54 +00:00
.PHONY : install
2010-08-05 15:10:33 -05:00
install : local
2007-05-16 18:51:46 +00:00
install -m 755 -d ${ PROFILES_DEST }
2012-11-21 07:39:40 -08:00
install -m 755 -d ${ PROFILES_DEST } /disable
for dir in ${ SUBDIRS } ; do \
install -m 755 -d " ${ PROFILES_DEST } / $$ {dir# ${ PROFILES_SOURCE } } " ; \
done
for file in $$ ( find ${ PROFILES_SOURCE } -type f -print) ; do \
install -m 644 " $$ {file} " " ${ PROFILES_DEST } / $$ (dirname $$ {file# ${ PROFILES_SOURCE } }) " ; \
done
2007-05-16 18:51:46 +00:00
install -m 755 -d ${ EXTRAS_DEST }
install -m 644 ${ EXTRAS_SOURCE } /* ${ EXTRAS_DEST }
2006-04-11 21:52:54 +00:00
2010-08-05 16:00:23 -05:00
LOCAL_ADDITIONS = $( filter-out ${ PROFILES_SOURCE } /local/README, $( wildcard ${ PROFILES_SOURCE } /local/*) )
2006-04-11 21:52:54 +00:00
.PHONY : clean
clean :
2015-01-23 15:52:09 -08:00
-rm -f ${ LOCAL_ADDITIONS }
2006-06-05 16:39:29 +00:00
i f n d e f V E R B O S E
Q = @
e l s e
Q =
e n d i f
2016-12-10 10:25:31 -08:00
.PHONY : docs
# docs: should we have some here?
docs :
2011-03-18 22:31:26 -07:00
IGNORE_FILES = ${ EXTRAS_SOURCE } /README
2012-12-21 22:43:11 -08:00
CHECK_PROFILES = $( filter-out ${ IGNORE_FILES } ${ SUBDIRS } , $( wildcard ${ PROFILES_SOURCE } /*) $( wildcard ${ EXTRAS_SOURCE } /*) )
2018-10-13 15:41:15 +03:00
# use find because Make wildcard is not recursive:
CHECK_ABSTRACTIONS = $( shell find ${ ABSTRACTIONS_SOURCE } -type f -print)
2006-06-05 16:39:29 +00:00
.PHONY : check
2019-01-27 19:13:50 +01:00
check : check -parser check -logprof check -abstractions .d
2013-01-02 14:33:12 -08:00
.PHONY : check -parser
2020-07-23 18:57:53 -07:00
check-parser : test -dependencies local
2011-03-18 22:31:26 -07:00
@echo " *** Checking profiles from ${ PROFILES_SOURCE } and ${ EXTRAS_SOURCE } against apparmor_parser "
2006-06-05 16:39:29 +00:00
$( Q) for profile in ${ CHECK_PROFILES } ; do \
2012-12-21 22:43:11 -08:00
[ -n " ${ VERBOSE } " ] && echo " Testing $$ {profile} " ; \
2018-09-16 22:06:46 +02:00
${ PARSER } --config-file= ../parser/tst/parser.conf -S -b ${ PWD } /apparmor.d $$ { profile} > /dev/null || exit 1; \
2006-06-05 16:39:29 +00:00
done
2013-01-02 14:33:12 -08:00
2018-10-13 15:41:15 +03:00
@echo " *** Checking abstractions from ${ ABSTRACTIONS_SOURCE } against apparmor_parser "
$( Q) for abstraction in ${ CHECK_ABSTRACTIONS } ; do \
[ -n " ${ VERBOSE } " ] && echo " Testing $$ {abstraction} " ; \
2020-05-31 00:45:17 +02:00
echo " abi <abi/3.0>, #include <tunables/global> profile test { #include < $$ {abstraction}> } " \
2018-10-13 15:41:15 +03:00
| ${ PARSER } --config-file= ../parser/tst/parser.conf -S -b ${ PWD } /apparmor.d -I ${ PWD } > /dev/null \
|| exit 1; \
done
2013-01-02 14:33:12 -08:00
.PHONY : check -logprof
2020-07-23 18:57:53 -07:00
check-logprof : test -dependencies local
2007-05-16 18:51:46 +00:00
@echo " *** Checking profiles from ${ PROFILES_SOURCE } against logprof "
2011-03-18 22:31:26 -07:00
$( Q) ${ LOGPROF } -d ${ PROFILES_SOURCE } -f /dev/null || exit 1
2019-01-27 19:13:50 +01:00
.PHONY : check -abstractions .d
check-abstractions.d :
2020-05-30 19:46:08 +02:00
@echo "*** Checking if all abstractions (with a few exceptions) contain include if exists <abstractions/*.d>"
2019-01-27 19:13:50 +01:00
$( Q) cd apparmor.d/abstractions && for file in * ; do \
test -d " $$ file " && continue ; \
2020-01-27 23:44:59 +01:00
test " $$ file " = 'ubuntu-browsers' && continue ; \
test " $$ file " = 'ubuntu-helpers' && continue ; \
2020-05-30 19:46:08 +02:00
grep -q " ^ include if exists <abstractions/ $$ {file}.d> $$ " $$ file || { echo " $$ file does not contain 'include if exists <abstractions/ $$ {file}.d>' " ; exit 1; } ; \
2019-01-27 19:13:50 +01:00
done