Home | History | Annotate | Download | only in diff
      1 # Copyright 2016, Tresys Technology, LLC
      2 #
      3 # This file is part of SETools.
      4 #
      5 # SETools is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Lesser General Public License as
      7 # published by the Free Software Foundation, either version 2.1 of
      8 # the License, or (at your option) any later version.
      9 #
     10 # SETools is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Lesser General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Lesser General Public
     16 # License along with SETools.  If not, see
     17 # <http://www.gnu.org/licenses/>.
     18 #
     19 from collections import namedtuple
     20 
     21 from .descriptors import DiffResultDescriptor
     22 from .difference import Difference
     23 
     24 
     25 modified_properties_record = namedtuple("modified_property", ["property", "added", "removed"])
     26 
     27 
     28 class PropertiesDifference(Difference):
     29 
     30     """
     31     Determine the difference in policy properties
     32     (unknown permissions, MLS, etc.) between two policies.
     33     """
     34 
     35     modified_properties = DiffResultDescriptor("diff_properties")
     36 
     37     def diff_properties(self):
     38         self.modified_properties = []
     39 
     40         if self.left_policy.handle_unknown != self.right_policy.handle_unknown:
     41             self.modified_properties.append(
     42                 modified_properties_record("handle_unknown",
     43                                            self.right_policy.handle_unknown,
     44                                            self.left_policy.handle_unknown))
     45 
     46         if self.left_policy.mls != self.right_policy.mls:
     47             self.modified_properties.append(
     48                 modified_properties_record("MLS",
     49                                            self.right_policy.mls,
     50                                            self.left_policy.mls))
     51 
     52         if self.left_policy.version != self.right_policy.version:
     53             self.modified_properties.append(
     54                 modified_properties_record("version",
     55                                            self.right_policy.version,
     56                                            self.left_policy.version))
     57 
     58     #
     59     # Internal functions
     60     #
     61     def _reset_diff(self):
     62         """Reset diff results on policy changes."""
     63         self.log.debug("Resetting property differences")
     64         self.modified_properties = None
     65