selinux-refpolicy/refpolicy/Makefile

353 lines
10 KiB
Makefile
Raw Normal View History

#
# Makefile for the security policy.
#
# Targets:
#
# install - compile and install the policy configuration, and context files.
# load - compile, install, and load the policy configuration.
# reload - compile, install, and load/reload the policy configuration.
# relabel - relabel filesystems based on the file contexts configuration.
# checklabels - check filesystems against the file context configuration
# restorelabels - check filesystems against the file context configuration
# and restore the label of files with incorrect labels
# policy - compile the policy configuration locally for testing/development.
#
# The default target is 'policy'.
#
2005-04-14 20:18:17 +00:00
########################################
#
# Configurable portions of the Makefile
#
# Build compatibility policies
POLICYCOMPAT = 18
# Build MLS policies
MLS=n
2005-04-14 20:18:17 +00:00
# set distribution
2005-05-25 20:58:09 +00:00
override M4PARAM += -D distro_redhat
2005-04-14 20:18:17 +00:00
# Uncomment this to disable command echoing
#QUIET:=@
########################################
#
# Invariant portions of the Makefile
#
# executable paths
PREFIX := /usr
BINDIR := $(PREFIX)/bin
SBINDIR := $(PREFIX)/sbin
CHECKPOLICY := $(BINDIR)/checkpolicy
2005-05-24 20:44:31 +00:00
LOADPOLICY := $(SBINDIR)/load_policy
2005-04-14 20:18:17 +00:00
SETFILES := $(SBINDIR)/setfiles
# enable MLS if requested.
ifeq ($(MLS),y)
override M4PARAM += -D enable_mls
CHECKPOLICY += -M
endif
ifneq ($(POLICYCOMPAT),)
CHECKPOLICY += -c $(POLICYCOMPAT)
endif
2005-04-14 20:18:17 +00:00
# determine the policy version and current kernel version if possible
PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
2005-04-14 20:18:17 +00:00
KV := $(shell cat /selinux/policyvers)
# dont print version warnings if we are unable to determine
# the currently running kernel's policy version
ifeq ($(KV),)
KV := $(PV)
2005-04-14 20:18:17 +00:00
endif
FC := file_contexts
POLVER := policy.$(PV)
TYPE := strict
# install paths
TOPDIR = $(DESTDIR)/etc/selinux
INSTALLDIR = $(TOPDIR)/$(TYPE)
POLICYPATH = $(INSTALLDIR)/policy
SRCPATH = $(INSTALLDIR)/src
USERPATH = $(INSTALLDIR)/users
CONTEXTPATH = $(INSTALLDIR)/contexts
LOADPATH = $(POLICYPATH)/$(POLVER)
FCPATH = $(CONTEXTPATH)/files/file_contexts
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
BASE_MODULE = kernel
FLASKDIR = flask
2005-06-01 17:27:56 +00:00
APPCONF = appconfig
2005-04-14 20:18:17 +00:00
2005-05-25 20:58:09 +00:00
APPDIR := $(CONTEXTPATH)
APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
2005-06-01 17:27:56 +00:00
CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
USER_FILES := users
2005-05-25 20:58:09 +00:00
2005-04-14 20:18:17 +00:00
DETECTED_DIRS := $(shell find $(wildcard *) -maxdepth 0 -type d)
2005-06-01 17:27:56 +00:00
ALL_LAYERS := $(filter-out tmp CVS $(APPCONF) $(FLASKDIR),$(DETECTED_DIRS))
2005-04-14 20:18:17 +00:00
PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) mls
2005-06-01 17:27:56 +00:00
ALL_INTERFACES := $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if))
ALL_TE_FILES := $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te))
POST_TE_FILES := users constraints initial_sid_contexts fs_use
2005-04-14 20:18:17 +00:00
2005-06-01 17:27:56 +00:00
ALL_FC_FILES := $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc))
2005-04-14 20:18:17 +00:00
POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf
2005-04-14 20:18:17 +00:00
########################################
#
# default action: build policy locally
#
default: policy
policy: $(POLVER)
2005-05-25 20:58:09 +00:00
install: $(LOADPATH) $(FCPATH) $(USERPATH)/local.users
load: tmp/load
2005-04-14 20:18:17 +00:00
########################################
#
# Build a binary policy locally
#
$(POLVER): policy.conf
2005-05-24 17:31:39 +00:00
@echo "Compiling $(POLVER)"
2005-04-14 20:18:17 +00:00
ifneq ($(PV),$(KV))
@echo
@echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
@echo
endif
$(QUIET) $(CHECKPOLICY) $^ -o $@
2005-04-14 20:18:17 +00:00
########################################
#
# Install a binary policy
#
$(LOADPATH): policy.conf
@mkdir -p $(POLICYPATH)
2005-05-24 17:31:39 +00:00
@echo "Compiling and installing $(LOADPATH)"
2005-04-14 20:18:17 +00:00
ifneq ($(PV),$(KV))
@echo
@echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
@echo
endif
$(QUIET) $(CHECKPOLICY) $^ -o $@
2005-04-14 20:18:17 +00:00
########################################
#
# Load the binary policy
#
reload tmp/load: $(LOADPATH) $(FCPATH)
2005-05-24 17:31:39 +00:00
@echo "Loading $(LOADPATH)"
$(QUIET) $(LOADPOLICY) -q $(LOADPATH)
@touch tmp/load
2005-04-14 20:18:17 +00:00
########################################
#
# Construct a monolithic policy.conf
#
policy.conf: $(POLICY_SECTIONS)
2005-05-24 17:31:39 +00:00
@echo "Creating policy.conf"
# checkpolicy can use the #line directives provided by -s for error reporting:
2005-05-25 20:58:09 +00:00
$(QUIET) m4 $(M4PARAM) -D monolithic_policy -s $^ > tmp/$@.tmp
2005-04-14 20:18:17 +00:00
$(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
2005-05-24 17:31:39 +00:00
# the ordering of these ocontexts matters:
2005-04-14 20:18:17 +00:00
$(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
$(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
$(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
tmp/pre_te_files.conf: $(PRE_TE_FILES)
@test -d tmp || mkdir -p tmp
$(QUIET) cat $^ > $@
2005-06-01 17:27:56 +00:00
tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) $(BASE_MODULE)/corenetwork.if $(BASE_MODULE)/corenetwork.te
2005-04-14 20:18:17 +00:00
@test -d tmp || mkdir -p tmp
$(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
$(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_TE_FILES))); do \
2005-04-14 20:18:17 +00:00
echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
>> $@ ;\
done
$(QUIET) echo "')" >> $@
$(QUIET) for i in $(notdir $(ALL_TE_FILES)); do \
echo "define(\`$$i')" >> $@ ;\
done
2005-05-25 20:58:09 +00:00
$(QUIET) egrep "^network_(interface|node|port)\(.*\)" $(BASE_MODULE)/corenetwork.te \
| m4 $(M4PARAM) -D monolithic_policy -D interface_pass $(BASE_MODULE)/global.if $(BASE_MODULE)/corenetwork.if - \
| sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
2005-05-24 17:31:39 +00:00
# this is so the xml works:
$(QUIET) echo "## </module>" >> $@
2005-04-14 20:18:17 +00:00
tmp/all_interfaces.conf: $(ALL_INTERFACES)
@test -d tmp || mkdir -p tmp
$(QUIET) cat $^ > $@
tmp/all_te_files.conf: $(ALL_TE_FILES)
@test -d tmp || mkdir -p tmp
$(QUIET) cat $^ > $@
tmp/post_te_files.conf: $(POST_TE_FILES)
@test -d tmp || mkdir -p tmp
$(QUIET) cat $^ > $@
# extract attributes and put them first. extract post te stuff
# like genfscon and put last. portcon, nodecon, and netifcon
# is delayed since they are generated by m4
tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
$(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
$(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
2005-04-14 20:18:17 +00:00
$(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
$(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
$(QUIET) sed -e /^attribute/d -e '/^type /d' -e /^genfscon/d < tmp/all_te_files.conf > tmp/only_te_rules.conf
2005-04-14 20:18:17 +00:00
########################################
#
# Remove the dontaudit rules from the policy.conf
#
enableaudit: policy.conf
@test -d tmp || mkdir -p tmp
@echo "Removing dontaudit rules from policy.conf"
$(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit
$(QUIET) mv tmp/policy.audit policy.conf
2005-05-18 20:58:13 +00:00
########################################
#
# Construct file_contexts
#
$(FC): kernel/global.if $(ALL_FC_FILES)
@test -d tmp || mkdir -p tmp
$(QUIET) m4 $(M4PARAM) $^ > $@
2005-05-24 20:44:31 +00:00
########################################
#
# Install file_contexts
#
2005-05-25 20:58:09 +00:00
$(FCPATH): $(FC) $(USERPATH)/system.users
2005-05-24 20:44:31 +00:00
@mkdir -p $(CONTEXTPATH)/files
$(QUIET) install -m 644 $(FC) $(FCPATH)
# $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
# $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(TYPE) $(USEPWD)
2005-04-14 20:18:17 +00:00
########################################
#
# Filesystem labeling
#
FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
2005-04-14 20:18:17 +00:00
checklabels: $(FC) $(SETFILES)
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-04-14 20:18:17 +00:00
$(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
restorelabels: $(FC) $(SETFILES)
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-04-14 20:18:17 +00:00
$(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
relabel: $(FC) $(SETFILES)
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-04-14 20:18:17 +00:00
$(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
2005-05-18 20:58:13 +00:00
########################################
#
# Documentation generation
#
xml: policy.xml
policy.xml: $(ALL_INTERFACES) tmp/generated_definitions.conf
2005-05-24 17:31:39 +00:00
@echo "Creating $@"
$(QUIET) echo "<policy>" > $@
2005-05-25 20:58:09 +00:00
$(QUIET) egrep -h "^##[[:space:]]" $^ | sed -e 's/^##[[:space:]]//g' >> $@
2005-05-24 17:31:39 +00:00
$(QUIET) echo "</policy>" >> $@
2005-05-18 20:58:13 +00:00
2005-05-25 20:58:09 +00:00
########################################
#
# Runtime binary policy patching of users
#
$(USERPATH)/system.users: $(USER_FILES) tmp/generated_definitions.conf
@mkdir -p $(USERPATH)
@echo "Installing system.users"
@echo "# " > tmp/system.users
@echo "# Do not edit this file. " >> tmp/system.users
@echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
@echo "# Please edit local.users to make local changes." >> tmp/system.users
@echo "#" >> tmp/system.users
$(QUIET) m4 $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \
egrep -v "^[[:space:]]*($$|#)" >> tmp/system.users
$(QUIET) install -m 644 tmp/system.users $@
$(USERPATH)/local.users: local.users
@mkdir -p $(USERPATH)
@echo "Installing local.users"
$(QUIET) install -C -b -m 644 $< $@
########################################
#
# Appconfig files
#
install-appconfig: $(APPFILES)
2005-06-01 17:27:56 +00:00
$(CONTEXTPATH)/files/media: $(APPCONF)/media
2005-05-25 20:58:09 +00:00
mkdir -p $(CONTEXTPATH)/files/
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/removable_context: $(APPCONF)/removable_context
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
$(APPDIR)/customizable_types: policy.conf
mkdir -p $(APPDIR)
@grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > tmp/customizable_types
install -m 644 tmp/customizable_types $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/default_type: $(APPCONF)/default_type
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)
install -m 644 $< $@
2005-06-01 17:27:56 +00:00
$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
2005-05-25 20:58:09 +00:00
mkdir -p $(APPDIR)/users
install -m 644 $< $@
2005-04-14 20:18:17 +00:00
clean:
rm -fR tmp
2005-05-18 20:58:13 +00:00
rm -f policy.xml
2005-04-14 20:18:17 +00:00
rm -f policy.conf
rm -f policy.$(PV)
rm -f $(FC)
2005-05-24 17:31:39 +00:00
.PHONY: default policy install reload enableaudit checklabels restorelabels relabel xml clean