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
# install paths
Chris PeBenito fb0a3a
POLICYPATH = $(INSTALLDIR)/policy
Chris PeBenito fb0a3a
LOADPATH = $(POLICYPATH)/$(POLVER)
Chris PeBenito fb0a3a
FCPATH = $(CONTEXTPATH)/files/file_contexts
Chris PeBenito fb0a3a
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
Chris PeBenito fb0a3a
Chris PeBenito c767b1
FC := file_contexts
Chris PeBenito c767b1
POLVER := policy.$(PV)
Chris PeBenito 2ed0d1
Chris PeBenito 049e11
APPFILES += $(INSTALLDIR)/booleans
Chris PeBenito fb0a3a
Chris PeBenito c767b1
# for monolithic policy use all base and module to create policy
Chris PeBenito cf0ff5
ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS))
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
Chris PeBenito fb0a3a
ALL_TE_FILES := $(ALL_MODULES)
Chris PeBenito fb0a3a
ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
Chris PeBenito fb0a3a
Chris PeBenito a08248
PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
Chris PeBenito ffd048
POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
Chris PeBenito fb0a3a
Chris PeBenito 4f9f30
POLICY_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 c767b1
HOMEDIR_TEMPLATE = homedir_template
Chris PeBenito c767b1
Chris PeBenito c767b1
# search layer dirs for source files
Chris PeBenito c767b1
vpath %.te $(ALL_LAYERS)
Chris PeBenito c767b1
vpath %.if $(ALL_LAYERS)
Chris PeBenito c767b1
vpath %.fc $(ALL_LAYERS)
Chris PeBenito c767b1
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# default action: build policy locally
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
default: policy
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
policy: $(POLVER)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
load: tmp/load
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Build a binary policy locally
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(POLVER): policy.conf
Chris PeBenito fb0a3a
	@echo "Compiling $(NAME) $(POLVER)"
Chris PeBenito fb0a3a
ifneq ($(PV),$(KV))
Chris PeBenito fb0a3a
	@echo
Chris PeBenito fb0a3a
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito fb0a3a
	@echo
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	$(QUIET) $(CHECKPOLICY) $^ -o $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Install a binary policy
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(LOADPATH): policy.conf
Chris PeBenito fb0a3a
	@mkdir -p $(POLICYPATH)
Chris PeBenito fb0a3a
	@echo "Compiling and installing $(NAME) $(LOADPATH)"
Chris PeBenito fb0a3a
ifneq ($(PV),$(KV))
Chris PeBenito fb0a3a
	@echo
Chris PeBenito fb0a3a
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito fb0a3a
	@echo
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	$(QUIET) $(CHECKPOLICY) $^ -o $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Load the binary policy
Chris PeBenito fb0a3a
#
Chris PeBenito c767b1
reload tmp/load: $(LOADPATH) $(FCPATH) $(APPFILES)
Chris PeBenito fb0a3a
	@echo "Loading $(NAME) $(LOADPATH)"
Chris PeBenito fb0a3a
	$(QUIET) $(LOADPOLICY) -q $(LOADPATH)
Chris PeBenito fb0a3a
	@touch tmp/load
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct a monolithic policy.conf
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
policy.conf: $(POLICY_SECTIONS)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) 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: $(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 2a9456
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
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 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: $(ALL_TE_FILES)
Chris PeBenito fb0a3a
ifeq ($(ALL_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: $(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
# Remove the dontaudit rules from the policy.conf
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
enableaudit: policy.conf
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	@echo "Removing dontaudit rules from policy.conf"
Chris PeBenito fb0a3a
	$(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
Chris PeBenito fb0a3a
	$(QUIET) mv tmp/policy.audit policy.conf
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct file_contexts
Chris PeBenito fb0a3a
#
Chris PeBenito c767b1
$(FC): tmp/$(FC).tmp $(FCSORT)
Chris PeBenito c767b1
	$(QUIET) $(FCSORT) $< $@
Chris PeBenito c767b1
	$(QUIET) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
Chris PeBenito c767b1
	$(QUIET) sed -i -e /HOME/d -e /ROLE/d $@
Chris PeBenito c767b1
Chris PeBenito c767b1
tmp/$(FC).tmp: $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES)
Chris PeBenito fb0a3a
ifeq ($(ALL_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) 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 fb0a3a
# Install file_contexts
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
Chris PeBenito fb0a3a
	@echo "Validating $(NAME) file_contexts."
Chris PeBenito fb0a3a
	$(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC)
Chris PeBenito fb0a3a
	@echo "Installing file_contexts."
Chris PeBenito fb0a3a
	@mkdir -p $(CONTEXTPATH)/files
Chris PeBenito fb0a3a
	$(QUIET) install -m 644 $(FC) $(FCPATH)
Chris PeBenito fb0a3a
	$(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
Chris PeBenito fb0a3a
	$(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Filesystem labeling
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
Chris PeBenito fb0a3a
Chris PeBenito c767b1
checklabels: $(FCPATH) $(SETFILES)
Chris PeBenito c767b1
	@echo "Checking labels on filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito fb0a3a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito fb0a3a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito fb0a3a
		false ;\
Chris PeBenito fb0a3a
	fi
Chris PeBenito c767b1
	$(QUIET) $(SETFILES) -v -n $(FCPATH) $(FILESYSTEMS)
Chris PeBenito fb0a3a
Chris PeBenito c767b1
restorelabels: $(FCPATH) $(SETFILES)
Chris PeBenito c767b1
	@echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito fb0a3a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito fb0a3a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito fb0a3a
		false ;\
Chris PeBenito fb0a3a
	fi
Chris PeBenito c767b1
	$(QUIET) $(SETFILES) -v $(FCPATH) $(FILESYSTEMS)
Chris PeBenito fb0a3a
Chris PeBenito c767b1
relabel:  $(FCPATH) $(SETFILES)
Chris PeBenito c767b1
	@echo "Relabeling filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito fb0a3a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito fb0a3a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito fb0a3a
		false ;\
Chris PeBenito fb0a3a
	fi
Chris PeBenito c767b1
	$(QUIET) $(SETFILES) $(FCPATH) $(FILESYSTEMS)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito 8df65f
# Run policy source checks
Chris PeBenito 8df65f
#
Chris PeBenito 8df65f
check: policy.conf $(FC)
Chris PeBenito 8df65f
	$(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res
Chris PeBenito 8df65f
Chris PeBenito 8df65f
longcheck: policy.conf $(FC)
Chris PeBenito 8df65f
	$(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res
Chris PeBenito 8df65f
Chris PeBenito 8df65f
########################################
Chris PeBenito 8df65f
#
Chris PeBenito 049e11
# Appconfig files
Chris PeBenito 049e11
#
Chris PeBenito 049e11
$(APPDIR)/customizable_types: policy.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 policy.conf
Chris PeBenito fb0a3a
	rm -f policy.$(PV)
Chris PeBenito fb0a3a
	rm -f $(FC)
Chris PeBenito c767b1
	rm -f $(HOMEDIR_TEMPLATE)
Chris PeBenito 8df65f
	rm -f *.res
Chris PeBenito c767b1
	rm -fR tmp
Chris PeBenito fb0a3a
Chris PeBenito 8df65f
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean