/usr/lib/python3.9/site-packages/sepolgen/__pycache__
Edit: /usr/lib/python3.9/site-packages/sepolgen/__pycache__/policygen.cpython-39.pyc (12920B)
a
BÒi÷; ã @ sÌ d Z ddlZddlZddlmZ zddlT W n Y n0 ddlmZ ddlmZ ddlm Z ddlm
Z
dd lmZ dd
lmZ dZ
dZdZG dd
„ d
ƒZdefdd„Zdd„ ZG dd„ dƒZdd„ ZdS )z>
classes and algorithms for the generation of SELinux policy.
é N)Ú*é )Ú refpolicy)Úobjectmodel)Úaccess)Ú
interfaces)Úmatching)Úutilé c @ s„ e Zd ZdZddd„Zd dd„Zd!dd „Zefd
d„Zdd
„ Z dd„ Z
dd„ Zd"dd„Zdd„ 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 generation 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
t ¡ | _d| _d| _d| _ dS )zøInitialize a PolicyGenerator with an optional
existing module.
If the module parameter is not None then access
will be added to the passed in module. Otherwise
a new reference policy module will be created.
NF)
ÚifgenÚNO_EXPLANATIONÚexplainÚgen_requiresÚmoduler ZModuleÚ dontauditÚxpermsÚdomains)Úselfr © r ú6/usr/lib/python3.9/site-packages/sepolgen/policygen.pyÚ__init__E s
zPolicyGenerator.__init__c C s* |rt ||ƒ| _d| _nd| _| ¡ 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 Ústatusr 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}| j ¡ D ]
}||_qd S )NTF)r r Úmodule_declarationsr )r r Úmodr r r Z__set_module_styleƒ s
z"PolicyGenerator.__set_module_styleú1.0c C sX d}| j ¡ D ]}|}q|s4t ¡ }| j j d|¡ ||_||_| jrNd|_nd|_dS )z?Set the name of the module and optionally the version.
Nr TF) r r" r ZModuleDeclarationÚchildrenÚinsertÚnameÚversionr )r r' r( Úmr# r r r Úset_module_name‹ s zPolicyGenerator.set_module_namec C s | j rt | jƒ | jS r )r r )r r r r Ú
get_moduleœ s
zPolicyGenerator.get_modulec C sn t |¡}| jr|j|_d|_| jr>tt t || jd�¡ƒ|_|j
tjkrl| jd7 _|j
rl| jd7 _|j
tjkr†| jd7 _|j
tjkrât|jƒdkrÆ| jdd d d
„ |jD ƒ¡ 7 _n| jd|jd d 7 _|j
tjk�rL| jd
7 _| jd7 _| jd|jd 7 _|jdd… D ]}| jd| 7 _�q2�z |j
tjk�rLd|jv �rLd|jv �s‚d|jv �rL| j�s ttdd�d d | _g }dd
„ ttgt|jt|jt|jiƒD ƒD ]}|| jv�rÌ| |¡ �qÌt|ƒdk�r| jd|j|jd |¡f 7 _n0t|ƒdk�rL| jd|j|jd |¡f 7 _W n Y n0 | jj |¡ dS )z Add access vector rule.
Ú )Ú verbosityz0
#!!!! This avc is allowed in the current policyzN
#!!!! This av rule may have been overridden by an extended permission av rulez:
#!!!! This avc has a dontaudit rule in the current policyr zH
#!!!! This avc can be allowed using one of the these booleans:
# %sz, c S s g | ]}|d ‘qS )r r ©Ú.0Úxr r r Ú
º ó z1PolicyGenerator.__add_av_rule..z5
#!!!! This avc can be allowed using the boolean '%s'r zŽ
#!!!! This avc is a constraint violation. You would need to modify the attributes of either the source or target types to allow this access.z
#Constraint rule: z
# Nz?
# Possible cause is the source %s and target %s are different.ÚwriteÚdirÚopenÚdomain)r' Útypesc S s g | ]}|t ‘qS r )ZTCONTEXTr. r r r r1 Í r2 zL
#!!!! The source type '%s' can write to a '%s' of the following type:
# %s
zM
#!!!! The source type '%s' can write to a '%s' of the following types:
# %s
)!r ZAVRuler Z DONTAUDITÚ rule_typeÚcommentr ÚstrÚCommentÚexplain_accessÚtypeÚ audit2whyZALLOWr ZBOOLEANÚlenÚdataÚjoinZ
CONSTRAINTZTERULEÚpermsÚ obj_classr ZseinfoZ ATTRIBUTEZsesearchZSCONTEXTÚsrc_typeZCLASSZPERMSÚappendr r% )r ÚavZruleÚreasonr7 Úir r r Z
__add_av_rule¤ sV
&ÿþþ,$&zPolicyGenerator.__add_av_rulec C s<