Home | History | Annotate | Download | only in policyrep
      1 # Copyright 2014-2015, 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 . import qpol
     20 from . import symbol
     21 
     22 
     23 def polcap_factory(policy, name):
     24     """Factory function for creating policy capability objects."""
     25 
     26     if isinstance(name, PolicyCapability):
     27         assert name.policy == policy
     28         return name
     29     elif isinstance(name, qpol.qpol_polcap_t):
     30         return PolicyCapability(policy, name)
     31     else:
     32         raise TypeError("Policy capabilities cannot be looked up.")
     33 
     34 
     35 class PolicyCapability(symbol.PolicySymbol):
     36 
     37     """A policy capability."""
     38 
     39     def statement(self):
     40         return "policycap {0};".format(self)
     41