3 Kl�f�x � I @ s� d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z �dZ dddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdOdNdPdQ�4ZdRZdSZ dTZdUZdVZdWZdXZdYZdZZd[Zd\Zd]Zd^Zd_Zd`ZdaZdbZdcZddZdedf� Zdgdh� Z didj� Z!dkdl� Z"dmdn� Z#dodp� Z$dqdr� Z%dsdt� Z&dudv� Z'da(da)dwa*da+dxa,�d dydz�Z-d{d|� Z.d}d~� Z/dd�� Z0d�d�� Z1d�d�� Z2d�d�� Z3d�d�� Z4d�d�� Z5d�d�� Z6d�d�� Z7d�d�� Z8d�d�� Z9d�d�� Z:d�d�� Z;d�d�� Z<d�d�� Z=d�d�� Z>d�d�� Z?d�d�� Z@d�d�� ZAd�d�� ZBd�d�� ZCd�d�� ZDd�d�� ZEd�d�� ZFd�d�� ZGd�d�� ZHd�d�� ZId�d�� ZJd�d�� ZKd�d�� ZLd�d�� ZMd�d�� ZNd�d�� ZOd�d�� ZPd�d ZQd�dĄ ZRd�dƄ ZSd�dȄ ZTd�dʄ ZUd�d̄ ZVd�d΄ ZWd�dЄ ZXd�d҄ ZYd�dԄ ZZd�dք Z[d�d Z\d�dڄ Z]d�d܄ Z^d�dބ Z_d�d� Z`d�d� Zad�d� Zbd�d� Zcd�d� Zdd�d� Zed�d� Zfd�d� Zgd�d� Zhd�d� Zid�d� Zjd�d�� Zkd�d�� Zld�d�� Zmd�d�� Znd�d�� Zodapdaqd��d � Zr�d �d�d�Zs�d�d� Zt�d�d�d�ZudS ( � N� )�access)�defaults)�lex)� refpolicy)�yacc�TICK�SQUOTE�OBRACE�CBRACE�SEMI�COLON�OPAREN�CPAREN�COMMA�MINUS�TILDE�ASTERISK�AMP�BAR�EXPL�EQUAL�FILENAME� IDENTIFIER�NUMBER�PATH� IPV6_ADDR�MODULE� POLICY_MODULE�REQUIRE�SID�GENFSCON�FS_USE_XATTR�FS_USE_TRANS�FS_USE_TASK�PORTCON�NODECON�NETIFCON�PIRQCON�IOMEMCON� IOPORTCON�PCIDEVICECON� DEVICETREECON�CLASS� TYPEATTRIBUTE� ROLEATTRIBUTE�TYPE� ATTRIBUTE�ATTRIBUTE_ROLE�ALIAS� TYPEALIAS�BOOL�TRUE�FALSE�IF�ELSE�ROLE�TYPES�ALLOW� DONTAUDIT� AUDITALLOW� NEVERALLOW� PERMISSIVE� TYPEBOUNDS�TYPE_TRANSITION�TYPE_CHANGE�TYPE_MEMBER�RANGE_TRANSITION�ROLE_TRANSITION� OPT_POLICY� INTERFACE�TUNABLE_POLICY�GEN_REQ�TEMPLATE�GEN_CONTEXT�IFELSE�IFDEF�IFNDEF�DEFINE)4�moduleZ policy_moduleZrequireZsidZgenfscon�fs_use_xattr�fs_use_trans�fs_use_taskZportconZnodeconZnetifconZpirqconZiomemconZ ioportconZpcideviceconZ devicetreecon�classZ typeattributeZ roleattribute�typeZ attributeZattribute_role�aliasZ typealias�bool�trueZfalse�if�else�role�typesZallow� dontaudit� auditallow� neverallowZ permissiveZ typeboundsZtype_transition�type_change�type_memberZrange_transitionZrole_transitionZoptional_policy� interfaceZtunable_policyZgen_require�templateZgen_contextZifelseZifndef�ifdefZdefinez\`z\'z\{z\}z\;+z\:z\(z\)z\,z\-z\~z\*z\&z\|z\!z\=z[0-9\.]+z/[a-zA-Z0-9)_\.\*/\$]*z c C s | S )z2[a-fA-F0-9]{0,4}:[a-fA-F0-9]{0,4}:([a-fA-F0-9]|:)*� )�trf rf �/usr/lib/python3.6/refparser.py�t_IPV6_ADDR� s ri c C s | j jd7 _dS )zdnl.*\nr N)�lexer�lineno)rg rf rf rh �t_m4comment� s rl c C s | j d� dS )zdefine.*refpolicywarn\(.*\nr N)�skip)rg rf rf rh �t_refpolicywarn1� s rn c C s | j jd7 _dS )zrefpolicywarn\(.*\nr N)rj rk )rg rf rf rh �t_refpolicywarn� s ro c C s t j| jd�| _| S )z#[a-zA-Z_\$][a-zA-Z0-9_\-\+\.\$\*~]*r )�reserved�get�valuerV )rg rf rf rh �t_IDENTIFIER� s rs c C s t j| jd�| _| S )z\"[a-zA-Z0-9_\-\+\.\$\*~ :]+\"r )rp rq rr rV )rg rf rf rh � t_FILENAME s rt c C s | j jd7 _dS )z\#.*\nr N)rj rk )rg rf rf rh � t_comment s ru c C s t d| jd � | jd� d S )NzIllegal character '%s'r r )�printrr rm )rg rf rf rh �t_error s rw c C s | j jt| j�7 _dS )z\n+N)rj rk �lenrr )rg rf rf rh � t_newline s ry � Tc C sX | d krd S xF| D ]>}|d kr q||_ |d k rB|jjd||f� q|jjd|� qW d S )Nr )�parent�children�insert)Zstmtsr{ �val�srf rf rh �collect- s r� c C s8 x2| D ]*}t j|�r&|jt j|�� q|j|� qW d S )N)�sptZhas_key�updateZby_name�add)Zidsr �idrf rf rh �expand9 s r� c C sN t | �dkr&| d r&tjj| d � n$t | �dkrJ| d rJtjj| d � dS )z^statements : statement | statements statement | empty � r N)rx �mr| �append)�prf rf rh �p_statementsA s r� c C s | d | d<