Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito c38127
# Rules and Targets for building modular policies
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
Chris PeBenito e0a900
ALL_MODULES := $(BASE_MODS) $(MOD_MODS) $(OFF_MODS)
Chris PeBenito fb0a3a
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
Chris PeBenito fb0a3a
Chris PeBenito 5b45ff
BASE_PKG := $(BUILDDIR)base.pp
Chris PeBenito 5b45ff
BASE_FC := $(BUILDDIR)base.fc
Chris PeBenito 5b45ff
BASE_CONF := $(BUILDDIR)base.conf
Chris PeBenito c9f20d
BASE_MOD := $(TMPDIR)/base.mod
Chris PeBenito fb0a3a
Chris PeBenito 90b331
USERS_EXTRA := $(TMPDIR)/users_extra
Chris PeBenito 90b331
Chris PeBenito 3abd5e
BASE_SECTIONS := $(TMPDIR)/pre_te_files.conf $(TMPDIR)/all_attrs_types.conf $(TMPDIR)/global_bools.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/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 5b45ff
MOD_PKGS := $(addprefix $(BUILDDIR),$(notdir $(MOD_MODS:.te=.pp)))
Chris PeBenito c04f2a
Chris PeBenito c767b1
# policy packages to install
Chris PeBenito c9f20d
INSTPKG := $(addprefix $(MODPKGDIR)/,$(notdir $(BASE_PKG)) $(MOD_PKGS))
Chris PeBenito c767b1
Chris PeBenito c04f2a
# search layer dirs for source files
Chris PeBenito e2680f
vpath %.te $(ALL_LAYERS)
Chris PeBenito e2680f
vpath %.if $(ALL_LAYERS)
Chris PeBenito e2680f
vpath %.fc $(ALL_LAYERS)
Chris PeBenito fb0a3a
Chris PeBenito e60b98
.SECONDARY:
Chris PeBenito e60b98
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# default action: create all module packages
Chris PeBenito fb0a3a
#
Chris PeBenito ddb9aa
default: policy
Chris PeBenito fb0a3a
Chris PeBenito ddb9aa
all policy: 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 c9f20d
	$(verbose) $(SEMODULE) -s $(NAME) -b $(MODPKGDIR)/$(notdir $(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 5b45ff
$(MODPKGDIR)/%.pp: $(BUILDDIR)%.pp
Chris PeBenito c767b1
	@mkdir -p $(MODPKGDIR)
Chris PeBenito 6b1c8e
	@echo "Installing $(NAME) $(@F) policy package."
Chris PeBenito 9b3756
	$(verbose) install -m 0644 $^ $(MODPKGDIR)
Chris PeBenito c767b1
Chris PeBenito c767b1
########################################
Chris PeBenito c767b1
#
Chris PeBenito c767b1
# Build module packages
Chris PeBenito c767b1
#
Chris PeBenito c9f20d
$(TMPDIR)/%.mod: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf %.te
Chris PeBenito c767b1
	@echo "Compliling $(NAME) $(@F) module"
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 4ace0f
	$(call peruser-expansion,$(basename $(@F)),$@.role)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
Chris PeBenito 9b3756
	$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
Chris PeBenito c767b1
Chris PeBenito c9f20d
$(TMPDIR)/%.mod.fc: $(M4SUPPORT) %.fc
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) $(M4SUPPORT) $^ > $@
Chris PeBenito c767b1
Chris PeBenito 5b45ff
$(BUILDDIR)%.pp: $(TMPDIR)/%.mod $(TMPDIR)/%.mod.fc
Chris PeBenito c767b1
	@echo "Creating $(NAME) $(@F) policy package"
Chris PeBenito c9f20d
	@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
Chris PeBenito 9b3756
	$(verbose) $(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 ace368
$(BASE_PKG): $(BASE_MOD) $(BASE_FC) $(USERS_EXTRA) $(SEUSERS)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module package"
Chris PeBenito c9f20d
	@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
Chris PeBenito ace368
	$(verbose) $(SEMOD_PKG) -o $@ -m $(BASE_MOD) -f $(BASE_FC) -u $(USERS_EXTRA) -s $(SEUSERS)
Chris PeBenito fb0a3a
Chris PeBenito c9f20d
$(BASE_MOD): $(BASE_CONF)
Chris PeBenito fb0a3a
	@echo "Compiling $(NAME) base module"
Chris PeBenito 9b3756
	$(verbose) $(CHECKMODULE) $^ -o $@
Chris PeBenito fb0a3a
Chris PeBenito 90b331
$(USERS_EXTRA): $(M4SUPPORT) $(USER_FILES)
Chris PeBenito 90b331
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 90b331
	$(verbose) $(M4) $(M4PARAM) -D users_extra $^ | \
Chris PeBenito 90b331
		$(SED) -r -n -e 's/^[[:blank:]]*//g' -e '/^user/p' > $@
Chris PeBenito 90b331
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito c767b1
# Construct a base.conf
Chris PeBenito fb0a3a
#
Chris PeBenito c9f20d
$(BASE_CONF): $(BASE_SECTIONS)
Chris PeBenito 58b2a3
	@echo "Creating $(NAME) base module $(@F)"
Chris PeBenito 3abd5e
	@test -d $(@D) || mkdir -p $(@D)
Chris PeBenito 3abd5e
	$(verbose) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito 3abd5e
$(TMPDIR)/pre_te_files.conf: M4PARAM += -D self_contained_policy
Chris PeBenito c9f20d
$(TMPDIR)/pre_te_files.conf: $(BASE_PRE_TE_FILES)
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito c9f20d
$(TMPDIR)/generated_definitions.conf: $(BASE_TE_FILES)
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito c04f2a
# define all available object classes
Chris PeBenito 9b3756
	$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@
Chris PeBenito 71fe0f
# per-userdomain templates
Chris PeBenito 9b3756
	$(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
Chris PeBenito 9b3756
	$(verbose) for i in $(patsubst %.te,%,$(BASE_MODS)); do \
Chris PeBenito 71fe0f
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
Chris PeBenito 71fe0f
			>> $@ ;\
Chris PeBenito 71fe0f
	done
Chris PeBenito 9b3756
	$(verbose) echo "')" >> $@
Chris PeBenito fb0a3a
# define foo.te
Chris PeBenito 9b3756
	$(verbose) for i in $(notdir $(BASE_TE_FILES)); do \
Chris PeBenito fb0a3a
		echo "define(\`$$i')" >> $@ ;\
Chris PeBenito fb0a3a
	done
Chris PeBenito 5b45ff
	$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
Chris PeBenito fb0a3a
Chris PeBenito 3abd5e
$(TMPDIR)/global_bools.conf: M4PARAM += -D self_contained_policy
Chris PeBenito 3abd5e
$(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito 3abd5e
Chris PeBenito c9f20d
$(TMPDIR)/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 c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	@echo "divert(-1)" > $@
Chris PeBenito 3abd5e
	$(verbose) $(M4) $^ | $(SED) -e s/dollarsstar/\$$\*/g >> $@
Chris PeBenito 3abd5e
	@echo "divert" >> $@
Chris PeBenito 3abd5e
Chris PeBenito 3abd5e
$(TMPDIR)/rolemap.conf: M4PARAM += -D self_contained_policy
Chris PeBenito 3abd5e
$(TMPDIR)/rolemap.conf: $(ROLEMAP)
Chris PeBenito 3abd5e
	$(call parse-rolemap,base,$@)
Chris PeBenito fb0a3a
Chris PeBenito 3abd5e
$(TMPDIR)/all_te_files.conf: M4PARAM += -D self_contained_policy
Chris PeBenito 3abd5e
$(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(BASE_TE_FILES) $(TMPDIR)/rolemap.conf
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 c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) -s $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito 3abd5e
$(TMPDIR)/post_te_files.conf: M4PARAM += -D self_contained_policy
Chris PeBenito 3abd5e
$(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(BASE_POST_TE_FILES)
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
# extract attributes and put them first. extract post te stuff
Chris PeBenito 3abd5e
# like genfscon and put last.
Chris PeBenito c9f20d
$(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf: $(TMPDIR)/all_te_files.conf $(TMPDIR)/post_te_files.conf
Chris PeBenito f62f4c
	$(verbose) $(get_type_attr_decl) $(TMPDIR)/all_te_files.conf | $(SORT) > $(TMPDIR)/all_attrs_types.conf
Chris PeBenito c9f20d
	$(verbose) cat $(TMPDIR)/post_te_files.conf > $(TMPDIR)/all_post.conf
Chris PeBenito 3abd5e
# these have to run individually because order matters:
Chris PeBenito 3abd5e
	$(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(GREP) ^genfscon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5e
	$(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/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 c9f20d
$(BASE_FC): $(TMPDIR)/$(notdir $(BASE_FC)).tmp $(FCSORT)
Chris PeBenito 9b3756
	$(verbose) $(FCSORT) $< $@
Chris PeBenito c767b1
Chris PeBenito c9f20d
$(TMPDIR)/$(notdir $(BASE_FC)).tmp: $(M4SUPPORT) $(TMPDIR)/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 c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito bf080a
# Remove the dontaudit rules from the base.conf
Chris PeBenito bf080a
#
Chris PeBenito c9f20d
enableaudit: $(BASE_CONF)
Chris PeBenito c9f20d
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 58b2a3
	@echo "Removing dontaudit rules from $(^F)"
Chris PeBenito 3abd5e
	$(verbose) $(GREP) -v dontaudit $(BASE_CONF) > $(TMPDIR)/base.audit
Chris PeBenito c9f20d
	$(verbose) mv $(TMPDIR)/base.audit $(BASE_CONF)
Chris PeBenito bf080a
Chris PeBenito bf080a
########################################
Chris PeBenito bf080a
#
Chris PeBenito 049e11
# Appconfig files
Chris PeBenito 049e11
#
Chris PeBenito c9f20d
$(APPDIR)/customizable_types: $(BASE_CONF)
Chris PeBenito 049e11
	@mkdir -p $(APPDIR)
Chris PeBenito 3abd5e
	$(verbose) $(GREP) "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
Chris PeBenito c9f20d
	$(verbose) install -m 644 $(TMPDIR)/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 c9f20d
	rm -f $(BASE_CONF)
Chris PeBenito 712566
	rm -f $(BASE_FC)
Chris PeBenito 5b45ff
	rm -f $(BUILDDIR)*.pp
Chris PeBenito c9f20d
	rm -fR $(TMPDIR)
Chris PeBenito fb0a3a
Chris PeBenito ddb9aa
.PHONY: default all policy base modules install load clean