Home | History | Annotate | Download | only in policyrep
      1 # Copyright 2014, 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 exception
     20 from . import qpol
     21 from . import symbol
     22 from . import context
     23 
     24 
     25 def initialsid_factory(policy, name):
     26     """Factory function for creating initial sid objects."""
     27 
     28     if isinstance(name, InitialSID):
     29         assert name.policy == policy
     30         return name
     31     elif isinstance(name, qpol.qpol_isid_t):
     32         return InitialSID(policy, name)
     33 
     34     try:
     35         return InitialSID(policy, qpol.qpol_isid_t(policy, name))
     36     except ValueError:
     37         raise exception.InvalidInitialSid("{0} is not a valid initial sid".format(name))
     38 
     39 
     40 class InitialSID(symbol.PolicySymbol):
     41 
     42     """An initial SID statement."""
     43 
     44     @property
     45     def context(self):
     46         """The context for this initial SID."""
     47         return context.context_factory(self.policy, self.qpol_symbol.context(self.policy))
     48 
     49     def statement(self):
     50         return "sid {0} {0.context}".format(self)
     51