name : rbacrules.cpython-39.opt-1.pyc
a

q�qe��@s�ddlmZddlmZddlmZmZmZmZm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZdd
lmZddlmZGdd
�d
e�ZGdd�de
�ZGdd�dee�ZGdd�dee	�ZdS)�)�defaultdict)�
NamedTuple�)�AnyRBACRule�RBACRuletype�Role�	RoleAllow�RoleTransition�)�DiffResultDescriptor)�
Difference�Wrapper)�class_wrapper_factory)�role_wrapper_factory)�type_or_attr_wrapper_factory)�RuleListc@s*eZdZUdZeed<eed<eed<dS)�ModifiedRBACRulez,Difference details for a modified RBAC rule.�ruleZ
added_defaultZremoved_defaultN)�__name__�
__module__�__qualname__�__doc__r�__annotations__r�rr�</usr/lib64/python3.9/site-packages/setools/diff/rbacrules.pyrs
rc@s�eZdZUdZed�Zed�Zed�Zed�Zed�Z	dZ
eee
fed<dZeee
fed<dd�dd	�Zdd�d
d�Zdd�dd
�Zdd�dd�ZdS)�RBACRulesDifferencez<Determine the difference in RBAC rules between two policies.�diff_role_allows�diff_role_transitionsN�_left_rbac_rules�_right_rbac_rules)�returncCsh|j�d�|��|jdus&|jdur.|��|�|�|jtj	t
�|�|jtj	t
��\|_|_}dS)zAGenerate the difference in role allow rules between the policies.zJGenerating role allow differences from {0.left_policy} to {0.right_policy}N)
�log�info�formatrr�_create_rbac_rule_lists�	_set_diff�_expand_generatorrZallow�RoleAllowWrapper�added_role_allows�removed_role_allows)�self�_rrrr,s���z$RBACRulesDifference.diff_role_allowscCs�|j�d�|��|jdus&|jdur.|��|�|�|jtj	t
�|�|jtj	t
��\}}}g}|D]2\}}t|j�t|j�krh|�
t||j|j��qh||_||_||_dS)zFGenerate the difference in role_transition rules between the policies.zOGenerating role_transition differences from {0.left_policy} to {0.right_policy}N)r!r"r#rrr$r%r&rZrole_transition�RoleTransitionWrapperr�default�appendr�added_role_transitions�removed_role_transitions�modified_role_transitions)r*ZaddedZremovedZmatchedZmodifiedZ	left_ruleZ
right_rulerrrr=s2�����
�z)RBACRulesDifference.diff_role_transitionscCs�tt�|_|j�d�|��|j��D]}|j|j�	|�q&tt�|_
|j�d�|��|j��D]}|j
|j�	|�qd|j�d�dS)z$Create rule lists for both policies.z-Building RBAC rule lists from {0.left_policy}z.Building RBAC rule lists from {0.right_policy}z#Completed building RBAC rule lists.N)r�listrr!�debugr#Zleft_policyZ	rbacrulesZruletyper.rZright_policy�r*rrrrr$`s

z+RBACRulesDifference._create_rbac_rule_listscCs:|j�d�d|_d|_d|_d|_d|_d|_d|_dS)z%Reset diff results on policy changes.zResetting RBAC rule differencesN)	r!r3r(r)r/r0r1rr�r*rrr�_reset_diffpszRBACRulesDifference._reset_diff)rrrrrr(r)r/r0r1rrrrrrrrr$r6rrrrrs
#rc@s<eZdZdZdZedd�dd�Zdd�Zd	d
�Zdd�Z	dS)
r'z.Wrap role allow rules to allow set operations.��source�targetN�rr cCs,||_t|j�|_t|j�|_t|�|_dS�N)�originrr8r9�hash�keyr4rrr�__init__�szRoleAllowWrapper.__init__cCs|jSr;�r>r5rrr�__hash__�szRoleAllowWrapper.__hash__cCs|j|jkSr;r@�r*�otherrrr�__lt__�szRoleAllowWrapper.__lt__cCs|j|jko|j|jkSr;r7rBrrr�__eq__�szRoleAllowWrapper.__eq__)
rrrr�	__slots__rr?rArDrErrrrr'~sr'c@s<eZdZdZdZedd�dd�Zdd�Zd	d
�Zdd�Z	dS)
r,z3Wrap role_transition rules to allow set operations.�r8r9�tclassNr:cCs8||_t|j�|_t|j�|_t|j�|_t|�|_dSr;)	r<rr8rr9rrHr=r>r4rrrr?�s
zRoleTransitionWrapper.__init__cCs|jSr;r@r5rrrrA�szRoleTransitionWrapper.__hash__cCs|j|jkSr;r@rBrrrrD�szRoleTransitionWrapper.__lt__cCs$|j|jko"|j|jko"|j|jkSr;rGrBrrrrE�s

�
�zRoleTransitionWrapper.__eq__)
rrrrrFr	r?rArDrErrrrr,�sr,N)�collectionsr�typingrZ	policyreprrrrr	Zdescriptorsr�
differencerr
ZobjclassrZrolesr�typesrrrrr'r,rrrr�<module>s	b

© 2025 Cubjrnet7