Home | History | Annotate | Download | only in policyrep
      1 # Copyright 2015-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 ..exception import SEToolsException
     20 
     21 #
     22 # Policyrep base exception
     23 #
     24 
     25 
     26 class PolicyrepException(SEToolsException):
     27 
     28     """Base class for all policyrep exceptions."""
     29     pass
     30 
     31 
     32 #
     33 # General Policyrep exceptions
     34 #
     35 
     36 
     37 class InvalidPolicy(SyntaxError, PolicyrepException):
     38 
     39     """Exception for invalid policy."""
     40     pass
     41 
     42 
     43 class MLSDisabled(PolicyrepException):
     44 
     45     """
     46     Exception when MLS is disabled.
     47     """
     48     pass
     49 
     50 
     51 #
     52 # Invalid component exceptions
     53 #
     54 class InvalidSymbol(ValueError, PolicyrepException):
     55 
     56     """
     57     Base class for invalid symbols.  Typically this is attempting to
     58     look up an object in the policy, but it does not exist.
     59     """
     60     pass
     61 
     62 
     63 class InvalidBoolean(InvalidSymbol):
     64 
     65     """Exception for invalid Booleans."""
     66     pass
     67 
     68 
     69 class InvalidCategory(InvalidSymbol):
     70 
     71     """Exception for invalid MLS categories."""
     72     pass
     73 
     74 
     75 class InvalidClass(InvalidSymbol):
     76 
     77     """Exception for invalid object classes."""
     78     pass
     79 
     80 
     81 class InvalidCommon(InvalidSymbol):
     82 
     83     """Exception for invalid common permission sets."""
     84     pass
     85 
     86 
     87 class InvalidInitialSid(InvalidSymbol):
     88 
     89     """Exception for invalid initial sids."""
     90     pass
     91 
     92 
     93 class InvalidLevel(InvalidSymbol):
     94 
     95     """
     96     Exception for an invalid level.
     97     """
     98     pass
     99 
    100 
    101 class InvalidLevelDecl(InvalidSymbol):
    102 
    103     """
    104     Exception for an invalid level declaration.
    105     """
    106     pass
    107 
    108 
    109 class InvalidRange(InvalidSymbol):
    110 
    111     """
    112     Exception for an invalid range.
    113     """
    114     pass
    115 
    116 
    117 class InvalidRole(InvalidSymbol):
    118 
    119     """Exception for invalid roles."""
    120     pass
    121 
    122 
    123 class InvalidSensitivity(InvalidSymbol):
    124 
    125     """
    126     Exception for an invalid sensitivity.
    127     """
    128     pass
    129 
    130 
    131 class InvalidType(InvalidSymbol):
    132 
    133     """Exception for invalid types and attributes."""
    134     pass
    135 
    136 
    137 class InvalidUser(InvalidSymbol):
    138 
    139     """Exception for invalid users."""
    140     pass
    141 
    142 #
    143 # Rule type exceptions
    144 #
    145 
    146 
    147 class InvalidRuleType(InvalidSymbol):
    148 
    149     """Exception for invalid rule types."""
    150     pass
    151 
    152 
    153 class InvalidBoundsType(InvalidSymbol):
    154 
    155     """Exception for invalid *bounds rule types."""
    156     pass
    157 
    158 
    159 class InvalidConstraintType(InvalidSymbol):
    160 
    161     """Exception for invalid constraint types."""
    162     pass
    163 
    164 
    165 class InvalidDefaultType(InvalidRuleType):
    166 
    167     """Exception for invalid default_* types."""
    168     pass
    169 
    170 
    171 class InvalidFSUseType(InvalidRuleType):
    172 
    173     """Exception for invalid fs_use_* types."""
    174     pass
    175 
    176 
    177 class InvalidMLSRuleType(InvalidRuleType):
    178 
    179     """Exception for invalid MLS rule types."""
    180     pass
    181 
    182 
    183 class InvalidRBACRuleType(InvalidRuleType):
    184 
    185     """Exception for invalid RBAC rule types."""
    186     pass
    187 
    188 
    189 class InvalidTERuleType(InvalidRuleType):
    190 
    191     """Exception for invalid TE rule types."""
    192     pass
    193 
    194 
    195 #
    196 # Object use errors
    197 #
    198 class SymbolUseError(AttributeError, PolicyrepException):
    199 
    200     """
    201     Base class for incorrectly using an object.  Typically this is
    202     for classes with strong similarities, but with slight variances in
    203     functionality, e.g. allow vs type_transition rules.
    204     """
    205     pass
    206 
    207 
    208 class RuleUseError(SymbolUseError):
    209 
    210     """
    211     Base class for incorrect parameters for a rule.  For
    212     example, trying to get the permissions of a rule that has no
    213     permissions.
    214     """
    215     pass
    216 
    217 
    218 class ConstraintUseError(SymbolUseError):
    219 
    220     """Exception when getting permissions from a validatetrans."""
    221     pass
    222 
    223 
    224 class NoStatement(SymbolUseError):
    225 
    226     """
    227     Exception for objects that have no inherent statement, such
    228     as conditional expressions and MLS ranges.
    229     """
    230     pass
    231 
    232 
    233 #
    234 # Default rule exceptions
    235 #
    236 class InvalidDefaultValue(InvalidSymbol):
    237 
    238     """Exception for invalid default (not source/target)"""
    239     pass
    240 
    241 
    242 class InvalidDefaultRange(InvalidSymbol):
    243 
    244     """Exception for invalid default range"""
    245     pass
    246 
    247 
    248 #
    249 # Other exceptions
    250 #
    251 class NoCommon(AttributeError, PolicyrepException):
    252 
    253     """
    254     Exception when a class does not inherit a common permission set.
    255     """
    256     pass
    257 
    258 
    259 class NoDefaults(InvalidSymbol):
    260 
    261     """Exception for classes that have no default_* statements."""
    262     pass
    263 
    264 
    265 class RuleNotConditional(AttributeError, PolicyrepException):
    266 
    267     """
    268     Exception when getting the conditional expression for rules
    269     that are unconditional (not conditional).
    270     """
    271     pass
    272 
    273 
    274 class TERuleNoFilename(AttributeError, PolicyrepException):
    275 
    276     """
    277     Exception when getting the file name of a
    278     type_transition rule that has no file name.
    279     """
    280     pass
    281