|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c38127 |
# Rules and Targets for building modular policies
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
all_modules := $(base_mods) $(mod_mods) $(off_mods)
|
|
Chris PeBenito |
c634db |
all_interfaces := $(all_modules:.te=.if)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
base_pkg := $(builddir)base.pp
|
|
Chris PeBenito |
c634db |
base_fc := $(builddir)base.fc
|
|
Chris PeBenito |
c634db |
base_conf := $(builddir)base.conf
|
|
Chris PeBenito |
c634db |
base_mod := $(tmpdir)/base.mod
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
users_extra := $(tmpdir)/users_extra
|
|
Chris PeBenito |
90b331 |
|
|
Chris PeBenito |
c634db |
base_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 |
fb0a3a |
|
|
Chris PeBenito |
c634db |
base_pre_te_files := $(secclass) $(isids) $(avs) $(m4support) $(poldir)/mls $(poldir)/mcs
|
|
Chris PeBenito |
c634db |
base_te_files := $(base_mods)
|
|
Chris PeBenito |
c634db |
base_post_te_files := $(user_files) $(poldir)/constraints
|
|
Chris PeBenito |
c634db |
base_fc_files := $(base_mods:.te=.fc)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
|
|
Chris PeBenito |
c04f2a |
|
|
Chris PeBenito |
c767b1 |
# policy packages to install
|
|
Chris PeBenito |
c634db |
instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c04f2a |
# search layer dirs for source files
|
|
Chris PeBenito |
c634db |
vpath %.te $(all_layers)
|
|
Chris PeBenito |
c634db |
vpath %.if $(all_layers)
|
|
Chris PeBenito |
c634db |
vpath %.fc $(all_layers)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
4b01e2 |
# broken in make 3.81:
|
|
Chris PeBenito |
4b01e2 |
#.SECONDARY:
|
|
Chris PeBenito |
e60b98 |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# default action: create all module packages
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
ddb9aa |
default: policy
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
ddb9aa |
all policy: base modules
|
|
Chris PeBenito |
06a536 |
|
|
Chris PeBenito |
c634db |
base: $(base_pkg)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
modules: $(mod_pkgs)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
install: $(instpkg) $(appfiles)
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c767b1 |
########################################
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c767b1 |
# Load all configured modules
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c634db |
load: $(instpkg) $(appfiles)
|
|
Chris PeBenito |
212832 |
# make sure two directories exist since they are not
|
|
Chris PeBenito |
212832 |
# created by semanage
|
|
Chris PeBenito |
212832 |
@mkdir -p $(policypath) $(dir $(fcpath))
|
|
Chris PeBenito |
c767b1 |
@echo "Loading configured modules."
|
|
Chris PeBenito |
c634db |
$(verbose) $(SEMODULE) -s $(NAME) -b $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c767b1 |
########################################
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c767b1 |
# Install policy packages
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c634db |
$(modpkgdir)/%.pp: $(builddir)%.pp
|
|
Chris PeBenito |
c634db |
@mkdir -p $(modpkgdir)
|
|
Chris PeBenito |
6b1c8e |
@echo "Installing $(NAME) $(@F) policy package."
|
|
Chris PeBenito |
c634db |
$(verbose) $(INSTALL) -m 0644 $^ $(modpkgdir)
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c767b1 |
########################################
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c767b1 |
# Build module packages
|
|
Chris PeBenito |
c767b1 |
#
|
|
Chris PeBenito |
c634db |
$(tmpdir)/%.mod: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf %.te
|
|
Chris PeBenito |
c767b1 |
@echo "Compliling $(NAME) $(@F) module"
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
bbcd3c |
$(call perrole-expansion,$(basename $(@F)),$@.role)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/%.mod.fc: $(m4support) %.fc
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
c634db |
$(verbose) $(M4) $(M4PARAM) $(m4support) $^ > $@
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c634db |
$(builddir)%.pp: $(tmpdir)/%.mod $(tmpdir)/%.mod.fc
|
|
Chris PeBenito |
c767b1 |
@echo "Creating $(NAME) $(@F) policy package"
|
|
Chris PeBenito |
c634db |
@test -d $(builddir) || mkdir -p $(builddir)
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
# Create a base module package
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
e070dd |
$(base_pkg): $(base_mod) $(base_fc) $(users_extra) $(tmpdir)/seusers $(net_contexts)
|
|
Chris PeBenito |
fb0a3a |
@echo "Creating $(NAME) base module package"
|
|
Chris PeBenito |
c634db |
@test -d $(builddir) || mkdir -p $(builddir)
|
|
Chris PeBenito |
e070dd |
$(verbose) $(SEMOD_PKG) -o $@ -m $(base_mod) -f $(base_fc) -u $(users_extra) -s $(tmpdir)/seusers -n $(net_contexts)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(base_mod): $(base_conf)
|
|
Chris PeBenito |
fb0a3a |
@echo "Compiling $(NAME) base module"
|
|
Chris PeBenito |
9b3756 |
$(verbose) $(CHECKMODULE) $^ -o $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
e070dd |
$(tmpdir)/seusers: $(seusers)
|
|
Chris PeBenito |
e070dd |
@mkdir -p $(tmpdir)
|
|
Chris PeBenito |
e070dd |
$(verbose) $(M4) $(M4PARAM) $(m4support) $^ | $(GREP) '^[a-z_]' > $@
|
|
Chris PeBenito |
e070dd |
|
|
Chris PeBenito |
c634db |
$(users_extra): $(m4support) $(user_files)
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
90b331 |
$(verbose) $(M4) $(M4PARAM) -D users_extra $^ | \
|
|
Chris PeBenito |
90b331 |
$(SED) -r -n -e 's/^[[:blank:]]*//g' -e '/^user/p' > $@
|
|
Chris PeBenito |
90b331 |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c767b1 |
# Construct a base.conf
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c634db |
$(base_conf): $(base_sections)
|
|
Chris PeBenito |
58b2a3 |
@echo "Creating $(NAME) base module $(@F)"
|
|
Chris PeBenito |
3abd5e |
@test -d $(@D) || mkdir -p $(@D)
|
|
Chris PeBenito |
3abd5e |
$(verbose) cat $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/pre_te_files.conf: M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
c634db |
$(tmpdir)/pre_te_files.conf: $(base_pre_te_files)
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/generated_definitions.conf: $(base_te_files)
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
c04f2a |
# define all available object classes
|
|
Chris PeBenito |
c634db |
$(verbose) $(genperm) $(avs) $(secclass) > $@
|
|
Chris PeBenito |
bbcd3c |
$(verbose) $(call create-base-per-role-tmpl,$(patsubst %.te,%,$(base_mods)),$@)
|
|
Chris PeBenito |
c634db |
$(verbose) test -f $(booleans) && $(setbools) $(booleans) >> $@ || true
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/global_bools.conf: M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
c634db |
$(tmpdir)/global_bools.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(globalbool) $(globaltun)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
3abd5e |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/all_interfaces.conf: $(m4support) $(all_interfaces)
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
c634db |
@echo "ifdef(\`__if_error',\`m4exit(1)')" > $(tmpdir)/iferror.m4
|
|
Chris PeBenito |
3abd5e |
@echo "divert(-1)" > $@
|
|
Chris PeBenito |
c634db |
$(verbose) $(M4) $^ $(tmpdir)/iferror.m4 >> $(tmpdir)/$(@F).tmp
|
|
Chris PeBenito |
c634db |
$(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(tmpdir)/$(@F).tmp >> $@
|
|
Chris PeBenito |
3abd5e |
@echo "divert" >> $@
|
|
Chris PeBenito |
3abd5e |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/rolemap.conf: M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
c634db |
$(tmpdir)/rolemap.conf: $(rolemap)
|
|
Chris PeBenito |
3abd5e |
$(call parse-rolemap,base,$@)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/all_te_files.conf: M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
c634db |
$(tmpdir)/all_te_files.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf $(base_te_files) $(tmpdir)/rolemap.conf
|
|
Chris PeBenito |
c634db |
ifeq "$(strip $(base_te_files))" ""
|
|
Chris PeBenito |
c634db |
$(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
|
|
Chris PeBenito |
fb0a3a |
endif
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) -s $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/post_te_files.conf: M4PARAM += -D self_contained_policy
|
|
Chris PeBenito |
c634db |
$(tmpdir)/post_te_files.conf: $(m4support) $(base_post_te_files)
|
|
Chris PeBenito |
c634db |
@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 |
c634db |
$(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 |
c634db |
$(verbose) $(get_type_attr_decl) $(tmpdir)/all_te_files.conf | $(SORT) > $(tmpdir)/all_attrs_types.conf
|
|
Chris PeBenito |
c634db |
$(verbose) cat $(tmpdir)/post_te_files.conf > $(tmpdir)/all_post.conf
|
|
Chris PeBenito |
3abd5e |
# these have to run individually because order matters:
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) '^sid ' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) '^fs_use_(xattr|task|trans)' $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) ^genfscon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $(tmpdir)/all_post.conf || true
|
|
Chris PeBenito |
c634db |
$(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 |
c767b1 |
# Construct a base.fc
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
c634db |
$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp $(fcsort)
|
|
Chris PeBenito |
c634db |
$(verbose) $(fcsort) $< $@
|
|
Chris PeBenito |
c767b1 |
|
|
Chris PeBenito |
c634db |
$(tmpdir)/$(notdir $(base_fc)).tmp: $(m4support) $(tmpdir)/generated_definitions.conf $(base_fc_files)
|
|
Chris PeBenito |
c634db |
ifeq ($(base_fc_files),)
|
|
Chris PeBenito |
c634db |
$(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) base module file contexts."
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
3abd5e |
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
fb0a3a |
########################################
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
bf080a |
# Remove the dontaudit rules from the base.conf
|
|
Chris PeBenito |
bf080a |
#
|
|
Chris PeBenito |
c634db |
enableaudit: $(base_conf)
|
|
Chris PeBenito |
c634db |
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
Chris PeBenito |
58b2a3 |
@echo "Removing dontaudit rules from $(^F)"
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) -v dontaudit $(base_conf) > $(tmpdir)/base.audit
|
|
Chris PeBenito |
c634db |
$(verbose) mv $(tmpdir)/base.audit $(base_conf)
|
|
Chris PeBenito |
bf080a |
|
|
Chris PeBenito |
bf080a |
########################################
|
|
Chris PeBenito |
bf080a |
#
|
|
Chris PeBenito |
049e11 |
# Appconfig files
|
|
Chris PeBenito |
049e11 |
#
|
|
Chris PeBenito |
c634db |
$(appdir)/customizable_types: $(base_conf)
|
|
Chris PeBenito |
c634db |
@mkdir -p $(appdir)
|
|
Chris PeBenito |
c634db |
$(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(tmpdir)/customizable_types
|
|
Chris PeBenito |
c634db |
$(verbose) $(INSTALL) -m 644 $(tmpdir)/customizable_types $@
|
|
Chris PeBenito |
049e11 |
|
|
Chris PeBenito |
049e11 |
########################################
|
|
Chris PeBenito |
049e11 |
#
|
|
Chris PeBenito |
ea5333 |
# Validate linking and expanding of modules
|
|
Chris PeBenito |
ea5333 |
#
|
|
Chris PeBenito |
c634db |
validate: $(base_pkg) $(mod_pkgs)
|
|
Chris PeBenito |
ea5333 |
@echo "Validating policy linking."
|
|
Chris PeBenito |
c634db |
$(verbose) $(SEMOD_LNK) -o $(tmpdir)/test.lnk $^
|
|
Chris PeBenito |
c634db |
$(verbose) $(SEMOD_EXP) $(tmpdir)/test.lnk $(tmpdir)/policy.bin
|
|
Chris PeBenito |
ea5333 |
@echo "Success."
|
|
Chris PeBenito |
ea5333 |
|
|
Chris PeBenito |
ea5333 |
########################################
|
|
Chris PeBenito |
ea5333 |
#
|
|
Chris PeBenito |
fb0a3a |
# Clean the sources
|
|
Chris PeBenito |
fb0a3a |
#
|
|
Chris PeBenito |
fb0a3a |
clean:
|
|
Chris PeBenito |
c634db |
rm -f $(base_conf)
|
|
Chris PeBenito |
c634db |
rm -f $(base_fc)
|
|
Chris PeBenito |
c634db |
rm -f $(builddir)*.pp
|
|
Chris PeBenito |
6962bb |
rm -f $(net_contexts)
|
|
Chris PeBenito |
c634db |
rm -fR $(tmpdir)
|
|
Chris PeBenito |
fb0a3a |
|
|
Chris PeBenito |
ea5333 |
.PHONY: default all policy base modules install load clean validate
|