Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Rules and Targets for building monolithic policies
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
# determine the policy version and current kernel version if possible
Chris PeBenito c634db2
pv := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
Chris PeBenito c634db2
kv := $(shell cat /selinux/policyvers)
Chris PeBenito c634db2
Chris PeBenito c634db2
# dont print version warnings if we are unable to determine
Chris PeBenito c634db2
# the currently running kernel's policy version
Chris PeBenito c634db2
ifeq "$(kv)" ""
Chris PeBenito c634db2
	kv := $(pv)
Chris PeBenito c634db2
endif
Chris PeBenito c634db2
Chris PeBenito c634db2
policy_conf = $(builddir)policy.conf
Chris PeBenito c634db2
fc = $(builddir)file_contexts
Chris PeBenito c634db2
polver = $(builddir)policy.$(pv)
Chris PeBenito c634db2
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 c634db2
loadpath = $(policypath)/$(notdir $(polver))
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
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 c634db2
all_modules := $(strip $(base_mods) $(mod_mods))
Chris PeBenito ab23bb9
# off module interfaces included to make sure all interfaces are expanded.
Chris PeBenito c634db2
all_interfaces := $(all_modules:.te=.if) $(off_mods:.te=.if)
Chris PeBenito c634db2
all_te_files := $(all_modules)
Chris PeBenito c634db2
all_fc_files := $(all_modules:.te=.fc)
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
pre_te_files := $(secclass) $(isids) $(avs) $(m4support) $(poldir)/mls $(poldir)/mcs
Chris PeBenito c634db2
post_te_files := $(user_files) $(poldir)/constraints
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
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 c634db2
vpath %.te $(all_layers)
Chris PeBenito c634db2
vpath %.if $(all_layers)
Chris PeBenito c634db2
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 c634db2
policy: $(polver)
Chris PeBenito fb0a3a9
Chris PeBenito d17bab0
install: $(loadpath) $(fcpath) $(appfiles)
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
load: $(tmpdir)/load
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
checklabels: $(fcpath)
Chris PeBenito c634db2
restorelabels: $(fcpath)
Chris PeBenito c634db2
relabel:  $(fcpath)
Chris PeBenito c634db2
resetlabels:  $(fcpath)
Chris PeBenito 120988c
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Build a binary policy locally
Chris PeBenito fb0a3a9
#
Chris PeBenito 8acfcbc
ifneq "$(UNK_PERMS)" ""
Chris PeBenito 8acfcbc
$(polver): CHECKPOLICY += -U $(UNK_PERMS)
Chris PeBenito 8acfcbc
endif
Chris PeBenito c634db2
$(polver): $(policy_conf)
Chris PeBenito c634db2
	@echo "Compiling $(NAME) $(polver)"
Chris PeBenito c634db2
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 8acfcbc
ifneq "$(UNK_PERMS)" ""
Chris PeBenito 8acfcbc
$(loadpath): CHECKPOLICY += -U $(UNK_PERMS)
Chris PeBenito 8acfcbc
endif
Chris PeBenito c634db2
$(loadpath): $(policy_conf)
Chris PeBenito c634db2
	@mkdir -p $(policypath)
Chris PeBenito c634db2
	@echo "Compiling and installing $(NAME) $(loadpath)"
Chris PeBenito c634db2
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 c634db2
reload $(tmpdir)/load: $(loadpath) $(fcpath) $(ncpath) $(appfiles)
Chris PeBenito c634db2
	@echo "Loading $(NAME) $(loadpath)"
Chris PeBenito c634db2
	$(verbose) $(LOADPOLICY) -q $(loadpath)
Chris PeBenito c634db2
	@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 c634db2
$(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 c634db2
$(tmpdir)/pre_te_files.conf: $(pre_te_files)
Chris PeBenito c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
$(tmpdir)/generated_definitions.conf: $(all_te_files)
Chris PeBenito c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 7013167
# define all available object classes
Chris PeBenito c634db2
	$(verbose) $(genperm) $(avs) $(secclass) > $@
Chris PeBenito bbcd3c9
	$(verbose) $(call create-base-per-role-tmpl,$(basename $(notdir $(all_modules))),$@)
Chris PeBenito c634db2
	$(verbose) test -f $(booleans) && $(setbools) $(booleans) >> $@ || true
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
$(tmpdir)/global_bools.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(globalbool) $(globaltun)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito 3abd5ee
Chris PeBenito c634db2
$(tmpdir)/all_interfaces.conf: $(m4support) $(all_interfaces)
Chris PeBenito c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito c634db2
	@echo "ifdef(\`__if_error',\`m4exit(1)')" > $(tmpdir)/iferror.m4
Chris PeBenito 3abd5ee
	@echo "divert(-1)" > $@
Chris PeBenito c634db2
	$(verbose) $(M4) $^ $(tmpdir)/iferror.m4 >> $(tmpdir)/$(@F).tmp
Chris PeBenito c634db2
	$(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(tmpdir)/$(@F).tmp >> $@
Chris PeBenito 3abd5ee
	@echo "divert" >> $@
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
$(tmpdir)/rolemap.conf: $(rolemap)
Chris PeBenito 96fc0a4
	$(verbose) echo "" > $@
Chris PeBenito 3abd5ee
	$(call parse-rolemap,base,$@)
Chris PeBenito 3abd5ee
Chris PeBenito c634db2
$(tmpdir)/all_te_files.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf $(all_te_files) $(tmpdir)/rolemap.conf
Chris PeBenito c634db2
ifeq "$(strip $(all_te_files))" ""
Chris PeBenito c634db2
	$(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a9
endif
Chris PeBenito c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) -s $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
$(tmpdir)/post_te_files.conf: $(m4support) $(post_te_files)
Chris PeBenito c634db2
	@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 c634db2
$(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 c634db2
	$(verbose) $(get_type_attr_decl) $(tmpdir)/all_te_files.conf | $(SORT) > $(tmpdir)/all_attrs_types.conf
Chris PeBenito c634db2
	$(verbose) cat $(tmpdir)/post_te_files.conf > $(tmpdir)/all_post.conf
Chris PeBenito 3abd5ee
# these have to run individually because order matters:
Chris PeBenito c634db2
	$(verbose) $(GREP) '^sid ' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(verbose) $(GREP) ^genfscon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
Chris PeBenito c634db2
	$(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 c634db2
enableaudit: $(policy_conf)
Chris PeBenito c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito c634db2
	@echo "Removing dontaudit rules from $(notdir $(policy_conf))"
Chris PeBenito c634db2
	$(verbose) $(GREP) -v dontaudit $^ > $(tmpdir)/policy.audit
Chris PeBenito c634db2
	$(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 c634db2
$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsort)
Chris PeBenito c634db2
	$(verbose) $(fcsort) $< $@
Chris PeBenito c634db2
	$(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 c634db2
$(tmpdir)/$(notdir $(fc)).tmp: $(m4support) $(tmpdir)/generated_definitions.conf $(all_fc_files)
Chris PeBenito c634db2
ifeq ($(all_fc_files),)
Chris PeBenito c634db2
	$(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 c634db2
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 3abd5ee
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito fb0a3a9
Chris PeBenito c634db2
$(homedir_template): $(fc)
Chris PeBenito fc47b34
Chris PeBenito fb0a3a9
########################################
Chris PeBenito fb0a3a9
#
Chris PeBenito fb0a3a9
# Install file_contexts
Chris PeBenito fb0a3a9
#
Chris PeBenito c634db2
$(fcpath): $(fc) $(loadpath) $(userpath)/system.users
Chris PeBenito fb0a3a9
	@echo "Validating $(NAME) file_contexts."
Chris PeBenito c634db2
	$(verbose) $(SETFILES) -q -c $(loadpath) $(fc)
Chris PeBenito fb0a3a9
	@echo "Installing file_contexts."
Chris PeBenito c634db2
	@mkdir -p $(contextpath)/files
Chris PeBenito c634db2
	$(verbose) $(INSTALL) -m 644 $(fc) $(fcpath)
Chris PeBenito c634db2
	$(verbose) $(INSTALL) -m 644 $(homedir_template) $(homedirpath)
Chris PeBenito c634db2
	$(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 c634db2
$(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 c634db2
check: $(builddir)check.res
Chris PeBenito c634db2
$(builddir)check.res: $(policy_conf) $(fc)
Chris PeBenito c634db2
	$(SECHECK) -s --profile=development --policy=$(policy_conf) --fcfile=$(fc) > $@
Chris PeBenito 8df65f1
Chris PeBenito c634db2
longcheck: $(builddir)longcheck.res
Chris PeBenito c634db2
$(builddir)longcheck.res: $(policy_conf) $(fc)
Chris PeBenito c634db2
	$(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 c634db2
$(appdir)/customizable_types: $(policy_conf)
Chris PeBenito c634db2
	@mkdir -p $(appdir)
Chris PeBenito c634db2
	$(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(tmpdir)/customizable_types
Chris PeBenito c634db2
	$(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 c634db2
	rm -f $(policy_conf)
Chris PeBenito c634db2
	rm -f $(polver)
Chris PeBenito c634db2
	rm -f $(fc)
Chris PeBenito c634db2
	rm -f $(homedir_template)
Chris PeBenito 6962bb3
	rm -f $(net_contexts)
Chris PeBenito 8df65f1
	rm -f *.res
Chris PeBenito c634db2
	rm -fR $(tmpdir)
Chris PeBenito fb0a3a9
Chris PeBenito 8df65f1
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean