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 b4cd15
#
Chris PeBenito 8e0ef1
# Please see build.conf for policy build options.
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b67488
# NO OPTIONS BELOW HERE
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito c9f20d
# Include the local build.conf if it exists, otherwise
Chris PeBenito c9f20d
# include the configuration of the root directory.
Chris PeBenito 1a7175
include build.conf
Chris PeBenito 1a7175
Chris PeBenito 1a7175
ifdef LOCAL_ROOT
Chris PeBenito 1a7175
	-include $(LOCAL_ROOT)/build.conf
Chris PeBenito c9f20d
endif
Chris PeBenito 8e0ef1
Chris PeBenito 120988
# refpolicy version
Chris PeBenito c634db
version = $(shell cat VERSION)
Chris PeBenito 120988
Chris PeBenito c9f20d
ifdef LOCAL_ROOT
Chris PeBenito c634db
builddir := $(LOCAL_ROOT)/
Chris PeBenito c634db
tmpdir := $(LOCAL_ROOT)/tmp
Chris PeBenito c634db
tags := $(LOCAL_ROOT)/tags
Chris PeBenito c9f20d
else
Chris PeBenito c634db
tmpdir := tmp
Chris PeBenito c634db
tags := tags
Chris PeBenito c9f20d
endif
Chris PeBenito c9f20d
Chris PeBenito b4cd15
# executable paths
Chris PeBenito 906f10
BINDIR ?= /usr/bin
Chris PeBenito 906f10
SBINDIR ?= /usr/sbin
Chris PeBenito e2ae08
ifdef TEST_TOOLCHAIN
Chris PeBenito 75beb9
tc_usrbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)$(BINDIR)
Chris PeBenito 75beb9
tc_usrsbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)$(SBINDIR)
Chris PeBenito 75beb9
tc_sbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)/sbin
Chris PeBenito e2ae08
else
Chris PeBenito 75beb9
tc_usrbindir := $(BINDIR)
Chris PeBenito 75beb9
tc_usrsbindir := $(SBINDIR)
Chris PeBenito 75beb9
tc_sbindir := /sbin
Chris PeBenito e2ae08
endif
Chris PeBenito 75beb9
CHECKPOLICY ?= $(tc_usrbindir)/checkpolicy
Chris PeBenito 75beb9
CHECKMODULE ?= $(tc_usrbindir)/checkmodule
Chris PeBenito 75beb9
SEMODULE ?= $(tc_usrsbindir)/semodule
Chris PeBenito 75beb9
SEMOD_PKG ?= $(tc_usrbindir)/semodule_package
Chris PeBenito 75beb9
SEMOD_LNK ?= $(tc_usrbindir)/semodule_link
Chris PeBenito 75beb9
SEMOD_EXP ?= $(tc_usrbindir)/semodule_expand
Chris PeBenito 75beb9
LOADPOLICY ?= $(tc_usrsbindir)/load_policy
Chris PeBenito e2ae08
SETFILES ?= $(tc_sbindir)/setfiles
Chris PeBenito 906f10
XMLLINT ?= $(BINDIR)/xmllint
Chris PeBenito 906f10
SECHECK ?= $(BINDIR)/sechecker
Chris PeBenito 044735
Chris PeBenito 0e686f
# interpreters and aux tools
Chris PeBenito 0e686f
AWK ?= gawk
Chris PeBenito 0e686f
GREP ?= egrep
Chris PeBenito cfd5c5
INSTALL ?= install
Chris PeBenito 0e686f
M4 ?= m4
Chris PeBenito 0e686f
PYTHON ?= python
Chris PeBenito 0e686f
SED ?= sed
Chris PeBenito f62f4c
SORT ?= LC_ALL=C sort
Chris PeBenito 0e686f
Chris PeBenito 0e686f
CFLAGS += -Wall
Chris PeBenito c7b41e
Chris PeBenito fb0a3a
# policy source layout
Chris PeBenito c634db
poldir := policy
Chris PeBenito c634db
moddir := $(poldir)/modules
Chris PeBenito c634db
flaskdir := $(poldir)/flask
Chris PeBenito c634db
secclass := $(flaskdir)/security_classes
Chris PeBenito c634db
isids := $(flaskdir)/initial_sids
Chris PeBenito c634db
avs := $(flaskdir)/access_vectors
Chris PeBenito fb0a3a
Chris PeBenito c9f20d
# local source layout
Chris PeBenito c9f20d
ifdef LOCAL_ROOT
Chris PeBenito c634db
local_poldir := $(LOCAL_ROOT)/policy
Chris PeBenito c634db
local_moddir := $(local_poldir)/modules
Chris PeBenito c9f20d
endif
Chris PeBenito c9f20d
Chris PeBenito fb0a3a
# policy building support tools
Chris PeBenito c634db
support := support
Chris PeBenito 1a79cf
genxml := $(PYTHON) -E $(support)/segenxml.py
Chris PeBenito 1a79cf
gendoc := $(PYTHON) -E $(support)/sedoctool.py
Chris PeBenito 1a79cf
genperm := $(PYTHON) -E $(support)/genclassperms.py
Chris PeBenito c634db
fcsort := $(tmpdir)/fc_sort
Chris PeBenito c634db
setbools := $(AWK) -f $(support)/set_bools_tuns.awk
Chris PeBenito c634db
get_type_attr_decl := $(SED) -r -f $(support)/get_type_attr_decl.sed
Chris PeBenito c634db
comment_move_decl := $(SED) -r -f $(support)/comment_move_decl.sed
Chris PeBenito 1a79cf
gennetfilter := $(PYTHON) -E $(support)/gennetfilter.py
Chris PeBenito e276d5
m4iferror := $(support)/iferror.m4
Chris PeBenito fc47b3
# use our own genhomedircon to make sure we have a known usable one,
Chris PeBenito fc47b3
# so policycoreutils updates are not required (RHEL4)
Chris PeBenito 1a79cf
genhomedircon := $(PYTHON) -E $(support)/genhomedircon
Chris PeBenito 3a80ec
Chris PeBenito fb0a3a
# documentation paths
Chris PeBenito c634db
docs := doc
Chris PeBenito c634db
xmldtd = $(docs)/policy.dtd
Chris PeBenito 56e1b3
metaxml = metadata.xml
Chris PeBenito c634db
doctemplate = $(docs)/templates
Chris PeBenito c634db
docfiles = $(docs)/Makefile.example $(addprefix $(docs)/,example.te example.if example.fc)
Chris PeBenito fb0a3a
Chris PeBenito c9f20d
ifndef LOCAL_ROOT
Chris PeBenito c634db
polxml = $(docs)/policy.xml
Chris PeBenito c634db
tunxml = $(docs)/global_tunables.xml
Chris PeBenito c634db
boolxml = $(docs)/global_booleans.xml
Chris PeBenito c634db
htmldir = $(docs)/html
Chris PeBenito c9f20d
else
Chris PeBenito c634db
polxml = $(LOCAL_ROOT)/doc/policy.xml
Chris PeBenito c634db
tunxml = $(LOCAL_ROOT)/doc/global_tunables.xml
Chris PeBenito c634db
boolxml = $(LOCAL_ROOT)/doc/global_booleans.xml
Chris PeBenito c634db
htmldir = $(LOCAL_ROOT)/doc/html
Chris PeBenito c9f20d
endif
Chris PeBenito c9f20d
Chris PeBenito fb0a3a
# config file paths
Chris PeBenito c634db
globaltun = $(poldir)/global_tunables
Chris PeBenito c634db
globalbool = $(poldir)/global_booleans
Chris PeBenito c634db
rolemap = $(poldir)/rolemap
Chris PeBenito c634db
user_files := $(poldir)/users
Chris PeBenito c07f9c
policycaps := $(poldir)/policy_capabilities
Chris PeBenito fb0a3a
Chris PeBenito c9f20d
# local config file paths
Chris PeBenito c9f20d
ifndef LOCAL_ROOT
Chris PeBenito c634db
mod_conf = $(poldir)/modules.conf
Chris PeBenito c634db
booleans = $(poldir)/booleans.conf
Chris PeBenito c634db
tunables = $(poldir)/tunables.conf
Chris PeBenito c9f20d
else
Chris PeBenito c634db
mod_conf = $(local_poldir)/modules.conf
Chris PeBenito c634db
booleans = $(local_poldir)/booleans.conf
Chris PeBenito c634db
tunables = $(local_poldir)/tunables.conf
Chris PeBenito c9f20d
endif
Chris PeBenito c9f20d
Chris PeBenito fb0a3a
# install paths
Chris PeBenito c634db
PKGNAME ?= refpolicy-$(version)
Chris PeBenito c634db
prefix = $(DESTDIR)/usr
Chris PeBenito c634db
topdir = $(DESTDIR)/etc/selinux
Chris PeBenito c634db
installdir = $(topdir)/$(strip $(NAME))
Chris PeBenito c634db
srcpath = $(installdir)/src
Chris PeBenito c634db
userpath = $(installdir)/users
Chris PeBenito 212832
policypath = $(installdir)/policy
Chris PeBenito c634db
contextpath = $(installdir)/contexts
Chris PeBenito 212832
homedirpath = $(contextpath)/files/homedir_template
Chris PeBenito c634db
fcpath = $(contextpath)/files/file_contexts
Chris PeBenito c634db
ncpath = $(contextpath)/netfilter_contexts
Chris PeBenito c634db
sharedir = $(prefix)/share/selinux
Chris PeBenito c634db
modpkgdir = $(sharedir)/$(strip $(NAME))
Chris PeBenito c634db
headerdir = $(modpkgdir)/include
Chris PeBenito c634db
docsdir = $(prefix)/share/doc/$(PKGNAME)
Chris PeBenito c767b1
Chris PeBenito 134191
# enable MLS if requested.
Chris PeBenito 350b6a
ifeq "$(TYPE)" "mls"
Chris PeBenito 3f026a
	M4PARAM += -D enable_mls
Chris PeBenito 3f026a
	CHECKPOLICY += -M
Chris PeBenito 3f026a
	CHECKMODULE += -M
Chris PeBenito 6962bb
	gennetfilter += -m
Chris PeBenito 134191
endif
Chris PeBenito 134191
Chris PeBenito a08248
# enable MLS if MCS requested.
Chris PeBenito 350b6a
ifeq "$(TYPE)" "mcs"
Chris PeBenito 3f026a
	M4PARAM += -D enable_mcs
Chris PeBenito 3f026a
	CHECKPOLICY += -M
Chris PeBenito 3f026a
	CHECKMODULE += -M
Chris PeBenito 6962bb
	gennetfilter += -c
Chris PeBenito b67488
endif
Chris PeBenito b67488
Chris PeBenito 25a0c6
# enable distribution-specific policy
Chris PeBenito 25a0c6
ifneq ($(DISTRO),)
Chris PeBenito 3f026a
	M4PARAM += -D distro_$(DISTRO)
Chris PeBenito 25a0c6
endif
Chris PeBenito 25a0c6
Chris PeBenito 2f1a8f
# rhel4 also implies redhat
Chris PeBenito 2f1a8f
ifeq "$(DISTRO)" "rhel4"
Chris PeBenito 2f1a8f
	M4PARAM += -D distro_redhat
Chris PeBenito 2f1a8f
endif
Chris PeBenito 2f1a8f
Chris PeBenito 12cf80
ifeq "$(DISTRO)" "ubuntu"
Chris PeBenito 12cf80
	M4PARAM += -D distro_debian
Chris PeBenito 12cf80
endif
Chris PeBenito 12cf80
Chris PeBenito b67488
ifneq ($(OUTPUT_POLICY),)
Chris PeBenito 3f026a
	CHECKPOLICY += -c $(OUTPUT_POLICY)
Chris PeBenito b67488
endif
Chris PeBenito b67488
Chris PeBenito 3f026a
# if not set, use the type as the name.
Chris PeBenito 3f026a
NAME ?= $(TYPE)
Chris PeBenito 134191
Chris PeBenito 8acfcb
# default unknown permissions setting
Chris PeBenito 8acfcb
#UNK_PERMS ?= deny
Chris PeBenito 8acfcb
Chris PeBenito 142e9f
ifeq ($(DIRECT_INITRC),y)
Chris PeBenito 3f026a
	M4PARAM += -D direct_sysadm_daemon
Chris PeBenito 142e9f
endif
Chris PeBenito 142e9f
Chris PeBenito 296273
ifeq "$(UBAC)" "y"
Chris PeBenito 296273
	M4PARAM += -D enable_ubac
Chris PeBenito 296273
endif
Chris PeBenito 296273
Chris PeBenito e070dd
# default MLS/MCS sensitivity and category settings.
Chris PeBenito e070dd
MLS_SENS ?= 16
Chris PeBenito e070dd
MLS_CATS ?= 256
Chris PeBenito e070dd
MCS_CATS ?= 256
Chris PeBenito e070dd
Chris PeBenito 9b3756
ifeq ($(QUIET),y)
Chris PeBenito 9b3756
	verbose = @
Chris PeBenito 9b3756
endif
Chris PeBenito 9b3756
Chris PeBenito e070dd
M4PARAM += -D mls_num_sens=$(MLS_SENS) -D mls_num_cats=$(MLS_CATS) -D mcs_num_cats=$(MCS_CATS) -D hide_broken_symptoms
Chris PeBenito ee7f66
Chris PeBenito 37227d
# we need exuberant ctags; unfortunately it is named
Chris PeBenito 37227d
# differently on different distros
Chris PeBenito 37227d
ifeq ($(DISTRO),debian)
Chris PeBenito 37227d
	CTAGS := ctags-exuberant
Chris PeBenito 37227d
endif
Chris PeBenito 37227d
Chris PeBenito 37227d
ifeq ($(DISTRO),gentoo)
Chris PeBenito 37227d
	CTAGS := exuberant-ctags	
Chris PeBenito 37227d
endif
Chris PeBenito 37227d
Chris PeBenito a4fae7
CTAGS ?= ctags
Chris PeBenito 37227d
Chris PeBenito c634db
m4support := $(wildcard $(poldir)/support/*.spt)
Chris PeBenito 201445
ifdef LOCAL_ROOT
Chris PeBenito c634db
m4support += $(wildcard $(local_poldir)/support/*.spt)
Chris PeBenito 201445
endif
Chris PeBenito 0fbe15
Chris PeBenito c634db
appconf := config/appconfig-$(TYPE)
Chris PeBenito c634db
seusers := $(appconf)/seusers
Chris PeBenito c634db
appdir := $(contextpath)
Chris PeBenito 8a2492
user_default_contexts := $(wildcard config/appconfig-$(TYPE)/*_default_contexts)
Chris PeBenito 8a2492
user_default_contexts_names := $(addprefix $(contextpath)/users/,$(subst _default_contexts,,$(notdir $(user_default_contexts))))
Chris PeBenito 2c12b4
appfiles := $(addprefix $(appdir)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts x_contexts customizable_types securetty_types) $(contextpath)/files/media $(user_default_contexts_names)
Chris PeBenito c634db
net_contexts := $(builddir)net_contexts
Chris PeBenito c9a26b
Chris PeBenito 96fc0a
all_layers := $(shell find $(wildcard $(moddir)/*) -maxdepth 0 -type d)
Chris PeBenito c9f20d
ifdef LOCAL_ROOT
Chris PeBenito 96fc0a
all_layers += $(shell find $(wildcard $(local_moddir)/*) -maxdepth 0 -type d)
Chris PeBenito c9f20d
endif
Chris PeBenito e12e57
Chris PeBenito c634db
generated_te := $(basename $(foreach dir,$(all_layers),$(wildcard $(dir)/*.te.in)))
Chris PeBenito c634db
generated_if := $(basename $(foreach dir,$(all_layers),$(wildcard $(dir)/*.if.in)))
Chris PeBenito c634db
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 c634db
detected_mods := $(sort $(foreach dir,$(all_layers),$(wildcard $(dir)/*.te)) $(generated_te))
Chris PeBenito 19db6b
Chris PeBenito 96fc0a
modxml := $(addprefix $(tmpdir)/, $(detected_mods:.te=.xml))
Chris PeBenito 96fc0a
layerxml := $(sort $(addprefix $(tmpdir)/, $(notdir $(addsuffix .xml,$(all_layers)))))
Chris PeBenito 96fc0a
layer_names := $(sort $(notdir $(all_layers)))
Chris PeBenito 96fc0a
all_metaxml = $(call detect-metaxml, $(layer_names))
Chris PeBenito 56e1b3
Chris PeBenito fb0a3a
# modules.conf setting for base module
Chris PeBenito c634db
configbase := base
Chris PeBenito fb0a3a
Chris PeBenito e0a900
# modules.conf setting for loadable module
Chris PeBenito c634db
configmod := module
Chris PeBenito fb0a3a
Chris PeBenito e0a900
# modules.conf setting for unused module
Chris PeBenito c634db
configoff := off
Chris PeBenito e0a900
Chris PeBenito c9f20d
# test for module overrides from command line
Chris PeBenito c634db
mod_test = $(filter $(APPS_OFF), $(APPS_BASE) $(APPS_MODS))
Chris PeBenito c634db
mod_test += $(filter $(APPS_MODS), $(APPS_BASE))
Chris PeBenito c634db
ifneq "$(strip $(mod_test))" ""
Chris PeBenito c634db
        $(error Applications must be base, module, or off, and not in more than one list! $(strip $(mod_test)) found in multiple lists!)
Chris PeBenito c9f20d
endif
Chris PeBenito c9f20d
Chris PeBenito 201445
# add on suffix to modules specified on command line
Chris PeBenito c634db
cmdline_base := $(addsuffix .te,$(APPS_BASE))
Chris PeBenito c634db
cmdline_mods := $(addsuffix .te,$(APPS_MODS))
Chris PeBenito c634db
cmdline_off := $(addsuffix .te,$(APPS_OFF))
Chris PeBenito 201445
Chris PeBenito fb0a3a
# extract settings from modules.conf
Chris PeBenito c634db
mod_conf_base := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configbase)") print $$1 }' $(mod_conf) 2> /dev/null)))
Chris PeBenito c634db
mod_conf_mods := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configmod)") print $$1 }' $(mod_conf) 2> /dev/null)))
Chris PeBenito c634db
mod_conf_off := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configoff)") print $$1 }' $(mod_conf) 2> /dev/null)))
Chris PeBenito 201445
Chris PeBenito c634db
base_mods := $(cmdline_base)
Chris PeBenito c634db
mod_mods := $(cmdline_mods)
Chris PeBenito c634db
off_mods := $(cmdline_off)
Chris PeBenito 87e73c
Chris PeBenito c634db
base_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_base))
Chris PeBenito c634db
mod_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_mods))
Chris PeBenito c634db
off_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_off))
Chris PeBenito 87e73c
Chris PeBenito 87e73c
# add modules not in modules.conf to the off list
Chris PeBenito c634db
off_mods += $(filter-out $(base_mods) $(mod_mods) $(off_mods),$(notdir $(detected_mods)))
Chris PeBenito 712566
Chris PeBenito 90b331
# filesystems to be used in labeling targets
Chris PeBenito c634db
filesystems = $(shell mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';)
Chris PeBenito 120988
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito 4ace0f
# Functions
Chris PeBenito 4ace0f
#
Chris PeBenito 4ace0f
Chris PeBenito bbcd3c
# parse-rolemap-compat modulename,outputfile
Chris PeBenito bbcd3c
define parse-rolemap-compat
Chris PeBenito bbcd3c
	$(verbose) $(M4) $(M4PARAM) $(rolemap) | \
Chris PeBenito bbcd3c
		$(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
Chris PeBenito bbcd3c
endef
Chris PeBenito bbcd3c
Chris PeBenito 4ace0f
# parse-rolemap modulename,outputfile
Chris PeBenito 4ace0f
define parse-rolemap
Chris PeBenito c634db
	$(verbose) $(M4) $(M4PARAM) $(rolemap) | \
Chris PeBenito bbcd3c
		$(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_role_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
Chris PeBenito 4ace0f
endef
Chris PeBenito 4ace0f
Chris PeBenito bbcd3c
# perrole-expansion modulename,outputfile
Chris PeBenito bbcd3c
define perrole-expansion
Chris PeBenito bbcd3c
	$(verbose) echo "ifdef(\`""$1""_per_role_template',\`" > $2
Chris PeBenito 4ace0f
	$(call parse-rolemap,$1,$2)
Chris PeBenito 9b3756
	$(verbose) echo "')" >> $2
Chris PeBenito bbcd3c
Chris PeBenito bbcd3c
	$(verbose) echo "ifdef(\`""$1""_per_userdomain_template',\`" >> $2
Chris PeBenito bbcd3c
	$(verbose) echo "errprint(\`Warning: per_userdomain_templates have been renamed to per_role_templates (""$1""_per_userdomain_template)'__endline__)" >> $2
Chris PeBenito bbcd3c
	$(call parse-rolemap-compat,$1,$2)
Chris PeBenito bbcd3c
	$(verbose) echo "')" >> $2
Chris PeBenito bbcd3c
endef
Chris PeBenito bbcd3c
Chris PeBenito bbcd3c
# create-base-per-role-tmpl modulenames,outputfile
Chris PeBenito bbcd3c
define create-base-per-role-tmpl
Chris PeBenito bbcd3c
	$(verbose) echo "define(\`base_per_role_template',\`" >> $2
Chris PeBenito bbcd3c
Chris PeBenito bbcd3c
	$(verbose) for i in $1; do \
Chris PeBenito bbcd3c
		echo "ifdef(\`""$$i""_per_role_template',\`""$$i""_per_role_template("'$$*'")')" \
Chris PeBenito bbcd3c
			>> $2 ;\
Chris PeBenito bbcd3c
	done
Chris PeBenito bbcd3c
Chris PeBenito bbcd3c
	$(verbose) for i in $1; do \
Chris PeBenito bbcd3c
		echo "ifdef(\`""$$i""_per_userdomain_template',\`" >> $2 ;\
Chris PeBenito bbcd3c
		echo "errprint(\`Warning: per_userdomain_templates have been renamed to per_role_templates (""$$i""_per_userdomain_template)'__endline__)" >> $2 ;\
Chris PeBenito bbcd3c
		echo """$$i""_per_userdomain_template("'$$*'")')"  >> $2 ;\
Chris PeBenito bbcd3c
	done
Chris PeBenito bbcd3c
	$(verbose) echo "')" >> $@
Chris PeBenito bbcd3c
Chris PeBenito 4ace0f
endef
Chris PeBenito 4ace0f
Chris PeBenito 96fc0a
# detect-metaxml layer_names
Chris PeBenito 96fc0a
ifdef LOCAL_ROOT
Chris PeBenito 96fc0a
define detect-metaxml
Chris PeBenito 96fc0a
	$(shell for i in $1; do \
Chris PeBenito 96fc0a
		if [ -d $(moddir)/$$i -a -d $(local_moddir)/$$i ]; then \
Chris PeBenito 96fc0a
			if [ -f $(local_moddir)/$$i/$(metaxml) ]; then \
Chris PeBenito 96fc0a
				echo $(local_moddir)/$$i/$(metaxml) ;\
Chris PeBenito 96fc0a
			else \
Chris PeBenito 96fc0a
				echo $(moddir)/$$i/$(metaxml) ;\
Chris PeBenito 96fc0a
			fi \
Chris PeBenito 96fc0a
		elif [ -d $(local_moddir)/$$i ]; then
Chris PeBenito 96fc0a
			echo $(local_moddir)/$$i/$(metaxml) ;\
Chris PeBenito 96fc0a
		else \
Chris PeBenito 96fc0a
			echo $(moddir)/$$i/$(metaxml) ;\
Chris PeBenito 96fc0a
		fi \
Chris PeBenito 96fc0a
	done )
Chris PeBenito 96fc0a
endef
Chris PeBenito 96fc0a
else
Chris PeBenito 96fc0a
define detect-metaxml
Chris PeBenito 96fc0a
	$(shell for i in $1; do echo $(moddir)/$$i/$(metaxml); done)
Chris PeBenito 96fc0a
endef
Chris PeBenito 96fc0a
endif
Chris PeBenito 96fc0a
Chris PeBenito 4ace0f
########################################
Chris PeBenito 4ace0f
#
Chris PeBenito fb0a3a
# Load appropriate rules
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito fb0a3a
ifeq ($(MONOLITHIC),y)
Chris PeBenito 5b45ff
	include Rules.monolithic
Chris PeBenito fb0a3a
else
Chris PeBenito 5b45ff
	include Rules.modular
Chris PeBenito b4cd15
endif
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito fb0a3a
# Generated files
Chris PeBenito 88d14a
#
Chris PeBenito c9f20d
# NOTE: There is no "local" version of these files.
Chris PeBenito c9f20d
#
Chris PeBenito c634db
generate: $(generated_te) $(generated_if) $(generated_fc)
Chris PeBenito fffba0
Chris PeBenito 686f11
$(moddir)/kernel/corenetwork.if: $(moddir)/kernel/corenetwork.te.in $(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 686f11
	$(verbose) cat $@.in >> $@
Chris PeBenito 686f11
	$(verbose) $(GREP) "^[[:blank:]]*network_(interface|node|port|packet)\(.*\)" $< \
Chris PeBenito 686f11
		| $(M4) -D self_contained_policy $(M4PARAM) $@.m4 - \
Chris PeBenito cfd5c5
		| $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
Chris PeBenito f2e4ab
Chris PeBenito c634db
$(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 cfd5c5
	$(verbose) $(M4) -D self_contained_policy $(M4PARAM) $^ \
Chris PeBenito cfd5c5
		| $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
Chris PeBenito f2e4ab
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito 6962bb
# Network packet labeling
Chris PeBenito 6962bb
#
Chris PeBenito c634db
$(net_contexts): $(moddir)/kernel/corenetwork.te.in
Chris PeBenito 6962bb
	@echo "Creating netfilter network labeling rules"
Chris PeBenito 6962bb
	$(verbose) $(gennetfilter) $^ > $@
Chris PeBenito 6962bb
Chris PeBenito 6962bb
########################################
Chris PeBenito 6962bb
#
Chris PeBenito 84eb35
# Create config files
Chris PeBenito 84eb35
#
Chris PeBenito c634db
conf: $(mod_conf) $(booleans) $(generated_te) $(generated_if) $(generated_fc)
Chris PeBenito d2d6c8
Chris PeBenito c634db
$(mod_conf) $(booleans): $(polxml)
Chris PeBenito c634db
	@echo "Updating $(mod_conf) and $(booleans)"
Chris PeBenito c634db
	$(verbose) $(gendoc) -b $(booleans) -m $(mod_conf) -x $(polxml)
Chris PeBenito 84eb35
Chris PeBenito 84eb35
########################################
Chris PeBenito 84eb35
#
Chris PeBenito c9f20d
# Generate the fc_sort program
Chris PeBenito c9f20d
#
Chris PeBenito c634db
$(fcsort) : $(support)/fc_sort.c
Chris PeBenito 96fc0a
	$(verbose) $(CC) $(CFLAGS) $^ -o $@
Chris PeBenito c9f20d
Chris PeBenito c9f20d
########################################
Chris PeBenito c9f20d
#
Chris PeBenito 6d314f
# Documentation generation
Chris PeBenito 6d314f
#
Chris PeBenito 96fc0a
$(layerxml): %.xml: $(all_metaxml) $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods)) $(subst .te,.if, $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods)))
Chris PeBenito 56e1b3
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 96fc0a
	$(verbose) cat $(filter %$(notdir $*)/$(metaxml), $(all_metaxml)) > $@
Chris PeBenito 96fc0a
	$(verbose) for i in $(basename $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods))); do $(genxml) -w -m $$i >> $@; done
Chris PeBenito 96fc0a
ifdef LOCAL_ROOT
Chris PeBenito 96fc0a
	$(verbose) for i in $(basename $(filter $(addprefix $(local_moddir)/, $(notdir $*))%, $(detected_mods))); do $(genxml) -w -m $$i >> $@; done
Chris PeBenito 96fc0a
endif	
Chris PeBenito 56e1b3
Chris PeBenito 56e1b3
$(tunxml): $(globaltun)
Chris PeBenito 56e1b3
	$(verbose) $(genxml) -w -t $< > $@
Chris PeBenito 56e1b3
Chris PeBenito 56e1b3
$(boolxml): $(globalbool)
Chris PeBenito 56e1b3
	$(verbose) $(genxml) -w -b $< > $@
Chris PeBenito 56e1b3
Chris PeBenito 56e1b3
$(polxml): $(layerxml) $(tunxml) $(boolxml)
Chris PeBenito 1a7175
	@echo "Creating $(@F)"
Chris PeBenito c634db
	@test -d $(dir $(polxml)) || mkdir -p $(dir $(polxml))
Chris PeBenito c634db
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito 9b3756
	$(verbose) echo '' > $@
Chris PeBenito c634db
	$(verbose) echo '' >> $@
Chris PeBenito 56e1b3
	$(verbose) echo '<policy>' >> $@
Chris PeBenito 96fc0a
	$(verbose) for i in $(basename $(notdir $(layerxml))); do echo "<layer name=\"$$i\">" >> $@; cat $(tmpdir)/$$i.xml >> $@; echo "</layer>" >> $@; done
Chris PeBenito 96fc0a
	$(verbose) cat $(tunxml) $(boolxml) >> $@
Chris PeBenito 56e1b3
	$(verbose) echo '</policy>' >> $@
Chris PeBenito c634db
	$(verbose) if test -x $(XMLLINT) && test -f $(xmldtd); then \
Chris PeBenito c634db
		$(XMLLINT) --noout --path $(dir $(xmldtd)) --dtdvalid $(xmldtd) $@ ;\
Chris PeBenito 004db9
	fi
Chris PeBenito 6d314f
Chris PeBenito 56e1b3
xml: $(polxml)
Chris PeBenito 3d5980
Chris PeBenito c634db
html $(tmpdir)/html: $(polxml)
Chris PeBenito c634db
	@echo "Building html interface reference documentation in $(htmldir)"
Chris PeBenito c634db
	@test -d $(htmldir) || mkdir -p $(htmldir)
Chris PeBenito c634db
	@test -d $(tmpdir) || mkdir -p $(tmpdir)
Chris PeBenito c634db
	$(verbose) $(gendoc) -d $(htmldir) -T $(doctemplate) -x $(polxml)
Chris PeBenito c634db
	$(verbose) cp $(doctemplate)/*.css $(htmldir)
Chris PeBenito c634db
	@touch $(tmpdir)/html
Chris PeBenito 20030e
Chris PeBenito c9a26b
########################################
Chris PeBenito c9a26b
#
Chris PeBenito c9a26b
# Runtime binary policy patching of users
Chris PeBenito c9a26b
#
Chris PeBenito c634db
$(userpath)/system.users: $(m4support) $(tmpdir)/generated_definitions.conf $(user_files)
Chris PeBenito c634db
	@mkdir -p $(tmpdir)
Chris PeBenito c634db
	@mkdir -p $(userpath)
Chris PeBenito c9a26b
	@echo "Installing system.users"
Chris PeBenito c634db
	@echo "# " > $(tmpdir)/system.users
Chris PeBenito c634db
	@echo "# Do not edit this file. " >> $(tmpdir)/system.users
Chris PeBenito c634db
	@echo "# This file is replaced on reinstalls of this policy." >> $(tmpdir)/system.users
Chris PeBenito c634db
	@echo "# Please edit local.users to make local changes." >> $(tmpdir)/system.users
Chris PeBenito c634db
	@echo "#" >> $(tmpdir)/system.users
Chris PeBenito cfd5c5
	$(verbose) $(M4) -D self_contained_policy $(M4PARAM) $^ | $(SED) -r -e 's/^[[:blank:]]+//' \
Chris PeBenito c634db
		-e '/^[[:blank:]]*($$|#)/d' >> $(tmpdir)/system.users
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(tmpdir)/system.users $@
Chris PeBenito c9a26b
Chris PeBenito c634db
$(userpath)/local.users: config/local.users
Chris PeBenito c634db
	@mkdir -p $(userpath)
Chris PeBenito c9a26b
	@echo "Installing local.users"
Chris PeBenito cfd5c5
	$(verbose) $(INSTALL) -b -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito c9a26b
########################################
Chris PeBenito c9a26b
#
Chris PeBenito e070dd
# Build Appconfig files
Chris PeBenito e070dd
#
Chris PeBenito e070dd
$(tmpdir)/initrc_context: $(appconf)/initrc_context
Chris PeBenito e070dd
	@mkdir -p $(tmpdir)
Chris PeBenito e070dd
	$(verbose) $(M4) $(M4PARAM) $(m4support) $^ | $(GREP) '^[a-z]' > $@
Chris PeBenito e070dd
Chris PeBenito e070dd
########################################
Chris PeBenito e070dd
#
Chris PeBenito e070dd
# Install Appconfig files
Chris PeBenito c9a26b
#
Chris PeBenito c634db
install-appconfig: $(appfiles)
Chris PeBenito c9a26b
Chris PeBenito c634db
$(installdir)/booleans: $(booleans)
Chris PeBenito c634db
	@mkdir -p $(tmpdir)
Chris PeBenito c634db
	@mkdir -p $(installdir)
Chris PeBenito cfd5c5
	$(verbose) $(SED) -r -e 's/false/0/g' -e 's/true/1/g' \
Chris PeBenito c634db
		-e '/^[[:blank:]]*($$|#)/d' $(booleans) | $(SORT) > $(tmpdir)/booleans
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(tmpdir)/booleans $@
Chris PeBenito 1beba1
Chris PeBenito c634db
$(contextpath)/files/media: $(appconf)/media
Chris PeBenito c634db
	@mkdir -p $(contextpath)/files/
Chris PeBenito cfd5c5
	$(verbose) $(INSTALL) -m 644 $< $@
Chris PeBenito c9a26b
Chris PeBenito 8a2492
$(contextpath)/users/%: $(appconf)/%_default_contexts
Chris PeBenito c634db
	@mkdir -p $(appdir)/users
Chris PeBenito 8a2492
	$(verbose) $(INSTALL) -m 644 $^ $@
Chris PeBenito 9b3756
Chris PeBenito b23e1c
$(appdir)/%: $(appconf)/%
Chris PeBenito b23e1c
	@mkdir -p $(appdir)
Chris PeBenito b23e1c
	$(verbose) $(INSTALL) -m 644 $< $@
Chris PeBenito b23e1c
Chris PeBenito 9b3756
########################################
Chris PeBenito 9b3756
#
Chris PeBenito 9b3756
# Install policy headers
Chris PeBenito 9b3756
#
Chris PeBenito 56e1b3
install-headers: $(layerxml) $(tunxml) $(boolxml)
Chris PeBenito c634db
	@mkdir -p $(headerdir)
Chris PeBenito 1a7175
	@echo "Installing $(TYPE) policy headers."
Chris PeBenito 96fc0a
	$(verbose) $(INSTALL) -m 644 $^ $(headerdir)
Chris PeBenito c634db
	$(verbose) $(M4) $(M4PARAM) $(rolemap) > $(headerdir)/$(notdir $(rolemap))
Chris PeBenito c634db
	$(verbose) mkdir -p $(headerdir)/support
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(m4support) $(word $(words $(genxml)),$(genxml)) $(xmldtd) $(headerdir)/support
Chris PeBenito c634db
	$(verbose) $(genperm) $(avs) $(secclass) > $(headerdir)/support/all_perms.spt
Chris PeBenito c634db
	$(verbose) for i in $(notdir $(all_layers)); do \
Chris PeBenito c634db
		mkdir -p $(headerdir)/$$i ;\
Chris PeBenito 96fc0a
		$(INSTALL) -m 644 $(moddir)/$$i/*.if $(headerdir)/$$i ;\
Chris PeBenito 885b83
	done
Chris PeBenito c634db
	$(verbose) echo "TYPE ?= $(TYPE)" > $(headerdir)/build.conf
Chris PeBenito c634db
	$(verbose) echo "NAME ?= $(NAME)" >> $(headerdir)/build.conf
Chris PeBenito 885b83
ifneq "$(DISTRO)" ""
Chris PeBenito c634db
	$(verbose) echo "DISTRO ?= $(DISTRO)" >> $(headerdir)/build.conf
Chris PeBenito 885b83
endif
Chris PeBenito c634db
	$(verbose) echo "MONOLITHIC ?= n" >> $(headerdir)/build.conf
Chris PeBenito c634db
	$(verbose) echo "DIRECT_INITRC ?= $(DIRECT_INITRC)" >> $(headerdir)/build.conf
Chris PeBenito 296273
	$(verbose) echo "override UBAC := $(UBAC)" >> $(headerdir)/build.conf
Chris PeBenito e070dd
	$(verbose) echo "override MLS_SENS := $(MLS_SENS)" >> $(headerdir)/build.conf
Chris PeBenito e070dd
	$(verbose) echo "override MLS_CATS := $(MLS_CATS)" >> $(headerdir)/build.conf
Chris PeBenito e070dd
	$(verbose) echo "override MCS_CATS := $(MCS_CATS)" >> $(headerdir)/build.conf
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(support)/Makefile.devel $(headerdir)/Makefile
Chris PeBenito c9a26b
Chris PeBenito c592e5
########################################
Chris PeBenito c592e5
#
Chris PeBenito 120988
# Install policy documentation
Chris PeBenito 120988
#
Chris PeBenito c634db
install-docs: $(tmpdir)/html
Chris PeBenito c634db
	@mkdir -p $(docsdir)/html
Chris PeBenito 120988
	@echo "Installing policy documentation"
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(docfiles) $(docsdir)
Chris PeBenito c634db
	$(verbose) $(INSTALL) -m 644 $(wildcard $(htmldir)/*) $(docsdir)/html
Chris PeBenito 120988
Chris PeBenito 120988
########################################
Chris PeBenito 120988
#
Chris PeBenito c592e5
# Install policy sources
Chris PeBenito c592e5
#
Chris PeBenito c592e5
install-src:
Chris PeBenito c634db
	rm -rf $(srcpath)/policy.old
Chris PeBenito c634db
	-mv $(srcpath)/policy $(srcpath)/policy.old
Chris PeBenito c634db
	mkdir -p $(srcpath)/policy
Chris PeBenito c634db
	cp -R . $(srcpath)/policy
Chris PeBenito c592e5
Chris PeBenito 102a59
########################################
Chris PeBenito 102a59
#
Chris PeBenito 37227d
# Generate tags file
Chris PeBenito 37227d
#
Chris PeBenito c634db
tags: $(tags)
Chris PeBenito c634db
$(tags):
Chris PeBenito 37227d
	@($(CTAGS) --version | grep -q Exuberant) || (echo ERROR: Need exuberant-ctags to function!; exit 1)
Chris PeBenito c634db
	@LC_ALL=C $(CTAGS) -f $(tags) --langdef=te --langmap=te:..te.if.spt \
Chris PeBenito 37227d
	 --regex-te='/^type[ \t]+(\w+)(,|;)/\1/t,type/' \
Chris PeBenito 37227d
	 --regex-te='/^typealias[ \t]+\w+[ \t+]+alias[ \t]+(\w+);/\1/t,type/' \
Chris PeBenito 37227d
	 --regex-te='/^attribute[ \t]+(\w+);/\1/a,attribute/' \
Chris PeBenito 37227d
	 --regex-te='/^[ \t]*define\(`(\w+)/\1/d,define/' \
Chris PeBenito 37227d
	 --regex-te='/^[ \t]*interface\(`(\w+)/\1/i,interface/' \
Chris PeBenito 423198
	 --regex-te='/^[ \t]*template\(`(\w+)/\1/i,template/' \
Chris PeBenito 37227d
	 --regex-te='/^[ \t]*bool[ \t]+(\w+)/\1/b,bool/' policy/modules/*/*.{if,te} policy/support/*.spt
Chris PeBenito 37227d
Chris PeBenito 37227d
########################################
Chris PeBenito 37227d
#
Chris PeBenito 120988
# Filesystem labeling
Chris PeBenito 120988
#
Chris PeBenito 120988
checklabels:
Chris PeBenito 120988
	@echo "Checking labels on filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito c634db
	@if test -z "$(filesystems)"; then \
Chris PeBenito 120988
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 120988
		false ;\
Chris PeBenito 120988
	fi
Chris PeBenito c634db
	$(verbose) $(SETFILES) -v -n $(fcpath) $(filesystems)
Chris PeBenito 120988
Chris PeBenito 120988
restorelabels:
Chris PeBenito 120988
	@echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito c634db
	@if test -z "$(filesystems)"; then \
Chris PeBenito 120988
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 120988
		false ;\
Chris PeBenito 120988
	fi
Chris PeBenito c634db
	$(verbose) $(SETFILES) -v $(fcpath) $(filesystems)
Chris PeBenito 120988
Chris PeBenito 120988
relabel:
Chris PeBenito 120988
	@echo "Relabeling filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito c634db
	@if test -z "$(filesystems)"; then \
Chris PeBenito 120988
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 120988
		false ;\
Chris PeBenito 120988
	fi
Chris PeBenito c634db
	$(verbose) $(SETFILES) $(fcpath) $(filesystems)
Chris PeBenito 120988
Chris PeBenito 120988
resetlabels:
Chris PeBenito 120988
	@echo "Resetting labels on filesystem types: ext2 ext3 xfs jfs"
Chris PeBenito c634db
	@if test -z "$(filesystems)"; then \
Chris PeBenito 120988
		echo "No filesystems with extended attributes found!" ;\
Chris PeBenito 120988
		false ;\
Chris PeBenito 120988
	fi
Chris PeBenito c634db
	$(verbose) $(SETFILES) -F $(fcpath) $(filesystems)
Chris PeBenito 120988
Chris PeBenito 120988
########################################
Chris PeBenito 120988
#
Chris PeBenito 102a59
# Clean everything
Chris PeBenito 102a59
#
Chris PeBenito 0fbe15
bare: clean
Chris PeBenito c634db
	rm -f $(polxml)
Chris PeBenito 56e1b3
	rm -f $(layerxml)
Chris PeBenito 56e1b3
	rm -f $(modxml)
Chris PeBenito c634db
	rm -f $(tunxml)
Chris PeBenito c634db
	rm -f $(boolxml)
Chris PeBenito c634db
	rm -f $(mod_conf)
Chris PeBenito c634db
	rm -f $(booleans)
Chris PeBenito c634db
	rm -fR $(htmldir)
Chris PeBenito c634db
	rm -f $(tags)
Chris PeBenito c9f20d
# don't remove these files if we're given a local root
Chris PeBenito c9f20d
ifndef LOCAL_ROOT
Chris PeBenito c634db
	rm -f $(fcsort)
Chris PeBenito c634db
	rm -f $(support)/*.pyc
Chris PeBenito c634db
ifneq ($(generated_te),)
Chris PeBenito c634db
	rm -f $(generated_te)
Chris PeBenito c767b1
endif
Chris PeBenito c634db
ifneq ($(generated_if),)
Chris PeBenito c634db
	rm -f $(generated_if)
Chris PeBenito c767b1
endif
Chris PeBenito c634db
ifneq ($(generated_fc),)
Chris PeBenito c634db
	rm -f $(generated_fc)
Chris PeBenito c767b1
endif
Chris PeBenito c9f20d
endif
Chris PeBenito 0fbe15
Chris PeBenito 96fc0a
.PHONY: install-src install-appconfig install-headers generate xml conf html bare tags
Chris PeBenito b8c798
.SUFFIXES:
Chris PeBenito b8c798
.SUFFIXES: .c