/usr/lib/python3.9/site-packages/sepolgen/__pycache__
NameSizeModeActions
access.cpython-39.opt-1.pyc113610644editdlrm
access.cpython-39.pyc113610644editdlrm
audit.cpython-39.opt-1.pyc172600644editdlrm
audit.cpython-39.pyc172600644editdlrm
classperms.cpython-39.opt-1.pyc24710644editdlrm
classperms.cpython-39.pyc24710644editdlrm
defaults.cpython-39.opt-1.pyc22980644editdlrm
defaults.cpython-39.pyc22980644editdlrm
interfaces.cpython-39.opt-1.pyc125920644editdlrm
interfaces.cpython-39.pyc125920644editdlrm
lex.cpython-39.opt-1.pyc213770644editdlrm
lex.cpython-39.pyc213770644editdlrm
matching.cpython-39.opt-1.pyc61690644editdlrm
matching.cpython-39.pyc61690644editdlrm
module.cpython-39.opt-1.pyc71700644editdlrm
module.cpython-39.pyc71700644editdlrm
objectmodel.cpython-39.opt-1.pyc39710644editdlrm
objectmodel.cpython-39.pyc39710644editdlrm
output.cpython-39.opt-1.pyc35450644editdlrm
output.cpython-39.pyc35450644editdlrm
policygen.cpython-39.opt-1.pyc128870644editdlrm
policygen.cpython-39.pyc129200644editdlrm
refparser.cpython-39.opt-1.pyc292590644editdlrm
refparser.cpython-39.pyc292590644editdlrm
refpolicy.cpython-39.opt-1.pyc401730644editdlrm
refpolicy.cpython-39.pyc401730644editdlrm
sepolgeni18n.cpython-39.opt-1.pyc3940644editdlrm
sepolgeni18n.cpython-39.pyc3940644editdlrm
util.cpython-39.opt-1.pyc63640644editdlrm
util.cpython-39.pyc63640644editdlrm
yacc.cpython-39.opt-1.pyc531330644editdlrm
yacc.cpython-39.pyc532120644editdlrm
__init__.cpython-39.opt-1.pyc1440644editdlrm
__init__.cpython-39.pyc1440644editdlrm
Edit: /usr/lib/python3.9/site-packages/sepolgen/__pycache__/policygen.cpython-39.pyc (12920B)
a BÒi÷;ã@sÌdZddlZddlZddlmZz ddlTWn Yn0ddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dZ dZd ZGd d „d ƒZdefdd„Zdd„ZGdd„dƒZdd„ZdS)z> classes and algorithms for the generation of SELinux policy. éN)Ú*é)Ú refpolicy)Ú objectmodel)Úaccess)Ú interfaces)Úmatching)Úutiléc@s„eZdZdZddd„Zd dd„Zd!dd „Zefd d „Zd d „Z dd„Z dd„Z d"dd„Z dd„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. NcCs>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ÚmodulerZModuleÚ dontauditÚxpermsÚdomains)Úselfr©rú6/usr/lib/python3.9/site-packages/sepolgen/policygen.pyÚ__init__Es zPolicyGenerator.__init__cCs*|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)rZif_setÚ perm_mapsrrrÚset_gen_refpolYs  zPolicyGenerator.set_gen_refpolTcCs ||_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ÚstatusrrrÚset_gen_requiresksz PolicyGenerator.set_gen_requirescCs ||_dS)z)Set whether access is explained. N)r)rrrrrÚset_gen_explainuszPolicyGenerator.set_gen_explaincCs ||_dS©N)r)rrrrrÚset_gen_dontauditzsz!PolicyGenerator.set_gen_dontauditcCs ||_dS)zSSet whether extended permission access vector rules are generated. N)r)rrrrrÚset_gen_xperms}szPolicyGenerator.set_gen_xpermscCs*|jr d}nd}|j ¡D] }||_qdS)NTF)r rÚmodule_declarationsr)rrÚmodrrrZ__set_module_styleƒs z"PolicyGenerator.__set_module_styleú1.0cCsXd}|j ¡D]}|}q|s4t ¡}|jj d|¡||_||_|jrNd|_nd|_dS)z?Set the name of the module and optionally the version. NrTF) rr"rZModuleDeclarationÚchildrenÚinsertÚnameÚversionr )rr'r(Úmr#rrrÚset_module_name‹szPolicyGenerator.set_module_namecCs|jrt|jƒ|jSr)rr)rrrrÚ get_moduleœs zPolicyGenerator.get_modulec Csnt |¡}|jr|j|_d|_|jr>tt t ||jd�¡ƒ|_|j t j krl|jd7_|j rl|jd7_|j t jkr†|jd7_|j t jkrât|jƒdkrÆ|jdd d d „|jDƒ¡7_n|jd |jd d 7_|j t jk�rL|jd 7_|jd7_|jd|jd 7_|jdd…D]}|jd|7_�q2�z|j t jk�rLd|jv�rLd|jv�s‚d|jv�rL|j�s ttdd�d d|_g}dd „tt gt|jt|jt|jiƒDƒD]}||jv�rÌ| |¡�qÌt|ƒdk�r|jd|j|jd |¡f7_n0t|ƒdk�rL|jd|j|jd |¡f7_Wn Yn0|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 policyrzH #!!!! This avc can be allowed using one of the these booleans: # %sz, cSsg|] }|d‘qS)rr©Ú.0ÚxrrrÚ ºóz1PolicyGenerator.__add_av_rule..z5 #!!!! This avc can be allowed using the boolean '%s'rzŽ #!!!! 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'ÚtypescSsg|] }|t‘qSr)ZTCONTEXTr.rrrr1Ír2zL #!!!! 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 )!rZAVRulerZ DONTAUDITÚ rule_typeÚcommentrÚstrÚCommentÚexplain_accessÚtypeÚ audit2whyZALLOWrZBOOLEANÚlenÚdataÚjoinZ CONSTRAINTZTERULEÚpermsÚ obj_classrZseinfoZ ATTRIBUTEZsesearchZSCONTEXTÚsrc_typeZCLASSZPERMSÚappendrr%)rÚavZruleÚreasonr7ÚirrrZ __add_av_rule¤sV    &ÿþþ, $&zPolicyGenerator.__add_av_rulecCs<|j ¡D],}t ||¡}|jr(|j|_|jj  |¡q dS)z5Add extended permission access vector rules. N) rÚkeysrZ AVExtRulerZDONTAUDITXPERMr8rr%rE)rrFÚopZextrulerrrZ__add_ext_av_rulesÙs  z"PolicyGenerator.__add_ext_av_rulescCs\|jr*|j ||j¡\}}|jj |¡n|}|D]$}| |¡|jr2|jr2| |¡q2dS)zJAdd the access from the access vector set to this module. N) r Úgenrrr%ÚextendÚ_PolicyGenerator__add_av_rulerÚ"_PolicyGenerator__add_ext_av_rules)rZav_setZ raw_allowÚifcallsrFrrrÚ add_accessäs   zPolicyGenerator.add_accesscCs|D]}|jj |¡qdSr)rr%rE)rZ role_type_setÚ role_typerrrÚadd_role_typesùszPolicyGenerator.add_role_types)N)NN)T)r$)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrÚSHORT_EXPLANATIONrr r!rr*r+rMrNrPrRrrrrr -s    5 r c sg‰‡‡fdd„}|tkr´|jD]Š}ˆ d|j¡ˆ dt|jƒt|jƒf¡ˆ d|jt  |j ¡f¡ˆ d|j |j |j f¡ˆ tjd|jdd d d d �¡q |ƒnb|�rˆ d |j|j|j|j ¡f¡t|jƒdk�r|jd}ˆ d|j |j |j f¡|ƒˆS)aªExplain why a policy statement was generated. Return a string containing a text explanation of why a policy statement was generated. The string is commented and wrapped and can be directly inserted into a policy. Params: av - access vector representing the access. Should have .audit_msgs set appropriately. verbosity - the amount of explanation provided. Should be set to NO_EXPLANATION, SHORT_EXPLANATION, or LONG_EXPLANATION. Returns: list of strings - strings explaining the access or an empty string if verbosity=NO_EXPLANATION or there is not sufficient information to provide an explanation. csJˆsdSˆ d¡ˆ ¡D]*}t|jˆjƒ}ˆ d| ¡|jf¡qdS)Nz Interface options:z %s # [%d])rEÚallÚcall_interfaceÚ interfacerFZ to_stringZdist)ÚmatchÚifcall©ÚmlÚsrrÚexplain_interfacess   z*explain_access..explain_interfacesz %sz scontext="%s" tcontext="%s"z class="%s" perms="%s"z comm="%s" exe="%s" path="%s"z message="ú"éPz z )Úinitial_indentÚsubsequent_indentz) src="%s" tgt="%s" class="%s", perms="%s"rz comm="%s" exe="%s" path="%s")ÚLONG_EXPLANATIONZ audit_msgsrEÚheaderr:ZscontextZtcontextZtclassrZlist_to_space_strZaccessesZcommZexeÚpathrLÚtextwrapÚwrapÚmessagerDÚtgt_typerCrBZ to_space_strr?)rFr^r-r`Úmsgrr]rr<ýs2  ÿÿÿ ÿ r<cCsØg}g}| |j ¡¡|jdd„dd�t ¡}|j|_tt |ƒƒD]z}||j tj krj|j   |j¡qF||j tjkrŠ|j   |j¡qF||j tjkrª|j   |j¡qFt||j ƒdsFJ‚qFt |j ƒdksÔJ‚|S)NcSs|jSr©Únum©ZparamrrrÚ9r2z call_interface..T©ÚkeyÚreverser)rLÚparamsÚvaluesÚsortrZ InterfaceCallr'ZifnameÚranger?r=ÚSRC_TYPEÚargsrErDÚTGT_TYPErkÚ OBJ_CLASSrCÚprint)rZrFrtryr\rHrrrrY4s" rYc@s.eZdZd dd„Zdd„Zdd„Zdd „ZdS) rNcCs&||_| |¡t |¡|_g|_dSr)ÚifsÚhack_check_ifsrZ AccessMatcherÚmatcherÚcalls)rr}rrrrrNs  zInterfaceGenerator.__init__cCsŒ|j ¡D]|}g}| |j ¡¡|jdd„dd�tt|ƒƒD]D}|d||jkr`d|_q ||j t j t j t j fvr@d|_q q@q dS)NcSs|jSrrmrorrrrp\r2z3InterfaceGenerator.hack_check_ifs..TrqrF)rrurLrtrvrwr?rnZenabledr=rrxrzr{)rr}r0rtrHrrrr~Tsÿz!InterfaceGenerator.hack_check_ifsc Cs²| |¡}g}|jD]>}t| ¡j|jƒ}|rDt t|j||ƒ¡|_ |  ||f¡qg}|D]L\}}d} |D],} |   |¡rl| j r”|j r”| j   |j ¡d} ql| s\|  |¡q\||fS)NFT) r[r€rYZbestrZrFrr;r<r9rEÚmatchesÚmerge) rÚavsr-Úraw_avrOr^r\Údr}ÚfoundZo_ifcallrrrrKks$      zInterfaceGenerator.gencCsLg}|D]>}t ¡}|j |j||¡t|ƒr<|j |¡q| |¡q|Sr)rZ MatchListrZ search_ifsr}r?r€rE)rrƒr„rFZansrrrr[‚s zInterfaceGenerator.match)N)rSrTrUrr~rKr[rrrrrMs rcCs"dd„}| ¡D] }||ƒqdS)z*Add require statements to the module. cSsºt ¡}| ¡D]:}|j |j¡|j |j¡|jD]}| ||j ¡q6q|  ¡D]}|j D]}|j  |¡q^qT|  ¡D] }|j  |j¡|j |j¡qz|j d¡|j d|¡dS)Nrr)rZRequireZavrulesr7ÚupdateZ src_typesZ tgt_typesZ obj_classesZ add_obj_classrBZinterface_callsryÚaddZ role_typesZrolesZroleÚdiscardr%r&)ÚnodeÚrZavruleÚobjr\ÚargrQrrrÚcollect_requires’s      z&gen_requires..collect_requiresN)Znodes)rrŽrŠrrrr�s r)rVÚ itertoolsrhZselinux.audit2whyr>Zsetoolsr,rrrrrr r rWrer r<rYrrrrrrÚs,        Q7B