+
    ,iG  c                   s  a  R t)0 t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
Ht ^ RIt ^ RIt^ RIHtHtHt ^RIHtHtHtHtHt ^RIH t H!t!H"t" ]R	,          t#Rt$] ^ k  ! R R
]PJ                  4      t&]
 ! R R	]PN                  4      4       t(R#   ] d9   t]P*                  ! ]4      P/                  ]P0                   R24        RtALRtAii ; i)i    N)IterableMapping)suppress)	dataclassInitVar)NetworkXErrorNetworkXNoPathNodeNotFoundz failed to import.)	exceptionmixinspermmap	policyrepquery)CriteriaDescriptorEdgeAttrIntMaxEdgeAttrListInfoFlowStepInfoFlowAnalysisc                   s(  a a ] tR t^t oRt ! R R]P                  4      t]P                  ]P                  3t
]P                  ]P                  3t]]P                   ,          ! RR7      t]]P                   ,          ! RR7      t]P                  tR^RRR	RR
]P                  R^RRRR/V3R lV 3R lllt]V3R lR l4       t]P.                  V3R lR l4       t]V3R lR l4       t]P.                  V3R lR l4       t]V3R lR l4       t]P.                  V3R lR l4       t]V3R lR l4       t]P.                  V3R lR l4       tV3R  lR! ltV3R" lR# ltV3R$ lR% ltV3R& lR' ltV3R( lR) ltV3R* lR+ lt V3R, lt!R-t"Vt#V ;t$# ).r   a  
Information flow analysis.

Parameters:
policy      The policy to analyze.
perm_map    The permission map or path to the permission map file.

Keyword Parameters
source      The source type of the analysis.
target      The target type of the analysis.
mode        The analysis mode (see InfoFlowAnalysisMode)
min_weight  The minimum permission weight to include in the analysis.
            (default is 1)
exclude     The types excluded from the information flow analysis.
            (default is none)
booleans    If None, all rules will be added to the analysis (default).
            otherwise it should be set to a dict with keys corresponding
            to boolean names and values of True/False. Any unspecified
            booleans will use the policy's default values.

c                   s*    ] tR t^4tRtRtRtRtRtRt	R# )InfoFlowAnalysis.ModezInformation flow analysis modeszAll shortest pathszAll paths up tozFlows out of the source type.zFlows into the target type. N)
__name__
__module____qualname____firstlineno____doc__ShortestPathsAllPathsFlowsOutFlowsIn__static_attributes__r       7/usr/lib64/python3.14/site-packages/setools/infoflow.pyModer   4   s    -,$2/r   r    lookup_type)Zlookup_function
min_weightsourceNtargetmodedepth_limitexcludebooleansc                sT  < V ^8  d   QhRS[ P                  RS[P                  RS[RS[ P
                  S[,          R,          RS[ P
                  S[,          R,          RS[RS[R,          R	S[S[ P
                  S[,          ,          R,          R
S[	S[S[
3,          R,          RR/
# )   policyperm_mapr"   r#   Nr$   r%   r&   r'   r(   return)r   ZSELinuxPolicyr
   PermissionMapintTypestrr    r    r   boolformat__classdict__   "r   __annotate__InfoFlowAnalysis.__annotate__E   s      y66 'BWBW  "#-4 ##-4 	
 "Dj #9>>C#784? #39-4 AEr   c              sX  < \         S
V `  WW4WVVWR 7	       V  V  V  RV n        RV n         \        P
                  ! 4       V n        V P                  P                  4       V n        R#   \         d9    T P                  P                  R4       T P                  P                  R4       h i ; i))r+   r"   r#   r$   r%   r&   r'   r(   TzKNetworkX is not available.  This is required for Information Flow Analysis.z2This is typically in the python3-networkx package.N)super__init__rebuildgraphrebuildsubgraphnxDiGraphGcopysubGZ	NameErrorlogZcritical)selfr*   r+   r"   r#   r$   r%   r&   r'   r(   	__class__s   """$$$$$$$r   r9   ZInfoFlowAnalysis.__init__E   s     	z &{!( 	 	= 	 #	ZZ\DFDI 	HH H IHHRS		s   9A& &AB)c                s.   < V ^8  d   QhRS[ R,          /# r)   r,   Nr.   r2   r5   r   r6   r7   c   s     ! !S4Z !r   c                    V P                   # N)_depth_limitrB      &r   r&   InfoFlowAnalysis.depth_limitb   s       r   c                s2   < V ^8  d   QhRS[ R,          RR/# )r)   valueNr,   rE   r2   r5   r   r6   r7   g   s     " "t " "r   c                s>    Ve   V^8  d   \        R4      hWn        R # )Nz,Information flow max depth must be positive.)
ValueErrorrH   )rB   rL      &&r   r&   rK   f   s     KLL!r   c                    < V ^8  d   QhRS[ /# r)   r,   rE   r2   r5   r   r6   r7   o   s        C  r   c                rF   rG   )_min_weightrI   rJ   r   r"   InfoFlowAnalysis.min_weightn   s    r   c                s$   < V ^8  d   QhRS[ RR/# )r)   weightr,   NrE   r2   r5   r   r6   r7   s   s     $ $ $ $r   c                sX    ^Tu;8:  d   ^
8:  g   M \        R4      hWn        RV n        R# )   z4Min information flow weight must be an integer 1-10.TN)rM   rQ   r;   )rB   rS   rN   r   r"   rR   r   s1    F b FH H "#r   c                s4   < V ^8  d   QhRS[ P                  /# rP   r
   r-   r2   r5   r   r6   r7   |   s      '// r   c                rF   rG   )	_perm_maprI   rJ   r   r+   InfoFlowAnalysis.perm_map{   s    ~~r   c                s8   < V ^8  d   QhRS[ P                  RR/# )r)   r+   r,   NrU   r2   r5   r   r6   r7      s!     $ $!6!6 $4 $r   c                s.    Wn         R V n        R V n        R# TN)rV   r:   r;   )rB   r+   rN   r   r+   rW      s    ! #r   c                sD   < V ^8  d   QhRS[ S[P                  ,          /# rP   )listr   r/   r2   r5   r   r6   r7      s      inn- r   c                rF   rG   )_excluderI   rJ   r   r'   InfoFlowAnalysis.exclude   s    }}r   c                sf   < V ^8  d   QhRS[ S[P                  S[,          ,          R,          RR/# )r)   typesNr,   )r    r   r/   r0   r2   r5   r   r6   r7      s.     $ $Xinns&:;dB $t $r   c                s    V'       d1   V Uu. uF  q P                   P                  V4      NK  	  upV n        M. V n        R V n        R# u upi rX   )r*   r!   rZ   r;   )rB   r\   ts   && r   r'   r[      s@    W\2]W\RS;;3J3J13MW\2]DMDM#	 3^s   #A	c                sN   < V ^8  d   QhRS[ S[,          S[ R,          ,          /# )r)   r,   r   )r    InfoFlowPathr2   r5   r   r6   r7      s&     9L 9L,/(>2JJ 9Lr   c              #  s	  a "   S P                   '       d   S P                  4        S P                  P                  R S P                   24       S P                  P                  RS P                  : 24       S P                  P                  RS P                  : 24       S P                  P                  RS P                  : RS P                  : 24       \        \        \        \        4      ;_uu_ 4        S P                  ;\        P                  P                   8X  d    \#        S P                  S P                  34      '       g   \%        R4      hS P                  P                  RS P                   RS P                   R24       \&        P(                  ! S P*                  S P                  S P                  4       F8  pV 3R	 l\&        P,                  P.                  P1                  V4       4       x  K:  	  EM;\        P                  P2                  8X  d    \#        S P                  S P                  34      '       g   \%        R4      hS P                  P                  R
S P                   RS P                   RS P                   R24       \&        P4                  ! S P*                  S P                  S P                  S P                  R7       F8  pV 3R l\&        P,                  P.                  P1                  V4       4       x  K:  	  EM;\        P                  P6                  8X  d    S P                  '       g   \%        R4      hS P                  P                  RS P                   RS P                   24       \&        P8                  ! S P*                  S P                  S P                  R7       F  w  r#\;        S P*                  W#4      x  K  	  M\        P                  P<                  8X  d   S P                  '       g   \%        R4      hS P                  P                  RS P                   R2RS P                   24       \&        P8                  ! S P*                  S P                  RS P                  R7       F  w  r2\;        S P*                  W#4      x  K  	  M \%        RS P                   24      hRRR4       R#   + '       g   i     R# ; i5i)z)Generating information flow results from self.source=self.target=
self.mode=, self.depth_limit=*Source and target types must be specified.4Generating all shortest information flow paths from  to ...c              3   T   <"   T F  w  r\        SP                  W4      x  K  	  R # 5irG   r   r@   .0r#   r$   rB      &  r   	<genexpr>+InfoFlowAnalysis.results.<locals>.<genexpr>   )      S5Q>6  ,DIIvFF5Q   %(+Generating all information flow paths from , max length Zcutoffc              3   rg   rG   rh   ri   rk   r   rl   rm      rn   ro   Source type must be specified.(Generating all information flows out of , max depth r&   Target type must be specified.&Generating all information flows into  
max depth Treverser&   Unknown analysis mode: N)r;   _build_subgraphrA   infor*   debugr#   r$   r%   r&   r   r   r   r   r   r    r   allrM   r<   all_shortest_pathsr@   utilsmiscpairwiser   all_simple_pathsr   Z	bfs_edgesr   r   rB   pathr#   r$   s   f   r   resultsZInfoFlowAnalysis.results   s      "A$++OP,$++(),$++()*$))%9(8(8':;<nlMBB))8%**88T[[9::()UVVHHMM"X%)[[Mdkk]##G H !# 5 5diidkk ZS57XX]]5K5KD5QS S ![ 4%**33T[[9::()UVVHHMM"O%)[[Mdkk] C0040@0@/A#F G !# 3 3DIIt{{DKK;?;K;K!MS57XX]]5K5KD5QS S!M
 4%**33;;;()IJJHHMM$LT[[M Z//3/?/?.@#B C*,,,tyy$++CGCSCS+U*499fEE+U &**22;;;()IJJHHMM$J4;;-WX"Y$.t/?/?.@"AC +-,,tyy$++W[CGCSCS+U*499fEE+U $'>tyyk%JKKa CBBBs-   C5S#8ISCSB5S
S#S 		S#c                   < V ^8  d   QhRR/# )r)   r,   
nx.DiGraphr   r2   r5   r   r6   r7      s     JG JG< JGr   c           	     s
   V P                   '       d   V P                  4        V P                  P                  RV P                   24       V P                  P                  RV P                  : 24       V P                  P                  RV P                  : 24       V P                  P                  RV P                  : RV P                  : 24        V P                  ;\        P                  P                  8X  Ed
    \        V P                  V P                  34      '       g   \        R4      hV P                  P                  RV P                   RV P                   R	24       \        P                   ! V P"                  V P                  V P                  4      pV UUu. uF4  p\        P$                  P&                  P)                  V4       F  q3NK  	  K6  	  ppp\        P*                  ! 4       pVP-                  V4       V# ;\        P                  P.                  8X  Ed#    \        V P                  V P                  34      '       g   \        R4      hV P                  P                  R
V P                   RV P                   RV P                   R	24       \        P0                  ! V P"                  V P                  V P                  V P                  R7      pV UUu. uF4  p\        P$                  P&                  P)                  V4       F  q3NK  	  K6  	  ppp\        P*                  ! 4       pVP-                  V4       V# ;\        P                  P2                  8X  d    V P                  '       g   \        R4      hV P                  P                  RV P                   RV P                   24       \        P4                  ! V P"                  V P                  V P                  R7      # \        P                  P6                  8X  d   V P                  '       g   \        R4      hV P                  P                  RV P                   R2RV P                   24       \        P4                  ! V P"                  V P                  RV P                  R7      p\        P8                  ! VRR7      #  \        RV P                   24      hu uppi u uppi   \:         d    p\<        P>                  ! RT 24      ThRp?ii ; i)a  
Return the results of the analysis as a NetworkX directed graph.
Caller has the responsibility of converting the graph to a
visualization.

For example, to convert to a pygraphviz graph:
    pgv = nx.nx_agraph.to_agraph(g.graphical_results())
    pgv.layout(prog="dot")
z3Generating graphical information flow results from r_   r`   ra   rb   rc   rd   re   rf   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   Tr{   F)r?   r}   z&Unable to generate graphical results: N) r;   r~   rA   r   r*   r   r#   r$   r%   r&   r   r    r   r   rM   r<   r   r@   r   r   r   r=   Zadd_edges_fromr   r   r   Zbfs_treer   r|   Z	Exceptionr   ZAnalysisException)rB   Zpathsr   ZpairedgesZoutZexs   &      r   graphical_resultsZ"InfoFlowAnalysis.graphical_results   s      "KDKK=YZ,$++(),$++()*$))%9(8(8':;<6	G))8%**88T[[9::()UVVHHMM"X%)[[Mdkk]##G H11$))T[[$++VE.3]ed@V@VW[@\T@\TeE]**,C&&u-J3%**33T[[9::()UVVHHMM"O%)[[Mdkk] C0040@0@/A#F G //		4;;7;7G7GIE.3]ed@V@VW[@\T@\TeE]**,C&&u-J3%**33;;;()IJJHHMM$LT[[M Z//3/?/?.@#B C;;tyy$++4K[K[\\%**22;;;()IJJHHMM$J4;;-WX"Y$.t/?/?.@"AC++diid262B2BDC ::c66$'>tyyk%JKKS ^ ^8  	G--8=?DFG	GsX   CS $:S*S 	CS &:S *S 1S =A6S 4/S $BS 6%S T&T  Tc                rO   rP   r0   r2   r5   r   r6   r7     s     # #3 #r   c                s   V P                   '       d   V P                  4        R\        P                  ! V P                  4      : R\        P
                  ! V P                  4      : R\        V P                  4      : R2# )z9
Get the information flow graph statistics.

Return: str
znx.number_of_nodes(self.G)=z
nx.number_of_edges(self.G)=z
len(self.G)=
)r:   _build_graphr<   number_of_nodesr>   number_of_edgesZlenrI   rJ   r   	get_statsZInfoFlowAnalysis.get_stats  sk     -"$$TVV,. /.$$TVV,. /dff+r# 	#r   c                sJ   < V ^8  d   QhRS[ S[P                  ,          RS[/# )r)   r   r,   )rY   r   r/   r^   r2   r5   r   r6   r7   *  s$     : :D$8 :\ :r   c              #  s   "   \         P                  P                  P                  V4       F  w  r#\	        V P
                  W#4      x  K  	  R# 5i)a  
Generator which returns the source, target, and associated rules
for each information flow step.

Parameter:
path   A list of graph node names representing an information flow path.

Yield: tuple(source, target, rules)

source  The source type for this step of the information flow.
target  The target type for this step of the information flow.
rules   The list of rules creating this information flow step.
N)r<   r   r   r   r   r@   r   s   &&  r   _generate_stepsZ InfoFlowAnalysis._generate_steps*  s7      !hhmm44T:NFtyy&99 ;s   AAc                r   rD   r   r2   r5   r   r6   r7   J  s     !@ !@d !@r   c           	     s   V P                   P                  4        R V P                   R2V P                   n        V P                  P                  V P                  4       V P                  P                  RV P                   R24       V P                  P                  RV P                  : 24       V P                  P                  4        EFs  pVP                  \        P                  P                  8w  d   K/  V P                  P                  \        P                   ! \        P"                  V4      4      p\$        P&                  ! VP(                  P+                  4       VP,                  P+                  4       4       F  w  r4W48w  g   K  VP.                  '       dE   \1        V P                   W4RR7      pVP2                  P5                  V4       VP.                  Vn        VP8                  '       g   Kw  \1        V P                   WCRR7      pVP2                  P5                  V4       VP8                  Vn        K  	  EKv  	  RV n        RV n        V P                  P                  R4       V P                  P                  R	\>        P@                  ! V P                   4       R
\>        PB                  ! V P                   4       R24       R# )zInformation flow graph for .z%Building information flow graph from rf   zself.perm_map=T)createFz*Completed building information flow graph.zGraph stats: nodes: 	, edges: N)"r>   Zclearr*   namer+   Z
map_policyrA   r   r   ZterulesZruletyper   Z
TERuletypeZallowZrule_weighttypingZcastZAVRule	itertoolsZproductr#   Zexpandr$   Zwriter   rulesappendrS   Zreadr:   r;   r<   r   r   )rB   rulerS   sr]   edges   &     r   r   ZInfoFlowAnalysis._build_graphJ  s   3DKK=B  -=dkk]#NO.$--)*+KK'')D}}	 4 4 : ::]]..v{{9;K;KT/RSF!))$++*<*<*>@R@R@TU 6|||+DFFAF

))$/&,ll{{{+DFFAF

))$/&,kk V *( "#BC-b.@.@.H-I J!!#!3!3DFF!; <A? 	@r   c                r   rD   r   r2   r5   r   r6   r7   m  s     3C 3C 3Cr   c                s   V P                   '       d   V P                  4        V P                  P                  R 4       V P                  P	                  RV P
                  : 24       V P                  P	                  RV P                  : 24       V P                  P	                  RV P                  : 24       V P                  P                  4        Uu. uF  qV P                  9  g   K  VNK  	  ppV P                  P                  V4      P                  4       V n        V P
                  ^8  d   . pV P                  P                  4        FI  w  rE\        V P                  WE4      pVP                  V P
                  8  g   K8  VP!                  V4       KK  	  V P                  P#                  V4       V P                  Ee   . pV P                  P                  4        F  w  rE\        V P                  WE4      p. pVP$                   F8  pVP&                  ! R
/ V P                  B '       d   K'  VP!                  V4       K:  	  . p	V F7  pW9  g   K  VP$                  P)                  V4       V	P!                  V4       K9  	  VP$                  '       d   K  VP!                  V4       K  	  V P                  P#                  V4       RV n        V P                  P                  R4       V P                  P	                  R\,        P.                  ! V P                  4       R\,        P0                  ! V P                  4       R	24       R# u upi )z%Building information flow subgraph...zself.min_weight=zself.exclude=zself.booleans=NFz-Completed building information flow subgraph.zSubgraph stats: nodes: r   r   r   )r:   r   rA   r   r   r"   r'   r(   r>   nodesZsubgraphr?   r@   r   r   rS   r   Zremove_edges_fromr   ZenabledZremover;   r<   r   r   )
rB   Znr   Zdelete_listr   r]   r   Z	rule_listr   Zdeleted_ruless
   &         r   r~   Z InfoFlowAnalysis._build_subgraphm  sq   =>*$//+,--$,,)*.$--)*+ !FFLLNDNqt||.CNDFFOOE*//1	
 ??QK		)#DIIq4;;0&&t, *
 II''4==$K		)#DIIq4 	 JJD<<8$--88!((. ' 9;%D0

))$/%,,T2 &
 zzz&&t,# *& II''4$EF01C1CDII1N0O P!!#!3!3DII!> ?qB 	CQ Es   M,Mc                s   < V ^8  d   Qh/ S[ P                  S[S[R3,          ,          ;R&   S[ P                  S[S[R3,          ,          ;R&   S[S[S[3,          R,          ;R&   # )r)   .DIRECT_MODESTRANSITIVE_MODESNr(   )r   Finaltupler    r   r0   r1   r2   r5   r   r6   r7      sd     B ,,uT3Y/0PC D ll5s#34ZE N c4i 4''O r   )r>   rH   rZ   rQ   rV   r:   r;   r@   )%r   r   r   r   r   enumZEnumr    r   r   r   r   r   r   r   r   r/   r#   r$   r%   r9   Zpropertyr&   Zsetterr"   r+   r'   r   r   r   r   r   r~   __annotate_func__r   __classdictcell____classcell__rC   r4      @@r   r   r      s    ,0tyy 0 59LL$--3PL8<8J8JDMM7Z	/NF	/NFD#$7; 8< #00	
 ,- CG 8< : ! ! " "     $ $   __$ $
   ^^$ $9L 9LvJG JGX# #": :@!@ !@F3C 3Cc
  r   c                   s   a a ] tR tRt oRtRt]! 4       t]! R4      t	V3R lR lt
V3R lV 3R lltR	 tV3R
 ltRtVtV ;t# )r   i  a.  
A graph edge.  Also used for returning information flow steps.

Parameters:
graph       The NetworkX graph.
source      The source type of the edge.
target      The target type of the edge.

Keyword Parameters:
create      (T/F) create the edge if it does not exist.
            The default is False.
FZcapacityc                r   rD   r   r2   r5   r   r6   InfoFlowStep.__annotate__  s     I It Ir   c                s   V P                   P                  V P                  V P                  4      '       gV   V'       dC   V P                   P	                  V P                  V P                  ^R7       RV n        RV n        R# \        R4      hR# )rT   )rS   Nz$InfoFlowStep does not exist in graph)r>   Zhas_edger#   r$   Zadd_edger   rS   rM   )rB   r   rN   r   __post_init__ZInfoFlowStep.__post_init__  s_    vvt{{DKK88T[[C!
" !GHH 9r   c                s&   < V ^8  d   QhRS[ RS[ /# )r)   specr,   r   r2   r5   r   r6   r     s     , ,s ,s ,r   c                s  < VR 8X  dJ   RP                  R \        V P                  4       4       4      pV P                   RV P                   RV 2# V'       g   V P                   RV P                   2# \
        SV `  V4      # )fullr   c              3   s,   "   T F
  pR V 2x  K  	  R# 5i)z   Nr   )rj   Zrs   & r   rl   Z*InfoFlowStep.__format__.<locals>.<genexpr>  s     D1CAA3i1Cs   z -> )ZjoinZsortedr   r#   r$   r8   
__format__)rB   r   r   rC   s   && r   r   ZInfoFlowStep.__format__  sr    6>IID

1CDDEkk]$t{{m2eW==kk]$t{{m447%d++r   c                s$    V P                  R 4      # )r   )r   rI   rJ   r   __str__ZInfoFlowStep.__str__  s    v&&r   c                s   < V ^8  d   Qh/ R;R&   S[ P                  ;R&   S[ P                  ;R&   S[S[,          ;R&   # )r)   r   r>   r#   r$   r   )r   r/   r   r1   r2   r5   r   r6   r     sD       O! " NN# $ NN% & DM!' r   )r   rS   )r   r   r   r   r   r   r   r   r   rS   r   r   r   r   r   r   r   r   r   r   r   r     sG       "FNE J'FI I, ,'_  r   c                s    V ^8  d   Qh/ ^ \         9   d,   \        P                  \        \        R3,          ,          ;R&   # )r)   .__all__)__conditional_annotations__r   r   r   r0   )r3   s   "r   r6   r6      s*    ( ^ ]eCHo	& ]) r   )r   r   r^   )*r   r   r   ZloggingZcollections.abcr    r   Z
contextlibr   Zdataclassesr   r   r   Znetworkxr<   Znetworkx.exceptionr   r   r   ZImportErrorZiexZ	getLoggerr   r   r   Z r   r	   r
   r   r   Zdescriptorsr   r   r   r^   r   ZDirectedGraphAnalysisr   ZNetworkXGraphEdger   r6   )r   s   @r   <module>r      s   
    -  * GNN
 ; : I I')] ]DCu22 DCN /'6++ /' /'g  Gh%%
2D&EFFGs   B C.CC