3 O+e[: � @ s� d dl Z d dlZd dlmZ d dlZd dlmZmZ ddl m Z mZ ddlm Z ddlmZ dgZG d d� d�ZG d d� d�ZdS )� N)�suppress)� NetworkXError�NetworkXNoPath� )�EdgeAttrIntMax�EdgeAttrList)�RuleNotConditional)� TERuletype�InfoFlowAnalysisc @ s� e Zd ZdZd!dd�Zedd� �Zejdd� �Zed d � �Zejdd � �Zedd � �Z e jdd � �Z dd� Z d"dd�Zdd� Zd#dd�Z dd� Zdd� Zdd� Zdd � ZdS )$r zInformation flow analysis.r Nc C sJ t jt�| _|| _|| _|| _|| _|| _d| _ d| _ tj� | _ d| _dS )a� Parameters: policy The policy to analyze. perm_map The permission map or path to the permission map file. minweight The minimum permission weight to include in the analysis. (default is 1) exclude The types excluded from the information flow analysis. (default is none) booleans If None, all rules will be added to the analysis (default). otherwise it should be set to a dict with keys corresponding to boolean names and values of True/False. Any unspecified booleans will use the policy's default values. TN)�loggingZ getLogger�__name__�log�policy� min_weight�perm_map�exclude�booleans�rebuildgraph�rebuildsubgraph�nxZDiGraph�G�subG)�selfr r r r r � r � /usr/lib64/python3.6/infoflow.py�__init__% s zInfoFlowAnalysis.__init__c C s | j S )N)�_min_weight)r r r r r A s zInfoFlowAnalysis.min_weightc C s0 d| kodkn s t d��|| _d| _d S )Nr � z4Min information flow weight must be an integer 1-10.T)� ValueErrorr r )r �weightr r r r E s c C s | j S )N)� _perm_map)r r r r r N s zInfoFlowAnalysis.perm_mapc C s || _ d| _d| _d S )NT)r r r )r r r r r r R s c C s | j S )N)�_exclude)r r r r r X s zInfoFlowAnalysis.excludec s* |r� fdd�|D �� _ ng � _ d� _d S )Nc s g | ]}� j j|��qS r )r �lookup_type)�.0�t)r r r � <listcomp>_ s z,InfoFlowAnalysis.exclude.<locals>.<listcomp>T)r! r )r �typesr )r r r \ s c c sj | j j|�}| j j|�}| jr&| j� | jjdj||�� tt�� | j t j| j||��V W dQ R X dS )a Generator which yields one shortest path between the source and target types (there may be more). Parameters: source The source type. target The target type. Yield: generator(steps) steps Yield: tuple(source, target, rules) source The source type for this step of the information flow. target The target type for this step of the information flow. rules The list of rules creating this information flow step. z@Generating one shortest information flow path from {0} to {1}...N) r r"