3 ^t @ sr d dl Z d dlZddlmZmZ ddlmZmZ ddlm Z m Z ddlmZ ddl mZ G dd d ejejZdS ) N )mixinsquery)CriteriaDescriptorCriteriaSetDescriptor)InvalidTypeRuleUseError)RBACRuletype)match_indirect_regexc s e Zd ZdZeedZeddZdZ dZ dZdZdZ edd ZdZed dZdZedd Zejd d Z fddZdd Z ZS ) RBACRuleQuerya Query the RBAC rules. Parameter: policy The policy to query. Keyword Parameters/Class attributes: ruletype The list of rule type(s) to match. source The name of the source role/attribute to match. source_indirect If true, members of an attribute will be matched rather than the attribute itself. source_regex If true, regular expression matching will be used on the source role/attribute. Obeys the source_indirect option. target The name of the target role/attribute to match. target_indirect If true, members of an attribute will be matched rather than the attribute itself. target_regex If true, regular expression matching will be used on the target role/attribute. Obeys target_indirect option. tclass The object class(es) to match. tclass_regex If true, use a regular expression for matching the rule's object class. default The name of the default role to match. default_regex If true, regular expression matching will be used on the default role. ) enum_classsource_regexlookup_roleFTNtclass_regexZlookup_class default_regexc C s | j S )N)_target)self r %/usr/lib64/python3.6/rbacrulequery.pytargetG s zRBACRuleQuery.targetc C sZ |sd | _ nJ| jr tj|| _ n6y| jj|| _ W n" tk rT | jj|| _ Y nX d S )N)r target_regexrecompilepolicyZlookup_type_or_attrr r )r valuer r r r K s c s$ t t| j|f| tjt| _d S )N)superr __init__loggingZ getLogger__name__log)r r kwargs) __class__r r r W s zRBACRuleQuery.__init__c c s> | j jdj| | j jdj| | j jdj| | j jdj| | j| j | j jdj| x| jj D ]}| jr|j| jkrqr| jrt |j| j| j | j rqr| jrt |j| j| j | j rqry| j|swrW n tk r wrY nX | jr0yt |j| jd| jswrW n tk r. wrY nX |V qrW dS )z/Generator which yields all matching RBAC rules.z,Generating RBAC rule results from {0.policy}zRuletypes: {0.ruletype}zLSource: {0.source!r}, indirect: {0.source_indirect}, regex: {0.source_regex}zLTarget: {0.target!r}, indirect: {0.target_indirect}, regex: {0.target_regex}z0Default: {0.default!r}, regex: {0.default_regex}TN)r infoformatdebugZ_match_object_class_debugr Z rbacrulesruletypesourcer source_indirectr r target_indirectr Z_match_object_classr defaultr )r Zruler r r results[ sP zRBACRuleQuery.results)r __module____qualname____doc__r r r% r r&