Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Rules and Targets for building monolithic policies
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
Chris PeBenito 5b45ffb
POLICY_CONF = $(BUILDDIR)policy.conf
Chris PeBenito 5b45ffb
FC = $(BUILDDIR)file_contexts
Chris PeBenito 5b45ffb
POLVER = $(BUILDDIR)policy.$(PV)
Chris PeBenito 5b45ffb
HOMEDIR_TEMPLATE = $(BUILDDIR)homedir_template
Chris PeBenito c9f20d5
Chris PeBenito 3abd5ee
M4PARAM += -D self_contained_policy
Chris PeBenito 3abd5ee
Chris PeBenito fb0a3a9
# install paths
Chris PeBenito fb0a3a9
POLICYPATH = $(INSTALLDIR)/policy
Chris PeBenito 5b45ffb
LOADPATH = $(POLICYPATH)/$(notdir $(POLVER))
Chris PeBenito fb0a3a9
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
Chris PeBenito fb0a3a9
Chris PeBenito eb8a263
APPFILES += $(INSTALLDIR)/booleans $(USERPATH)/local.users
Chris PeBenito fb0a3a9
Chris PeBenito c767b14
# for monolithic policy use all base and module to create policy
Chris PeBenito cf0ff55
ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS))
Chris PeBenito ab23bb9
# off module interfaces included to make sure all interfaces are expanded.
Chris PeBenito ab23bb9
ALL_INTERFACES := $(ALL_MODULES:.te=.if) $(OFF_MODS:.te=.if)
Chris PeBenito fb0a3a9
ALL_TE_FILES := $(ALL_MODULES)
Chris PeBenito fb0a3a9
ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
Chris PeBenito fb0a3a9
Chris PeBenito a082484
PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
Chris PeBenito ffd0484
POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
Chris PeBenito fb0a3a9
Chris PeBenito 3abd5ee
POLICY_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 c767b14
Chris PeBenito c767b14
# search layer dirs for source files
Chris PeBenito e2680fb
vpath %.te $(ALL_LAYERS)
Chris PeBenito e2680fb
vpath %.if $(ALL_LAYERS)
Chris PeBenito e2680fb
vpath %.fc $(ALL_LAYERS)
Chris PeBenito c767b14
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# default action: build policy locally
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
default: policy
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
policy: $(POLVER)
Chris PeBenito fb0a3a9
Chris PeBenito eb8a263
install: $(LOADPATH) $(FCPATH) $(NCPATH) $(APPFILES)
Chris PeBenito fb0a3a9
Chris PeBenito c9f20d5
load: $(TMPDIR)/load
Chris PeBenito fb0a3a9
Chris PeBenito 120988c
checklabels: $(FCPATH)
Chris PeBenito 120988c
restorelabels: $(FCPATH)
Chris PeBenito 120988c
relabel:  $(FCPATH)
Chris PeBenito 120988c
resetlabels:  $(FCPATH)
Chris PeBenito 120988c
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Build a binary policy locally
Chris PeBenito fb0a3a9
#
Chris PeBenito c9f20d5
$(POLVER): $(POLICY_CONF)
Chris PeBenito fb0a3a9
	@echo "Compiling $(NAME) $(POLVER)"
Chris PeBenito fb0a3a9
ifneq ($(PV),$(KV))
Chris PeBenito fb0a3a9
	@echo
Chris PeBenito fb0a3a9
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito fb0a3a9
	@echo
Chris PeBenito fb0a3a9
endif
Chris PeBenito 5b45ffb
	$(verbose) $(CHECKPOLICY) $^ -o $@
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Install a binary policy
Chris PeBenito fb0a3a9
#
Chris PeBenito c9f20d5
$(LOADPATH): $(POLICY_CONF)
Chris PeBenito fb0a3a9
	@mkdir -p $(POLICYPATH)
Chris PeBenito fb0a3a9
	@echo "Compiling and installing $(NAME) $(LOADPATH)"
Chris PeBenito fb0a3a9
ifneq ($(PV),$(KV))
Chris PeBenito fb0a3a9
	@echo
Chris PeBenito fb0a3a9
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito fb0a3a9
	@echo
Chris PeBenito fb0a3a9
endif
Chris PeBenito 9b3756b
	$(verbose) $(CHECKPOLICY) $^ -o $@
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Load the binary policy
Chris PeBenito fb0a3a9
#
Chris PeBenito eb8a263
reload $(TMPDIR)/load: $(LOADPATH) $(FCPATH) $(NCPATH) $(APPFILES)
Chris PeBenito fb0a3a9
	@echo "Loading $(NAME) $(LOADPATH)"
Chris PeBenito 9b3756b
	$(verbose) $(LOADPOLICY) -q $(LOADPATH)
Chris PeBenito c9f20d5
	@touch $(TMPDIR)/load
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Construct a monolithic policy.conf
Chris PeBenito fb0a3a9
#
Chris PeBenito c9f20d5
$(POLICY_CONF): $(POLICY_SECTIONS)
Chris PeBenito c9f20d5
	@echo "Creating $(NAME) $(@F)"
Chris PeBenito 3abd5ee
	@test -d $(@D) || mkdir -p $(@D)
Chris PeBenito 3abd5ee
	$(verbose) cat $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito c9f20d5
$(TMPDIR)/pre_te_files.conf: $(PRE_TE_FILES)
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito 988a441
$(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES)
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 7013167
# define all available object classes
Chris PeBenito 7013167
	$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@
Chris PeBenito 7013167
# per-userdomain templates:
Chris PeBenito 7013167
	$(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
Chris PeBenito 3abd5ee
	$(verbose) $(foreach mod,$(basename $(notdir $(ALL_MODULES))), \
Chris PeBenito 3abd5ee
		echo "ifdef(\`""$(mod)""_per_userdomain_template',\`""$(mod)""_per_userdomain_template("'$$*'")')" >> $@ ;)
Chris PeBenito 9b3756b
	$(verbose) echo "')" >> $@
Chris PeBenito 5b45ffb
	$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
Chris PeBenito fb0a3a9
Chris PeBenito 3abd5ee
$(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito 3abd5ee
Chris PeBenito c9f20d5
$(TMPDIR)/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 5706fac
	@echo "ifdef(\`__if_error',\`m4exit(1)')" > $(TMPDIR)/iferror.m4
Chris PeBenito 3abd5ee
	@echo "divert(-1)" > $@
Chris PeBenito 5706fac
	$(verbose) $(M4) $^ $(TMPDIR)/iferror.m4 >> $(TMPDIR)/$(@F).tmp
Chris PeBenito 5706fac
	$(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(TMPDIR)/$(@F).tmp >> $@
Chris PeBenito 3abd5ee
	@echo "divert" >> $@
Chris PeBenito fb0a3a9
Chris PeBenito 3abd5ee
$(TMPDIR)/rolemap.conf: $(ROLEMAP)
Chris PeBenito 3abd5ee
	$(call parse-rolemap,base,$@)
Chris PeBenito 3abd5ee
Chris PeBenito 3abd5ee
$(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(ALL_TE_FILES) $(TMPDIR)/rolemap.conf
Chris PeBenito c72f53f
ifeq "$(strip $(ALL_TE_FILES))" ""
Chris PeBenito fb0a3a9
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a9
endif
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) -s $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito 3abd5ee
$(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(POST_TE_FILES)
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
# extract attributes and put them first. extract post te stuff
Chris PeBenito 3abd5ee
# like genfscon and put last.
Chris PeBenito c9f20d5
$(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 f62f4c7
	$(verbose) $(get_type_attr_decl) $(TMPDIR)/all_te_files.conf | $(SORT) > $(TMPDIR)/all_attrs_types.conf
Chris PeBenito c9f20d5
	$(verbose) cat $(TMPDIR)/post_te_files.conf > $(TMPDIR)/all_post.conf
Chris PeBenito 3abd5ee
# these have to run individually because order matters:
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) ^genfscon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
Chris PeBenito 3abd5ee
	$(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Remove the dontaudit rules from the policy.conf
Chris PeBenito fb0a3a9
#
Chris PeBenito c9f20d5
enableaudit: $(POLICY_CONF)
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito c9f20d5
	@echo "Removing dontaudit rules from $(notdir $(POLICY_CONF))"
Chris PeBenito 8e86e4e
	$(verbose) $(GREP) -v dontaudit $^ > $(TMPDIR)/policy.audit
Chris PeBenito c9f20d5
	$(verbose) mv $(TMPDIR)/policy.audit $(POLICY_CONF)
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Construct file_contexts
Chris PeBenito fb0a3a9
#
Chris PeBenito c9f20d5
$(FC): $(TMPDIR)/$(notdir $(FC)).tmp $(FCSORT)
Chris PeBenito 5d92a20
	$(verbose) $(FCSORT) $< $@
Chris PeBenito 3abd5ee
	$(verbose) $(GREP) -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
Chris PeBenito 3abd5ee
	$(verbose) $(SED) -i -e /HOME/d -e /ROLE/d $@
Chris PeBenito c767b14
Chris PeBenito c9f20d5
$(TMPDIR)/$(notdir $(FC)).tmp: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(ALL_FC_FILES)
Chris PeBenito fb0a3a9
ifeq ($(ALL_FC_FILES),)
Chris PeBenito fb0a3a9
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a9
endif
Chris PeBenito fb0a3a9
	@echo "Creating $(NAME) file_contexts."
Chris PeBenito c9f20d5
	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito fc47b34
$(HOMEDIR_TEMPLATE): $(FC)
Chris PeBenito fc47b34
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Install file_contexts
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
Chris PeBenito fb0a3a9
	@echo "Validating $(NAME) file_contexts."
Chris PeBenito 9b3756b
	$(verbose) $(SETFILES) -q -c $(LOADPATH) $(FC)
Chris PeBenito fb0a3a9
	@echo "Installing file_contexts."
Chris PeBenito fb0a3a9
	@mkdir -p $(CONTEXTPATH)/files
Chris PeBenito cfd5c5e
	$(verbose) $(INSTALL) -m 644 $(FC) $(FCPATH)
Chris PeBenito cfd5c5e
	$(verbose) $(INSTALL) -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
Chris PeBenito fc47b34
	$(verbose) $(genhomedircon) -d $(TOPDIR) -t $(NAME) $(USEPWD)
Chris PeBenito fc47b34
ifeq "$(DISTRO)" "rhel4"
Chris PeBenito fc47b34
# Setfiles in RHEL4 does not look at file_contexts.homedirs.
Chris PeBenito fc47b34
	$(verbose) cat $@.homedirs >> $@
Chris PeBenito fc47b34
# Delete the file_contexts.homedirs in case the toolchain has
Chris PeBenito fc47b34
# been updated, to prevent duplicate match errors.
Chris PeBenito fc47b34
	$(verbose) rm -f $@.homedirs
Chris PeBenito 185ab24
endif
Chris PeBenito fb0a3a9
Chris PeBenito fb0a3a9
########################################
Chris PeBenito 5a7c06f
#
Chris PeBenito 5a7c06f
# Intall netfilter_contexts
Chris PeBenito 5a7c06f
#
Chris PeBenito 5a7c06f
$(NCPATH): $(net_contexts)
Chris PeBenito 5a7c06f
	@echo "Installing $(NAME) netfilter_contexts."
Chris PeBenito cfd5c5e
	$(verbose) $(INSTALL) -m 0644 $^ $@
Chris PeBenito 5a7c06f
Chris PeBenito 5a7c06f
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito 8df65f1
# Run policy source checks
Chris PeBenito 8df65f1
#
Chris PeBenito 5b45ffb
check: $(BUILDDIR)check.res
Chris PeBenito 5b45ffb
$(BUILDDIR)check.res: $(POLICY_CONF) $(FC)
Chris PeBenito 5b45ffb
	$(SECHECK) -s --profile=development --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
Chris PeBenito 8df65f1
Chris PeBenito 5b45ffb
longcheck: $(BUILDDIR)longcheck.res
Chris PeBenito 5b45ffb
$(BUILDDIR)longcheck.res: $(POLICY_CONF) $(FC)
Chris PeBenito 5b45ffb
	$(SECHECK) -s --profile=all --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
Chris PeBenito 8df65f1
Chris PeBenito 8df65f1
########################################
Chris PeBenito 8df65f1
#
Chris PeBenito 049e11a
# Appconfig files
Chris PeBenito 049e11a
#
Chris PeBenito efc94af
$(APPDIR)/customizable_types: $(POLICY_CONF)
Chris PeBenito 049e11a
	@mkdir -p $(APPDIR)
Chris PeBenito 85a0f96
	$(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(TMPDIR)/customizable_types
Chris PeBenito cfd5c5e
	$(verbose) $(INSTALL) -m 644 $(TMPDIR)/customizable_types $@ 
Chris PeBenito 049e11a
Chris PeBenito 049e11a
########################################
Chris PeBenito 049e11a
#
Chris PeBenito fb0a3a9
# Clean the sources
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
clean:
Chris PeBenito c9f20d5
	rm -f $(POLICY_CONF)
Chris PeBenito 5b45ffb
	rm -f $(POLVER)
Chris PeBenito fb0a3a9
	rm -f $(FC)
Chris PeBenito c767b14
	rm -f $(HOMEDIR_TEMPLATE)
Chris PeBenito 6962bb3
	rm -f $(net_contexts)
Chris PeBenito 8df65f1
	rm -f *.res
Chris PeBenito c9f20d5
	rm -fR $(TMPDIR)
Chris PeBenito fb0a3a9
Chris PeBenito 8df65f1
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean