JFIF$        dd7 

Viewing File: /usr/lib64/python3.9/site-packages/setools/diff/__pycache__/constraints.cpython-39.opt-1.pyc

a

q�qe� �@s�ddlmZddlmZmZmZmZddlmZm	Z	m
Z
mZmZddl
mZddlmZmZmZddlmZdd	lmZGd
d�de�ZGdd
�d
ee�ZdS)�)�defaultdict)�	FrozenSet�List�Optional�Union�)�
AnyConstraint�ConstraintRuletype�Role�Type�User�)�DiffResultDescriptor)�
Difference�
SymbolWrapper�Wrapper)�class_wrapper_factory)�RuleListc@s�eZdZUdZed�Zed�Zed�Zed�Zed�Z	ed�Z
ed�Zed�ZdZ
eeefed<dZeeefed<dd	�d
d�Zdd	�dd
�Zdd	�dd�Zdd	�dd�Zdd	�dd�Zdd	�dd�ZdS)�ConstraintsDifferencea�
    Determine the difference in constraints between two policies.

    Since the compiler does not union constraints, there may be multiple
    constraints with the same ruletype, object class, and permission
    set, so constraints can only be added or removed, not modified.

    The constraint expressions are compared only on a basic level.
    Expressions that are logically equivalent but are structurally
    different, for example, by associativity, will be considered
    different.  Type and role attributes are also not expanded,
    so if there are changes to attribute members, it will not
    be reflected as a difference.
    �diff_constrains�diff_mlsconstrains�diff_validatetrans�diff_mlsvalidatetransN�_left_constraints�_right_constraints)�returncCsl|j�d�|��|jdus&|jdur.|��|�dd�|jtjD�dd�|jtjD��\|_	|_
}dS)zAGenerate the difference in constraint rules between the policies.zJGenerating constraint differences from {0.left_policy} to {0.right_policy}Ncss|]}t|�VqdS�N��ConstraintWrapper��.0�c�r"�>/usr/lib64/python3.9/site-packages/setools/diff/constraints.py�	<genexpr>?�z8ConstraintsDifference.diff_constrains.<locals>.<genexpr>css|]}t|�VqdSrrrr"r"r#r$@r%)�log�info�formatrr�_create_constrain_lists�	_set_diffr	Z	constrain�added_constrains�removed_constrains��self�_r"r"r#r2s
��z%ConstraintsDifference.diff_constrainscCsl|j�d�|��|jdus&|jdur.|��|�dd�|jtjD�dd�|jtjD��\|_	|_
}dS)zEGenerate the difference in MLS constraint rules between the policies.zNGenerating MLS constraint differences from {0.left_policy} to {0.right_policy}Ncss|]}t|�VqdSrrrr"r"r#r$Pr%z;ConstraintsDifference.diff_mlsconstrains.<locals>.<genexpr>css|]}t|�VqdSrrrr"r"r#r$Rr%)r&r'r(rrr)r*r	Zmlsconstrain�added_mlsconstrains�removed_mlsconstrainsr-r"r"r#rBs��
�
��z(ConstraintsDifference.diff_mlsconstrainscCsl|j�d�|��|jdus&|jdur.|��|�dd�|jtjD�dd�|jtjD��\|_	|_
}dS)zDGenerate the difference in validatetrans rules between the policies.zMGenerating validatetrans differences from {0.left_policy} to {0.right_policy}Ncss|]}t|�VqdSrrrr"r"r#r$cr%z;ConstraintsDifference.diff_validatetrans.<locals>.<genexpr>css|]}t|�VqdSrrrr"r"r#r$er%)r&r'r(rrr)r*r	Z
validatetrans�added_validatetrans�removed_validatetransr-r"r"r#rUs��
�
��z(ConstraintsDifference.diff_validatetranscCsl|j�d�|��|jdus&|jdur.|��|�dd�|jtjD�dd�|jtjD��\|_	|_
}dS)zHGenerate the difference in MLS validatetrans rules between the policies.zPGenerating mlsvalidatetrans differences from {0.left_policy} to {0.right_policy}Ncss|]}t|�VqdSrrrr"r"r#r$vr%z>ConstraintsDifference.diff_mlsvalidatetrans.<locals>.<genexpr>css|]}t|�VqdSrrrr"r"r#r$xr%)r&r'r(rrr)r*r	Zmlsvalidatetrans�added_mlsvalidatetrans�removed_mlsvalidatetransr-r"r"r#rhs��
�
��z+ConstraintsDifference.diff_mlsvalidatetranscCs�tt�|_|j�d�|��|j��D]}|j|j�	|�q&|j�
�D] \}}|j�d�t|�|��qHtt�|_|j�d�|��|j
��D]}|j|j�	|�q�|j�
�D] \}}|j�d�t|�|��q�|j�d�dS)z$Create rule lists for both policies.z.Building constraint lists from {0.left_policy}zLoaded {0} {1} rules.z/Building constraint lists from {0.right_policy}z)Completed building constraint rule lists.N)r�listrr&�debugr(Zleft_policy�constraints�ruletype�append�items�lenrZright_policy)r.�ruler9Zrulesr"r"r#r)~s

z-ConstraintsDifference._create_constrain_listscCsL|j�d�d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_dS)z%Reset diff results on policy changes.z%Resetting all constraints differencesN)r&r7r+r,r0r1r2r3r4r5rr�r.r"r"r#�_reset_diff�sz!ConstraintsDifference._reset_diff)�__name__�
__module__�__qualname__�__doc__rr+r,r0r1r2r3r4r5rrr	r�__annotations__rrrrrr)r?r"r"r"r#rs"
rc@s<eZdZdZdZedd�dd�Zdd�Zd	d
�Zdd�Z	dS)
rz#Wrap constraints for diff purposes.�r9�tclass�perms�exprN)r=rcCs�||_|j|_t|j�|_z|j|_Wnty>d|_Yn0t|�|_g|_|j	D]6}t
|t�r�|j�tdd�|D���qV|j�|�qVdS)Ncss|]}t|�VqdSr)r)r �itemr"r"r#r$�r%z-ConstraintWrapper.__init__.<locals>.<genexpr>)
�originr9rrFrG�AttributeError�hash�keyrHZ
expression�
isinstance�	frozensetr:)r.r=�opr"r"r#�__init__�s


zConstraintWrapper.__init__cCs|jSr�rMr>r"r"r#�__hash__�szConstraintWrapper.__hash__cCs|j|jkSrrR�r.�otherr"r"r#�__lt__�szConstraintWrapper.__lt__cCs0|j|jko.|j|jko.|j|jko.|j|jkSrrErTr"r"r#�__eq__�s
�
�
�zConstraintWrapper.__eq__)
r@rArBrC�	__slots__rrQrSrVrWr"r"r"r#r�srN)�collectionsr�typingrrrrZ	policyreprr	r
rrZdescriptorsr�
differencerrrZobjclassrrrrr"r"r"r#�<module>s
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!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