Skip to contentSkip to conversation

XML Documentaion Modification and Third Party Module support

PATCH In review David Sugar 2 participants 2 messages Feb 10, 2006

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

PATCH 1/1 XML Documentaion Modification and Third Party Module support

This is a patch for reference policy that achieved the following

1) install a set of headers for each $NAME, instead of a single generic set, and put the .if files into layer directories under
the /usr/share/selinux/$NAME/include directory.
2) install the layer, booleans and tunables xml files into the include directory
3) install the xml generation tool (segenxml.py)
4) include the <desc> xml tag around parameter descriptions for global_tunables and global_booleans
5) install build.conf into the include directory
6) install Makefile.example into the include directory

7) modify segenxml.py to work for out of layer (third party) modules
8) modify segenxml.py to generate xml files for global_tunables and global_booleans

Also a sed script is included to change the xml in the .if files to wrap the parameter information in a <summary> tag.

#1-3 & 7-8 will allow policy.xml to be regenerated when someone is generating a 3rd part module.

#4 will make translations easily doable in the future

#5-6 will make the user module building work similar to building kernel modules outside of /usr/src/linux

Dave Sugar
Tresys Technology
[email protected]

Makefile.example +4 -138
Index: doc/Makefile.example
===================================================================
@@ -1,140 +1,6 @@
 
--include build.conf
+NAME ?= refpolicy
+SHAREDIR := /usr/share/selinux
+HEADERDIR := $(SHAREDIR)/$(NAME)/include
 
-# executables
-PREFIX := /usr
-BINDIR := $(PREFIX)/bin
-SBINDIR := $(PREFIX)/sbin
-CHECKMODULE := $(BINDIR)/checkmodule
-SEMODULE := $(SBINDIR)/semodule
-SEMOD_PKG := $(BINDIR)/semodule_package
-
-# helper tools
-AWK ?= gawk
-INSTALL ?= install
-M4 ?= m4
-SED ?= sed
-EINFO ?= echo
-
-# installation paths
-SHAREDIR := $(PREFIX)/share/selinux
-MODPKGDIR := $(SHAREDIR)/$(NAME)
-HEADERDIR := $(SHAREDIR)/refpolicy/include
-
-# set default build options
-TYPE ?= strict
-NAME ?= $(TYPE)
-DIRECT_INITRC ?= n
-POLY ?= n
-
-# compile strict policy if requested.
-ifneq ($(findstring strict,$(TYPE)),)
-	M4PARAM += -D strict_policy
-endif
-
-# compile targeted policy if requested.
-ifneq ($(findstring targeted,$(TYPE)),)
-	M4PARAM += -D targeted_policy
-endif
-
-# enable MLS if requested.
-ifneq ($(findstring -mls,$(TYPE)),)
-	M4PARAM += -D enable_mls
-	CHECKPOLICY += -M
-	CHECKMODULE += -M
-endif
-
-# enable MLS if MCS requested.
-ifneq ($(findstring -mcs,$(TYPE)),)
-	M4PARAM += -D enable_mcs
-	CHECKPOLICY += -M
-	CHECKMODULE += -M
-endif
-
-# enable distribution-specific policy
-ifneq ($(DISTRO),)
-	M4PARAM += -D distro_$(DISTRO)
-endif
-
-# enable polyinstantiation
-ifeq ($(POLY),y)
-	M4PARAM += -D enable_polyinstantiation
-endif
-
-ifeq ($(DIRECT_INITRC),y)
-	M4PARAM += -D direct_sysadm_daemon
-endif
-
-ifneq ($(VERBOSE),y)
-	quiet := @
-endif
-
-M4PARAM += -D hide_broken_symptoms
-
-# policy headers
-m4support := $(wildcard $(HEADERDIR)/*.spt)
-all_interfaces := $(wildcard $(HEADERDIR)/*.if)
-rolemap := $(HEADERDIR)/rolemap
-
-detected_mods := $(wildcard *.te)
-detected_ifs := $(detected_mods:.te=.if)
-all_packages := $(detected_mods:.te=.pp)
-install_mods := $(MODPKGDIR)/$(all_packages)
-
-########################################
-#
-# Functions
-#
-
-# parse-rolemap modulename,outputfile
-define parse-rolemap
-	$(verbose) $(M4) $(M4PARAM) $(rolemap) | \
-		$(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
-endef
-
-# peruser-expansion modulename,outputfile
-define peruser-expansion
-	$(verbose) echo "ifdef(\`""$1""_per_userdomain_template',\`" > $2
-	$(call parse-rolemap,$1,$2)
-	$(verbose) echo "')" >> $2
-endef
-
-########################################
-#
-# Main targets
-#
-
-all: $(all_packages)
-
-########################################
-#
-# Build module packages
-#
-tmp/%.mod: $(m4support) tmp/all_interfaces.conf %.te
-	@$(EINFO) "Compliling $(NAME) $(basename $(@F)) module"
-	@test -d tmp || mkdir -p tmp
-	$(call peruser-expansion,$(basename $(@F)),[email protected])
-	$(verbose) $(M4) $(M4PARAM) -s $^ [email protected] > $(@:.mod=.tmp)
-	$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
-
-tmp/%.mod.fc: $(m4support) %.fc
-	$(verbose) $(M4) $(M4PARAM) $^ > $@
-
-%.pp: tmp/%.mod tmp/%.mod.fc
-	@echo "Creating $(NAME) $(@F) policy package"
-	$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
-
-tmp/all_interfaces.conf: $(m4support) $(all_interfaces) $(detected_ifs)
-	@test -d tmp || mkdir -p tmp
-	$(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
-
-########################################
-#
-# Clean the environment
-#
-
-clean:
-	rm -fR tmp
-	rm -f *.pp
-
-.PHONY: clean install all default
+include $(HEADERDIR)/Makefile
policy.dtd +3 -3
Index: doc/policy.dtd
===================================================================
@@ -11,11 +11,11 @@
 <!ELEMENT required (#PCDATA)>
 <!ATTLIST required
       val (true|false) "false">
-<!ELEMENT tunable (#PCDATA)>
+<!ELEMENT tunable (desc)>
 <!ATTLIST tunable
       name CDATA #REQUIRED
       dftval CDATA #REQUIRED>
-<!ELEMENT bool (#PCDATA)>
+<!ELEMENT bool (desc)>
 <!ATTLIST bool
       name CDATA #REQUIRED
       dftval CDATA #REQUIRED>
@@ -25,7 +25,7 @@
 <!ELEMENT template (summary,desc?,param+)>
 <!ATTLIST template name CDATA #REQUIRED lineno CDATA #REQUIRED>
 <!ELEMENT desc (#PCDATA|%inline.class;)*>
-<!ELEMENT param (#PCDATA)>
+<!ELEMENT param (summary)>
 <!ATTLIST param 
       name CDATA #REQUIRED
       optional (true|false) "false">
templates/global_tun_list.html +1 -1
Index: doc/templates/global_tun_list.html
===================================================================
@@ -8,7 +8,7 @@
 <p>[[tun['def_val']]]</p>
 [[if tun['desc']]]
 <h5>Description</h5>
-<p>[[tun['desc']]]</p>
+[[tun['desc']]]
 [[end]]
 </div></div>
 [[end]]
templates/global_bool_list.html +1 -1
Index: doc/templates/global_bool_list.html
===================================================================
@@ -8,7 +8,7 @@
 <p>[[bool['def_val']]]</p>
 [[if bool['desc']]]
 <h5>Description</h5>
-<p>[[bool['desc']]]</p>
+[[bool['desc']]]
 [[end]]
 </div></div>
 [[end]]
Makefile.devel +180 -0

180 lines not on this page · raw message

sedoctool.py +24 -15
Index: support/sedoctool.py
===================================================================
@@ -55,7 +55,10 @@
 	"""
 
 	for node in doc.getElementsByTagName("tunable"):
-		s = string.split(format_txt_desc(node), "\n")
+		for desc in node.getElementsByTagName("desc"):
+			tun_desc = format_txt_desc(desc)
+		s = string.split(tun_desc, "\n")
+		file_name.write("#\n")
 		for line in s:
 			file_name.write("# %s\n" % line)
 		tun_name = tun_val = None
@@ -403,13 +406,15 @@
 			interface_desc = interface_summary = None
 			interface_name = interface.getAttribute("name")
 			interface_line = interface.getAttribute("lineno")
-			for desc in interface.getElementsByTagName("desc"):
-				interface_desc = format_html_desc(desc)
-			for desc in interface.getElementsByTagName("summary"):
-				interface_summary = format_html_desc(desc)
-			
+			for desc in interface.childNodes:
+				if desc.nodeName == "desc":
+					interface_desc = format_html_desc(desc)
+				elif desc.nodeName == "summary":
+					interface_summary = format_html_desc(desc)
+
 			for args in interface.getElementsByTagName("param"):
-				paramdesc = args.firstChild.data
+				for desc in args.getElementsByTagName("summary"):
+					paramdesc = format_html_desc(desc)
 				paramname = args.getAttribute("name")
 				if args.getAttribute("optional") == "true":
 					paramopt = "Yes"
@@ -442,13 +447,15 @@
 			template_desc = template_summary = None
 			template_name = template.getAttribute("name")
 			template_line = template.getAttribute("lineno")
-			for desc in template.getElementsByTagName("desc"):
-				template_desc = format_html_desc(desc)
-			for desc in template.getElementsByTagName("summary"):
-				template_summary = format_html_desc(desc)
-			
+			for desc in template.childNodes:
+				if desc.nodeName == "desc":
+					template_desc = format_html_desc(desc)
+				elif desc.nodeName == "summary":
+					template_summary = format_html_desc(desc)
+
 			for args in template.getElementsByTagName("param"):
-				paramdesc = args.firstChild.data
+				for desc in args.getElementsByTagName("summary"):
+					paramdesc = format_html_desc(desc)
 				paramname = args.getAttribute("name")
 				if args.getAttribute("optional") == "true":
 					paramopt = "Yes"
@@ -558,7 +565,8 @@
 		if tunable.parentNode.nodeName == "policy":
 			tunable_name = tunable.getAttribute("name")
 			default_value = tunable.getAttribute("dftval")
-			description = format_html_desc(tunable)
+			for desc in tunable.getElementsByTagName("desc"):
+				description = format_html_desc(desc)
 			global_tun_buf.append( { "tun_name" : tunable_name,
 						"def_val" : default_value,
 						"desc" : description } )
@@ -582,7 +590,8 @@
 		if boolean.parentNode.nodeName == "policy":
 			bool_name = boolean.getAttribute("name")
 			default_value = boolean.getAttribute("dftval")
-			description = format_html_desc(boolean)
+			for desc in boolean.getElementsByTagName("desc"):
+				description = format_html_desc(desc)
 			global_bool_buf.append( { "bool_name" : bool_name,
 						"def_val" : default_value,
 						"desc" : description } )
segenxml.py +142 -54

314 lines not on this page · raw message

Makefile +23 -6
Index: Makefile
===================================================================
@@ -273,7 +273,7 @@
 	@mkdir -p tmp
 	$(verbose) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
 	$(verbose) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
-	$(verbose) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@
+	$(verbose) $(GENXML) -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) -o tmp $(ALL_LAYERS) >> $@
 	$(verbose) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
 		$(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
 	fi
@@ -358,21 +358,38 @@
 #
 # Install policy headers
 #
-install-headers: $(DETECTED_MODS:.te=.if) $(ROLEMAP) $(M4SUPPORT)
+install-headers: doc/policy.xml
 	@mkdir -p $(HEADERDIR)
 	@echo "Installing policy headers"
-	$(verbose) install -m 644 $^ $(HEADERDIR)
-	$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $(HEADERDIR)/all_perms.spt
+	$(verbose) install -m 644 tmp/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
+	$(verbose) $(GENPERM) $(AVS) $(SECCLASS) > $(HEADERDIR)/support/all_perms.spt
+	$(verbose) for i in $(notdir $(ALL_LAYERS)); do \
+		mkdir -p $(HEADERDIR)/$$i ;\
+		install -m 644 $(MODDIR)/$$i/*.if \
+			$(MODDIR)/$$i/metadata.xml \
+			$(HEADERDIR)/$$i ;\
+	done
+	$(verbose) echo "TYPE=$(TYPE)" > $(HEADERDIR)/build.conf
+	$(verbose) echo "NAME=$(NAME)" >> $(HEADERDIR)/build.conf
+ifneq "$(DISTRO)" ""
+	$(verbose) echo "DISTRO=$(DISTRO)" >> $(HEADERDIR)/build.conf
+endif
+	$(verbose) echo "MONOLITHIC=n" >> $(HEADERDIR)/build.conf
+	$(verbose) echo "DIRECT_INITRC=$(DIRECT_INITRC)" >> $(HEADERDIR)/build.conf
+	$(verbose) echo "POLY=$(POLY)" >> $(HEADERDIR)/build.conf
+	$(verbose) install -m 644 $(SUPPORT)/Makefile.devel $(HEADERDIR)/Makefile
 
 ########################################
 #
 # Install policy documentation
 #
-install-docs: $(DOCFILES) build.conf tmp/html
+install-docs: tmp/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
 
 ########################################
global_booleans +12 -0
Index: policy/global_booleans
===================================================================
@@ -4,15 +4,27 @@
 # file should be used.
 #
 
+## <desc>
+## <p>
 ## Enabling secure mode disallows programs, such as
 ## newrole, from transitioning to administrative
 ## user domains.
+## </p>
+## </desc>
 gen_bool(secure_mode,false)
 
+## <desc>
+## <p>
 ## Disable transitions to insmod.
+## </p>
+## </desc>
 gen_bool(secure_mode_insmod,false)
 
+## <desc>
+## <p>
 ## boolean to determine whether the system permits loading policy, setting
 ## enforcing mode, and changing boolean values.  Set this to true and you
 ## have to reboot to set it back
+## </p>
+## </desc>
 gen_bool(secure_mode_policyload,false)
global_tunables +244 -2

455 lines not on this page · raw message

/<param .*>/a\
## <summary>
/<\/param>/i\
## </summary>

#1 lore raw
Quoted 1 line · David Sugar

This is a patch for reference policy that achieved the following

Merged.

Quoted 29 lines

1) install a set of headers for each $NAME, instead of a single generic set, and put the .if files into layer directories under
the /usr/share/selinux/$NAME/include directory.
2) install the layer, booleans and tunables xml files into the include directory
3) install the xml generation tool (segenxml.py)
4) include the <desc> xml tag around parameter descriptions for global_tunables and global_booleans
5) install build.conf into the include directory
6) install Makefile.example into the include directory

7) modify segenxml.py to work for out of layer (third party) modules
8) modify segenxml.py to generate xml files for global_tunables and global_booleans

Also a sed script is included to change the xml in the .if files to wrap the parameter information in a <summary> tag.

#1-3 & 7-8 will allow policy.xml to be regenerated when someone is generating a 3rd part module.

#4 will make translations easily doable in the future

#5-6 will make the user module building work similar to building kernel modules outside of /usr/src/linux

Dave Sugar
Tresys Technology
[email protected]

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.