Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
# Makefile for the security policy.
Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
# Targets:
Chris PeBenito 88d14a
# 
Chris PeBenito 88d14a
# install       - compile and install the policy configuration, and context files.
Chris PeBenito 88d14a
# load          - compile, install, and load the policy configuration.
Chris PeBenito 88d14a
# reload        - compile, install, and load/reload the policy configuration.
Chris PeBenito 88d14a
# relabel       - relabel filesystems based on the file contexts configuration.
Chris PeBenito 88d14a
# checklabels   - check filesystems against the file context configuration
Chris PeBenito 88d14a
# restorelabels - check filesystems against the file context configuration
Chris PeBenito 88d14a
#                 and restore the label of files with incorrect labels
Chris PeBenito 88d14a
# policy        - compile the policy configuration locally for testing/development.
Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
# The default target is 'policy'.
Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Configurable portions of the Makefile
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito 25a0c6
# Policy version
Chris PeBenito 25a0c6
# By default, checkpolicy will create the highest
Chris PeBenito 25a0c6
# version policy it supports.  Setting this will
Chris PeBenito 25a0c6
# override the version.
Karl MacMillan ebb884
#OUTPUT_POLICY = 18
Chris PeBenito 134191
Chris PeBenito b67488
# Policy Type
Chris PeBenito b67488
# strict, targeted, strict-mls, targeted-mls
Chris PeBenito b67488
# strict and strict-mls are currently supported.
Chris PeBenito b67488
TYPE = strict
Chris PeBenito b4cd15
Chris PeBenito 25a0c6
# Policy Name
Chris PeBenito b67488
# If set, this will be used as the policy
Chris PeBenito b67488
# name.  Otherwise the policy type will be
Chris PeBenito b67488
# used for the name.
Karl MacMillan ebb884
NAME = refpolicy
Chris PeBenito b67488
Chris PeBenito 25a0c6
# Distribution
Chris PeBenito 25a0c6
# Some distributions have portions of policy
Chris PeBenito 25a0c6
# for programs or configurations specific to the
Chris PeBenito 25a0c6
# distribution.  Setting this will enable options
Chris PeBenito 25a0c6
# for the distribution.
Chris PeBenito 25a0c6
# redhat, gentoo, debian, and suse are current options.
Chris PeBenito 25a0c6
# Fedora users should enable redhat.
Chris PeBenito 25a0c6
#DISTRO = redhat
Chris PeBenito 25a0c6
Chris PeBenito b67488
# Build monolithic policy.  Putting n here
Chris PeBenito b67488
# will build a loadable module policy.
Chris PeBenito b67488
# Only monolithic policies are currently supported.
Chris PeBenito b67488
MONOLITHIC=y
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Uncomment this to disable command echoing
Chris PeBenito b4cd15
#QUIET:=@
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b67488
# NO OPTIONS BELOW HERE
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# executable paths
Chris PeBenito b4cd15
PREFIX := /usr
Chris PeBenito b4cd15
BINDIR := $(PREFIX)/bin
Chris PeBenito b4cd15
SBINDIR := $(PREFIX)/sbin
Chris PeBenito b4cd15
CHECKPOLICY := $(BINDIR)/checkpolicy
Chris PeBenito 547283
LOADPOLICY := $(SBINDIR)/load_policy
Chris PeBenito b4cd15
SETFILES := $(SBINDIR)/setfiles
Chris PeBenito 1beba1
GENHOMEDIRCON := $(SBINDIR)/genhomedircon
Chris PeBenito 044735
Chris PeBenito c7b41e
CFLAGS := -Wall
Chris PeBenito c7b41e
Chris PeBenito 3a80ec
SUPPORT := support
Chris PeBenito 95db42
GENXML := $(SUPPORT)/segenxml.py
Chris PeBenito 3a80ec
GENDOC := $(SUPPORT)/sedoctool.py
Chris PeBenito 254bbc
FCSORT := $(SUPPORT)/fc_sort
Chris PeBenito 84eb35
SETTUN := $(SUPPORT)/set_tunables
Chris PeBenito 3a80ec
Chris PeBenito 004db9
XMLLINT := $(BINDIR)/xmllint
Chris PeBenito b4cd15
Chris PeBenito 134191
# enable MLS if requested.
Chris PeBenito b67488
ifneq ($(findstring mls,$(TYPE)),)
Chris PeBenito 134191
	override M4PARAM += -D enable_mls
Chris PeBenito 134191
	CHECKPOLICY += -M
Chris PeBenito 134191
endif
Chris PeBenito 134191
Chris PeBenito b67488
# compile targeted policy if requested.
Chris PeBenito b67488
ifneq ($(findstring targeted,$(TYPE)),)
Chris PeBenito b67488
	override M4PARAM += -D targeted_policy
Chris PeBenito b67488
endif
Chris PeBenito b67488
Chris PeBenito 25a0c6
# enable distribution-specific policy
Chris PeBenito 25a0c6
ifneq ($(DISTRO),)
Chris PeBenito 25a0c6
	override M4PARAM += -D distro_$(DISTRO)
Chris PeBenito 25a0c6
endif
Chris PeBenito 25a0c6
Chris PeBenito b67488
ifeq ($(MONOLITHIC),y)
Chris PeBenito b67488
	override M4PARAM += -D monolithic_policy
Chris PeBenito b67488
endif
Chris PeBenito b67488
Chris PeBenito b67488
ifneq ($(OUTPUT_POLICY),)
Chris PeBenito b67488
	CHECKPOLICY += -c $(OUTPUT_POLICY)
Chris PeBenito b67488
endif
Chris PeBenito b67488
Chris PeBenito b67488
ifeq ($(NAME),)
Chris PeBenito b67488
	NAME := $(TYPE)
Chris PeBenito 134191
endif
Chris PeBenito 134191
Chris PeBenito b4cd15
# determine the policy version and current kernel version if possible
Chris PeBenito 134191
PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
Chris PeBenito b4cd15
KV := $(shell cat /selinux/policyvers)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# dont print version warnings if we are unable to determine
Chris PeBenito b4cd15
# the currently running kernel's policy version
Chris PeBenito b4cd15
ifeq ($(KV),)
Chris PeBenito 134191
	KV := $(PV)
Chris PeBenito b4cd15
endif
Chris PeBenito b4cd15
Chris PeBenito b4cd15
FC := file_contexts
Chris PeBenito b4cd15
POLVER := policy.$(PV)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# install paths
Chris PeBenito b4cd15
TOPDIR = $(DESTDIR)/etc/selinux
Chris PeBenito b67488
INSTALLDIR = $(TOPDIR)/$(NAME)
Chris PeBenito b4cd15
POLICYPATH = $(INSTALLDIR)/policy
Chris PeBenito b4cd15
SRCPATH = $(INSTALLDIR)/src
Chris PeBenito b4cd15
USERPATH = $(INSTALLDIR)/users
Chris PeBenito b4cd15
CONTEXTPATH = $(INSTALLDIR)/contexts
Chris PeBenito b4cd15
LOADPATH = $(POLICYPATH)/$(POLVER)
Chris PeBenito b4cd15
FCPATH = $(CONTEXTPATH)/files/file_contexts
Chris PeBenito b4cd15
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
Chris PeBenito b4cd15
Chris PeBenito b67488
POLDIR = policy
Chris PeBenito b67488
MODDIR = $(POLDIR)/modules
Chris PeBenito b67488
Chris PeBenito b67488
BASE_MODULE = $(MODDIR)/kernel
Chris PeBenito b67488
FLASKDIR = $(POLDIR)/flask
Chris PeBenito c98340
ifneq ($(findstring targeted,$(TYPE)),)
Chris PeBenito c98340
	APPCONF := config/appconfig-targeted
Chris PeBenito c98340
else
Chris PeBenito c98340
	APPCONF := config/appconfig-strict
Chris PeBenito c98340
endif
Chris PeBenito 0350b1
M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
Chris PeBenito b4cd15
Chris PeBenito 84eb35
GLOBALTUN := $(POLDIR)/global_tunables
Chris PeBenito 19db6b
MOD_CONF := $(POLDIR)/modules.conf
Chris PeBenito 84eb35
TUNABLES := $(POLDIR)/tunables.conf
Chris PeBenito 0fbe15
Chris PeBenito c9a26b
APPDIR := $(CONTEXTPATH)
Chris PeBenito 1beba1
APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media $(INSTALLDIR)/booleans
Chris PeBenito 2926f9
CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
Chris PeBenito b67488
USER_FILES := $(POLDIR)/users 
Chris PeBenito c9a26b
Chris PeBenito 57869a
ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
Chris PeBenito e12e57
Chris PeBenito e12e57
GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
Chris PeBenito e12e57
GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
Chris PeBenito e12e57
GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
Chris PeBenito e12e57
Chris PeBenito 8ae194
# sort here since it removes duplicates, which can happen
Chris PeBenito 8ae194
# when a generated file is already generated
Chris PeBenito 8ae194
DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
Chris PeBenito 19db6b
Chris PeBenito e8b3e3
MODBASE := base
Chris PeBenito e8b3e3
MODMOD := module
Chris PeBenito a3fdce
BASE_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te)))
Chris PeBenito a3fdce
MOD_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te)))
Chris PeBenito e8b3e3
Chris PeBenito e8b3e3
# for monolithic policy use all base and module to create policy
Chris PeBenito e8b3e3
# for modular policy, use only base
Chris PeBenito e8b3e3
ifeq ($(MONOLITHIC),y)
Chris PeBenito e8b3e3
	ENABLEMOD := $(BASE_MODS) $(MOD_MODS)
Chris PeBenito e8b3e3
else
Chris PeBenito e8b3e3
	ENABLEMOD := $(BASE_MODS)
Chris PeBenito e8b3e3
endif
Chris PeBenito e8b3e3
Chris PeBenito 19db6b
ALL_MODULES := $(filter $(ENABLEMOD),$(DETECTED_MODS))
Chris PeBenito b4cd15
Chris PeBenito b67488
PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls
Chris PeBenito 0fbe15
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
Chris PeBenito 0fbe15
ALL_TE_FILES := $(ALL_MODULES)
Chris PeBenito b67488
POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints
Chris PeBenito b4cd15
Chris PeBenito 0fbe15
ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
Chris PeBenito 92e928
HOMEDIR_TEMPLATE = tmp/homedir_template
Chris PeBenito b4cd15
Chris PeBenito 84eb35
POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
Chris PeBenito b4cd15
Chris PeBenito 20030e
DOCS = doc
Chris PeBenito 12b559
POLXML = $(DOCS)/policy.xml
Chris PeBenito 20030e
XMLDTD = $(DOCS)/policy.dtd
Chris PeBenito 57869a
LAYERXML = metadata.xml
Chris PeBenito 20030e
HTMLDIR = $(DOCS)/html
Chris PeBenito 20030e
DOCTEMPLATE = $(DOCS)/templates
Chris PeBenito 36e54b
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# default action: build policy locally
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
default: policy
Chris PeBenito b4cd15
Chris PeBenito b4cd15
policy: $(POLVER)
Chris PeBenito b4cd15
Chris PeBenito 44cda5
install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
Chris PeBenito c9a26b
Chris PeBenito c9a26b
load: tmp/load
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Build a binary policy locally
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
$(POLVER): policy.conf
Chris PeBenito b67488
	@echo "Compiling $(NAME) $(POLVER)"
Chris PeBenito b4cd15
ifneq ($(PV),$(KV))
Chris PeBenito b4cd15
	@echo
Chris PeBenito b67488
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito b4cd15
	@echo
Chris PeBenito b4cd15
endif
Chris PeBenito 134191
	$(QUIET) $(CHECKPOLICY) $^ -o $@
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Install a binary policy
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
$(LOADPATH): policy.conf
Chris PeBenito b4cd15
	@mkdir -p $(POLICYPATH)
Chris PeBenito b67488
	@echo "Compiling and installing $(NAME) $(LOADPATH)"
Chris PeBenito b4cd15
ifneq ($(PV),$(KV))
Chris PeBenito b4cd15
	@echo
Chris PeBenito b67488
	@echo "WARNING: Policy version mismatch!  Is your OUTPUT_POLICY set correctly?"
Chris PeBenito b4cd15
	@echo
Chris PeBenito b4cd15
endif
Chris PeBenito 134191
	$(QUIET) $(CHECKPOLICY) $^ -o $@
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito 88d14a
# Load the binary policy
Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
reload tmp/load: $(LOADPATH) $(FCPATH)
Chris PeBenito b67488
	@echo "Loading $(NAME) $(LOADPATH)"
Chris PeBenito 88d14a
	$(QUIET) $(LOADPOLICY) -q $(LOADPATH)
Chris PeBenito 88d14a
	@touch tmp/load
Chris PeBenito 88d14a
Chris PeBenito 88d14a
########################################
Chris PeBenito 88d14a
#
Chris PeBenito b4cd15
# Construct a monolithic policy.conf
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
policy.conf: $(POLICY_SECTIONS)
Chris PeBenito b67488
	@echo "Creating $(NAME) policy.conf"
Chris PeBenito d2d6c8
# checkpolicy can use the #line directives provided by -s for error reporting:
Chris PeBenito b67488
	$(QUIET) m4 $(M4PARAM) -s $^ > tmp/$@.tmp
Chris PeBenito b4cd15
	$(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
Chris PeBenito d2d6c8
# the ordering of these ocontexts matters:
Chris PeBenito b4cd15
	$(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
Chris PeBenito b4cd15
	$(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
Chris PeBenito b4cd15
	$(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
Chris PeBenito b4cd15
Chris PeBenito b4cd15
tmp/pre_te_files.conf: $(PRE_TE_FILES)
Chris PeBenito b4cd15
	@test -d tmp || mkdir -p tmp
Chris PeBenito b4cd15
	$(QUIET) cat $^ > $@
Chris PeBenito b4cd15
Chris PeBenito d2d6c8
tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES)
Chris PeBenito d2d6c8
# per-userdomain templates:
Chris PeBenito b4cd15
	@test -d tmp || mkdir -p tmp
Chris PeBenito b4cd15
	$(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
Chris PeBenito 0fbe15
	$(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
Chris PeBenito b4cd15
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
Chris PeBenito b4cd15
			>> $@ ;\
Chris PeBenito b4cd15
	done
Chris PeBenito b4cd15
	$(QUIET) echo "')" >> $@
Chris PeBenito d2d6c8
# define foo.te
Chris PeBenito 0fbe15
	$(QUIET) for i in $(notdir $(ALL_MODULES)); do \
Chris PeBenito b4cd15
		echo "define(\`$$i')" >> $@ ;\
Chris PeBenito b4cd15
	done
Chris PeBenito 84eb35
	$(QUIET) $(SETTUN) $(TUNABLES) >> $@
Chris PeBenito b4cd15
Chris PeBenito 199895
tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
Chris PeBenito 19db6b
ifeq ($(ALL_INTERFACES),)
Chris PeBenito 19db6b
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito 19db6b
endif
Chris PeBenito b4cd15
	@test -d tmp || mkdir -p tmp
Chris PeBenito 199895
	$(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
Chris PeBenito b4cd15
Chris PeBenito 3a80ec
tmp/all_te_files.conf: $(ALL_TE_FILES)
Chris PeBenito 19db6b
ifeq ($(ALL_TE_FILES),)
Chris PeBenito 19db6b
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito 19db6b
endif
Chris PeBenito b4cd15
	@test -d tmp || mkdir -p tmp
Chris PeBenito 3a80ec
	$(QUIET) cat $^ > $@
Chris PeBenito b4cd15
Chris PeBenito b4cd15
tmp/post_te_files.conf: $(POST_TE_FILES)
Chris PeBenito b4cd15
	@test -d tmp || mkdir -p tmp
Chris PeBenito b4cd15
	$(QUIET) cat $^ > $@
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# extract attributes and put them first. extract post te stuff
Chris PeBenito b4cd15
# like genfscon and put last.  portcon, nodecon, and netifcon
Chris PeBenito b4cd15
# is delayed since they are generated by m4
Chris PeBenito f66a1a
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 f66a1a
	$(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
Chris PeBenito f66a1a
	$(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
Chris PeBenito b4cd15
	$(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
Chris PeBenito cabfa5
	$(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito cabfa5
	$(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito b4cd15
	$(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito cabfa5
	$(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
Chris PeBenito cabfa5
			-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
Chris PeBenito cabfa5
			< tmp/all_te_files.conf > tmp/only_te_rules.conf
Chris PeBenito b4cd15
Chris PeBenito f2e4ab
$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
Chris PeBenito 61bbe5
	@echo "#" > $@
Chris PeBenito 61bbe5
	@echo "# This is a generated file!  Instead of modifying this file, the" >> $@
Chris PeBenito 61bbe5
	@echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
Chris PeBenito 61bbe5
	@echo "#" >> $@
Chris PeBenito 61bbe5
	$(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@
Chris PeBenito f2e4ab
	$(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
Chris PeBenito d2d6c8
		| m4 $(M4PARAM) $(M4SUPPORT) $(MODDIR)/kernel/corenetwork.if.m4 - \
Chris PeBenito f2e4ab
		| sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
Chris PeBenito f2e4ab
Chris PeBenito f2e4ab
$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
Chris PeBenito 61bbe5
	@echo "#" > $@
Chris PeBenito 61bbe5
	@echo "# This is a generated file!  Instead of modifying this file, the" >> $@
Chris PeBenito 61bbe5
	@echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
Chris PeBenito 61bbe5
	@echo "#" >> $@
Chris PeBenito d2d6c8
	$(QUIET) m4 $(M4PARAM) $(M4SUPPORT) $^ \
Chris PeBenito 61bbe5
		| sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
Chris PeBenito f2e4ab
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito 88d14a
# Remove the dontaudit rules from the policy.conf
Chris PeBenito 88d14a
#
Chris PeBenito 88d14a
enableaudit: policy.conf
Chris PeBenito 88d14a
	@test -d tmp || mkdir -p tmp
Chris PeBenito 88d14a
	@echo "Removing dontaudit rules from policy.conf"
Chris PeBenito 88d14a
	$(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
Chris PeBenito 88d14a
	$(QUIET) mv tmp/policy.audit policy.conf
Chris PeBenito 88d14a
Chris PeBenito 88d14a
########################################
Chris PeBenito 88d14a
#
Chris PeBenito 6d314f
# Construct file_contexts
Chris PeBenito 6d314f
#
Chris PeBenito 14b25b
$(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) $(FCSORT) $(POLVER)
Chris PeBenito d233bf
ifeq ($(ALL_FC_FILES),)
Chris PeBenito d233bf
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito d233bf
endif
Chris PeBenito 6d314f
	@test -d tmp || mkdir -p tmp
Chris PeBenito 92e928
	$(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) > tmp/$@.tmp
Chris PeBenito 92e928
	$(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE)
Chris PeBenito 92e928
	$(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp
Chris PeBenito 92e928
	$(QUIET) $(FCSORT) tmp/$@.tmp $@
Chris PeBenito 14b25b
	@echo "Validating file_contexts."
Chris PeBenito 14b25b
	$(SETFILES) -q -c $(POLVER) $(FC)
Chris PeBenito 6d314f
Chris PeBenito 6d314f
########################################
Chris PeBenito 6d314f
#
Chris PeBenito 547283
# Install file_contexts
Chris PeBenito 547283
#
Chris PeBenito 3a80ec
$(FCPATH): $(FC) $(USERPATH)/system.users
Chris PeBenito 547283
	@mkdir -p $(CONTEXTPATH)/files
Chris PeBenito 547283
	$(QUIET) install -m 644 $(FC) $(FCPATH)
Chris PeBenito 92e928
	$(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
Chris PeBenito 92e928
	$(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
Chris PeBenito 547283
Chris PeBenito 547283
########################################
Chris PeBenito 547283
#
Chris PeBenito b4cd15
# Filesystem labeling
Chris PeBenito b4cd15
#
Chris PeBenito 88d14a
FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
Chris PeBenito b4cd15
Chris PeBenito 88d14a
checklabels: $(FC) $(SETFILES)
Chris PeBenito 88d14a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito 88d14a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 88d14a
		false ;\
Chris PeBenito 88d14a
	fi
Chris PeBenito b4cd15
	$(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
Chris PeBenito b4cd15
Chris PeBenito 88d14a
restorelabels: $(FC) $(SETFILES)
Chris PeBenito 88d14a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito 88d14a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 88d14a
		false ;\
Chris PeBenito 88d14a
	fi
Chris PeBenito b4cd15
	$(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
relabel:  $(FC) $(SETFILES)
Chris PeBenito 88d14a
	@if test -z "$(FILESYSTEMS)"; then \
Chris PeBenito 88d14a
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 88d14a
		false ;\
Chris PeBenito 88d14a
	fi
Chris PeBenito b4cd15
	$(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
Chris PeBenito b4cd15
Chris PeBenito 6d314f
########################################
Chris PeBenito 6d314f
#
Chris PeBenito 84eb35
# Create config files
Chris PeBenito 84eb35
#
Chris PeBenito 19db6b
conf: $(MOD_CONF) $(TUNABLES) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
Chris PeBenito d2d6c8
Chris PeBenito 19db6b
$(MOD_CONF) $(TUNABLES): $(POLXML)
Chris PeBenito 19db6b
	@echo "Updating $(MOD_CONF) and $(TUNABLES)"
Chris PeBenito 19db6b
	$(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(TUNABLES) -m ../$(MOD_CONF) -x ../$(POLXML)
Chris PeBenito 84eb35
Chris PeBenito 84eb35
########################################
Chris PeBenito 84eb35
#
Chris PeBenito 6d314f
# Documentation generation
Chris PeBenito 6d314f
#
Chris PeBenito 6d314f
Chris PeBenito d2d6c8
# minimal dependencies here, because we don't want to rebuild 
Chris PeBenito 84eb35
# this and its dependents every time the dependencies
Chris PeBenito 19db6b
# change.  Also use all .if files here, rather then just the
Chris PeBenito 19db6b
# enabled modules.
Chris PeBenito d233bf
$(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
Chris PeBenito 88c72f
	@echo "Creating $@"
Chris PeBenito 84eb35
	@mkdir -p tmp
Chris PeBenito 004db9
	$(QUIET) echo '' > $@
Chris PeBenito 95db42
	$(QUIET) echo '' >> $@
Chris PeBenito 95db42
	$(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) $(ALL_LAYERS) >> $@
Chris PeBenito 044735
	$(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
Chris PeBenito 044735
		$(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
Chris PeBenito 004db9
	fi
Chris PeBenito 6d314f
Chris PeBenito 12b559
html: $(POLXML)
Chris PeBenito 20030e
	@mkdir -p $(HTMLDIR)
Chris PeBenito 12b559
	$(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
Chris PeBenito 20030e
	$(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
Chris PeBenito 20030e
Chris PeBenito c9a26b
########################################
Chris PeBenito c9a26b
#
Chris PeBenito c9a26b
# Runtime binary policy patching of users
Chris PeBenito c9a26b
#
Chris PeBenito c9a26b
$(USERPATH)/system.users: $(USER_FILES) tmp/generated_definitions.conf
Chris PeBenito c9a26b
	@mkdir -p $(USERPATH)
Chris PeBenito c9a26b
	@echo "Installing system.users"
Chris PeBenito c9a26b
	@echo "# " > tmp/system.users
Chris PeBenito c9a26b
	@echo "# Do not edit this file. " >> tmp/system.users
Chris PeBenito c9a26b
	@echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
Chris PeBenito c9a26b
	@echo "# Please edit local.users to make local changes." >> tmp/system.users
Chris PeBenito c9a26b
	@echo "#" >> tmp/system.users
Chris PeBenito c9a26b
	$(QUIET) m4 $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \
Chris PeBenito c9a26b
		egrep -v "^[[:space:]]*($$|#)" >> tmp/system.users
Chris PeBenito c9a26b
	$(QUIET) install -m 644 tmp/system.users $@
Chris PeBenito c9a26b
Chris PeBenito 1beba1
$(USERPATH)/local.users: config/local.users
Chris PeBenito c9a26b
	@mkdir -p $(USERPATH)
Chris PeBenito c9a26b
	@echo "Installing local.users"
Chris PeBenito c7b41e
	$(QUIET) install -b -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito c9a26b
########################################
Chris PeBenito c9a26b
#
Chris PeBenito c9a26b
# Appconfig files
Chris PeBenito c9a26b
#
Chris PeBenito c9a26b
install-appconfig: $(APPFILES)
Chris PeBenito c9a26b
Chris PeBenito 1beba1
$(INSTALLDIR)/booleans: $(TUNABLES)
Chris PeBenito 1beba1
	@mkdir -p $(INSTALLDIR)
Chris PeBenito 1beba1
	$(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(TUNABLES) \
Chris PeBenito 1beba1
		| sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans
Chris PeBenito 1beba1
	$(QUIET) install -m 644 tmp/booleans $@
Chris PeBenito 1beba1
Chris PeBenito 2926f9
$(CONTEXTPATH)/files/media: $(APPCONF)/media
Chris PeBenito 1beba1
	@mkdir -p $(CONTEXTPATH)/files/
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/removable_context: $(APPCONF)/removable_context
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito c9a26b
$(APPDIR)/customizable_types: policy.conf
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
Chris PeBenito 1beba1
	$(QUIET) install -m 644 tmp/customizable_types $@ 
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/default_type: $(APPCONF)/default_type
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 2926f9
$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
Chris PeBenito 1beba1
	@mkdir -p $(APPDIR)/users
Chris PeBenito 1beba1
	$(QUIET) install -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito c592e5
########################################
Chris PeBenito c592e5
#
Chris PeBenito c592e5
# Install policy sources
Chris PeBenito c592e5
#
Chris PeBenito c592e5
install-src:
Chris PeBenito c592e5
	rm -rf $(SRCPATH)/policy.old
Chris PeBenito c592e5
	-mv $(SRCPATH)/policy $(SRCPATH)/policy.old
Chris PeBenito c592e5
	mkdir -p $(SRCPATH)/policy
Chris PeBenito c592e5
	cp -R . $(SRCPATH)/policy
Chris PeBenito c592e5
Chris PeBenito 102a59
########################################
Chris PeBenito 102a59
#
Chris PeBenito 102a59
# Clean the sources
Chris PeBenito 102a59
#
Chris PeBenito b4cd15
clean:
Chris PeBenito b4cd15
	rm -fR tmp
Chris PeBenito b4cd15
	rm -f policy.conf
Chris PeBenito b4cd15
	rm -f policy.$(PV)
Chris PeBenito b4cd15
	rm -f $(FC)
Chris PeBenito b4cd15
Chris PeBenito 102a59
########################################
Chris PeBenito 102a59
#
Chris PeBenito 102a59
# Clean everything
Chris PeBenito 102a59
#
Chris PeBenito 0fbe15
bare: clean
Chris PeBenito 12b559
	rm -f $(POLXML)
Chris PeBenito 254bbc
	rm -f $(SUPPORT)/*.pyc
Chris PeBenito 254bbc
	rm -f $(FCSORT)
Chris PeBenito 19db6b
	rm -f $(MOD_CONF)
Chris PeBenito 0fbe15
	rm -f $(TUNABLES)
Chris PeBenito 20030e
	rm -fR $(HTMLDIR)
Chris PeBenito e12e57
ifneq ($(GENERATED_TE),)
Chris PeBenito e12e57
	rm -f $(GENERATED_TE)
Chris PeBenito e12e57
endif
Chris PeBenito e12e57
ifneq ($(GENERATED_IF),)
Chris PeBenito e12e57
	rm -f $(GENERATED_IF)
Chris PeBenito e12e57
endif
Chris PeBenito e12e57
ifneq ($(GENERATED_FC),)
Chris PeBenito e12e57
	rm -f $(GENERATED_FC)
Chris PeBenito e12e57
endif
Chris PeBenito 0fbe15
Chris PeBenito 102a59
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel conf clean bare