ó â„^c@s…dZddlZddlmZddlmZddlmZdejfd„ƒYZd d d „ƒYZd dd „ƒYZ dS(sI Classes and algorithms for matching requested access to access vectors. iÿÿÿÿNi(taccess(t objectmodel(tutiltMatchcBs eZddd„Zd„ZRS(icCs(||_||_t|_d|_dS(N(t interfacetdisttFalsetinfo_dir_changetNonet__hash__(tselfRR((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt__init__ s   cCsTy5|j|jf}|j|jf}|||ƒSWnttfk rOtSXdS(N(RRtAttributeErrort TypeErrortNotImplemented(R tothertmethodtatb((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt_compare(s N(t__name__t __module__RR R(((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyRst MatchListcBsMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(i–cCs4g|_g|_|j|_t|_d|_dS(N(tchildrentbastardstDEFAULT_THRESHOLDt thresholdRtallow_info_dir_changeRtav(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR 3s     cCs8t|jƒr|jdSt|jƒr4|jdSdS(Ni(tlenRRR(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pytbest<s   cCst|jƒt|jƒS(N(RRR(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt__len__CscCs t|jƒS(N(titerR(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt__iter__IscCstj|j|jƒS(N(t itertoolstchainRR(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pytallLscCs_|j|jkrK|j s%|jr8|jj|ƒq[|jj|ƒn|jj|ƒdS(N(RRRRRtappendR(R tmatch((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR%Os cCs|jjƒ|jjƒdS(N(RtsortR(R ((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR'Xs ( RRRR RRR!R$R%R'(((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR1s     t AccessMatchercBsAeZdd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs@d|_d|_|r$||_ntjƒ|_d|_dS(Ni id(t type_penaltyt obj_penaltyt perm_mapsRt PermMappingstinfo_dir_penalty(R R+((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR ^s    cCs+||kstj|ƒrdS|j SdS(Ni(Rt is_idparamR)(R RR((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt type_distancejscCss|jj|jƒ}t|ƒdkrD|jj|j|ƒ}| S|jj|jƒ}|jj|j|ƒSdS(Ni(tpermst differenceRR+tgetdefault_distancet obj_class(R tav_reqtav_provtdiffttotal((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt perm_distanceqs cCs d}||j|j|jƒ7}||j|j|jƒ7}|j|jkrstj|jƒ rs||j8}n|dkr|jj|j|j ƒ}n|j ||ƒ}|dkrÚ|dkrÏ||S||Sn+|dkr|dkrú||S||SndS(s+Determine the 'distance' between 2 access vectors. This function is used to find an access vector that matches a 'required' access. To do this we comput a signed numeric value that indicates how close the req access is to the 'provided' access vector. The closer the value is to 0 the closer the match, with 0 being an exact match. A value over 0 indicates that the prov access vector provides more access than the req (in practice, this means that the source type, target type, and object class is the same and the perms in prov is a superset of those in req. A value under 0 indicates that the prov access less - or unrelated - access to the req access. A different type or object class will result in a very low value. The values other than 0 should only be interpreted relative to one another - they have no exact meaning and are likely to change. Params: req - [AccessVector] The access that is required. This is the access being matched. prov - [AccessVector] The access provided. This is the potential match that is being evaluated for req. Returns: 0 : Exact match between the acess vectors. < 0 : The prov av does not provide all of the access in req. A smaller value indicates that the access is further. > 0 : The prov av provides more access than req. The larger the value the more access over req. iN( R/tsrc_typettgt_typeR3RR.R*R+R2R0R8(R treqtprovRtpdist((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt av_distance|s '%      cCsVd}x‹|D]ƒ}|j||ƒ}|dkr:|}q |dkrm|dkr_||7}q|| }q |dkr†||7}q ||8}q W|jj|j|jƒ}|jdkrtj|_x6|D]+}|j|jj|j|jƒB|_qÑWn|tj @dkrR|jtj @rR|dkrB||j 8}qR||j 7}n|S(s iN( RR>R+tgetdefault_directionR3R0tinfo_dirRt FLOW_NONEt FLOW_WRITER-(R tav_setRRtxttmptav_dir((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt av_set_matchÄs.          &# cCs˜||_x~tj|j|jj|jgƒƒD]U}|jsFq1n|j|j |ƒ}|dkr1t ||ƒ}|j |ƒq1q1W|j ƒdS(Ni( RR"R#t tgt_type_allt tgt_type_maptgetR:tenabledRGRRR%R'(R tifsetRt match_listtivRtm((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyt search_ifsìs   N( RRRR R/R8R>RGRP(((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyR(]s   H (((( t__doc__R"tRRRt ComparisonRRR((((s7/usr/lib64/python2.7/site-packages/sepolgen/matching.pyts ,