Skip to contentSkip to conversation

sepolgen updates

PATCH New Karl MacMillan 1 participant 1 message Apr 10, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sepolgen updates

Updates to the sepolgen parser and tools:
* Adding debugging option to sepolgen-ifgen
* Corrected handling of interface calls with list paramaters (e.g., foo_interface(a_t, { b_t c_t }).
* Added support for role transition rules in the parser
* Updated range transition rule handling to accept more statements
* Moved ignoring refpolicywarn statements to the lexer to better handle arbitrary text in the warnings.
* Fixed parsing of single files by sepolgen-ifgen (useful for testing)
* Loosened the matching slightly (higher distance interfaces returned by default).

 policycoreutils/audit2allow/sepolgen-ifgen |    6 +-
 sepolgen/src/sepolgen/interfaces.py        |   37 ++++++++-------
 sepolgen/src/sepolgen/matching.py          |    2 
 sepolgen/src/sepolgen/refparser.py         |   69 ++++++++++++++++++-----------
 sepolgen/src/sepolgen/refpolicy.py         |   12 ++---
 5 files changed, 76 insertions(+), 50 deletions(-)
policycoreutils/audit2allow/sepolgen-ifgen +4 -2
diff -r 2ee7ee69adbf policycoreutils/audit2allow/sepolgen-ifgen
@@ -45,7 +45,9 @@ def parse_options():
     parser.add_option("-i", "--interfaces", dest="headers", default=defaults.headers(),
                       help="location of the interface header files")
     parser.add_option("-v", "--verbose", action="store_true", default=False,
-                      help="print debuging output")                      
+                      help="print debuging output")
+    parser.add_option("-d", "--debug", action="store_true", default=False,
+                     help="extra debugging output")
     options, args = parser.parse_args()
     
     return options
@@ -67,7 +69,7 @@ def main():
         log = None
 
     try:
-        headers = refparser.parse_headers(options.headers, output=log)
+        headers = refparser.parse_headers(options.headers, output=log, debug=options.debug)
     except ValueError, e:
         print "error parsing headers"
         print str(e)
sepolgen/src/sepolgen/interfaces.py +21 -16
diff -r 2ee7ee69adbf sepolgen/src/sepolgen/interfaces.py
@@ -365,21 +365,25 @@ class InterfaceSet:
                 # been generated from an optional param.
                 return None
             else:
-                return ifcall.args[num - 1]
+                arg = ifcall.args[num - 1]
+                if isinstance(arg, list):
+                    return arg
+                else:
+                    return [arg]
         else:
-            return id
+            return [id]
 
     def map_add_av(self, ifv, av, ifcall):
-        src_type = self.map_param(av.src_type, ifcall)
-        if src_type is None:
-            return
-
-        tgt_type = self.map_param(av.tgt_type, ifcall)
-        if tgt_type is None:
-            return
-
-        obj_class = self.map_param(av.obj_class, ifcall)
-        if obj_class is None:
+        src_types = self.map_param(av.src_type, ifcall)
+        if src_types is None:
+            return
+
+        tgt_types = self.map_param(av.tgt_type, ifcall)
+        if tgt_types is None:
+            return
+
+        obj_classes = self.map_param(av.obj_class, ifcall)
+        if obj_classes is None:
             return
 
         new_perms = refpolicy.IdSet()
@@ -388,13 +392,14 @@ class InterfaceSet:
             if p is None:
                 continue
             else:
-                new_perms.add(p)
+                new_perms.update(p)
         if len(new_perms) == 0:
             return
 
-        ifv.access.add(src_type, tgt_type, obj_class, new_perms)
-
-
+        for src_type in src_types:
+            for tgt_type in tgt_types:
+                for obj_class in obj_classes:
+                    ifv.access.add(src_type, tgt_type, obj_class, new_perms)
 
     def do_expand_ifcalls(self, interface, if_by_name):
         # Descend an interface call tree adding the access
sepolgen/src/sepolgen/matching.py +1 -1
diff -r 2ee7ee69adbf sepolgen/src/sepolgen/matching.py
@@ -50,7 +50,7 @@ class Match:
                 return 1
 
 class MatchList:
-    DEFAULT_THRESHOLD = 100
+    DEFAULT_THRESHOLD = 120
     def __init__(self):
         # Match objects that pass the threshold
         self.children = []
sepolgen/src/sepolgen/refparser.py +43 -26

163 lines not on this page · raw message

sepolgen/src/sepolgen/refpolicy.py +7 -5
diff -r 2ee7ee69adbf sepolgen/src/sepolgen/refpolicy.py
@@ -579,9 +579,6 @@ class InterfaceCall(Leaf):
         self.args = []
         self.comments = []
 
-    def to_string(self):
-        return self.to_string()
-
     def matches(self, other):
         if self.ifname != other.ifname:
             return False
@@ -596,10 +593,15 @@ class InterfaceCall(Leaf):
         s = "%s(" % self.ifname
         i = 0
         for a in self.args:
+            if isinstance(a, list):
+                str = list_to_space_str(a)
+            else:
+                str = a
+                
             if i != 0:
-                s = s + ", %s" % a
+                s = s + ", %s" % str
             else:
-                s = s + a
+                s = s + str
             i += 1
         return s + ")"
 

--
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.