selinux-policy/refpolicy/Rules.monolithic

242 lines
7.5 KiB
Plaintext
Raw Normal View History

########################################
#
# Rules and Targets for building monolithic policies
#
# install paths
POLICYPATH = $(INSTALLDIR)/policy
LOADPATH = $(POLICYPATH)/$(POLVER)
FCPATH = $(CONTEXTPATH)/files/file_contexts
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
2005-11-22 22:07:12 +00:00
FC := file_contexts
POLVER := policy.$(PV)
2005-11-09 20:01:28 +00:00
2005-11-22 22:07:12 +00:00
APPFILES += $(APPDIR)/customizable_types $(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 := 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
2005-11-22 22:07:12 +00:00
HOMEDIR_TEMPLATE = homedir_template
# search layer dirs for source files
vpath %.te $(ALL_LAYERS)
vpath %.if $(ALL_LAYERS)
vpath %.fc $(ALL_LAYERS)
########################################
#
# default action: build policy locally
#
default: policy
policy: $(POLVER)
install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
load: tmp/load
########################################
#
# 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
$(QUIET) $(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
$(QUIET) $(CHECKPOLICY) $^ -o $@
########################################
#
# Load the binary policy
#
2005-11-22 22:07:12 +00:00
reload tmp/load: $(LOADPATH) $(FCPATH) $(APPFILES)
@echo "Loading $(NAME) $(LOADPATH)"
$(QUIET) $(LOADPOLICY) -q $(LOADPATH)
@touch tmp/load
########################################
#
# Construct a monolithic policy.conf
#
policy.conf: $(POLICY_SECTIONS)
@echo "Creating $(NAME) policy.conf"
# checkpolicy can use the #line directives provided by -s for error reporting:
$(QUIET) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
$(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
# the ordering of these ocontexts matters:
$(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 $^ > $@
tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES)
# per-userdomain templates:
@test -d tmp || mkdir -p tmp
$(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
$(QUIET) 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
$(QUIET) echo "')" >> $@
# define foo.te
$(QUIET) for i in $(notdir $(ALL_MODULES)); do \
echo "define(\`$$i')" >> $@ ;\
done
$(QUIET) $(SETTUN) $(BOOLEANS) >> $@
tmp/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 tmp || mkdir -p tmp
$(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
tmp/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 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
$(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
$(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
$(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
$(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
$(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
< tmp/all_te_files.conf > tmp/only_te_rules.conf
########################################
#
# 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
########################################
#
# Construct file_contexts
#
2005-11-22 22:07:12 +00:00
$(FC): tmp/$(FC).tmp $(FCSORT)
$(QUIET) $(FCSORT) $< $@
$(QUIET) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
$(QUIET) sed -i -e /HOME/d -e /ROLE/d $@
tmp/$(FC).tmp: $(M4SUPPORT) tmp/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 tmp || mkdir -p tmp
2005-11-22 22:07:12 +00:00
$(QUIET) m4 $(M4PARAM) $^ > $@
########################################
#
# Install file_contexts
#
$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
@echo "Validating $(NAME) file_contexts."
$(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC)
@echo "Installing file_contexts."
@mkdir -p $(CONTEXTPATH)/files
$(QUIET) install -m 644 $(FC) $(FCPATH)
$(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
$(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD)
########################################
#
# Filesystem labeling
#
FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
2005-11-22 22:07:12 +00:00
checklabels: $(FCPATH) $(SETFILES)
@echo "Checking labels on filesystem types: ext2 ext3 xfs jfs"
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-11-22 22:07:12 +00:00
$(QUIET) $(SETFILES) -v -n $(FCPATH) $(FILESYSTEMS)
2005-11-22 22:07:12 +00:00
restorelabels: $(FCPATH) $(SETFILES)
@echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs"
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-11-22 22:07:12 +00:00
$(QUIET) $(SETFILES) -v $(FCPATH) $(FILESYSTEMS)
2005-11-22 22:07:12 +00:00
relabel: $(FCPATH) $(SETFILES)
@echo "Relabeling filesystem types: ext2 ext3 xfs jfs"
@if test -z "$(FILESYSTEMS)"; then \
echo "No filesystems with extended attributes found!" ;\
false ;\
fi
2005-11-22 22:07:12 +00:00
$(QUIET) $(SETFILES) $(FCPATH) $(FILESYSTEMS)
2005-10-12 19:13:49 +00:00
########################################
#
# Run policy source checks
#
check: policy.conf $(FC)
$(SECHECK) -s --profile=development --policy=policy.conf --fcfile=$(FC) > $@.res
longcheck: policy.conf $(FC)
$(SECHECK) -s --profile=all --policy=policy.conf --fcfile=$(FC) > $@.res
########################################
#
# Clean the sources
#
clean:
rm -f policy.conf
rm -f policy.$(PV)
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
2005-11-22 22:07:12 +00:00
rm -fR tmp
2005-10-12 19:13:49 +00:00
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean