[selinux-policy: 1158/3172] add line number and file name to xml, from selide people

Daniel J Walsh dwalsh at fedoraproject.org
Thu Oct 7 20:45:06 UTC 2010


commit 5850761393df16ae6c6e980c5e5269db8d3d159c
Author: Chris PeBenito <cpebenito at tresys.com>
Date:   Fri Jan 27 15:47:52 2006 +0000

    add line number and file name to xml, from selide people

 refpolicy/Changelog           |    2 ++
 refpolicy/doc/policy.dtd      |    7 ++++---
 refpolicy/support/segenxml.py |   13 ++++++++-----
 3 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/refpolicy/Changelog b/refpolicy/Changelog
index 5d1e365..9c5445b 100644
--- a/refpolicy/Changelog
+++ b/refpolicy/Changelog
@@ -1,3 +1,5 @@
+- Add filename attribute to module XML tag and lineno attribute to
+  interface XML tag.
 - Changed QUIET build option to a yes or no option.
 - Add a Makefile used for compiling loadable modules in a
   user's development environment, building against policy headers.
diff --git a/refpolicy/doc/policy.dtd b/refpolicy/doc/policy.dtd
index 688a4d7..1b4cc17 100644
--- a/refpolicy/doc/policy.dtd
+++ b/refpolicy/doc/policy.dtd
@@ -6,7 +6,8 @@
       name CDATA #REQUIRED>
 <!ELEMENT module (summary,desc?,required?,(interface|template)*)>
 <!ATTLIST module 
-      name CDATA #REQUIRED>
+      name CDATA #REQUIRED
+      filename CDATA #REQUIRED>
 <!ELEMENT required (#PCDATA)>
 <!ATTLIST required
       val (true|false) "false">
@@ -20,9 +21,9 @@
       dftval CDATA #REQUIRED>
 <!ELEMENT summary (#PCDATA)>
 <!ELEMENT interface (summary,desc?,param+,infoflow?)>
-<!ATTLIST interface name CDATA #REQUIRED>
+<!ATTLIST interface name CDATA #REQUIRED lineno CDATA #REQUIRED>
 <!ELEMENT template (summary,desc?,param+)>
-<!ATTLIST template name CDATA #REQUIRED>
+<!ATTLIST template name CDATA #REQUIRED lineno CDATA #REQUIRED>
 <!ELEMENT desc (#PCDATA|%inline.class;)*>
 <!ELEMENT param (#PCDATA)>
 <!ATTLIST param 
diff --git a/refpolicy/support/segenxml.py b/refpolicy/support/segenxml.py
index d550262..14fb307 100755
--- a/refpolicy/support/segenxml.py
+++ b/refpolicy/support/segenxml.py
@@ -36,7 +36,7 @@ bool_files = []
 #	 -> ("interface", "kernel_read_system_state")
 #	"template(`base_user_template',`"
 #	 -> ("template", "base_user_template")
-INTERFACE = re.compile("^\s*(interface|template)\(`([A-Za-z0-9_]*)'")
+INTERFACE = re.compile("^\s*(interface|template)\(`(\w*)'")
 
 # Matches either a gen_bool or a gen_tunable statement. Will give the tuple:
 #	("tunable" or "bool", name, "true" or "false")
@@ -45,7 +45,7 @@ INTERFACE = re.compile("^\s*(interface|template)\(`([A-Za-z0-9_]*)'")
 #	 -> ("bool", "secure_mode", "false")
 #	"gen_tunable(allow_kerberos, false)"
 #	 -> ("tunable", "allow_kerberos", "false")
-BOOLEAN = re.compile("^\s*gen_(tunable|bool)\(\s*([A-Za-z0-9_]*)\s*,\s*(true|false)\s*\)")
+BOOLEAN = re.compile("^\s*gen_(tunable|bool)\(\s*(\w*)\s*,\s*(true|false)\s*\)")
 
 # Matches a XML comment in the policy, which is defined as any line starting
 #  with two # and at least one character of white space. Will give the single
@@ -77,8 +77,8 @@ def getModuleXML(file_name):
 	module_buf = []
 
 	# Infer the module name, which is the base of the file name.
-	module_buf.append("<module name=\"%s\">\n" 
-		% os.path.splitext(os.path.split(file_name)[-1])[0])
+	module_buf.append("<module name=\"%s\" filename=\"%s\">\n" 
+		% (os.path.splitext(os.path.split(file_name)[-1])[0], file_name))
 
 	temp_buf = []
 	interface = None
@@ -92,7 +92,9 @@ def getModuleXML(file_name):
 		module_code = module_code[1:]
 
 	# Go line by line and figure out what to do with it.
+	line_num = 0
 	for line in module_code:
+		line_num += 1
 		if finding_header:
 			# If there is a XML comment, add it to the temp buffer.
 			comment = XML_COMMENT.match(line)
@@ -130,7 +132,8 @@ def getModuleXML(file_name):
 			interface = INTERFACE.match(line)
 		if interface:
 			# Add the opening tag for the interface/template
-			module_buf.append("<%s name=\"%s\">\n" % interface.groups())
+			groups = interface.groups()
+			module_buf.append("<%s name=\"%s\" lineno=\"%s\">\n" % (groups[0], groups[1], line_num))
 
 			# Add all the comments attributed to this interface to
 			#  the module buffer.


More information about the scm-commits mailing list