2005-08-18 21:27:20 +00:00
|
|
|
########################################
|
|
|
|
#
|
2005-10-18 15:07:11 +00:00
|
|
|
# Rules and Targets for building modular policies
|
2005-08-18 21:27:20 +00:00
|
|
|
#
|
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
all_modules := $(base_mods) $(mod_mods) $(off_mods)
|
|
|
|
all_interfaces := $(all_modules:.te=.if)
|
2017-08-06 20:54:40 +00:00
|
|
|
enabled_mod_fc := $(addprefix $(tmpdir)/,$(notdir $(base_mods:.te=.mod.fc) $(mod_mods:.te=.mod.fc)))
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
base_pkg := $(builddir)base.pp
|
|
|
|
base_fc := $(builddir)base.fc
|
|
|
|
base_conf := $(builddir)base.conf
|
|
|
|
base_mod := $(tmpdir)/base.mod
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
users_extra := $(tmpdir)/users_extra
|
2006-02-15 19:46:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
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
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2020-03-21 13:31:23 +00:00
|
|
|
base_pre_te_files := $(secclass) $(isids) $(avs) $(m4support) $(ctx_defaults) $(poldir)/mls $(poldir)/mcs $(policycaps)
|
2006-08-31 17:28:35 +00:00
|
|
|
base_te_files := $(base_mods)
|
|
|
|
base_post_te_files := $(user_files) $(poldir)/constraints
|
|
|
|
base_fc_files := $(base_mods:.te=.fc)
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
|
2005-08-22 17:07:17 +00:00
|
|
|
|
2005-11-22 22:07:12 +00:00
|
|
|
# policy packages to install
|
2006-08-31 17:28:35 +00:00
|
|
|
instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))
|
2005-11-22 22:07:12 +00:00
|
|
|
|
2005-08-22 17:07:17 +00:00
|
|
|
# search layer dirs for source files
|
2006-08-31 17:28:35 +00:00
|
|
|
vpath %.te $(all_layers)
|
|
|
|
vpath %.if $(all_layers)
|
|
|
|
vpath %.fc $(all_layers)
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2017-08-06 20:54:40 +00:00
|
|
|
.SECONDARY: $(enabled_mod_fc:.mod.fc=.mod) $(enabled_mod_fc)
|
2006-02-13 22:00:58 +00:00
|
|
|
|
2005-08-18 21:27:20 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# default action: create all module packages
|
|
|
|
#
|
2006-02-15 21:35:27 +00:00
|
|
|
default: policy
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-02-15 21:35:27 +00:00
|
|
|
all policy: base modules
|
2005-10-21 16:00:24 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
base: $(base_pkg)
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
modules: $(mod_pkgs)
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
install: $(instpkg) $(appfiles)
|
2005-11-22 22:07:12 +00:00
|
|
|
|
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Load all configured modules
|
|
|
|
#
|
2006-08-31 17:28:35 +00:00
|
|
|
load: $(instpkg) $(appfiles)
|
2006-10-10 15:09:59 +00:00
|
|
|
# make sure two directories exist since they are not
|
|
|
|
# created by semanage
|
2005-11-22 22:07:12 +00:00
|
|
|
@echo "Loading configured modules."
|
2011-10-19 14:59:16 +00:00
|
|
|
@$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
|
2016-09-02 10:58:42 +00:00
|
|
|
$(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))
|
2005-11-22 22:07:12 +00:00
|
|
|
|
2022-03-22 17:21:23 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Load all configured modules and remove foreign ones
|
|
|
|
#
|
|
|
|
pure-load: $(instpkg) $(appfiles)
|
|
|
|
# make sure two directories exist since they are not
|
|
|
|
# created by semanage
|
|
|
|
@echo "Loading configured modules."
|
|
|
|
@$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
|
|
|
|
$(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod)) $(foreach omod,$(filter-out base $(notdir $(mod_mods:.te=)),$(shell $(SEMODULE) -l)),-r $(omod))
|
|
|
|
|
2005-11-22 22:07:12 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Install policy packages
|
|
|
|
#
|
2006-08-31 17:28:35 +00:00
|
|
|
$(modpkgdir)/%.pp: $(builddir)%.pp
|
2006-01-23 14:42:37 +00:00
|
|
|
@echo "Installing $(NAME) $(@F) policy package."
|
2011-10-19 14:59:16 +00:00
|
|
|
@$(INSTALL) -d -m 0755 $(@D)
|
2006-08-31 17:28:35 +00:00
|
|
|
$(verbose) $(INSTALL) -m 0644 $^ $(modpkgdir)
|
2005-11-22 22:07:12 +00:00
|
|
|
|
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Build module packages
|
|
|
|
#
|
2017-02-18 15:20:20 +00:00
|
|
|
$(tmpdir)/%.mod: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf %.te $(m4terminate)
|
2016-04-26 21:17:58 +00:00
|
|
|
@echo "Compiling $(NAME) $(@F) module"
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2011-10-14 12:52:21 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) -s $^ > $(@:.mod=.tmp)
|
2006-01-26 20:35:55 +00:00
|
|
|
$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
|
2005-11-22 22:07:12 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/%.mod.fc: $(m4support) %.fc
|
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
|
|
|
$(verbose) $(M4) $(M4PARAM) $(m4support) $^ > $@
|
2005-11-22 22:07:12 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(builddir)%.pp: $(tmpdir)/%.mod $(tmpdir)/%.mod.fc
|
2005-11-22 22:07:12 +00:00
|
|
|
@echo "Creating $(NAME) $(@F) policy package"
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(builddir) || mkdir -p $(builddir)
|
2006-01-26 20:35:55 +00:00
|
|
|
$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2017-08-06 20:54:40 +00:00
|
|
|
$(tmpdir)/all_mods.fc: $(enabled_mod_fc)
|
2017-02-27 21:02:52 +00:00
|
|
|
$(verbose) cat $^ > $@
|
|
|
|
|
2005-08-18 21:27:20 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Create a base module package
|
|
|
|
#
|
2007-03-21 19:40:55 +00:00
|
|
|
$(base_pkg): $(base_mod) $(base_fc) $(users_extra) $(tmpdir)/seusers
|
2005-08-18 21:27:20 +00:00
|
|
|
@echo "Creating $(NAME) base module package"
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(builddir) || mkdir -p $(builddir)
|
2007-03-21 19:40:55 +00:00
|
|
|
$(verbose) $(SEMOD_PKG) -o $@ -m $(base_mod) -f $(base_fc) -u $(users_extra) -s $(tmpdir)/seusers
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(base_mod): $(base_conf)
|
2005-08-18 21:27:20 +00:00
|
|
|
@echo "Compiling $(NAME) base module"
|
2014-06-19 14:48:38 +00:00
|
|
|
$(verbose) $(CHECKMODULE) -U $(UNK_PERMS) $^ -o $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-10-04 17:25:34 +00:00
|
|
|
$(tmpdir)/seusers: $(seusers)
|
|
|
|
@mkdir -p $(tmpdir)
|
|
|
|
$(verbose) $(M4) $(M4PARAM) $(m4support) $^ | $(GREP) '^[a-z_]' > $@
|
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(users_extra): $(m4support) $(user_files)
|
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2024-02-22 16:38:21 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) -D users_extra $^ > $(tmpdir)/$(@F).tmp
|
|
|
|
$(verbose) $(SED) -r -n -e 's/^[[:blank:]]*//g' -e '/^user/p' $(tmpdir)/$(@F).tmp > $@
|
2006-02-15 19:46:20 +00:00
|
|
|
|
2005-08-18 21:27:20 +00:00
|
|
|
########################################
|
|
|
|
#
|
2005-11-22 22:07:12 +00:00
|
|
|
# Construct a base.conf
|
2005-08-18 21:27:20 +00:00
|
|
|
#
|
2006-08-31 17:28:35 +00:00
|
|
|
$(base_conf): $(base_sections)
|
2006-02-17 14:21:05 +00:00
|
|
|
@echo "Creating $(NAME) base module $(@F)"
|
2006-03-20 20:54:56 +00:00
|
|
|
@test -d $(@D) || mkdir -p $(@D)
|
|
|
|
$(verbose) cat $^ > $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/pre_te_files.conf: M4PARAM += -D self_contained_policy
|
|
|
|
$(tmpdir)/pre_te_files.conf: $(base_pre_te_files)
|
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2006-03-20 20:54:56 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2008-05-26 14:53:22 +00:00
|
|
|
$(tmpdir)/generated_definitions.conf:
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2005-08-22 17:07:17 +00:00
|
|
|
# define all available object classes
|
2020-04-16 00:40:58 +00:00
|
|
|
@cat $(m4divert) > $@
|
|
|
|
$(verbose) $(genperm) $(avs) $(secclass) >> $@
|
2006-09-06 22:07:25 +00:00
|
|
|
$(verbose) $(call create-base-per-role-tmpl,$(patsubst %.te,%,$(base_mods)),$@)
|
2006-08-31 17:28:35 +00:00
|
|
|
$(verbose) test -f $(booleans) && $(setbools) $(booleans) >> $@ || true
|
2020-04-16 00:40:58 +00:00
|
|
|
@cat $(m4undivert) >> $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/global_bools.conf: M4PARAM += -D self_contained_policy
|
|
|
|
$(tmpdir)/global_bools.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(globalbool) $(globaltun)
|
2006-03-20 20:54:56 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
|
|
|
|
2008-03-06 20:17:46 +00:00
|
|
|
$(tmpdir)/all_interfaces.conf: $(m4support) $(all_interfaces) $(m4iferror)
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2020-04-16 00:40:58 +00:00
|
|
|
@cat $(m4divert) > $@
|
2020-04-20 14:22:38 +00:00
|
|
|
$(verbose) $(M4) $^ > $(tmpdir)/$(@F).tmp
|
2006-08-31 17:28:35 +00:00
|
|
|
$(verbose) $(SED) -e s/dollarsstar/\$$\*/g $(tmpdir)/$(@F).tmp >> $@
|
2020-04-16 00:40:58 +00:00
|
|
|
@cat $(m4undivert) >> $@
|
2006-03-20 20:54:56 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/all_te_files.conf: M4PARAM += -D self_contained_policy
|
2017-02-18 15:20:20 +00:00
|
|
|
$(tmpdir)/all_te_files.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(tmpdir)/all_interfaces.conf $(base_te_files) $(m4terminate)
|
2006-08-31 17:28:35 +00:00
|
|
|
ifeq "$(strip $(base_te_files))" ""
|
|
|
|
$(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
|
2005-08-18 21:27:20 +00:00
|
|
|
endif
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2006-03-20 20:54:56 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) -s $^ > $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/post_te_files.conf: M4PARAM += -D self_contained_policy
|
2020-07-10 13:07:52 +00:00
|
|
|
$(tmpdir)/post_te_files.conf: $(m4support) $(tmpdir)/generated_definitions.conf $(base_post_te_files) $(tmpdir)/all_te_files.conf
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2020-07-10 13:07:52 +00:00
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*user ' $(tmpdir)/all_te_files.conf > $@ || true
|
|
|
|
$(verbose) $(M4) $(M4PARAM) $(m4support) $(tmpdir)/generated_definitions.conf $(base_post_te_files) >> $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
|
|
|
# extract attributes and put them first. extract post te stuff
|
2006-03-20 20:54:56 +00:00
|
|
|
# like genfscon and put last.
|
2014-02-18 23:26:33 +00:00
|
|
|
$(tmpdir)/all_attrs_types.conf: $(tmpdir)/all_te_files.conf
|
|
|
|
$(verbose) $(get_type_attr_decl) $^ | $(SORT) > $@
|
|
|
|
|
|
|
|
$(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.conf
|
|
|
|
$(verbose) cat $(tmpdir)/post_te_files.conf > $@
|
2006-03-20 20:54:56 +00:00
|
|
|
# these have to run individually because order matters:
|
2021-03-18 20:22:05 +00:00
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*sid ' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*fs_use_(xattr|task|trans)' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*genfscon' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*portcon' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*netifcon' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*nodecon' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*ibpkeycon' $(tmpdir)/all_te_files.conf >> $@ || true
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*ibendportcon' $(tmpdir)/all_te_files.conf >> $@ || true
|
2014-02-18 23:26:33 +00:00
|
|
|
|
|
|
|
$(tmpdir)/only_te_rules.conf: $(tmpdir)/all_te_files.conf
|
|
|
|
$(verbose) $(comment_move_decl) $^ > $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
|
|
|
########################################
|
|
|
|
#
|
2005-11-22 22:07:12 +00:00
|
|
|
# Construct a base.fc
|
2005-08-18 21:27:20 +00:00
|
|
|
#
|
2019-10-03 20:38:39 +00:00
|
|
|
$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp
|
2006-08-31 17:28:35 +00:00
|
|
|
$(verbose) $(fcsort) $< $@
|
2005-11-22 22:07:12 +00:00
|
|
|
|
2006-08-31 17:28:35 +00:00
|
|
|
$(tmpdir)/$(notdir $(base_fc)).tmp: $(m4support) $(tmpdir)/generated_definitions.conf $(base_fc_files)
|
|
|
|
ifeq ($(base_fc_files),)
|
|
|
|
$(error No enabled modules! $(notdir $(mod_conf)) may need to be generated by using "make conf")
|
2005-08-18 21:27:20 +00:00
|
|
|
endif
|
|
|
|
@echo "Creating $(NAME) base module file contexts."
|
2006-08-31 17:28:35 +00:00
|
|
|
@test -d $(tmpdir) || mkdir -p $(tmpdir)
|
2006-03-20 20:54:56 +00:00
|
|
|
$(verbose) $(M4) $(M4PARAM) $^ > $@
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2005-12-09 15:42:39 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Appconfig files
|
|
|
|
#
|
2006-08-31 17:28:35 +00:00
|
|
|
$(appdir)/customizable_types: $(base_conf)
|
|
|
|
$(verbose) $(GREP) '^[[:blank:]]*type .*customizable' $< | cut -d';' -f1 | cut -d',' -f1 | cut -d' ' -f2 | $(SORT) -u > $(tmpdir)/customizable_types
|
2011-10-19 14:59:16 +00:00
|
|
|
@$(INSTALL) -d -m 0755 $(@D)
|
|
|
|
$(verbose) $(INSTALL) -m 0644 $(tmpdir)/customizable_types $@
|
2005-12-09 15:42:39 +00:00
|
|
|
|
2006-05-02 20:14:41 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Validate linking and expanding of modules
|
|
|
|
#
|
2017-02-27 21:02:52 +00:00
|
|
|
validate: $(base_pkg) $(mod_pkgs) $(tmpdir)/all_mods.fc
|
2006-05-02 20:14:41 +00:00
|
|
|
@echo "Validating policy linking."
|
2017-02-27 21:02:52 +00:00
|
|
|
$(verbose) $(SEMOD_LNK) -o $(tmpdir)/test.lnk $(base_pkg) $(mod_pkgs)
|
2006-08-31 17:28:35 +00:00
|
|
|
$(verbose) $(SEMOD_EXP) $(tmpdir)/test.lnk $(tmpdir)/policy.bin
|
2017-02-27 21:02:52 +00:00
|
|
|
@echo "Validating policy file contexts."
|
|
|
|
$(verbose) $(SETFILES) -q -c $(tmpdir)/policy.bin $(tmpdir)/all_mods.fc
|
2006-05-02 20:14:41 +00:00
|
|
|
@echo "Success."
|
|
|
|
|
2005-08-18 21:27:20 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Clean the sources
|
|
|
|
#
|
|
|
|
clean:
|
2014-01-16 16:25:42 +00:00
|
|
|
$(verbose) rm -f $(base_conf)
|
|
|
|
$(verbose) rm -f $(base_fc)
|
|
|
|
$(verbose) rm -f $(builddir)*.pp
|
2020-04-22 16:13:02 +00:00
|
|
|
$(verbose) rm -f $(net_contexts) $(net_contexts_nft)
|
2014-01-16 16:25:42 +00:00
|
|
|
$(verbose) rm -fR $(tmpdir)
|
2005-08-18 21:27:20 +00:00
|
|
|
|
2022-03-22 17:21:23 +00:00
|
|
|
.PHONY: default all policy base modules install load pure-load clean validate
|