3 Klf; @ s d Z ddlZddlZddljZyddlT W n Y nX ddlmZ ddlmZ ddlm Z ddlm Z dd lmZ dd lmZ dZ dZdZG dd d ZdefddZdd ZG dd dZdd ZdS )z> classes and algorithms for the generation of SELinux policy. N)* ) refpolicy)objectmodel)access) interfaces)matching)util c @ s e Zd ZdZdddZd ddZd!dd Zefd dZdd Z dd Z dd Zd"ddZdd Z dd Zdd Zdd Zdd ZdS )#PolicyGeneratora Generate a reference policy module from access vectors. PolicyGenerator generates a new reference policy module or updates an existing module based on requested access in the form of access vectors. It generates allow rules and optionally module require statements, reference policy interfaces, and extended permission access vector rules. By default only allow rules are generated. The methods .set_gen_refpol, .set_gen_requires and .set_gen_xperms turns on interface generation, requires generation, and xperms rules genration respectively. PolicyGenerator can also optionally add comments explaining why a particular access was allowed based on the audit messages that generated the access. The access vectors passed in must have the .audit_msgs field set correctly and .explain set to SHORT|LONG_EXPLANATION to enable this feature. The module created by PolicyGenerator can be passed to output.ModuleWriter to output a text representation. Nc C s> d| _ t| _d| _|r|| _n tj | _d| _d| _d| _ dS )zInitialize a PolicyGenerator with an optional existing module. If the module paramater is not None then access will be added to the passed in module. Otherwise a new reference policy module will be created. NF) ifgenNO_EXPLANATIONexplaingen_requiresmoduler ZModule dontauditxpermsdomains)selfr r /usr/lib/python3.6/policygen.py__init__E s zPolicyGenerator.__init__c C s* |rt ||| _d| _nd| _| j dS )a? Set whether reference policy interfaces are generated. To turn on interface generation pass in an interface set to use for interface generation. To turn off interface generation pass in None. If interface generation is enabled requires generation will also be enabled. TN)InterfaceGeneratorr r "_PolicyGenerator__set_module_style)r Zif_set perm_mapsr r r set_gen_refpolY s zPolicyGenerator.set_gen_refpolTc C s || _ dS )a& Set whether module requires are generated. Passing in true will turn on requires generation and False will disable generation. If requires generation is disabled interface generation will also be disabled and can only be re-enabled via .set_gen_refpol. N)r )r Zstatusr r r set_gen_requiresk s z PolicyGenerator.set_gen_requiresc C s || _ dS )z)Set whether access is explained. N)r )r r r r r set_gen_explainu s zPolicyGenerator.set_gen_explainc C s || _ d S )N)r )r r r r r set_gen_dontauditz s z!PolicyGenerator.set_gen_dontauditc C s || _ dS )zSSet whether extended permission access vector rules are generated. N)r )r r r r r set_gen_xperms} s zPolicyGenerator.set_gen_xpermsc C s. | j rd}nd}x| jj D ] }||_qW d S )NTF)r r module_declarationsr )r r modr r r Z__set_module_style s z"PolicyGenerator.__set_module_style1.0c C s\ d}x| j j D ]}|}qW |s8tj }| j jjd| ||_||_| jrRd|_nd|_dS )z?Set the name of the module and optionally the version. Nr TF) r r r ZModuleDeclarationchildreninsertnameversionr )r r% r&