Skip to contentSkip to conversation

refpolicy: external modules

PATCH In review Spencer Shimko 2 participants 2 messages Feb 10, 2006 – Feb 15, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 refpolicy: external modules

All,

Attached is a patch to Makefile, Rules.monolithic, and Rules.modular in reference policy that does two things:

1. It contains an update version of the patch submitted to the list on 1/12/2006 to change policy module state from the command line at build time. The three variables used are APPS_OFF (disable a policy module off), APPS_ON (enable a policy module and include it in the base module), and APPS_MODS (enable a policy module and build it as a module). Example usage:
$make clean
$make APPS_OFF="gpg"

2. It includes a patch from Chris Ashworth that allows external policy trees to be used when building policy. The idea for this is two fold:
first it allows someone to build a module without having write access to the reference policy directory, second it allows someone to maintain an out-of-tree "third-party" module with little effort. It expects a similar filesystem layout including layers in the policy/modules directory and support macros (if any) in the policy/support directory. Example usage:
$make LOCAL_ROOT="/home/spencer/mypolicy"

Thanks,
Spencer

Signature · 4 lines
Spencer Shimko
Tresys Technology, LLC
(410) 290 - 1411 ext. 125
[email protected]
Makefile +107 -40
diff -urN refpolicy-old/Makefile refpolicy-new/Makefile
@@ -23,11 +23,33 @@
 # NO OPTIONS BELOW HERE
 #
 
-include build.conf
+# Top level directory - so make can be run from outside 
+# of the tree (if this is overridden on the command line)
+ROOT := .
+
+# Include the local build.conf if it exists, otherwise
+# include the configuration of the root directory.
+ifdef LOCAL_ROOT
+	include $(LOCAL_ROOT)/build.conf
+else
+	include $(ROOT)/build.conf
+endif
 
 # refpolicy version
 VERSION = $(shell cat VERSION)
 
+ifdef LOCAL_ROOT
+BUILDDIR := $(LOCAL_ROOT)
+TMP_ROOT := $(LOCAL_ROOT)
+TAGS := $(LOCAL_ROOT)/tags
+else
+BUILDDIR := $(ROOT)
+TMP_ROOT := $(ROOT)
+TAGS := $(ROOT)/tags
+endif
+
+TMPDIR := $(TMP_ROOT)/tmp
+
 # executable paths
 BINDIR := /usr/bin
 SBINDIR := /usr/sbin
@@ -43,16 +65,26 @@
 
 CFLAGS := -Wall
 
+# source directory names
+POL_ROOT := policy
+MOD_ROOT := modules
+
 # policy source layout
-POLDIR := policy
-MODDIR := $(POLDIR)/modules
+POLDIR := $(ROOT)/$(POL_ROOT)
+MODDIR := $(POLDIR)/$(MOD_ROOT)
 FLASKDIR := $(POLDIR)/flask
 SECCLASS := $(FLASKDIR)/security_classes
 ISIDS := $(FLASKDIR)/initial_sids
 AVS := $(FLASKDIR)/access_vectors
 
+# local source layout
+ifdef LOCAL_ROOT
+LOCAL_POLDIR := $(LOCAL_ROOT)/$(POL_ROOT)
+LOCAL_MODDIR := $(LOCAL_POLDIR)/$(MOD_ROOT)
+endif
+
 # policy building support tools
-SUPPORT := support
+SUPPORT := $(ROOT)/support
 GENXML := $(SUPPORT)/segenxml.py
 GENDOC := $(SUPPORT)/sedoctool.py
 GENPERM := $(SUPPORT)/genclassperms.py
@@ -60,7 +92,7 @@
 SETTUN := $(SUPPORT)/set_tunables
 
 # documentation paths
-DOCS = doc
+DOCS = $(ROOT)/doc
 POLXML = $(DOCS)/policy.xml
 XMLDTD = $(DOCS)/policy.dtd
 LAYERXML = metadata.xml
@@ -68,14 +100,30 @@
 DOCTEMPLATE = $(DOCS)/templates
 DOCFILES = $(DOCS)/Makefile.example $(addprefix $(DOCS)/,example.te example.if example.fc)
 
+# local doc paths
+ifdef LOCAL_ROOT
+POLXML = $(LOCAL_ROOT)/doc/policy.xml
+HTMLDIR = $(LOCAL_ROOT)/doc/html
+endif
+
+# config file names
+MOD_CONF_FILE := modules.conf
+BOOLEANS_FILE := booleans.conf
+
 # config file paths
 GLOBALTUN = $(POLDIR)/global_tunables
 GLOBALBOOL = $(POLDIR)/global_booleans
-MOD_CONF = $(POLDIR)/modules.conf
+MOD_CONF = $(POLDIR)/$(MOD_CONF_FILE)
 TUNABLES = $(POLDIR)/tunables.conf
-BOOLEANS = $(POLDIR)/booleans.conf
+BOOLEANS = $(POLDIR)/$(BOOLEANS_FILE)
 ROLEMAP = $(POLDIR)/rolemap
 
+# local config file paths
+ifdef LOCAL_ROOT
+MOD_CONF = $(LOCAL_POLDIR)/$(MOD_CONF_FILE)
+BOOLEANS = $(LOCAL_POLDIR)/$(BOOLEANS_FILE)
+endif
+
 # install paths
 PKGNAME ?= refpolicy-$(VERSION)
 PREFIX = $(DESTDIR)/usr
@@ -163,7 +211,7 @@
 	KV := $(PV)
 endif
 
-M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
+M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt $(LOCAL_POLDIR)/support/*.spt)
 
 APPCONF := config/appconfig-$(TYPE)
 APPDIR := $(CONTEXTPATH)
@@ -172,7 +220,9 @@
 USER_FILES := $(POLDIR)/users
 
 ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
-
+ifneq ($(LOCAL_ROOT),)
+	LOCAL_LAYERS := $(filter-out $(LOCAL_MODDIR)/CVS,$(shell find $(wildcard $(LOCAL_MODDIR)/*) -maxdepth 0 -type d))
+endif
 GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
 GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
 GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
@@ -190,10 +240,17 @@
 # modules.conf setting for unused module
 MODUNUSED := off
 
+# test for module overrides from command line
+MOD_TEST = $(filter $(APPS_OFF), $(APPS_ON) $(APPS_MODS))
+MOD_TEST += $(filter $(APPS_MODS), $(APPS_ON))
+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!)
+endif
+
 # extract settings from modules.conf
-BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
-MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
-OFF_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null))
+BASE_MODS := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null) $(APPS_ON)))
+MOD_MODS := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null) $(APPS_MODS)))
+OFF_MODS := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null) $(APPS_OFF)))
 
 # filesystems to be labeled
 FILESYSTEMS = $(shell mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';)
@@ -222,15 +279,17 @@
 #
 
 ifeq ($(MONOLITHIC),y)
-	include Rules.monolithic
+	include $(ROOT)/Rules.monolithic
 else
-	include Rules.modular
+	include $(ROOT)/Rules.modular
 endif
 
 ########################################
 #
 # Generated files
 #
+# NOTE: There is no "local" version of these files.
+#
 $(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
 	@echo "#" > $@
 	@echo "# This is a generated file!  Instead of modifying this file, the" >> $@
@@ -257,12 +316,14 @@
 
 $(MOD_CONF) $(BOOLEANS): $(POLXML)
 	@echo "Updating $(MOD_CONF) and $(BOOLEANS)"
-	$(verbose) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML)
+	$(verbose) cd $(DOCS) && $(GENDOC) -t $(BOOLEANS) -m $(MOD_CONF) -x $(POLXML)
 
 ########################################
 #
 # Documentation generation
 #
+#
+
 
 # minimal dependencies here, because we don't want to rebuild 
 # this and its dependents every time the dependencies
@@ -270,36 +331,37 @@
 # enabled modules.
 $(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
 	@echo "Creating $@"
-	@mkdir -p tmp
+	@test -d $(dir $(POLXML)) || mkdir -p $(dir $(POLXML))
 	$(verbose) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
 	$(verbose) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
-	$(verbose) $(GENXML) -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) -o tmp $(ALL_LAYERS) >> $@
+	$(verbose) $(GENXML) -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) -o $(TMPDIR) $(ALL_LAYERS) $(LOCAL_LAYERS) >> $@
 	$(verbose) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
-		$(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
+		$(XMLLINT) --noout --path $(dir $(XMLDTD)) --dtdvalid $(XMLDTD) $@ ;\
 	fi
 
-html tmp/html: $(POLXML)
+html $(TMPDIR)/html: $(POLXML)
 	@echo "Building html interface reference documentation in $(HTMLDIR)"
-	@mkdir -p $(HTMLDIR)
-	$(verbose) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
+	@test -d $(HTMLDIR) || @mkdir -p $(HTMLDIR)
+	$(verbose) cd $(DOCS) && $(GENDOC) -d $(HTMLDIR) -T $(DOCTEMPLATE) -x $(POLXML)
 	$(verbose) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
-	@touch tmp/html
+	@touch $(TMPDIR)/html
 
 ########################################
 #
 # Runtime binary policy patching of users
 #
-$(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES)
+$(USERPATH)/system.users: $(M4SUPPORT) $(TMPDIR)/generated_definitions.conf $(USER_FILES)
+	@mkdir -p $(TMPDIR)
 	@mkdir -p $(USERPATH)
 	@echo "Installing system.users"
-	@echo "# " > tmp/system.users
-	@echo "# Do not edit this file. " >> tmp/system.users
-	@echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
-	@echo "# Please edit local.users to make local changes." >> tmp/system.users
-	@echo "#" >> tmp/system.users
+	@echo "# " > $(TMPDIR)/system.users
+	@echo "# Do not edit this file. " >> $(TMPDIR)/system.users
+	@echo "# This file is replaced on reinstalls of this policy." >> $(TMPDIR)/system.users
+	@echo "# Please edit local.users to make local changes." >> $(TMPDIR)/system.users
+	@echo "#" >> $(TMPDIR)/system.users
 	$(verbose) m4 -D self_contained_policy $(M4PARAM) $^ | sed -r -e 's/^[[:blank:]]+//' \
-		-e '/^[[:blank:]]*($$|#)/d' >> tmp/system.users
-	$(verbose) install -m 644 tmp/system.users $@
+		-e '/^[[:blank:]]*($$|#)/d' >> $(TMPDIR)/system.users
+	$(verbose) install -m 644 $(TMPDIR)/system.users $@
 
 $(USERPATH)/local.users: config/local.users
 	@mkdir -p $(USERPATH)
@@ -313,10 +375,11 @@
 install-appconfig: $(APPFILES)
 
 $(INSTALLDIR)/booleans: $(BOOLEANS)
+	@mkdir -p $(TMPDIR)
 	@mkdir -p $(INSTALLDIR)
 	$(verbose) sed -r -e 's/false/0/g' -e 's/true/1/g' \
-		-e '/^[[:blank:]]*($$|#)/d' $(BOOLEANS) | sort > tmp/booleans
-	$(verbose) install -m 644 tmp/booleans $@
+		-e '/^[[:blank:]]*($$|#)/d' $(BOOLEANS) | sort > $(TMPDIR)/booleans
+	$(verbose) install -m 644 $(TMPDIR)/booleans $@
 
 $(CONTEXTPATH)/files/media: $(APPCONF)/media
 	@mkdir -p $(CONTEXTPATH)/files/
@@ -358,10 +421,10 @@
 #
 # Install policy headers
 #
-install-headers: doc/policy.xml
+install-headers: $(POLXML)
 	@mkdir -p $(HEADERDIR)
 	@echo "Installing policy headers"
-	$(verbose) install -m 644 tmp/global_{tunables,booleans}.xml $(HEADERDIR)
+	$(verbose) install -m 644 $(TMPDIR)/global_{tunables,booleans}.xml $(HEADERDIR)
 	$(verbose) m4 $(M4PARAM) $(ROLEMAP) > $(HEADERDIR)/$(notdir $(ROLEMAP))
 	$(verbose) mkdir -p $(HEADERDIR)/support
 	$(verbose) install -m 644 $(M4SUPPORT) $(GENXML) $(XMLDTD) $(HEADERDIR)/support
@@ -386,10 +449,11 @@
 #
 # Install policy documentation
 #
-install-docs: tmp/html
+install-docs: $(TMPDIR)/html
 	@mkdir -p $(DOCSDIR)/html
 	@echo "Installing policy documentation"
 	$(verbose) install -m 644 $(DOCFILES) $(DOCSDIR)
+	$(verbose) install -m 644 build.conf $(DOCSDIR)/build.conf.example
 	$(verbose) install -m 644 $(wildcard $(HTMLDIR)/*) $(DOCSDIR)/html
 
 ########################################
@@ -406,9 +470,9 @@
 #
 # Generate tags file
 #
-tags:
+$(TAGS):
 	@($(CTAGS) --version | grep -q Exuberant) || (echo ERROR: Need exuberant-ctags to function!; exit 1)
-	@LC_ALL=C $(CTAGS) --langdef=te --langmap=te:..te.if.spt \
+	@LC_ALL=C $(CTAGS) -f $(TAGS) --langdef=te --langmap=te:..te.if.spt \
 	 --regex-te='/^type[ \t]+(\w+)(,|;)/\1/t,type/' \
 	 --regex-te='/^typealias[ \t]+\w+[ \t+]+alias[ \t]+(\w+);/\1/t,type/' \
 	 --regex-te='/^attribute[ \t]+(\w+);/\1/a,attribute/' \
@@ -458,12 +522,14 @@
 #
 bare: clean
 	rm -f $(POLXML)
-	rm -f $(SUPPORT)/*.pyc
-	rm -f $(FCSORT)
 	rm -f $(MOD_CONF)
 	rm -f $(BOOLEANS)
 	rm -fR $(HTMLDIR)
-	rm -f tags
+	rm -f $(TAGS)
+# don't remove these files if we're given a local root
+ifndef LOCAL_ROOT
+	rm -f $(SUPPORT)/*.pyc
+	rm -f $(FCSORT)
 ifneq ($(GENERATED_TE),)
 	rm -f $(GENERATED_TE)
 endif
@@ -473,6 +539,7 @@
 ifneq ($(GENERATED_FC),)
 	rm -f $(GENERATED_FC)
 endif
+endif
 
 .PHONY: install-src install-appconfig conf html bare tags
 .SUFFIXES:
Rules.modular +62 -53

230 lines not on this page · raw message

Rules.monolithic +58 -55

241 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Spencer Shimko

Attached is a patch to Makefile, Rules.monolithic, and Rules.modular in reference policy that does two things:

Merged, with a few tweaks.

Quoted 18 lines

1. It contains an update version of the patch submitted to the list on 1/12/2006 to change policy module state from the command line at build time. The three variables used are APPS_OFF (disable a policy module off), APPS_ON (enable a policy module and include it in the base module), and APPS_MODS (enable a policy module and build it as a module). Example usage:
$make clean
$make APPS_OFF="gpg"

2. It includes a patch from Chris Ashworth that allows external policy trees to be used when building policy. The idea for this is two fold:
first it allows someone to build a module without having write access to the reference policy directory, second it allows someone to maintain an out-of-tree "third-party" module with little effort. It expects a similar filesystem layout including layers in the policy/modules directory and support macros (if any) in the policy/support directory. Example usage:
$make LOCAL_ROOT="/home/spencer/mypolicy"

Signature · 9 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.