
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
Kl„fv  ã            	   @   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 )ÚPermMappingszÛ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 )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rŒtdƒ‚|dkrœt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 )zÈ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   Ú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   
