selinux-policy/refpolicy/Rules.monolithic

230 lines
7.6 KiB
Plaintext
Raw Normal View History

########################################
#
# Rules and Targets for building monolithic policies
#
POLICY_CONF = $(BUILDDIR)policy.conf
FC = $(BUILDDIR)file_contexts
POLVER = $(BUILDDIR)policy.$(PV)
HOMEDIR_TEMPLATE = $(BUILDDIR)homedir_template
# install paths
POLICYPATH = $(INSTALLDIR)/policy
LOADPATH = $(POLICYPATH)/$(notdir $(POLVER))
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
APPFILES += $(INSTALLDIR)/booleans
2005-11-22 22:07:12 +00:00
# for monolithic policy use all base and module to create policy
2005-11-25 15:55:04 +00:00
ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS))
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
ALL_TE_FILES := $(ALL_MODULES)
ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
2005-09-16 13:36:26 +00:00
PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
2005-12-06 14:35:58 +00:00
POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
POLICY_SECTIONS := $(TMPDIR)/pre_te_files.conf $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(TMPDIR)/all_attrs_types.conf $(GLOBALBOOL) $(GLOBALTUN) $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf
2005-11-22 22:07:12 +00:00
# search layer dirs for source files
2006-02-15 18:35:02 +00:00
vpath %.te $(ALL_LAYERS)
vpath %.if $(ALL_LAYERS)
vpath %.fc $(ALL_LAYERS)
2005-11-22 22:07:12 +00:00
########################################
#
# default action: build policy locally
#
default: policy
policy: $(POLVER)
install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
load: $(TMPDIR)/load
checklabels: $(FCPATH)
restorelabels: $(FCPATH)
relabel: $(FCPATH)
resetlabels: $(FCPATH)
########################################
#
# Build a binary policy locally
#
$(POLVER): $(POLICY_CONF)
@echo "Compiling $(NAME) $(POLVER)"
ifneq ($(PV),$(KV))
@echo
@echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
@echo
endif
$(verbose) $(CHECKPOLICY) $^ -o $@
########################################
#
# Install a binary policy
#
$(LOADPATH): $(POLICY_CONF)
@mkdir -p $(POLICYPATH)
@echo "Compiling and installing $(NAME) $(LOADPATH)"
ifneq ($(PV),$(KV))
@echo
@echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
@echo
endif
$(verbose) $(CHECKPOLICY) $^ -o $@
########################################
#
# Load the binary policy
#
reload $(TMPDIR)/load: $(LOADPATH) $(FCPATH) $(APPFILES)
@echo "Loading $(NAME) $(LOADPATH)"
$(verbose) $(LOADPOLICY) -q $(LOADPATH)
@touch $(TMPDIR)/load
########################################
#
# Construct a monolithic policy.conf
#
$(POLICY_CONF): $(POLICY_SECTIONS)
@echo "Creating $(NAME) $(@F)"
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
# checkpolicy can use the #line directives provided by -s for error reporting:
$(verbose) m4 -D self_contained_policy $(M4PARAM) -s $^ > $(TMPDIR)/$(@F).tmp
$(verbose) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < $(TMPDIR)/$(@F).tmp > $@
# the ordering of these ocontexts matters:
$(verbose) grep ^portcon $(TMPDIR)/$(@F).tmp >> $@ || true
$(verbose) grep ^netifcon $(TMPDIR)/$(@F).tmp >> $@ || true
$(verbose) grep ^nodecon $(TMPDIR)/$(@F).tmp >> $@ || true
$(TMPDIR)/pre_te_files.conf: $(PRE_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
2006-02-16 16:45:56 +00:00
$(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES)
# per-userdomain templates:
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) echo "define(\`base_per_userdomain_template',\`" > $@
$(verbose) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
2005-08-25 20:27:20 +00:00
echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
>> $@ ;\
done
$(verbose) echo "')" >> $@
# define foo.te
$(verbose) for i in $(notdir $(ALL_MODULES)); do \
echo "define(\`$$i')" >> $@ ;\
done
$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
$(TMPDIR)/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
ifeq ($(ALL_INTERFACES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
$(TMPDIR)/all_te_files.conf: $(ALL_TE_FILES)
ifeq ($(ALL_TE_FILES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
$(call parse-rolemap,base,$@)
$(TMPDIR)/post_te_files.conf: $(POST_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) 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
$(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf: $(TMPDIR)/all_te_files.conf $(TMPDIR)/post_te_files.conf
$(verbose) grep ^attribute $(TMPDIR)/all_te_files.conf > $(TMPDIR)/all_attrs_types.conf || true
$(verbose) grep '^type ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_attrs_types.conf
$(verbose) cat $(TMPDIR)/post_te_files.conf > $(TMPDIR)/all_post.conf
$(verbose) grep '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) egrep '^fs_use_(xattr|task|trans)' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) grep ^genfscon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
< $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf
########################################
#
# Remove the dontaudit rules from the policy.conf
#
enableaudit: $(POLICY_CONF)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@echo "Removing dontaudit rules from $(notdir $(POLICY_CONF))"
$(verbose) grep -v dontaudit @^ > $(TMPDIR)/policy.audit
$(verbose) mv $(TMPDIR)/policy.audit $(POLICY_CONF)
########################################
#
# Construct file_contexts
#
$(FC): $(TMPDIR)/$(notdir $(FC)).tmp $(FCSORT)
$(verbose) $(FCSORT) $< $@
$(verbose) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
$(verbose) sed -i -e /HOME/d -e /ROLE/d $@
2005-11-22 22:07:12 +00:00
$(TMPDIR)/$(notdir $(FC)).tmp: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(ALL_FC_FILES)
ifeq ($(ALL_FC_FILES),)
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
endif
@echo "Creating $(NAME) file_contexts."
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $(M4PARAM) $^ > $@
########################################
#
# Install file_contexts
#
$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
@echo "Validating $(NAME) file_contexts."
$(verbose) $(SETFILES) -q -c $(LOADPATH) $(FC)
@echo "Installing file_contexts."
@mkdir -p $(CONTEXTPATH)/files
$(verbose) install -m 644 $(FC) $(FCPATH)
$(verbose) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
$(verbose) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
2005-10-12 19:13:49 +00:00
########################################
#
# Run policy source checks
#
check: $(BUILDDIR)check.res
$(BUILDDIR)check.res: $(POLICY_CONF) $(FC)
$(SECHECK) -s --profile=development --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
2005-10-12 19:13:49 +00:00
longcheck: $(BUILDDIR)longcheck.res
$(BUILDDIR)longcheck.res: $(POLICY_CONF) $(FC)
$(SECHECK) -s --profile=all --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
2005-10-12 19:13:49 +00:00
########################################
#
# Appconfig files
#
$(APPDIR)/customizable_types: policy.conf
@mkdir -p $(APPDIR)
2006-02-21 15:42:45 +00:00
$(verbose) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
$(verbose) install -m 644 $(TMPDIR)/customizable_types $@
########################################
#
# Clean the sources
#
clean:
rm -f $(POLICY_CONF)
rm -f $(POLVER)
rm -f $(FC)
2005-11-22 22:07:12 +00:00
rm -f $(HOMEDIR_TEMPLATE)
2005-10-12 19:13:49 +00:00
rm -f *.res
rm -fR $(TMPDIR)
2005-10-12 19:13:49 +00:00
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean