selinux-policy/refpolicy/Rules.modular

214 lines
7.3 KiB
Plaintext
Raw Normal View History

########################################
#
2005-10-18 15:07:11 +00:00
# Rules and Targets for building modular policies
#
ALL_MODULES := $(BASE_MODS) $(MOD_MODS) $(OFF_MODS)
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
BASE_PKG := $(BUILDDIR)/base.pp
BASE_FC := $(BUILDDIR)/base.fc
BASE_CONF := $(BUILDDIR)/base.conf
BASE_MOD := $(TMPDIR)/base.mod
BASE_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-09-16 13:36:26 +00:00
BASE_PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
BASE_TE_FILES := $(BASE_MODS)
BASE_POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
BASE_FC_FILES := $(BASE_MODS:.te=.fc)
MOD_MODULES := $(MOD_MODS:.te=.mod)
MOD_PKGS := $(addprefix $(BUILDDIR)/,$(notdir $(MOD_MODS:.te=.pp)))
2005-11-22 22:07:12 +00:00
# policy packages to install
INSTPKG := $(addprefix $(MODPKGDIR)/,$(notdir $(BASE_PKG)) $(MOD_PKGS))
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)
2006-02-13 22:00:58 +00:00
.SECONDARY:
########################################
#
# default action: create all module packages
#
default: base
all: base modules
base: $(BASE_PKG)
modules: $(MOD_PKGS)
2005-11-22 22:07:12 +00:00
install: $(INSTPKG) $(APPFILES)
########################################
#
# Load all configured modules
#
load: $(INSTPKG) $(APPFILES)
@echo "Loading configured modules."
$(verbose) $(SEMODULE) -s $(NAME) -b $(MODPKGDIR)/$(notdir $(BASE_PKG)) $(foreach mod,$(MOD_PKGS),-i $(MODPKGDIR)/$(mod))
2005-11-22 22:07:12 +00:00
########################################
#
# Install policy packages
#
$(MODPKGDIR)/%.pp: $(BUILDDIR)/%.pp
2005-11-22 22:07:12 +00:00
@mkdir -p $(MODPKGDIR)
@echo "Installing $(NAME) $(@F) policy package."
$(verbose) install -m 0644 $^ $(MODPKGDIR)
2005-11-22 22:07:12 +00:00
########################################
#
# Build module packages
#
$(TMPDIR)/%.mod: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf %.te
2005-11-22 22:07:12 +00:00
@echo "Compliling $(NAME) $(@F) module"
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(call peruser-expansion,$(basename $(@F)),$@.role)
$(verbose) m4 $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
2005-11-22 22:07:12 +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
$(BUILDDIR)/%.pp: $(TMPDIR)/%.mod $(TMPDIR)/%.mod.fc
2005-11-22 22:07:12 +00:00
@echo "Creating $(NAME) $(@F) policy package"
@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
########################################
#
# Create a base module package
#
$(BASE_PKG): $(BASE_MOD) $(BASE_FC)
@echo "Creating $(NAME) base module package"
@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
$(verbose) $(SEMOD_PKG) -o $@ -m $(BASE_MOD) -f $(BASE_FC)
$(BASE_MOD): $(BASE_CONF)
@echo "Compiling $(NAME) base module"
$(verbose) $(CHECKMODULE) $^ -o $@
########################################
#
2005-11-22 22:07:12 +00:00
# Construct a base.conf
#
$(BASE_CONF): $(BASE_SECTIONS)
@echo "Creating $(NAME) base module $(BASE_CONF)"
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@test -d $(dir $(BASE_CONF)) || mkdir -p $(dir $(BASE_CONF))
# 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: $(BASE_PRE_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
$(TMPDIR)/generated_definitions.conf: $(BASE_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
# define all available object classes
$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $@
2005-09-14 00:30:10 +00:00
# per-userdomain templates
$(verbose) echo "define(\`base_per_userdomain_template',\`" >> $@
$(verbose) for i in $(patsubst %.te,%,$(BASE_MODS)); do \
2005-09-14 00:30:10 +00:00
echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
>> $@ ;\
done
$(verbose) echo "')" >> $@
# define foo.te
$(verbose) for i in $(notdir $(BASE_TE_FILES)); do \
echo "define(\`$$i')" >> $@ ;\
done
$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@
$(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: $(BASE_TE_FILES)
ifeq ($(BASE_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: $(BASE_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
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(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
########################################
#
2005-11-22 22:07:12 +00:00
# Construct a base.fc
#
$(BASE_FC): $(TMPDIR)/$(notdir $(BASE_FC)).tmp $(FCSORT)
$(verbose) $(FCSORT) $< $@
2005-11-22 22:07:12 +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")
endif
@echo "Creating $(NAME) base module file contexts."
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $(M4PARAM) $^ > $@
2006-01-06 22:51:40 +00:00
########################################
#
# Remove the dontaudit rules from the base.conf
#
enableaudit: $(BASE_CONF)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@echo "Removing dontaudit rules from $(BASE_CONF)"
$(verbose) grep -v dontaudit $(BASE_CONF) > $(TMPDIR)/base.audit
$(verbose) mv $(TMPDIR)/base.audit $(BASE_CONF)
2006-01-06 22:51:40 +00:00
########################################
#
# Appconfig files
#
$(APPDIR)/customizable_types: $(BASE_CONF)
@mkdir -p $(APPDIR)
$(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 $(BASE_CONF)
2005-09-12 15:17:39 +00:00
rm -f $(BASE_FC)
rm -f $(BUILDDIR)/*.pp
rm -fR $(TMPDIR)
2005-11-22 22:07:12 +00:00
.PHONY: default all base modules install load clean