Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Rules and Targets for building monolithic policies
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
ALL_MODULES := $(filter $(BASE_MODS) $(MOD_MODS),$(DETECTED_MODS))
Chris PeBenito fb0a3a
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
BASE_PKG := base.pp
Chris PeBenito fb0a3a
BASE_FC := base.fc
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
BASE_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
BASE_PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls
Chris PeBenito fb0a3a
BASE_TE_FILES := $(BASE_MODS)
Chris PeBenito fb0a3a
BASE_POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints
Chris PeBenito fb0a3a
BASE_FC_FILES := $(BASE_MODS:.te=.fc)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
MOD_MODULES := $(MOD_MODS:.te=.mod)
Chris PeBenito fb0a3a
MOD_PKGS := $(MOD_MODS:.te=.pp)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# default action: create all module packages
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
default: base modules
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
base: $(BASE_PKG)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
modules: $(MOD_PKGS)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
#policy: $(POLVER)
Chris PeBenito fb0a3a
#install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
Chris PeBenito fb0a3a
#load: tmp/load
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Create a base module package
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(BASE_PKG): tmp/base.mod $(BASE_FC)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module package"
Chris PeBenito fb0a3a
	$(QUIET) $(SEMOD_PKG) $@ $^
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Compile a base module
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
tmp/base.mod: base.conf
Chris PeBenito fb0a3a
	@echo "Compiling $(NAME) base module"
Chris PeBenito fb0a3a
	$(QUIET) $(CHECKMODULE) $^ -o $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct a base module policy.conf
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
base.conf: $(BASE_SECTIONS)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module policy.conf"
Chris PeBenito fb0a3a
# checkpolicy can use the #line directives provided by -s for error reporting:
Chris PeBenito fb0a3a
	$(QUIET) m4 -D monolithic_policy $(M4PARAM) -s $^ > tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
Chris PeBenito fb0a3a
# the ordering of these ocontexts matters:
Chris PeBenito fb0a3a
	$(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/pre_te_files.conf: $(BASE_PRE_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES)
Chris PeBenito fb0a3a
# per-userdomain templates:
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
Chris PeBenito fb0a3a
	$(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
Chris PeBenito fb0a3a
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
Chris PeBenito fb0a3a
			>> $@ ;\
Chris PeBenito fb0a3a
	done
Chris PeBenito fb0a3a
	$(QUIET) echo "')" >> $@
Chris PeBenito fb0a3a
# define foo.te
Chris PeBenito fb0a3a
	$(QUIET) for i in $(notdir $(ALL_MODULES)); do \
Chris PeBenito fb0a3a
		echo "define(\`$$i')" >> $@ ;\
Chris PeBenito fb0a3a
	done
Chris PeBenito fb0a3a
	$(QUIET) $(SETTUN) $(TUNABLES) >> $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
Chris PeBenito fb0a3a
ifeq ($(ALL_INTERFACES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/all_te_files.conf: $(BASE_TE_FILES)
Chris PeBenito fb0a3a
ifeq ($(BASE_TE_FILES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/post_te_files.conf: $(BASE_POST_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
# extract attributes and put them first. extract post te stuff
Chris PeBenito fb0a3a
# like genfscon and put last.  portcon, nodecon, and netifcon
Chris PeBenito fb0a3a
# is delayed since they are generated by m4
Chris PeBenito fb0a3a
tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
Chris PeBenito fb0a3a
	$(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
Chris PeBenito fb0a3a
	$(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
Chris PeBenito fb0a3a
	$(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
Chris PeBenito fb0a3a
	$(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
Chris PeBenito fb0a3a
			-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
Chris PeBenito fb0a3a
			< tmp/all_te_files.conf > tmp/only_te_rules.conf
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct base module file contexts
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) $(FCSORT)
Chris PeBenito fb0a3a
ifeq ($(BASE_FC_FILES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module file contexts."
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) > tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE)
Chris PeBenito fb0a3a
	$(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) $(FCSORT) tmp/$@.tmp $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Build modules packages
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
%.pp: %.mod %.fc
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) $(@F) package"
Chris PeBenito fb0a3a
	$(QUIET) $(SEMOD_PKG) $@ %^
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Compile modules
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
%.mod: $(M4SUPPORT) tmp/all_interfaces.conf %.te
Chris PeBenito fb0a3a
	@echo "Compiling $(NAME) $(@F) module"
Chris PeBenito fb0a3a
	$(QUIET) m4 $(M4PARAM) -s $^ > tmp/$(@F).tmp
Chris PeBenito fb0a3a
	$(QUIET) $(CHECKMODULE) -m tmp/$(@F).tmp -o $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Clean the sources
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
clean:
Chris PeBenito fb0a3a
	rm -fR tmp
Chris PeBenito fb0a3a
	rm -f base.conf
Chris PeBenito fb0a3a
	rm -f $(BASE_PKG)
Chris PeBenito fb0a3a
	find . -iname "*.mod" | xargs rm -f
Chris PeBenito fb0a3a
	find . -iname "*.pp" | xargs rm -f
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
.PHONY: default base modules clean