Change build order to preserve m4 line number information so policy compile errors are useful again.

This commit is contained in:
Chris PeBenito 2006-03-20 20:54:56 +00:00
parent c28caf3055
commit 3abd5ee82a
6 changed files with 102 additions and 70 deletions

View File

@ -1,3 +1,5 @@
- Change build order to preserve m4 line number information so policy
compile errors are useful again.
- Additional MLS interfaces from Chad Hanson.
- Move some rules out of domain_type() and domain_base_type()
to the TE file, to use the domain attribute to take advantage

View File

@ -86,6 +86,8 @@ GENDOC := $(PYTHON) $(SUPPORT)/sedoctool.py
GENPERM := $(PYTHON) $(SUPPORT)/genclassperms.py
FCSORT := $(TMPDIR)/fc_sort
SETBOOLS := $(AWK) -f $(SUPPORT)/set_bools_tuns.awk
get_type_attr_decl := $(SED) -r -f $(SUPPORT)/get_type_attr_decl.sed
comment_move_decl := $(SED) -r -f $(SUPPORT)/comment_move_decl.sed
# documentation paths
DOCS := doc
@ -243,7 +245,7 @@ MODUNUSED := off
MOD_TEST = $(filter $(APPS_OFF), $(APPS_BASE) $(APPS_MODS))
MOD_TEST += $(filter $(APPS_MODS), $(APPS_BASE))
ifneq ($(strip $(MOD_TEST)),)
$(error Applications must be on, module, or off, and not in more than one list! $(strip $(MOD_TEST)) found in multiple lists!)
$(error Applications must be base, module, or off, and not in more than one list! $(strip $(MOD_TEST)) found in multiple lists!)
endif
# extract settings from modules.conf

View File

@ -13,7 +13,7 @@ BASE_MOD := $(TMPDIR)/base.mod
USERS_EXTRA := $(TMPDIR)/users_extra
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
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
BASE_PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
BASE_TE_FILES := $(BASE_MODS)
@ -72,12 +72,12 @@ $(TMPDIR)/%.mod: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all
@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) $(M4) $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
$(TMPDIR)/%.mod.fc: $(M4SUPPORT) %.fc
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $(M4PARAM) $(M4SUPPORT) $^ > $@
$(verbose) $(M4) $(M4PARAM) $(M4SUPPORT) $^ > $@
$(BUILDDIR)%.pp: $(TMPDIR)/%.mod $(TMPDIR)/%.mod.fc
@echo "Creating $(NAME) $(@F) policy package"
@ -108,19 +108,13 @@ $(USERS_EXTRA): $(M4SUPPORT) $(USER_FILES)
#
$(BASE_CONF): $(BASE_SECTIONS)
@echo "Creating $(NAME) base module $(@F)"
@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
@test -d $(@D) || mkdir -p $(@D)
$(verbose) cat $^ > $@
$(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)
$(verbose) cat $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
$(TMPDIR)/generated_definitions.conf: $(BASE_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@ -139,39 +133,49 @@ $(TMPDIR)/generated_definitions.conf: $(BASE_TE_FILES)
done
$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
$(TMPDIR)/global_bools.conf: M4PARAM += -D self_contained_policy
$(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN)
$(verbose) $(M4) $(M4PARAM) $^ > $@
$(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 > $@
@echo "divert(-1)" > $@
$(verbose) $(M4) $^ | $(SED) -e s/dollarsstar/\$$\*/g >> $@
@echo "divert" >> $@
$(TMPDIR)/all_te_files.conf: $(BASE_TE_FILES)
$(TMPDIR)/rolemap.conf: M4PARAM += -D self_contained_policy
$(TMPDIR)/rolemap.conf: $(ROLEMAP)
$(call parse-rolemap,base,$@)
$(TMPDIR)/all_te_files.conf: M4PARAM += -D self_contained_policy
$(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(BASE_TE_FILES) $(TMPDIR)/rolemap.conf
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,$@)
$(verbose) $(M4) $(M4PARAM) -s $^ > $@
$(TMPDIR)/post_te_files.conf: $(BASE_POST_TE_FILES)
$(TMPDIR)/post_te_files.conf: M4PARAM += -D self_contained_policy
$(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(BASE_POST_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
# 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
# like genfscon and put last.
$(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) $(get_type_attr_decl) $(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
# these have to run individually because order matters:
$(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) '^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) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf
########################################
#
@ -186,7 +190,7 @@ ifeq ($(BASE_FC_FILES),)
endif
@echo "Creating $(NAME) base module file contexts."
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $(M4PARAM) $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
########################################
#
@ -195,7 +199,7 @@ endif
enableaudit: $(BASE_CONF)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@echo "Removing dontaudit rules from $(^F)"
$(verbose) grep -v dontaudit $(BASE_CONF) > $(TMPDIR)/base.audit
$(verbose) $(GREP) -v dontaudit $(BASE_CONF) > $(TMPDIR)/base.audit
$(verbose) mv $(TMPDIR)/base.audit $(BASE_CONF)
########################################
@ -204,7 +208,7 @@ enableaudit: $(BASE_CONF)
#
$(APPDIR)/customizable_types: $(BASE_CONF)
@mkdir -p $(APPDIR)
$(verbose) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
$(verbose) $(GREP) "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
$(verbose) install -m 644 $(TMPDIR)/customizable_types $@
########################################

View File

@ -8,6 +8,8 @@ FC = $(BUILDDIR)file_contexts
POLVER = $(BUILDDIR)policy.$(PV)
HOMEDIR_TEMPLATE = $(BUILDDIR)homedir_template
M4PARAM += -D self_contained_policy
# install paths
POLICYPATH = $(INSTALLDIR)/policy
LOADPATH = $(POLICYPATH)/$(notdir $(POLVER))
@ -25,7 +27,7 @@ ALL_FC_FILES := $(ALL_MODULES:.te=.fc)
PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
POST_TE_FILES := $(USER_FILES) $(POLDIR)/constraints
POLICY_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
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
# search layer dirs for source files
vpath %.te $(ALL_LAYERS)
@ -91,28 +93,19 @@ reload $(TMPDIR)/load: $(LOADPATH) $(FCPATH) $(APPFILES)
#
$(POLICY_CONF): $(POLICY_SECTIONS)
@echo "Creating $(NAME) $(@F)"
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
# 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
@test -d $(@D) || mkdir -p $(@D)
$(verbose) cat $^ > $@
$(TMPDIR)/pre_te_files.conf: $(PRE_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
$(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES)
# per-userdomain templates:
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) echo "define(\`base_per_userdomain_template',\`" > $@
$(verbose) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
>> $@ ;\
done
$(verbose) $(foreach mod,$(basename $(notdir $(ALL_MODULES))), \
echo "ifdef(\`""$(mod)""_per_userdomain_template',\`""$(mod)""_per_userdomain_template("'$$*'")')" >> $@ ;)
$(verbose) echo "')" >> $@
# define foo.te
$(verbose) for i in $(notdir $(ALL_MODULES)); do \
@ -120,38 +113,45 @@ $(TMPDIR)/generated_definitions.conf: $(ALL_TE_FILES)
done
$(verbose) test -f $(BOOLEANS) && $(SETBOOLS) $(BOOLEANS) >> $@ || true
$(TMPDIR)/global_bools.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(GLOBALBOOL) $(GLOBALTUN)
$(verbose) $(M4) $(M4PARAM) $^ > $@
$(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 > $@
@echo "divert(-1)" > $@
$(verbose) $(M4) $^ | $(SED) -e s/dollarsstar/\$$\*/g >> $@
@echo "divert" >> $@
$(TMPDIR)/all_te_files.conf: $(ALL_TE_FILES)
$(TMPDIR)/rolemap.conf: $(ROLEMAP)
$(call parse-rolemap,base,$@)
$(TMPDIR)/all_te_files.conf: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(TMPDIR)/all_interfaces.conf $(ALL_TE_FILES) $(TMPDIR)/rolemap.conf
ifeq ($(ALL_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,$@)
$(verbose) $(M4) $(M4PARAM) -s $^ > $@
$(TMPDIR)/post_te_files.conf: $(POST_TE_FILES)
$(TMPDIR)/post_te_files.conf: $(M4SUPPORT) $(POST_TE_FILES)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) cat $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
# 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
# like genfscon and put last.
$(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.conf: $(TMPDIR)/all_te_files.conf $(TMPDIR)/post_te_files.conf
$(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) $(get_type_attr_decl) $(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
# these have to run individually because order matters:
$(verbose) $(GREP) '^sid ' $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) '^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) $(GREP) ^portcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) ^netifcon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(GREP) ^nodecon $(TMPDIR)/all_te_files.conf >> $(TMPDIR)/all_post.conf || true
$(verbose) $(comment_move_decl) $(TMPDIR)/all_te_files.conf > $(TMPDIR)/only_te_rules.conf
########################################
#
@ -160,7 +160,7 @@ $(TMPDIR)/all_attrs_types.conf $(TMPDIR)/only_te_rules.conf $(TMPDIR)/all_post.c
enableaudit: $(POLICY_CONF)
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
@echo "Removing dontaudit rules from $(notdir $(POLICY_CONF))"
$(verbose) grep -v dontaudit @^ > $(TMPDIR)/policy.audit
$(verbose) $(GREP) -v dontaudit @^ > $(TMPDIR)/policy.audit
$(verbose) mv $(TMPDIR)/policy.audit $(POLICY_CONF)
########################################
@ -169,8 +169,8 @@ enableaudit: $(POLICY_CONF)
#
$(FC): $(TMPDIR)/$(notdir $(FC)).tmp $(FCSORT)
$(verbose) $(FCSORT) $< $@
$(verbose) grep -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
$(verbose) sed -i -e /HOME/d -e /ROLE/d $@
$(verbose) $(GREP) -e HOME -e ROLE $@ > $(HOMEDIR_TEMPLATE)
$(verbose) $(SED) -i -e /HOME/d -e /ROLE/d $@
$(TMPDIR)/$(notdir $(FC)).tmp: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(ALL_FC_FILES)
ifeq ($(ALL_FC_FILES),)
@ -178,7 +178,7 @@ ifeq ($(ALL_FC_FILES),)
endif
@echo "Creating $(NAME) file_contexts."
@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
$(verbose) m4 $(M4PARAM) $^ > $@
$(verbose) $(M4) $(M4PARAM) $^ > $@
########################################
#
@ -211,7 +211,7 @@ $(BUILDDIR)longcheck.res: $(POLICY_CONF) $(FC)
#
$(APPDIR)/customizable_types: $(POLICY_CONF)
@mkdir -p $(APPDIR)
$(verbose) grep "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
$(verbose) $(GREP) "^type .*customizable" $< | cut -d',' -f1 | cut -d' ' -f2 > $(TMPDIR)/customizable_types
$(verbose) install -m 644 $(TMPDIR)/customizable_types $@
########################################

View File

@ -0,0 +1,12 @@
# comment out lines that are moved by the build
# process, so line numbers provided by m4 are preserved.
# lines in require blocks are not moved
/require \{/,/} # end require/b nextline
/^[[:blank:]]*(attribute|type) / s/^/# this line was moved by the build process: &/
/^[[:blank:]]*(port|node|netif|genfs)con /s/^/# this line was moved by the build process: &/
/^[[:blank:]]*fs_use_(xattr|task|trans) /s/^/# this line was moved by the build process: &/
/^[[:blank:]]*sid /s/^/# this line was moved by the build process: &/
:nextline

View File

@ -0,0 +1,12 @@
#n
# print out type and attribute declarations that
# are not inside require blocks.
/require \{/,/} # end require/b nextline
/^[[:blank:]]*(attribute|type) /{
s/^[[:blank:]]+//
p
}
:nextline