PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` 3 Klf; @sdZddlZddlZddljZy ddlTWn YnXddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dZ dZd ZGd d d ZdefddZddZGdddZddZdS)z> classes and algorithms for the generation of SELinux policy. N)*) refpolicy) objectmodel)access) interfaces)matching)utilc@seZdZdZdddZd ddZd!dd Zefd d Zd d Z ddZ ddZ d"ddZ ddZ ddZddZddZddZdS)#PolicyGeneratoraGenerate 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. NcCs>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_EXPLANATIONexplain gen_requiresmodulerZModule dontauditxpermsdomains)selfrr/usr/lib/python3.6/policygen.py__init__Es zPolicyGenerator.__init__cCs*|rt|||_d|_nd|_|jdS)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_mapsrrrset_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)rZstatusrrrset_gen_requiresksz PolicyGenerator.set_gen_requirescCs ||_dS)z)Set whether access is explained. N)r)rrrrrset_gen_explainuszPolicyGenerator.set_gen_explaincCs ||_dS)N)r)rrrrrset_gen_dontauditzsz!PolicyGenerator.set_gen_dontauditcCs ||_dS)zSSet whether extended permission access vector rules are generated. N)r)rrrrrset_gen_xperms}szPolicyGenerator.set_gen_xpermscCs.|jr d}nd}x|jjD] }||_qWdS)NTF)r rmodule_declarationsr)rrmodrrrZ__set_module_styles z"PolicyGenerator.__set_module_style1.0cCs\d}x|jjD]}|}qW|s8tj}|jjjd|||_||_|jrRd|_nd|_dS)z?Set the name of the module and optionally the version. NrTF) rr rZModuleDeclarationchildreninsertnameversionr )rr%r&mr!rrrset_module_nameszPolicyGenerator.set_module_namecCs|jrt|j|jS)N)rr)rrrr get_modules zPolicyGenerator.get_modulecCsvtj|}|jr|j|_d|_|jr>ttjt ||jd|_|j t j krl|jd7_|j rl|jd7_|j t jkr|jd7_|j t jkrt|jdkr|jddjd d |jD7_n|jd |jd d 7_|j t jkrP|jd 7_|jd7_|jd|jd 7_x*|jddD]}|jd|7_q4Wy|j t jkrTd|jkrTd|jksd|jkrT|jsttddd d|_g}xHdd tt gt|jt|jt|jiDD]}||jkr|j|qWt|dkr$|jd|j|jdj|f7_n0t|dkrT|jd|j|jdj|f7_Wn YnX|jj j|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|] }|dqS)rr).0xrrr sz1PolicyGenerator.__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.writediropenZdomain)r%typescSsg|] }|tqSr)ZTCONTEXT)r,r-rrrr.szL #!!!! 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_typecommentrstrCommentexplain_accesstype audit2whyZALLOWrZBOOLEANlendatajoinZ CONSTRAINTZTERULEperms obj_classrZseinfoZ ATTRIBUTEZsesearchZSCONTEXTsrc_typeZCLASSZPERMSappendrr#)ravZrulereasonr2irrrZ __add_av_rulesN    & . $&zPolicyGenerator.__add_av_rulecCs@x:|jjD],}tj||}|jr*|j|_|jjj |q WdS)z5Add extended permission access vector rules. N) rkeysrZ AVExtRulerZDONTAUDITXPERMr3rr#r@)rrAopZextrulerrrZ__add_ext_av_ruless  z"PolicyGenerator.__add_ext_av_rulescCs`|jr*|jj||j\}}|jjj|n|}x,|D]$}|j||jr4|jr4|j|q4WdS)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_allowifcallsrArrr add_accesss    zPolicyGenerator.add_accesscCs x|D]}|jjj|qWdS)N)rr#r@)rZ role_type_set role_typerrradd_role_typess zPolicyGenerator.add_role_types)N)NN)T)r")__name__ __module__ __qualname____doc__rrrSHORT_EXPLANATIONrrrrr(r)rHrIrKrMrrrrr -s    5 r csgfdd}|tkrx|jD]}jd|jjdt|jt|jfjd|jtj |j fjd|j |j |j fjtjd|jdd d d d q"W|nb|rjd |j|j|j|jjft|jdkr|jd}jd|j |j |j f|S)aExplain 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. csNsdSjdx6jD]*}t|jj}jd|j|jfqWdS)Nz Interface options:z %s # [%d])r@allcall_interface interfacerAZ to_stringZdist)matchifcall)mlsrrexplain_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 )Zinitial_indentZsubsequent_indentz) src="%s" tgt="%s" class="%s", perms="%s"rz comm="%s" exe="%s" path="%s")LONG_EXPLANATIONZ audit_msgsr@headerr5ZscontextZtcontextZtclassrZlist_to_space_strZaccessesZcommZexepathrGtextwrapZwrapmessager?tgt_typer>r=Z to_space_strr:)rArXr+rZmsgr)rXrYrr7s*   r7cCsg}g}|j|jj|jddddtj}|j|_xtt |D]z}||j tj krl|j j |jqH||j tjkr|j j |jqH||j tjkr|j j |jqHt||j dsHtqHWt |j dkst|S)NcSs|jS)N)num)paramrrr9sz call_interface..T)keyreverser)rGparamsvaluessortrZ InterfaceCallr%Zifnameranger:r8SRC_TYPEargsr@r?TGT_TYPErb OBJ_CLASSr>printAssertionError)rUrArirnrWrCrrrrT4s" rTc@s.eZdZd ddZddZddZdd ZdS) rNcCs&||_|j|tj||_g|_dS)N)ifshack_check_ifsrZ AccessMatchermatchercalls)rrsrrrrrNs  zInterfaceGenerator.__init__cCsx|jjD]|}g}|j|jj|jddddxPtt|D]@}|d||jkrbd|_P||j t j t j t j gkrDd|_PqDWq WdS)NcSs|jS)N)rd)rerrrrf\sz3InterfaceGenerator.hack_check_ifs..T)rgrhrF)rrjrGrirkrlr:rdZenabledr8rrmrorp)rrsr-rirCrrrrtTs z!InterfaceGenerator.hack_check_ifsc Cs|j|}g}xH|jD]>}t|jj|j}|rFtjt|j|||_ |j ||fqWg}xX|D]P\}}d} x4|D],} | j |rt| j r|j r| j j |j d} qtW| sb|j |qbW||fS)NFT) rVrvrTZbestrUrArr6r7r4r@Zmatchesmerge) ravsr+raw_avrJrXrWdrsfoundZo_ifcallrrrrFks$     zInterfaceGenerator.gencCsPg}xF|D]>}tj}|jj|j||t|r>|jj|q |j|q W|S)N)rZ MatchListruZ search_ifsrsr:rvr@)rrxryrAZansrrrrVs zInterfaceGenerator.match)N)rNrOrPrrtrFrVrrrrrMs rcCs&dd}x|jD] }||qWdS)z*Add require statements to the module. cSstj}xJ|jD]>}|jj|j|jj|jx|jD]}|j||j q:WqWx,|j D] }x|j D]}|jj |qjWq^Wx,|j D] }|jj |j|jj|jqW|jjd|jjd|dS)Nrr)rZRequireZavrulesr2updateZ src_typesZ tgt_typesZ obj_classesZ add_obj_classr=Zinterface_callsrnaddZ role_typesZrolesZrolediscardr#r$)noderZavruleobjrWargrLrrrcollect_requiress   z&gen_requires..collect_requiresN)Znodes)rrrrrrrsr)rQ itertoolsr`Zselinux.audit2whyr9Zsetoolsr*rrrrrr r rRr]r r7rTrrrrrrs,        Q7B