VULN_CHECK_I913V6 /i!dZddlZddlmZddlmZddlmZGddej ZGd d ZGd d Z y) zI Classes and algorithms for matching requested access to access vectors. N)access) objectmodel)utilceZdZddZdZy)MatchNc<||_||_d|_d|_yNF) interfacedistinfo_dir_change__hash__)selfr r s 6/usr/lib/python3.12/site-packages/sepolgen/matching.py__init__zMatch.__init__ s!" $ c |j|jf}|j|jf}|||S#ttf$r tcYSwxYwN)r r AttributeError TypeErrorNotImplemented)rothermethodabs r_comparezMatch._compare(sU "D001AU223A!Q<  * "! ! "s8;AANr)__name__ __module__ __qualname__rrrrrrs "rrc:eZdZdZdZdZdZdZdZdZ dZ y ) MatchListc^g|_g|_|j|_d|_d|_yr )childrenbastardsDEFAULT_THRESHOLD thresholdallow_info_dir_changeavrs rrzMatchList.__init__3s,  //%*"rct|jr|jdSt|jr|jdSyrlenr&r'r,s rbestzMatchList.best<s; t}} ==# # t}} ==# #rcXt|jt|jzSrr.r,s r__len__zMatchList.__len__Cs!4==!C $666rc,t|jSr)iterr&r,s r__iter__zMatchList.__iter__IsDMM""rcVtj|j|jSr) itertoolschainr&r'r,s rallz MatchList.allLst}}dmm<zMatchList.sortXs"  rN) rrr r(rr0r2r5r9r;r>r!rrr#r#1s+7 #=(rr#c2eZdZddZdZdZdZdZdZy) AccessMatcherNcd|_d|_|r||_d|_ytj|_d|_y)N d) type_penalty obj_penalty perm_mapsr PermMappingsinfo_dir_penalty)rrFs rrzAccessMatcher.__init__^sB &DN !$ )557DN!$rcR||k(stj|ry|j Sr)r is_idparamrD)rrrs r type_distancezAccessMatcher.type_distancejs( 6V&&q)%%% %rcP|jj|j}t|dk7r)|jj |j |}| S|jj|j}|jj |j |Sr)perms differencer/rFgetdefault_distance obj_class)rav_reqav_provdifftotals r perm_distancezAccessMatcher.perm_distanceqs}||&&w}}5 t9>NN66v7G7GNE6M==++FLL9D>>55f6F6FM Mrcd}||j|j|jz }||j|j|jz }|j|jk7r.t j |js||j z}|dkr1|jj|j|j}n|j||}|dkr|dkr||zS||z S|dk\r|dkr||z S||zSy)a,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 access 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. rN) rKsrc_typetgt_typerPrrJrErFrOrMrU)rreqprovr pdists r av_distancezAccessMatcher.av_distance|sN ""3<<?? ""3<<?? ==DNN *63D3DT^^3T D$$ $D !8NN66t~~tzzRE&&sD1E !8qye|#e|# QYqyt|#e|# rcxd}|D]@}|j||}||}|dk\r|dk\r||z }*|| z}1|dkr||z }<||z}B|jj|j|j}|j ^t j|_|D]D}|j |jj|j|jz|_F|t jzdk(rB|j t jzr%|dkr||jz}|S||jz }|S)z Nr) r\rFgetdefault_directionrPrMinfo_dirr FLOW_NONE FLOW_WRITErH)rav_setr+r xtmpav_dirs r av_set_matchzAccessMatcher.av_set_matchs8A""2q)C|19CKD$;D!8CKDCKD$44R\\288L ?? ")33FO"(//"&.."E"EakkSTSZSZ"[#\ [++ +q 0vI_I_7_ax--- --- rc\||_tj|j|jj |j gD]N}|js|j|j|}|dk\s2t||}|j|P|jyr) r+r7r8 tgt_type_all tgt_type_mapgetrXenabledrfrrr;r>)rifsetr+ match_listivr ms r search_ifszAccessMatcher.search_ifss //%"4"4"'"4"4"8"8b"IKB::$$RYY3Dqy"dO!!!$K rr) rrr rrKrUr\rfrpr!rrr@r@]s$ $& NF$P&Prr@) __doc__r7rrr Comparisonrr#r@r!rrrts?("DOO"$))X]]r