
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
Klfv              	   @   sp   d Z ddddddddd	g	Zd
ZdZdZeeB ZeeeedZedededediZG dd dZG dd dZ	dS )z
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.
ZsocketfdZprocessfileZlnk_fileZ	fifo_fileZdbusZ
capabilityZunix_stream_socket          )nrwbr   r   r   r	   c               @   s    e Zd ZdZdd Zdd ZdS )PermMapa  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)permdirweight)selfr   r   r    r   !/usr/lib/python3.6/objectmodel.py__init__T   s    zPermMap.__init__c             C   s   d| j t| j | jf S )Nz'<sepolgen.objectmodel.PermMap %s %s %d>)r   
dir_to_strr   r   )r   r   r   r   __repr__Y   s    zPermMap.__repr__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r
   M   s   r
   c               @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )PermMappingszThe 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 )N   )classesdefault_weight	FLOW_BOTHdefault_dir)r   r   r   r   r   d   s    zPermMappings.__init__c             C   s   d}x|D ]}|j  }t|dks
t|dks
|d dkr<q
|d dkrx|d }|| jkrbtdi | j|< | j| }q
t|dkrtd|dkrtd	t|d t|d  t|d
 }|||j< q
W dS )zsRead the permission mappings from a file. This reads the format used
        by Apol in the setools suite.
        Nr   r   #classzduplicate class in perm map   z"error in object classs permissionszpermission outside of classr   )splitlenr   
ValueErrorr
   
str_to_dirintr   )r   r   ZcurlineZfieldscpmr   r   r   	from_filei   s"    	
$

 zPermMappings.from_filec             C   s   | j | | S )zGet the permission map for the object permission.

        Returns:
          PermMap representing the permission
        Raises:
          KeyError if the object or permission is not defined
        )r   )r   objr   r   r   r   get   s    zPermMappings.getc             C   s8   y| j | | }W n  tk
r2   t|| j| jS X |S )a  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   KeyErrorr
   r   r   )r   r*   r   r(   r   r   r   
getdefault   s
    zPermMappings.getdefaultc             C   s,   t }x"|D ]}| j||}||jB }q
W |S )N)	FLOW_NONEr-   r   )r   r*   permsr   r   r(   r   r   r   getdefault_direction   s
    
z!PermMappings.getdefault_directionc             C   s,   d}x"|D ]}| j ||}||j7 }q
W |S )Nr   )r-   r   )r   r*   r/   Ztotalr   r(   r   r   r   getdefault_distance   s
    
z PermMappings.getdefault_distanceN)
r   r   r   r   r   r)   r+   r-   r0   r1   r   r   r   r   r   ^   s   
r   N)
r   Zimplicitly_typed_objectsr.   Z	FLOW_READZ
FLOW_WRITEr   r$   r   r
   r   r   r   r   r   <module>   s   
