+
        P@                         R t ^ RIt^ RIt^RIHt ^RIHt ^RIHt ^RIHt ^RIH	t	  ! R R4      t
R	 tR
 tR tR tR t ! R R4      t ! R R4      t ! R R4      t ! R R4      tR# )z7
Classes for representing and manipulating interfaces.
N)access)	refpolicy)objectmodel)matching)_c                   b   a  ] tR t^"t o RtR tR tR t]! ]]4      t	]! R R7      t
R tRtV tR	# )
Paramz3
Object representing a parameter for an interface.
c                    R V n         \        P                  V n        \        P                  ! 4       V n        RV n        R# ) TN)_Param__namer   SRC_TYPEtypeIdSetobj_classesrequiredselfs   &8/usr/lib/python3.14/site-packages/sepolgen/interfaces.py__init__Param.__init__&   s,    &&	$??,    c                n    \         P                  ! V4      '       g   \        R V,          4      hWn        R# )zName [%s] is not a paramN)r   
is_idparam
ValueErrorr   )r   names   &&r   set_nameParam.set_name,   s)      &&7$>??r   c                    V P                   # N)r   r   s   &r   get_nameParam.get_name1   s    {{r   c                :    \        V P                  R ,          4      # )   NN)intr   r   s   &r   <lambda>Param.<lambda>6   s    S2%7r   )fgetc                    R V P                   : R\        P                  V P                  ,          : RRP	                  V P
                  4      : R2# )z$<sepolgen.policygen.Param instance [z,  z]>)r   r   field_to_strr   joinr   r   s   &r   __repr__Param.__repr__8   s:    		911$))<<chhtGWGW>XZ 	Zr   )__namer   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   propertyr   numr,   __static_attributes____classdictcell____classdict__s   @r   r   r   "   s>     
 Hh'D
7
8CZ Zr   r   c                    ^ pW9   d   W0,          pWP                   8X  d   R# V\        P                  8X  g   V\        P                  8X  d   VP                   \        P                  8X  g    VP                   \        P                  8X  dr   ^pV'       d   VP                  .pM. p\
        P                  ! VP                  V4       F  pV\        P                  9   g   K  ^ p M	  \        P                  Vn         M'^pM$\        4       pWn        Wn         WSVP                  &   V'       d&   VP                  P                  VP                  4       V#     N)r   r   r   TGT_TYPE	obj_class	itertoolschainr   r   implicitly_typed_objectsr   r   add)r   r   avparamsretpavobjsobjs   &&&&    r   __param_insertrI   >   s    
C~L66>I&&&$)2D2D*DFFi(((AFFi6H6H,H C,, q}}f=+>>>C > ''AF
 CGqvv		",,'Jr   c                   ^ pRp\         P                  ! V P                  4      '       d-   \        V P                  \        P
                  W4      ^8X  d   ^p\         P                  ! V P                  4      '       d-   \        V P                  \        P                  W4      ^8X  d   ^p\         P                  ! V P                  4      '       d-   \        V P                  \        P                  W4      ^8X  d   ^pV# )a  Extract the parameters from an access vector.

Extract the parameters (in the form $N) from an access
vector, storing them as Param objects in a dictionary.
Some attempt is made at resolving conflicts with other
entries in the dict, but if an unresolvable conflict is
found it is reported to the caller.

The goal here is to figure out how interface parameters are
actually used in the interface - e.g., that $1 is a domain used as
a SRC_TYPE. In general an interface will look like this:

interface(`foo', `
   allow $1 foo : file read;
')

This is simple to figure out - $1 is a SRC_TYPE. A few interfaces
are more complex, for example:

interface(`foo_trans',`
   domain_auto_trans($1,fingerd_exec_t,fingerd_t)

   allow $1 fingerd_t:fd use;
   allow fingerd_t $1:fd use;
   allow fingerd_t $1:fifo_file rw_file_perms;
   allow fingerd_t $1:process sigchld;
')

Here the usage seems ambiguous, but it is not. $1 is still domain
and therefore should be returned as a SRC_TYPE.

Returns:
  0  - success
  1  - conflict found
F)
r   r   src_typerI   r   r   tgt_typer=   r>   	OBJ_CLASS)rC   rD   rE   	found_srcs   &&  r   av_extract_paramsrO   j   s    H CI%%"++y'9'92F!KC%%"++y'9'92F!KC&&",,	(;(;RHAMCJr   c                     \         P                  ! V P                  4      '       d'   \        V P                  \        P
                  R V4      # R # r   )r   r   rolerI   r   ROLE)rQ   rD   s   &&r   role_extract_paramsrS      s5    ##diivFF $r   c                   a V3R  lp^ pV! V P                   \        P                  4      '       d   ^pV! V P                  \        P                  4      '       d   ^pV! V P
                  \        P                  4      '       d   ^p\        P                  ! V P                  4      '       d/   \        V P                  \        P                  RS4      '       d   ^pV# )c                    < ^ pV  F8  p\         P                  ! V4      '       g   K!  \        W1RS4      '       g   K6  ^pK:  	  V# r;   )r   r   rI   )setr   rE   xrD   s   &&  r   extract_from_set2type_rule_extract_params.<locals>.extract_from_set   s>    A  ##!!488C  
r   N)	src_typesr   r   	tgt_typesr=   r   rM   r   r   	dest_typerI   	DEST_TYPE)rulerD   rX   rE   s   &f  r   type_rule_extract_paramsr_      s     C	(:(:;;	(:(:;;(()*=*=>>(($..)*=*=tVLLCJr   c                     ^ pV P                    FG  p\        P                  ! V4      '       g   K!  \        V\        P
                  RV4      '       g   KE  ^pKI  	  V# r;   )argsr   r   rI   r   r   )ifcallrD   rE   args   &&  r   ifcall_extract_paramsrd      sK    
C{{S!! c9#5#5tVDD  Jr   c                   ,   a  ] tR t^t o R tR tRtV tR# )AttributeVectorc                H    R V n         \        P                  ! 4       V n        R# )r
   N)r   r   AccessVectorSetr   s   &r   r   AttributeVector.__init__   s    	,,.r   c                <    V P                   P                  V4       R # r   )r   add_avr   rC   s   &&r   rk   AttributeVector.add_av   s    2r   )r   r   N)r/   r0   r1   r2   r   rk   r6   r7   r8   s   @r   rf   rf      s     / r   rf   c                   2   a  ] tR t^t o R tR tR tRtV tR# )AttributeSetc                    / V n         R # r   
attributesr   s   &r   r   AttributeSet.__init__   s	    r   c                6    WP                   VP                  &   R # r   )rr   r   )r   attrs   &&r   add_attrAttributeSet.add_attr   s    %)		"r   c                H   R  pRpV F{  pVRR pV^ ,          R8X  d$   V'       d   V P                  V4       V! V4      pK9  V'       g   KC  VP                  R4      p\        P                  ! V4      pVP	                  V4       K}  	  V'       d   V P                  V4       R# R# )c                     V ^R P                  4       p\        V4      ^8w  g   V^ ,          R8w  d   \        RV ,          4      h\        4       pV^,          Vn        V# )r#   	Attributez#Syntax error Attribute statement %s)splitlenSyntaxErrorrf   r   )linefieldsas   &  r   
parse_attr*AttributeSet.from_file.<locals>.parse_attr   sV    !BZ%%'F6{a6!9#;!"G$"NOO!AAYAFHr   N[,r{   )rv   r|   r   AccessVectorrk   )r   fdr   r   r   lrC   s   &&     r   	from_fileAttributeSet.from_file   s    	 D9DAw#~MM!$t$JJsO((+  MM! r   rq   N)	r/   r0   r1   r2   r   rv   r   r6   r7   r8   s   @r   ro   ro      s     * r   ro   c                   R   a  ] tR t^t o R/ 3R lt/ 3R ltR tR tR tR t	Rt
V tR# )	InterfaceVectorNc                    R V n         RV n        \        P                  ! 4       V n        / V n        V'       d   V P                  W4       RV n        R# )Tr
   FN)enabledr   r   rh   rD   from_interfaceexpanded)r   	interfacerr   s   &&&r   r   InterfaceVector.__init__   sE     	 ,,. 	6r   c                <   VP                   V n         VP                  4        Fq  pVP                  \        P                  P
                  8w  d   K.  R VP                   9   d   KA  \        P                  ! V4      pV F  pV P                  V4       K  	  Ks  	  V'       d   VP                  4        F  pVP                   F  pWrP                  9  d   K  VP                  V,          pVP                   F  p	\        P                  ! V	4      pVP                  VP                   8X  d   VP                  Vn        VP                  VP                   8X  d   VP                  Vn        V P                  V4       K  	  K  	  K  	  VP                  4        F   p
\!        WP"                  4      '       g   K   K"  	  VP%                  4        F   p\'        WP"                  4      '       g   K   K"  	  VP)                  4        F   p\+        WP"                  4      '       g   K   K"  	  R# )	dontauditN)r   avrules	rule_typer   AVRuleALLOWr   avrule_to_access_vectorsrk   typeattributesrr   copyrK   r   rL   rolesrS   rD   	typerulesr_   interface_callsrd   )r   r   rr   avruleavsrC   typeattributeru   attr_vecr   rQ   r^   rb   s   &&&          r   r   InterfaceVector.from_interface   s   NN	  '')F9#3#3#9#99inn,11&9CB  * !*!9!9!;)44D#8#88 )44T:H%__!YYq\;;(--7*7*<*<BK;;(--7*7*<*<BKB - 5 "<  OO%D"455 & '')D'kk:: *  //1F$V[[99 2r   c                r    \        WP                  4      ^8X  d    V P                  P                  V4       R# )r#   N)rO   rD   r   rk   rl   s   &&r   rk   InterfaceVector.add_av3  s(    R-22r   c                    . pVP                  R V P                  ,          4       V P                   F  pVP                  \        V4      4       K  	  RP	                  V4      # )z[InterfaceVector %s]
)appendr   r   strr+   )r   srC   s   &  r   	to_stringInterfaceVector.to_string9  sI    	'$))34++BHHSW yy|r   c                "    V P                  4       # r   )r,   r   s   &r   __str__InterfaceVector.__str__@  s    }}r   c                @    R V P                   : RV P                  : R2# )z<InterfaceVector :>)r   r   r   s   &r   r,   InterfaceVector.__repr__C  s    ,0IIt||DDr   )r   r   r   r   rD   )r/   r0   r1   r2   r   r   rk   r   r   r,   r6   r7   r8   s   @r   r   r      s5     !%" " 46 /hE Er   r   c                   z   a  ] tR tRt o RR ltR tR tR tR tR t	/ 3R	 lt
R/ 3R
 ltR tR tR tR tRtV tR# )InterfaceSetiG  Nc                <    / V n         / V n        . V n        Wn        R # r   )
interfacestgt_type_maptgt_type_alloutput)r   r   s   &&r   r   InterfaceSet.__init__H  s    r   c                r    V P                   '       d%   V P                   P                  VR ,           4       R# R# )r   N)r   write)r   r   s   &&r   oInterfaceSet.oN  s&    ;;;KKcDj) r   c                b   \        V P                  P                  4       R  R7       EF  pVP                  RVP                  ,          4       \        VP
                  P                  4       R R7       FE  pVP                  VP                  : R\        P                  VP                  ,          : R24       KG  	  VP                  R4       \        VP                  P                  4       4      pV F4  pVP                  RP                  V4      4       VP                  R4       K6  	  EK  	  R	# )
c                     V P                   # r   r   rW   s   &r   r%   &InterfaceSet.to_file.<locals>.<lambda>S  s    r   )keyz[InterfaceVector %s c                     V P                   # r   r   r   s   &r   r%   r   U  s    !&&r   r   r)   z]
r   r   N)sortedr   valuesr   r   rD   r   r*   r   r   to_listr+   )r   r   ivparamavlrC   s   &&    r   to_fileInterfaceSet.to_fileR  s    //17GHHBHH+bgg56		 0 0 28HIUZZ1G1G

1S1STU JHHUO**,-C"&  Ir   c                d   R  pRpV F{  pVRR pV^ ,          R8X  d$   V'       d   V P                  V4       V! V4      pK9  V'       g   KC  VP                  R4      p\        P                  ! V4      pVP	                  V4       K}  	  V'       d   V P                  V4       V P                  4        R# )c                    V ^R P                  4       p\        V4      ^8  g   V^ ,          R8w  d   \        RV ,          4      h\        4       pV^,          Vn        \        V4      ^8X  d   R# VR,           F  pVP                  R4      p\        V4      ^8w  d   \        RV ,          4      h\        4       pV^ ,          Vn        \        P                  V^,          ,          Vn        WRP                  VP                  &   K  	  V# )r#   r   z)Syntax error InterfaceVector statement %sN:   NNr   z-Invalid param in InterfaceVector statement %sr{   )
r|   r}   r~   r   r   r   r   str_to_fieldr   rD   )r   r   ifvfieldrF   r   s   &     r   	parse_ifv)InterfaceSet.from_file.<locals>.parse_ifv^  s    !BZ%%'F6{Q&)/@"@!"MPT"TUU!#CayCH6{aKK$q6Q;%&UX\&\]]qT
&33AaD9
).

5::& $ Jr   Nr   r   r{   )add_ifvr|   r   r   rk   index)r   r   r   r   r   r   rC   s   &&     r   r   InterfaceSet.from_file]  s    	$ D9DAw#~LL%oJJsO((+

2  LL

r   c                6    WP                   VP                  &   R # r   )r   r   )r   r   s   &&r   r   InterfaceSet.add_ifv  s    $'!r   c                   V P                   P                  4        F  p\        4       pVP                   Fk  p\        P                  ! VP
                  4      '       d(   V P                  P                  V4       \        4       p MVP                  VP
                  4       Km  	  V F0  pV P                  P                  V. 4      pVP                  V4       K2  	  K  	  R # r   )r   r   rV   r   r   rL   r   r   rB   r   
setdefault)r   r   r[   rC   r   r   s   &     r   r   InterfaceSet.index  s    ??))+CIjj$$R[[11%%,,S1 #Ibkk* ! "%%00r: " ,r   c                >    \        W4      pV P                  V4       R # r   )r   r   )r   r   rr   r   s   &&& r   rB   InterfaceSet.add  s    i4Sr   c                    \         P                  ! VP                  4       VP                  4       4       F  pV P	                  WC4       K  	  V P                  V4       V P                  4        R # r   )r?   r@   r   	templatesrB   expand_ifcallsr   )r   headersr   rr   is   &&&& r   add_headersInterfaceSet.add_headers  sO    !3!3!5w7H7H7JKAHHQ# L 	G$

r   c                   \         P                  ! V4      '       dd   \        VR ,          4      pV\        VP                  4      8  d   R# VP                  V^,
          ,          p\        V\        4      '       d   V# V.# V.# )r"   N)r   r   r$   r}   ra   
isinstancelist)r   idrb   r5   rc   s   &&&  r   	map_paramInterfaceSet.map_param  sh    R  bf+CS%% kk#'*c4((J5L4Kr   c           	        V P                  VP                  V4      pVf   R # V P                  VP                  V4      pVf   R # V P                  VP                  V4      pVf   R # \        P
                  ! 4       pVP                   F+  pV P                  W4      p	V	f   K  VP                  V	4       K-  	  \        V4      ^ 8X  d   R # V F1  p
V F(  pV F  pVP                  P                  WW4       K!  	  K*  	  K3  	  R # r   )r   rK   rL   r>   r   r   permsupdater}   r   rB   )r   r   rC   rb   rZ   r[   r   	new_permspermrF   rK   rL   r>   s   &&&&         r   
map_add_avInterfaceSet.map_add_av  s    NN2;;7	NN2;;7	nnR\\6:OO%	HHDt,Ay  #  y>Q!H%!,IJJNN8yL "- & "r   c                   VR 3.pV P                   VP                  ,          pRVn        \        V4      ^ 8  d   VP	                  R4      w  rVV P                   VP                  ,          pWQ8w  d:   VP
                   F  pV P                  WHV4       K  	  VP                  '       d   K  VP                  4        F`  p	V	P                  VP                  8X  d   V P                  \        R4      4        R #  W)P                  ,          p
TP                  Y34       Kb  	  K  R #   \         d0    T P                  \        RT	P                  ,          4      4        K  i ; i)NTzFound circular interface classz#Missing interface definition for %sr{   )r   r   r   r}   popr   r   r   ifnamer   r   KeyErrorr   )r   r   
if_by_namestackr   cur
cur_ifcallcur_ifvrC   rb   newifs   &&&        r   do_expand_ifcallsInterfaceSet.do_expand_ifcalls  s   
 T"#ooinn-%j1n#iimOCoochh/G!..BOOCZ8 )
 ###--/==INN2FF1=>?&}}5E
 e_- 0 (   FF1BV]]RSTs   5D!!6EEc                0   / p\         P                  ! VP                  4       VP                  4       4       F  pW2VP                  &   K  	  \         P                  ! VP                  4       VP                  4       4       F  pV P                  WB4       K  	  R # r   )r?   r@   r   r   r   r   )r   r   r   r   r   s   &&   r   r   InterfaceSet.expand_ifcalls  su     
!3!3!5w7H7H7JKA!"qvv L #););)=w?P?P?RSI""99 Tr   )r   r   r   r   r   )r/   r0   r1   r2   r   r   r   r   r   r   rB   r   r   r   r   r   r6   r7   r8   s   @r   r   r   G  sU     *	!F( )+  +/2  M8!.H: :r   r   )r3   r   r?   r
   r   r   r   r   sepolgeni18nr   r   rI   rO   rS   r_   rd   rf   ro   r   r    r   r   <module>r     sx   (       Z Z8(X2hG2	  >WE WEtp: p:r   