From 5850761393df16ae6c6e980c5e5269db8d3d159c Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Fri, 27 Jan 2006 15:47:52 +0000 Subject: [PATCH] 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 5d1e36548..9c5445b95 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 688a4d705..1b4cc179f 100644 --- a/refpolicy/doc/policy.dtd +++ b/refpolicy/doc/policy.dtd @@ -6,7 +6,8 @@ name CDATA #REQUIRED> + name CDATA #REQUIRED + filename CDATA #REQUIRED> @@ -20,9 +21,9 @@ dftval CDATA #REQUIRED> - + - + ("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("\n" - % os.path.splitext(os.path.split(file_name)[-1])[0]) + module_buf.append("\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.