ec80e1c
diff --exclude-from=exclude -N -u -r nsasepolgen/src/sepolgen/audit.py policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/audit.py
ec80e1c
--- nsasepolgen/src/sepolgen/audit.py	2007-09-13 08:21:11.000000000 -0400
ec80e1c
+++ policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/audit.py	2007-12-21 02:10:43.000000000 -0500
ec80e1c
@@ -32,7 +32,7 @@
ec80e1c
        string contain all of the audit messages returned by ausearch.
ec80e1c
     """
ec80e1c
     import subprocess
ec80e1c
-    output = subprocess.Popen(["/sbin/ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START"],
ec80e1c
+    output = subprocess.Popen(["/sbin/ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR"],
ec80e1c
                               stdout=subprocess.PIPE).communicate()[0]
ec80e1c
     return output
ec80e1c
 
ec80e1c
@@ -251,7 +251,9 @@
ec80e1c
             self.type = refpolicy.SecurityContext(dict["tcontext"]).type
ec80e1c
         except:
ec80e1c
             raise ValueError("Split string does not represent a valid compute sid message")
ec80e1c
-
ec80e1c
+    def output(self):
ec80e1c
+        return "role %s types %s;\n" % (self.role, self.type)
ec80e1c
+        
ec80e1c
 # Parser for audit messages
ec80e1c
 
ec80e1c
 class AuditParser:
ec80e1c
@@ -402,6 +404,26 @@
ec80e1c
             self.__parse(l)
ec80e1c
         self.__post_process()
ec80e1c
 
ec80e1c
+    def to_role(self, role_filter=None):
ec80e1c
+        """Return list of SELINUX_ERR messages matching the specified filter
ec80e1c
+
ec80e1c
+        Filter out types that match the filer, or all roles
ec80e1c
+
ec80e1c
+        Params:
ec80e1c
+           role_filter - [optional] Filter object used to filter the
ec80e1c
+              output.
ec80e1c
+        Returns:
ec80e1c
+           Access vector set representing the denied access in the
ec80e1c
+           audit logs parsed by this object.
ec80e1c
+        """
ec80e1c
+        roles = []
ec80e1c
+        if role_filter:
ec80e1c
+            for selinux_err in self.compute_sid_msgs:
ec80e1c
+                if role_filter.filter(selinux_err):
ec80e1c
+                    roles.append(selinux_err)
ec80e1c
+            return roles
ec80e1c
+        return self.compute_sid_msgs
ec80e1c
+
ec80e1c
     def to_access(self, avc_filter=None, only_denials=True):
ec80e1c
         """Convert the audit logs access into a an access vector set.
ec80e1c
 
bac931c
diff --exclude-from=exclude -N -u -r nsasepolgen/src/sepolgen/refparser.py policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/refparser.py
e61ad23
--- nsasepolgen/src/sepolgen/refparser.py	2007-09-13 08:21:11.000000000 -0400
7f6f582
+++ policycoreutils-2.0.34/sepolgen-1.0.10/src/sepolgen/refparser.py	2007-12-20 14:20:49.000000000 -0500
e61ad23
@@ -118,6 +118,7 @@
e61ad23
     'TEMPLATE',
e61ad23
     'GEN_CONTEXT',
e61ad23
     #   m4
e61ad23
+    'IFELSE',
e61ad23
     'IFDEF',
e61ad23
     'IFNDEF',
e61ad23
     'DEFINE'
e61ad23
@@ -174,6 +175,7 @@
e61ad23
     'template' : 'TEMPLATE',
e61ad23
     'gen_context' : 'GEN_CONTEXT',
e61ad23
     # M4
e61ad23
+    'ifelse' : 'IFELSE',
e61ad23
     'ifndef' : 'IFNDEF',
e61ad23
     'ifdef' : 'IFDEF',
e61ad23
     'define' : 'DEFINE'
e61ad23
@@ -220,6 +222,12 @@
e61ad23
     # Ignore all comments
e61ad23
     t.lexer.lineno += 1
e61ad23
 
e61ad23
+def t_refpolicywarn1(t):
e61ad23
+    r'define.*refpolicywarn\(.*\n'
e61ad23
+    # Ignore refpolicywarn statements - they sometimes
e61ad23
+    # contain text that we can't parse.
e61ad23
+    t.skip(1)
e61ad23
+
e61ad23
 def t_refpolicywarn(t):
e61ad23
     r'refpolicywarn\(.*\n'
e61ad23
     # Ignore refpolicywarn statements - they sometimes
7f6f582
@@ -258,10 +266,12 @@
e61ad23
 m = None
e61ad23
 #   error is either None (indicating no error) or a string error message.
e61ad23
 error = None
e61ad23
+parse_file = ""
e61ad23
 #   spt is the support macros (e.g., obj/perm sets) - it is an instance of
e61ad23
 #     refpolicy.SupportMacros and should always be present during parsing
e61ad23
 #     though it may not contain any macros.
7f6f582
 spt = None
7f6f582
+success=True
7f6f582
 
7f6f582
 # utilities
7f6f582
 def collect(stmts, parent, val=None):
7f6f582
@@ -382,6 +392,19 @@
e61ad23
         collect(p[12], x, val=False)
e61ad23
     p[0] = [x]
e61ad23
 
e61ad23
+def p_ifelse(p):
e61ad23
+    '''ifelse : IFELSE OPAREN TICK IDENTIFIER SQUOTE COMMA COMMA TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
e61ad23
+              | IFELSE OPAREN TICK IDENTIFIER SQUOTE COMMA TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
e61ad23
+    '''
e61ad23
+#    x = refpolicy.IfDef(p[4])
e61ad23
+#    v = True
e61ad23
+#    collect(p[8], x, val=v)
e61ad23
+#    if len(p) > 12:
e61ad23
+#        collect(p[12], x, val=False)
e61ad23
+#    p[0] = [x]
e61ad23
+    pass
e61ad23
+
e61ad23
+
e61ad23
 def p_ifdef(p):
e61ad23
     '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
e61ad23
              | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
7f6f582
@@ -446,6 +469,7 @@
e61ad23
               | optional_policy
e61ad23
               | tunable_policy
e61ad23
               | ifdef
e61ad23
+              | ifelse
e61ad23
               | conditional
e61ad23
     '''
e61ad23
     p[0] = p[1]
7f6f582
@@ -844,8 +868,11 @@
e61ad23
 
e61ad23
 def p_error(tok):
e61ad23
     global error
e61ad23
-    error = "Syntax error on line %d %s [type=%s]" % (tok.lineno, tok.value, tok.type)
e61ad23
+    global parse_file
7f6f582
+    global success
e61ad23
+    error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type)
e61ad23
     print error
7f6f582
+    success = False
e61ad23
 
e61ad23
 def prep_spt(spt):
7f6f582
     if not spt:
7f6f582
@@ -892,7 +919,7 @@
e61ad23
 def list_headers(root):
e61ad23
     modules = []
e61ad23
     support_macros = None
e61ad23
-    blacklist = ["init.if", "inetd.if", "uml.if", "thunderbird.if"]
e61ad23
+    blacklist = ["uml.if", "thunderbird.if"]
e61ad23
 
e61ad23
     for dirpath, dirnames, filenames in os.walk(root):
e61ad23
         for name in filenames:
7f6f582
@@ -941,12 +968,14 @@
e61ad23
             output.write(msg)
e61ad23
 
e61ad23
     def parse_file(f, module, spt=None):
e61ad23
+        global parse_file
e61ad23
         if debug:
e61ad23
             o("parsing file %s\n" % f)
e61ad23
         try:
e61ad23
             fd = open(f)
e61ad23
             txt = fd.read()
e61ad23
             fd.close()
e61ad23
+            parse_file = f
e61ad23
             parse(txt, module, spt, debug)
e61ad23
         except IOError, e:
e61ad23
             return