########################################
#
# Rules and Targets for building modular policies
#
ALL_MODULES := $(BASE_MODS) $(MOD_MODS) $(OFF_MODS)
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
BASE_PKG := base.pp
BASE_FC := base.fc
BASE_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALBOOL) $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
BASE_PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
BASE_TE_FILES := $(BASE_MODS)
BASE_POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
BASE_FC_FILES := $(BASE_MODS:.te=.fc)
MOD_MODULES := $(MOD_MODS:.te=.mod)
MOD_PKGS := $(MOD_MODS:.te=.pp)
# policy packages to install
INSTPKG := $(addprefix $(MODPKGDIR)/,$(BASE_PKG) $(MOD_PKGS))
# search layer dirs for source files
vpath %.te $(ALL_LAYERS)
vpath %.if $(ALL_LAYERS)
vpath %.fc $(ALL_LAYERS)
.SECONDARY:
########################################
#
# default action: create all module packages
#
default: base
all: base modules
base: $(BASE_PKG)
modules: $(MOD_PKGS)
install: $(INSTPKG) $(APPFILES)
########################################
#
# Load all configured modules
#
load: $(INSTPKG) $(APPFILES)
@echo "Loading configured modules."
$(verbose) $(SEMODULE) -s $(NAME) -b $(MODPKGDIR)/$(BASE_PKG) $(foreach mod,$(MOD_PKGS),-i $(MODPKGDIR)/$(mod))
########################################
#
# Install policy packages
#
$(MODPKGDIR)/%.pp: %.pp
@mkdir -p $(MODPKGDIR)
@echo "Installing $(NAME) $(@F) policy package."
$(verbose) install -m 0644 $^ $(MODPKGDIR)
########################################
#
# Build module packages
#
tmp/%.mod: $(M4SUPPORT) tmp/generated_definitions.conf tmp/all_interfaces.conf %.te
@echo "Compliling $(NAME) $(@F) module"
$(call peruser-expansion,$(basename $(@F)),$@.role)
$(verbose) m4 $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
tmp/%.mod.fc: $(M4SUPPORT) %.fc
$(verbose) m4 $(M4PARAM) $(M4SUPPORT) $^ > $@
%.pp: tmp/%.mod tmp/%.mod.fc
@echo "Creating $(NAME) $(@F) policy package"
$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
########################################
#
# Create a base module package
#
$(BASE_PKG): tmp/base.mod $(BASE_FC)
@echo "Creating $(NAME) base module package"
$(verbose) $(SEMOD_PKG) -o $@ -m tmp/base.mod -f $(BASE_FC)
tmp/base.mod: base.conf
@echo "Compiling $(NAME) base module"
$(verbose) $(CHECKMODULE) $^ -o $@
########################################
#
# Construct a base.conf
#
base.conf: $(BASE_SECTIONS)
@echo "Creating $(NAME) base module base.conf"
# checkpolicy can use the #line directives provided by -s for error reporting:
$(verbose) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
$(verbose) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
# the ordering of these ocontexts matters:
$(verbose) grep ^portcon tmp/$@.tmp >> $@ || true
$(verbose) grep ^netifcon tmp/$@.tmp >> $@ || true
$(verbose) grep ^nodecon tmp/$@.tmp >> $@ || true
tmp/pre_te_files.conf: $(BASE_PRE_TE_FILES)
@test -d tmp || mkdir -p tmp
$(verbose) cat $^ > $@
tmp/generated_definitions.conf: $(BASE_TE_FILES)
@test -d tmp || mkdir -p tmp
# define all available object classes
$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@
# per-userdomain templates
$(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
$(verbose) for i in $(patsubst %.te,%,$(BASE_MODS)); do \
echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
>> $@ ;\
done
$(verbose) echo "')" >> $@
# define foo.te
$(verbose) for i in $(notdir $(BASE_TE_FILES)); do \
echo "define(\`$$i')" >> $@ ;\
done
$(verbose) $(SETTUN) $(BOOLEANS) >> $@
tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
ifeq ($(ALL_INTERFACES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@test -d tmp || mkdir -p tmp
$(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
tmp/all_te_files.conf: $(BASE_TE_FILES)
ifeq ($(BASE_TE_FILES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@test -d tmp || mkdir -p tmp
$(verbose) cat $^ > $@
$(call parse-rolemap,base,$@)
tmp/post_te_files.conf: $(BASE_POST_TE_FILES)
@test -d tmp || mkdir -p tmp
$(verbose) cat $^ > $@
# extract attributes and put them first. extract post te stuff
# like genfscon and put last. portcon, nodecon, and netifcon
# is delayed since they are generated by m4
tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
$(verbose) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
$(verbose) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
$(verbose) cat tmp/post_te_files.conf > tmp/all_post.conf
$(verbose) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
$(verbose) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
$(verbose) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
$(verbose) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
< tmp/all_te_files.conf > tmp/only_te_rules.conf
########################################
#
# Construct a base.fc
#
$(BASE_FC): tmp/$(BASE_FC).tmp $(FCSORT)
$(verbose) $(FCSORT) $< $@
tmp/$(BASE_FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES)
ifeq ($(BASE_FC_FILES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@echo "Creating $(NAME) base module file contexts."
@test -d tmp || mkdir -p tmp
$(verbose) m4 $(M4PARAM) $^ > $@
########################################
#
# Remove the dontaudit rules from the base.conf
#
enableaudit: base.conf
@test -d tmp || mkdir -p tmp
@echo "Removing dontaudit rules from base.conf"
$(verbose) grep -v dontaudit base.conf > tmp/base.audit
$(verbose) mv tmp/base.audit base.conf
########################################
#
# Appconfig files
#
$(APPDIR)/customizable_types: base.conf
@mkdir -p $(APPDIR)
$(verbose) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
$(verbose) install -m 644 tmp/customizable_types $@
########################################
#
# Clean the sources
#
clean:
rm -f base.conf
rm -f *.pp
rm -f $(BASE_FC)
rm -fR tmp
.PHONY: default all base modules install load clean