Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito c38127
# Rules and Targets for building modular policies
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
Chris PeBenito c767b1
ALL_MODULES := $(BASE_MODS) $(MOD_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 4f9f30
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
Chris PeBenito fb0a3a
Chris PeBenito a08248
BASE_PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
Chris PeBenito fb0a3a
BASE_TE_FILES := $(BASE_MODS)
Chris PeBenito 2f33cd
BASE_POST_TE_FILES := $(USER_FILES) $(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 c04f2a
MOD_PKGS := $(notdir $(MOD_MODS:.te=.pp))
Chris PeBenito c04f2a
Chris PeBenito c767b1
# policy packages to install
Chris PeBenito c767b1
INSTPKG := $(addprefix $(MODPKGDIR)/,$(BASE_PKG) $(MOD_PKGS))
Chris PeBenito c767b1
Chris PeBenito c04f2a
# search layer dirs for source files
Chris PeBenito c04f2a
vpath %.te $(ALL_LAYERS)
Chris PeBenito c04f2a
vpath %.if $(ALL_LAYERS)
Chris PeBenito c04f2a
vpath %.fc $(ALL_LAYERS)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# default action: create all module packages
Chris PeBenito fb0a3a
#
Chris PeBenito fedd3c
default: base
Chris PeBenito fb0a3a
Chris PeBenito 06a536
all: base modules
Chris PeBenito 06a536
Chris PeBenito fb0a3a
base: $(BASE_PKG)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
modules: $(MOD_PKGS)
Chris PeBenito fb0a3a
Chris PeBenito c767b1
install: $(INSTPKG) $(APPFILES)
Chris PeBenito c767b1
Chris PeBenito c767b1
########################################
Chris PeBenito c767b1
#
Chris PeBenito c767b1
# Load all configured modules
Chris PeBenito c767b1
#
Chris PeBenito c767b1
load: $(INSTPKG) $(APPFILES)
Chris PeBenito c767b1
	@echo "Loading configured modules."
Chris PeBenito c767b1
	$(QUIET) $(SEMODULE) -s $(NAME) -b $(MODPKGDIR)/$(BASE_PKG) $(foreach mod,$(MOD_PKGS),-i $(MODPKGDIR)/$(mod))
Chris PeBenito c767b1
Chris PeBenito c767b1
########################################
Chris PeBenito c767b1
#
Chris PeBenito c767b1
# Install policy packages
Chris PeBenito c767b1
#
Chris PeBenito c767b1
$(MODPKGDIR)/%.pp: %.pp
Chris PeBenito c767b1
	@mkdir -p $(MODPKGDIR)
Chris PeBenito c767b1
	@echo "Installing $(@F) policy package."
Chris PeBenito c767b1
	$(QUIET) install -m 0644 $^ $(MODPKGDIR)
Chris PeBenito c767b1
Chris PeBenito c767b1
########################################
Chris PeBenito c767b1
#
Chris PeBenito c767b1
# Build module packages
Chris PeBenito c767b1
#
Chris PeBenito c767b1
tmp/%.mod: $(M4SUPPORT) tmp/generated_definitions.conf tmp/all_interfaces.conf %.te
Chris PeBenito c767b1
	@echo "Compliling $(NAME) $(@F) module"
Chris PeBenito c767b1
	$(QUIET) m4 $(M4PARAM) -s $^ > $(@:.mod=.tmp)
Chris PeBenito c767b1
	$(QUIET) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
Chris PeBenito c767b1
Chris PeBenito c767b1
tmp/%.mod.fc: $(M4SUPPORT) %.fc
Chris PeBenito c767b1
	$(QUIET) m4 $(M4PARAM) $(M4SUPPORT) $^ > $@
Chris PeBenito c767b1
Chris PeBenito c767b1
%.pp: tmp/%.mod tmp/%.mod.fc
Chris PeBenito c767b1
	@echo "Creating $(NAME) $(@F) policy package"
Chris PeBenito c767b1
	$(QUIET) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
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 2964dc
	$(QUIET) $(SEMOD_PKG) -o $@ -m tmp/base.mod -f $(BASE_FC)
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 c767b1
# Construct a base.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 0e15cd
	$(QUIET) m4 -D self_contained_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 28f032
tmp/generated_definitions.conf: $(ALL_LAYERS) $(BASE_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito c04f2a
# define all available object classes
Chris PeBenito c04f2a
	$(QUIET) $(GENPERM) $(AVS) $(SECCLASS) > $@
Chris PeBenito 71fe0f
# per-userdomain templates
Chris PeBenito 71fe0f
	$(QUIET) echo "define(\`per_userdomain_templates',\`" >> $@
Chris PeBenito 71fe0f
	$(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
Chris PeBenito 71fe0f
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
Chris PeBenito 71fe0f
			>> $@ ;\
Chris PeBenito 71fe0f
	done
Chris PeBenito 71fe0f
	$(QUIET) echo "')" >> $@
Chris PeBenito fb0a3a
# define foo.te
Chris PeBenito 28f032
	$(QUIET) for i in $(notdir $(BASE_TE_FILES)); do \
Chris PeBenito fb0a3a
		echo "define(\`$$i')" >> $@ ;\
Chris PeBenito fb0a3a
	done
Chris PeBenito 4f9f30
	$(QUIET) $(SETTUN) $(BOOLEANS) >> $@
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 c767b1
# Construct a base.fc
Chris PeBenito fb0a3a
#
Chris PeBenito c767b1
$(BASE_FC): tmp/$(BASE_FC).tmp $(FCSORT)
Chris PeBenito c767b1
	$(QUIET) $(FCSORT) $< $@
Chris PeBenito c767b1
Chris PeBenito c767b1
tmp/$(BASE_FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES)
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 c767b1
	$(QUIET) m4 $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito 049e11
# Appconfig files
Chris PeBenito 049e11
#
Chris PeBenito 049e11
$(APPDIR)/customizable_types: base.conf
Chris PeBenito 049e11
	@mkdir -p $(APPDIR)
Chris PeBenito 049e11
	$(QUIET) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
Chris PeBenito 049e11
	$(QUIET) install -m 644 tmp/customizable_types $@ 
Chris PeBenito 049e11
Chris PeBenito 049e11
########################################
Chris PeBenito 049e11
#
Chris PeBenito fb0a3a
# Clean the sources
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
clean:
Chris PeBenito fb0a3a
	rm -f base.conf
Chris PeBenito c04f2a
	rm -f *.pp
Chris PeBenito 712566
	rm -f $(BASE_FC)
Chris PeBenito c767b1
	rm -fR tmp
Chris PeBenito fb0a3a
Chris PeBenito c767b1
.PHONY: default all base modules install load clean