관리-도구
편집 파일: constraints.cpython-39.opt-1.pyc
a ����q�qe� ����������������������@���s����d�dl�mZ�d�dlmZmZmZmZ�ddlmZm Z m Z mZmZ�ddl mZ�ddlmZmZmZ�ddlmZ�dd lmZ�G�d d��de�ZG�dd ��d ee��ZdS�)�����)�defaultdict)� FrozenSet�List�Optional�Union����)� AnyConstraint�ConstraintRuletype�Role�Type�User����)�DiffResultDescriptor)� Difference� SymbolWrapper�Wrapper)�class_wrapper_factory)�RuleListc�������������������@���s����e�Zd�ZU�dZed�Zed�Zed�Zed�Zed�Z ed�Z ed�Zed�ZdZ eeef�ed<�dZeeef�ed<�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)�returnc�����������������C���sl���|�j��d�|����|�jdu�s&|�jdu�r.|�����|��dd��|�jtj�D��dd��|�jtj�D���\|�_ |�_ }dS�)zAGenerate the difference in constraint rules between the policies.zJGenerating constraint differences from {0.left_policy} to {0.right_policy}Nc�����������������s���s���|�]}t�|�V��qd�S��N��ConstraintWrapper��.0�c��r"����>/usr/lib64/python3.9/site-packages/setools/diff/constraints.py� <genexpr>?��������z8ConstraintsDifference.diff_constrains.<locals>.<genexpr>c�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���@���r%���)�log�info�formatr���r����_create_constrain_lists� _set_diffr ���Z constrain�added_constrains�removed_constrains��self�_r"���r"���r#���r���2���s���� ��z%ConstraintsDifference.diff_constrainsc�����������������C���sl���|�j��d�|����|�jdu�s&|�jdu�r.|�����|��dd��|�jtj�D��dd��|�jtj�D���\|�_ |�_ }dS�)zEGenerate the difference in MLS constraint rules between the policies.zNGenerating MLS constraint differences from {0.left_policy} to {0.right_policy}Nc�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���P���r%���z;ConstraintsDifference.diff_mlsconstrains.<locals>.<genexpr>c�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���R���r%���)r&���r'���r(���r���r���r)���r*���r ���Zmlsconstrain�added_mlsconstrains�removed_mlsconstrainsr-���r"���r"���r#���r���B���s������ � ��z(ConstraintsDifference.diff_mlsconstrainsc�����������������C���sl���|�j��d�|����|�jdu�s&|�jdu�r.|�����|��dd��|�jtj�D��dd��|�jtj�D���\|�_ |�_ }dS�)zDGenerate the difference in validatetrans rules between the policies.zMGenerating validatetrans differences from {0.left_policy} to {0.right_policy}Nc�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���c���r%���z;ConstraintsDifference.diff_validatetrans.<locals>.<genexpr>c�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���e���r%���)r&���r'���r(���r���r���r)���r*���r ���Z validatetrans�added_validatetrans�removed_validatetransr-���r"���r"���r#���r���U���s������ � ��z(ConstraintsDifference.diff_validatetransc�����������������C���sl���|�j��d�|����|�jdu�s&|�jdu�r.|�����|��dd��|�jtj�D��dd��|�jtj�D���\|�_ |�_ }dS�)zHGenerate the difference in MLS validatetrans rules between the policies.zPGenerating mlsvalidatetrans differences from {0.left_policy} to {0.right_policy}Nc�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���v���r%���z>ConstraintsDifference.diff_mlsvalidatetrans.<locals>.<genexpr>c�����������������s���s���|�]}t�|�V��qd�S�r���r���r���r"���r"���r#���r$���x���r%���)r&���r'���r(���r���r���r)���r*���r ���Zmlsvalidatetrans�added_mlsvalidatetrans�removed_mlsvalidatetransr-���r"���r"���r#���r���h���s������ � ��z+ConstraintsDifference.diff_mlsvalidatetransc�����������������C���s����t�t�|�_|�j�d�|����|�j���D�]}|�j|j�� |��q&|�j� ��D�] \}}|�j�d�t|�|���qHt�t�|�_|�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����listr���r&����debugr(���Zleft_policy�constraints�ruletype�append�items�lenr���Zright_policy)r.����ruler9���Zrulesr"���r"���r#���r)���~���s���� z-ConstraintsDifference._create_constrain_listsc�����������������C���sL���|�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&���r7���r+���r,���r0���r1���r2���r3���r4���r5���r���r����r.���r"���r"���r#����_reset_diff����s����z!ConstraintsDifference._reset_diff)�__name__� __module__�__qualname__�__doc__r���r+���r,���r0���r1���r2���r3���r4���r5���r���r���r ���r����__annotations__r���r���r���r���r���r)���r?���r"���r"���r"���r#���r������s"��� r���c�������������������@���s<���e�Zd�ZdZdZedd�dd�Zdd��Zd d ��Zdd��Z dS�) r���z#Wrap constraints for diff purposes.�r9����tclass�perms�exprN)r=���r���c�����������������C���s����||�_�|j|�_t|j�|�_z|j|�_W�n�ty>���d�|�_Y�n0�t|�|�_g�|�_|j D�]6}t |t�r�|�j�tdd��|D�����qV|�j�|��qVd�S�)Nc�����������������s���s���|�]}t�|�V��qd�S�r���)r���)r ����itemr"���r"���r#���r$�������r%���z-ConstraintWrapper.__init__.<locals>.<genexpr>) �originr9���r���rF���rG����AttributeError�hash�keyrH���Z expression� isinstance� frozensetr:���)r.���r=����opr"���r"���r#����__init__����s���� zConstraintWrapper.__init__c�����������������C���s���|�j�S�r����rM���r>���r"���r"���r#����__hash__����s����zConstraintWrapper.__hash__c�����������������C���s���|�j�|j�k�S�r���rR����r.����otherr"���r"���r#����__lt__����s����zConstraintWrapper.__lt__c�����������������C���s0���|�j�|j�ko.|�j|jko.|�j|jko.|�j|jkS�r���rE���rT���r"���r"���r#����__eq__����s���� � � �zConstraintWrapper.__eq__) r@���rA���rB���rC���� __slots__r���rQ���rS���rV���rW���r"���r"���r"���r#���r�������s���r���N)�collectionsr����typingr���r���r���r���Z policyrepr���r ���r ���r���r���Zdescriptorsr���� differencer���r���r���Zobjclassr���r���r���r���r"���r"���r"���r#����<module>���s����