|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Rules and Targets for building monolithic policies
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
5b45ff |
POLICY_CONF = $(BUILDDIR)policy.conf
|
|
Chris PeBenito |
5b45ff |
FC = $(BUILDDIR)file_contexts
|
|
Chris PeBenito |
5b45ff |
POLVER = $(BUILDDIR)policy.$(PV)
|
|
Chris PeBenito |
5b45ff |
HOMEDIR_TEMPLATE = $(BUILDDIR)homedir_template
|
|
Chris PeBenito |
c9f20d |
|
|
Chris PeBenito |
3abd5e |
M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
3abd5e |
|
|
Chris PeBenito |
fb0a3a |
# install paths
|
|
Chris PeBenito |
fb0a3a |
POLICYPATH = $(INSTALLDIR)/policy
|
|
Chris PeBenito |
5b45ff |
LOADPATH = $(POLICYPATH)/$(notdir $(POLVER))
|
|
Chris PeBenito |
fb0a3a |
HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
049e11 |
APPFILES += $(INSTALLDIR)/booleans
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c767b1 |
# for monolithic policy use all base and module to create policy
|
|
Chris PeBenito |
cf0ff5 |
ALL_MODULES := $(strip $(BASE_MODS) $(MOD_MODS))
|
|
Chris PeBenito |
ab23bb |
# off module interfaces included to make sure all interfaces are expanded.
|
|
Chris PeBenito |
ab23bb |
ALL_INTERFACES := $(ALL_MODULES:.te=.if) $(OFF_MODS:.te=.if)
|
|
Chris PeBenito |
fb0a3a |
ALL_TE_FILES := $(ALL_MODULES)
|
|
Chris PeBenito |
fb0a3a |
ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
a08248 |
PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
|
|
Chris PeBenito |
ffd048 |
POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
3abd5e |
POLICY_SECTIONS := $(TMPDIR)/pre_te_files.conf $(TMPDIR)/all_attrs_types.conf $(TMPDIR)/global_bools.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c767b1 |
# search layer dirs for source files
|
|
Chris PeBenito |
e2680f |
vpath %.te $(ALL_LAYERS)
|
|
Chris PeBenito |
e2680f |
vpath %.if $(ALL_LAYERS)
|
|
Chris PeBenito |
e2680f |
vpath %.fc $(ALL_LAYERS)
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# default action: build policy locally
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
default: policy
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
policy: $(POLVER)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c9f20d |
load: $(TMPDIR)/load
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
120988 |
checklabels: $(FCPATH)
|
|
Chris PeBenito |
120988 |
restorelabels: $(FCPATH)
|
|
Chris PeBenito |
120988 |
relabel: $(FCPATH)
|
|
Chris PeBenito |
120988 |
resetlabels: $(FCPATH)
|
|
Chris PeBenito |
120988 |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Build a binary policy locally
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
$(POLVER): $(POLICY_CONF)
|
|
Chris PeBenito |
fb0a3a |
@echo "Compiling $(NAME) $(POLVER)"
|
|
Chris PeBenito |
fb0a3a |
ifneq ($(PV),$(KV))
|
|
Chris PeBenito |
fb0a3a |
@echo
|
|
Chris PeBenito |
fb0a3a |
@echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
|
|
Chris PeBenito |
fb0a3a |
@echo
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
5b45ff |
$(verbose) $(CHECKPOLICY) $^ -o $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Install a binary policy
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
$(LOADPATH): $(POLICY_CONF)
|
|
Chris PeBenito |
fb0a3a |
@mkdir -p $(POLICYPATH)
|
|
Chris PeBenito |
fb0a3a |
@echo "Compiling and installing $(NAME) $(LOADPATH)"
|
|
Chris PeBenito |
fb0a3a |
ifneq ($(PV),$(KV))
|
|
Chris PeBenito |
fb0a3a |
@echo
|
|
Chris PeBenito |
fb0a3a |
@echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?"
|
|
Chris PeBenito |
fb0a3a |
@echo
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(CHECKPOLICY) $^ -o $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Load the binary policy
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
reload $(TMPDIR)/load: $(LOADPATH) $(FCPATH) $(APPFILES)
|
|
Chris PeBenito |
fb0a3a |
@echo "Loading $(NAME) $(LOADPATH)"
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(LOADPOLICY) -q $(LOADPATH)
|
|
Chris PeBenito |
c9f20d |
@touch $(TMPDIR)/load
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Construct a monolithic policy.conf
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
$(POLICY_CONF): $(POLICY_SECTIONS)
|
|
Chris PeBenito |
c9f20d |
@echo "Creating $(NAME) $(@F)"
|
|
Chris PeBenito |
3abd5e |
@test -d $(@D) || mkdir -p $(@D)
|
|
Chris PeBenito |
3abd5e |
$(verbose) cat $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c9f20d |
$(TMPDIR)/pre_te_files.conf: $(PRE_TE_FILES)
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
988a44 |
$(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES)
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
701316 |
# define all available object classes
|
|
Chris PeBenito |
701316 |
$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@
|
|
Chris PeBenito |
701316 |
# per-userdomain templates:
|
|
Chris PeBenito |
701316 |
$(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(foreach mod,$(basename $(notdir $(ALL_MODULES))), \
|
|
Chris PeBenito |
3abd5e |
echo "ifdef(\`""$(mod)""_per_userdomain_template',\`""$(mod)""_per_userdomain_template("'$$*'")')" >> $@ ;)
|
|
Chris PeBenito |
9b3756 |
$(verbose) echo "')" >> $@
|
|
Chris PeBenito |
5b45ff |
$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
3abd5e |
$(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
3abd5e |
|
|
Chris PeBenito |
c9f20d |
$(TMPDIR)/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
|
|
Chris PeBenito |
fb0a3a |
ifeq ($(ALL_INTERFACES),)
|
|
Chris PeBenito |
fb0a3a |
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
5706fa |
@echo "ifdef(\`__if_error',\`m4exit(1)')" > $(TMPDIR)/iferror.m4
|
|
Chris PeBenito |
3abd5e |
@echo "divert(-1)" > $@
|
|
Chris PeBenito |
5706fa |
$(verbose) $(M4) $^ $(TMPDIR)/iferror.m4 >> $(TMPDIR)/$(@F).tmp
|
|
Chris PeBenito |
5706fa |
$(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(TMPDIR)/$(@F).tmp >> $@
|
|
Chris PeBenito |
3abd5e |
@echo "divert" >> $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
3abd5e |
$(TMPDIR)/rolemap.conf: $(ROLEMAP)
|
|
Chris PeBenito |
3abd5e |
$(call parse-rolemap,base,$@)
|
|
Chris PeBenito |
3abd5e |
|
|
Chris PeBenito |
3abd5e |
$(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(ALL_TE_FILES) $(TMPDIR)/rolemap.conf
|
|
Chris PeBenito |
fb0a3a |
ifeq ($(ALL_TE_FILES),)
|
|
Chris PeBenito |
fb0a3a |
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) -s $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
3abd5e |
$(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(POST_TE_FILES)
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
# extract attributes and put them first. extract post te stuff
|
|
Chris PeBenito |
3abd5e |
# like genfscon and put last.
|
|
Chris PeBenito |
c9f20d |
$(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf: $(TMPDIR)/all_te_files.conf $(TMPDIR)/post_te_files.conf
|
|
Chris PeBenito |
f62f4c |
$(verbose) $(get_type_attr_decl) $(TMPDIR)/all_te_files.conf | $(SORT) > $(TMPDIR)/all_attrs_types.conf
|
|
Chris PeBenito |
c9f20d |
$(verbose) cat $(TMPDIR)/post_te_files.conf > $(TMPDIR)/all_post.conf
|
|
Chris PeBenito |
3abd5e |
# these have to run individually because order matters:
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) ^genfscon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Remove the dontaudit rules from the policy.conf
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
enableaudit: $(POLICY_CONF)
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
c9f20d |
@echo "Removing dontaudit rules from $(notdir $(POLICY_CONF))"
|
|
Chris PeBenito |
8e86e4 |
$(verbose) $(GREP) -v dontaudit $^ > $(TMPDIR)/policy.audit
|
|
Chris PeBenito |
c9f20d |
$(verbose) mv $(TMPDIR)/policy.audit $(POLICY_CONF)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Construct file_contexts
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c9f20d |
$(FC): $(TMPDIR)/$(notdir $(FC)).tmp $(FCSORT)
|
|
Chris PeBenito |
5d92a2 |
$(verbose) $(FCSORT) $< $@
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(GREP) -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(SED) -i -e /HOME/d -e /ROLE/d $@
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c9f20d |
$(TMPDIR)/$(notdir $(FC)).tmp: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(ALL_FC_FILES)
|
|
Chris PeBenito |
fb0a3a |
ifeq ($(ALL_FC_FILES),)
|
|
Chris PeBenito |
fb0a3a |
$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
fb0a3a |
@echo "Creating $(NAME) file_contexts."
|
|
Chris PeBenito |
c9f20d |
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fc47b3 |
$(HOMEDIR_TEMPLATE): $(FC)
|
|
Chris PeBenito |
fc47b3 |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Install file_contexts
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users
|
|
Chris PeBenito |
fb0a3a |
@echo "Validating $(NAME) file_contexts."
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(SETFILES) -q -c $(LOADPATH) $(FC)
|
|
Chris PeBenito |
fb0a3a |
@echo "Installing file_contexts."
|
|
Chris PeBenito |
fb0a3a |
@mkdir -p $(CONTEXTPATH)/files
|
|
Chris PeBenito |
9b3756 |
$(verbose) install -m 644 $(FC) $(FCPATH)
|
|
Chris PeBenito |
9b3756 |
$(verbose) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH)
|
|
Chris PeBenito |
fc47b3 |
$(verbose) $(genhomedircon) -d $(TOPDIR) -t $(NAME) $(USEPWD)
|
|
Chris PeBenito |
fc47b3 |
ifeq "$(DISTRO)" "rhel4"
|
|
Chris PeBenito |
fc47b3 |
# Setfiles in RHEL4 does not look at file_contexts.homedirs.
|
|
Chris PeBenito |
fc47b3 |
$(verbose) cat $@.homedirs >> $@
|
|
Chris PeBenito |
fc47b3 |
# Delete the file_contexts.homedirs in case the toolchain has
|
|
Chris PeBenito |
fc47b3 |
# been updated, to prevent duplicate match errors.
|
|
Chris PeBenito |
fc47b3 |
$(verbose) rm -f $@.homedirs
|
|
Chris PeBenito |
185ab2 |
endif
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
8df65f |
# Run policy source checks
|
|
Chris PeBenito |
8df65f |
#
|
|
Chris PeBenito |
5b45ff |
check: $(BUILDDIR)check.res
|
|
Chris PeBenito |
5b45ff |
$(BUILDDIR)check.res: $(POLICY_CONF) $(FC)
|
|
Chris PeBenito |
5b45ff |
$(SECHECK) -s --profile=development --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
|
|
Chris PeBenito |
8df65f |
|
|
Chris PeBenito |
5b45ff |
longcheck: $(BUILDDIR)longcheck.res
|
|
Chris PeBenito |
5b45ff |
$(BUILDDIR)longcheck.res: $(POLICY_CONF) $(FC)
|
|
Chris PeBenito |
5b45ff |
$(SECHECK) -s --profile=all --policy=$(POLICY_CONF) --fcfile=$(FC) > $@
|
|
Chris PeBenito |
8df65f |
|
|
Chris PeBenito |
8df65f |
########################################
|
|
Chris PeBenito |
8df65f |
#
|
|
Chris PeBenito |
049e11 |
# Appconfig files
|
|
Chris PeBenito |
049e11 |
#
|
|
Chris PeBenito |
efc94a |
$(APPDIR)/customizable_types: $(POLICY_CONF)
|
|
Chris PeBenito |
049e11 |
@mkdir -p $(APPDIR)
|
|
Chris PeBenito |
85a0f9 |
$(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(TMPDIR)/customizable_types
|
|
Chris PeBenito |
4ca6d0 |
$(verbose) install -m 644 $(TMPDIR)/customizable_types $@
|
|
Chris PeBenito |
049e11 |
|
|
Chris PeBenito |
049e11 |
########################################
|
|
Chris PeBenito |
049e11 |
#
|
|
Chris PeBenito |
fb0a3a |
# Clean the sources
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
clean:
|
|
Chris PeBenito |
c9f20d |
rm -f $(POLICY_CONF)
|
|
Chris PeBenito |
5b45ff |
rm -f $(POLVER)
|
|
Chris PeBenito |
fb0a3a |
rm -f $(FC)
|
|
Chris PeBenito |
c767b1 |
rm -f $(HOMEDIR_TEMPLATE)
|
|
Chris PeBenito |
6962bb |
rm -f $(net_contexts)
|
|
Chris PeBenito |
8df65f |
rm -f *.res
|
|
Chris PeBenito |
c9f20d |
rm -fR $(TMPDIR)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
8df65f |
.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel check longcheck clean
|