509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
í«„^l$  ã               @   s‚   d dl Z d dlZddlmZmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZmZmZ G dd	„ d	ejejejƒZdS )
é    Né   )ÚmixinsÚquery)ÚCriteriaDescriptorÚCriteriaSetDescriptor)ÚRuleUseErrorÚRuleNotConditional)ÚIoctlSetÚ
TERuletype)Úmatch_regexÚmatch_indirect_regexÚmatch_regex_or_setc                   s˜   e Zd ZdZeed�ZeddƒZdZ	dZ
eddƒZdZdZeddƒZdZed	d
ƒZdZdZdZdZedd„ ƒZejdd„ ƒZ‡ fdd„Zdd„ Z‡  ZS )ÚTERuleQueryae
  
    Query the Type Enforcement 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 type/attribute to match.
    source_indirect   If true, members of an attribute will be
                      matched rather than the attribute itself.
                      Default is true.
    source_regex      If true, regular expression matching will
                      be used on the source type/attribute.
                      Obeys the source_indirect option.
                      Default is false.
    target            The name of the target type/attribute to match.
    target_indirect   If true, members of an attribute will be
                      matched rather than the attribute itself.
                      Default is true.
    target_regex      If true, regular expression matching will
                      be used on the target type/attribute.
                      Obeys target_indirect option.
                      Default is false.
    tclass            The object class(es) to match.
    tclass_regex      If true, use a regular expression for
                      matching the rule's object class.
                      Default is false.
    perms             The set of permission(s) to match.
    perms_equal       If true, the permission set of the rule
                      must exactly match the permissions
                      criteria.  If false, any set intersection
                      will match.
                      Default is false.
    perms_regex       If true, regular expression matching will be used
                      on the permission names instead of set logic.
                      Default is false.
    perms_subset      If true, the rule matches if the permissions criteria
                      is a subset of the rule's permission set.
                      Default is false.
    default           The name of the default type to match.
    default_regex     If true, regular expression matching will be
                      used on the default type.
                      Default is false.
    boolean           The set of boolean(s) to match.
    boolean_regex     If true, regular expression matching will be
                      used on the booleans.
                      Default is false.
    boolean_equal     If true, the booleans in the conditional
                      expression of the rule must exactly match the
                      criteria.  If false, any set intersection
                      will match.  Default is false.
    )Ú
enum_classÚsource_regexZlookup_type_or_attrFTÚtarget_regexÚdefault_regexÚboolean_regexZlookup_booleanNc             C   s   | j S )N)Ú_xperms)Úself© r   ú#/usr/lib64/python3.6/terulequery.pyÚxpermsd   s    zTERuleQuery.xpermsc             C   s®   |r¤t ƒ }xŒ|D ]„\}}d|  ko*dkn  s>tdj|ƒƒ‚d|  koPdkn  sdtdj|ƒƒ‚||k rv|| }}|jdd„ t||d ƒD ƒƒ qW t|ƒ| _nd | _d S )Nr   iÿÿ  z{0:#07x} is not a valid ioctl.c             s   s   | ]
}|V  qd S )Nr   )Ú.0Úir   r   r   ú	<genexpr>w   s    z%TERuleQuery.xperms.<locals>.<genexpr>r   )ÚsetÚ
ValueErrorÚformatÚupdateÚranger	   r   )r   ÚvalueZpending_xpermsZlowZhighr   r   r   r   h   s    
"c                s$   t t| ƒj|f|Ž tjtƒ| _d S )N)Úsuperr   Ú__init__ÚloggingZ	getLoggerÚ__name__Úlog)r   ÚpolicyÚkwargs)Ú	__class__r   r   r#   }   s    zTERuleQuery.__init__c          $   c   sB  | j jdj| ƒƒ | j jdj| ƒƒ | j jdj| ƒƒ | j jdj| ƒƒ | j| j ƒ | j| j ƒ | j jdj| ƒƒ | j jdj| ƒƒ | j jdj| ƒƒ �x¤| jjƒ D �]”}| jr¾|j| jkr¾q¤| j	rÞt
|j	| j	| j| jƒ rÞq¤| jrþt
|j| j| j| jƒ rþq¤| j|ƒ�sq¤yN| j�rJ|j�rJ| j�r8t| jƒdk�r8w¤|j| jk�rXw¤n| j|ƒ�sXw¤W n tk
�rr   w¤Y nX y&| j�r˜t|j| j| jd	ƒ �r˜w¤W n tk
�r²   w¤Y nX | j�ròyt
|j| jd
| jƒ�sÖw¤W n tk
�rð   w¤Y nX | j�r4y t|jj| j| j | j!ƒ�sw¤W n t"k
�r2   w¤Y nX |V  q¤W dS )z-Generator which yields all matching TE rules.z*Generating TE rule results from {0.policy}zRuletypes: {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}z*Xperms: {0.xperms!r}, eq: {0.xperms_equal}z0Default: {0.default!r}, regex: {0.default_regex}zGBoolean: {0.boolean!r}, eq: {0.boolean_equal}, regex: {0.boolean_regex}r   FTN)#r&   Úinfor   ÚdebugZ_match_object_class_debugZ_match_perms_debugr'   ZterulesÚruletypeÚsourcer   Úsource_indirectr   ÚtargetÚtarget_indirectr   Z_match_object_classZpermsZextendedZperms_equalÚlenZ
xperm_typeZ_match_permsr   r   r   Úxperms_equalÚdefaultr   ÚbooleanZconditionalZbooleansÚboolean_equalr   r   )r   Zruler   r   r   Úresults�   sŒ    








zTERuleQuery.results)r%   Ú
__module__Ú__qualname__Ú__doc__r   r
   r,   r   r-   r   r.   r/   r   r0   r3   r   r4   r   r5   r   r2   Úpropertyr   Úsetterr#   r6   Ú__classcell__r   r   )r)   r   r      s&   6




r   )r$   ÚreÚ r   r   Zdescriptorsr   r   Z	exceptionr   r   Z	policyrepr	   r
   Úutilr   r   r   ZMatchObjClassZMatchPermissionZPolicyQueryr   r   r   r   r   Ú<module>   s   