ó
â„^c        	   @   s±   d  Z  d d d d d d d d d	 g	 Z d
 Z d Z d Z e e BZ i e d 6e d 6e d 6e d 6Z i d e 6d e 6d e 6d e 6Z d d d „  ƒ  YZ d d d „  ƒ  YZ	 d S(   s¬   
This module provides knowledge object classes and permissions. It should
be used to keep this knowledge from leaking into the more generic parts of
the policy generation.
t   sockett   fdt   processt   filet   lnk_filet	   fifo_filet   dbust
   capabilityt   unix_stream_socketi    i   i   t   nt   rt   wt   bt   PermMapc           B   s    e  Z d  Z d „  Z d „  Z RS(   s  A mapping between a permission and its information flow properties.

    PermMap represents the information flow properties of a single permission
    including the direction (read, write, etc.) and an abstract representation
    of the bandwidth of the flow (weight).
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   permt   dirt   weight(   t   selfR   R   R   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   __init__T   s    		c         C   s   d |  j  t |  j |  j f S(   Ns'   <sepolgen.objectmodel.PermMap %s %s %d>(   R   t
   dir_to_strR   R   (   R   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   __repr__Y   s    	
(   t   __name__t
   __module__t   __doc__R   R   (    (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyR   M   s   	t   PermMappingsc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÛ   The information flow properties of a set of object classes and permissions.

    PermMappings maps one or more classes and permissions to their PermMap objects
    describing their information flow charecteristics.
    c         C   s   i  |  _  d |  _ t |  _ d  S(   Ni   (   t   classest   default_weightt	   FLOW_BOTHt   default_dir(   R   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyR   d   s    		c      	   C   s'  d
 } x| D]} | j ƒ  } t | ƒ d k s t | ƒ d k s | d d k rY q n  | d d k r® | d } | |  j k r‘ t d ƒ ‚ n  i  |  j | <|  j | } q t | ƒ d k rÏ t d ƒ ‚ n  | d
 k rê t d ƒ ‚ n  t | d t | d t | d	 ƒ ƒ } | | | j <q Wd
 S(   ss   Read the permission mappings from a file. This reads the format used
        by Apol in the setools suite.
        i    i   t   #t   classs   duplicate class in perm mapi   s"   error in object classs permissionss   permission outside of classi   N(	   t   Nonet   splitt   lenR   t
   ValueErrorR   t
   str_to_dirt   intR   (   R   R   t   curt   linet   fieldst   ct   pm(    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt	   from_filei   s"    	4
(c         C   s   |  j  | | S(   sÈ   Get the permission map for the object permission.

        Returns:
          PermMap representing the permission
        Raises:
          KeyError if the object or permission is not defined
        (   R   (   R   t   objR   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   get…   s    c         C   s@   y |  j  | | } Wn$ t k
 r; t | |  j |  j ƒ SX| S(   s  Get the permission map for the object permission or a default.

        getdefault is the same as get except that a default PermMap is
        returned if the object class or permission is not defined. The
        default is FLOW_BOTH with a weight of 5.
        (   R   t   KeyErrorR   R   R   (   R   R+   R   R)   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt
   getdefault   s
    c         C   s:   t  } x- | D]% } |  j | | ƒ } | | j B} q W| S(   N(   t	   FLOW_NONER.   R   (   R   R+   t   permsR   R   R)   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   getdefault_directionœ   s
    c         C   s:   d } x- | D]% } |  j  | | ƒ } | | j 7} q W| S(   Ni    (   R.   R   (   R   R+   R0   t   totalR   R)   (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   getdefault_distance£   s
    (	   R   R   R   R   R*   R,   R.   R1   R3   (    (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyR   ^   s   			
		N(    (    (
   R   t   implicitly_typed_objectsR/   t	   FLOW_READt
   FLOW_WRITER   R#   R   R   R   (    (    (    s:   /usr/lib64/python2.7/site-packages/sepolgen/objectmodel.pyt   <module>   s   
""