2007-12-19 17:55:58 +00:00
|
|
|
diff --exclude-from=exclude -N -u -r nsasepolgen/src/sepolgen/refparser.py policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/refparser.py
|
2007-12-19 10:40:23 +00:00
|
|
|
--- nsasepolgen/src/sepolgen/refparser.py 2007-09-13 08:21:11.000000000 -0400
|
2007-12-20 19:24:11 +00:00
|
|
|
+++ policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/refparser.py 2007-12-20 14:20:49.000000000 -0500
|
2007-12-19 10:40:23 +00:00
|
|
|
@@ -118,6 +118,7 @@
|
|
|
|
'TEMPLATE',
|
|
|
|
'GEN_CONTEXT',
|
|
|
|
# m4
|
|
|
|
+ 'IFELSE',
|
|
|
|
'IFDEF',
|
|
|
|
'IFNDEF',
|
|
|
|
'DEFINE'
|
|
|
|
@@ -174,6 +175,7 @@
|
|
|
|
'template' : 'TEMPLATE',
|
|
|
|
'gen_context' : 'GEN_CONTEXT',
|
|
|
|
# M4
|
|
|
|
+ 'ifelse' : 'IFELSE',
|
|
|
|
'ifndef' : 'IFNDEF',
|
|
|
|
'ifdef' : 'IFDEF',
|
|
|
|
'define' : 'DEFINE'
|
|
|
|
@@ -220,6 +222,12 @@
|
|
|
|
# Ignore all comments
|
|
|
|
t.lexer.lineno += 1
|
|
|
|
|
|
|
|
+def t_refpolicywarn1(t):
|
|
|
|
+ r'define.*refpolicywarn\(.*\n'
|
|
|
|
+ # Ignore refpolicywarn statements - they sometimes
|
|
|
|
+ # contain text that we can't parse.
|
|
|
|
+ t.skip(1)
|
|
|
|
+
|
|
|
|
def t_refpolicywarn(t):
|
|
|
|
r'refpolicywarn\(.*\n'
|
|
|
|
# Ignore refpolicywarn statements - they sometimes
|
2007-12-20 19:24:11 +00:00
|
|
|
@@ -258,10 +266,12 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
m = None
|
|
|
|
# error is either None (indicating no error) or a string error message.
|
|
|
|
error = None
|
|
|
|
+parse_file = ""
|
|
|
|
# spt is the support macros (e.g., obj/perm sets) - it is an instance of
|
|
|
|
# refpolicy.SupportMacros and should always be present during parsing
|
|
|
|
# though it may not contain any macros.
|
2007-12-20 19:24:11 +00:00
|
|
|
spt = None
|
|
|
|
+success=True
|
|
|
|
|
|
|
|
# utilities
|
|
|
|
def collect(stmts, parent, val=None):
|
|
|
|
@@ -382,6 +392,19 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
collect(p[12], x, val=False)
|
|
|
|
p[0] = [x]
|
|
|
|
|
|
|
|
+def p_ifelse(p):
|
|
|
|
+ '''ifelse : IFELSE OPAREN TICK IDENTIFIER SQUOTE COMMA COMMA TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
|
|
|
|
+ | IFELSE OPAREN TICK IDENTIFIER SQUOTE COMMA TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
|
|
|
|
+ '''
|
|
|
|
+# x = refpolicy.IfDef(p[4])
|
|
|
|
+# v = True
|
|
|
|
+# collect(p[8], x, val=v)
|
|
|
|
+# if len(p) > 12:
|
|
|
|
+# collect(p[12], x, val=False)
|
|
|
|
+# p[0] = [x]
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
def p_ifdef(p):
|
|
|
|
'''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
|
|
|
|
| IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
|
2007-12-20 19:24:11 +00:00
|
|
|
@@ -446,6 +469,7 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
| optional_policy
|
|
|
|
| tunable_policy
|
|
|
|
| ifdef
|
|
|
|
+ | ifelse
|
|
|
|
| conditional
|
|
|
|
'''
|
|
|
|
p[0] = p[1]
|
2007-12-20 19:24:11 +00:00
|
|
|
@@ -844,8 +868,11 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
|
|
|
|
def p_error(tok):
|
|
|
|
global error
|
|
|
|
- error = "Syntax error on line %d %s [type=%s]" % (tok.lineno, tok.value, tok.type)
|
|
|
|
+ global parse_file
|
2007-12-20 19:24:11 +00:00
|
|
|
+ global success
|
2007-12-19 10:40:23 +00:00
|
|
|
+ error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type)
|
|
|
|
print error
|
2007-12-20 19:24:11 +00:00
|
|
|
+ success = False
|
2007-12-19 10:40:23 +00:00
|
|
|
|
|
|
|
def prep_spt(spt):
|
2007-12-20 19:24:11 +00:00
|
|
|
if not spt:
|
|
|
|
@@ -892,7 +919,7 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
def list_headers(root):
|
|
|
|
modules = []
|
|
|
|
support_macros = None
|
|
|
|
- blacklist = ["init.if", "inetd.if", "uml.if", "thunderbird.if"]
|
|
|
|
+ blacklist = ["uml.if", "thunderbird.if"]
|
|
|
|
|
|
|
|
for dirpath, dirnames, filenames in os.walk(root):
|
|
|
|
for name in filenames:
|
2007-12-20 19:24:11 +00:00
|
|
|
@@ -941,12 +968,14 @@
|
2007-12-19 10:40:23 +00:00
|
|
|
output.write(msg)
|
|
|
|
|
|
|
|
def parse_file(f, module, spt=None):
|
|
|
|
+ global parse_file
|
|
|
|
if debug:
|
|
|
|
o("parsing file %s\n" % f)
|
|
|
|
try:
|
|
|
|
fd = open(f)
|
|
|
|
txt = fd.read()
|
|
|
|
fd.close()
|
|
|
|
+ parse_file = f
|
|
|
|
parse(txt, module, spt, debug)
|
|
|
|
except IOError, e:
|
|
|
|
return
|