+
    	:i.  c                   s    R t ^RIHt ^RIHt ^ RIHt R t ! R R]P                  4      tR t	 ! R R	4      t
R
 tR t ! R R4      tR# )aW  
Classes representing basic access.

SELinux - at the most basic level - represents access as
the 4-tuple subject (type or context), target (type or context),
object class, permission. The policy language elaborates this basic
access to facilitate more concise rules (e.g., allow rules can have multiple
source or target types - see refpolicy for more information).

This module has objects for representing the most basic access (AccessVector)
and sets of that access (AccessVectorSet). These objects are used in Madison
in a variety of ways, but they are the fundamental representation of access.
)	refpolicy)util)	audit2whyc                s    \        V 4      ^8  d$   V ^ ,          R8X  d    \        V R,          4       R# R#   \         d     R# i ; i)zDetermine if an id is a parameter in the form $N, where N is
an integer.

Returns:
  True if the id is a parameter
  False if the id is not a parameter
Z$:i   NNFT)lenZint
ValueError)Zid   &4/usr/lib/python3.14/site-packages/sepolgen/access.py
is_idparamr   '   sE     2w{r!u|	2K 	  		s   6 AAc                   sR   a  ] tR t^8t o RtRR ltR tR tR tR t	R t
R	 tR
tV tR# )AccessVectora  
An access vector is the basic unit of access in SELinux.

Access vectors are the most basic representation of access within
SELinux. It represents the access a source type has to a target
type in terms of an object class and a set of permissions.

Access vectors are distinct from AVRules in that they can only
store a single source type, target type, and object class. The
simplicity of AccessVectors makes them useful for storing access
in a form that is easy to search and compare.

The source, target, and object are stored as string. No checking
done to verify that the strings are valid SELinux identifiers.
Identifiers in the form $N (where N is an integer) are reserved as
interface parameters and are treated as wild cards in many
circumstances.

Properties:
 .src_type - The source type allowed access. [String or None]
 .tgt_type - The target type to which access is allowed. [String or None]
 .obj_class - The object class to which access is allowed. [String or None]
 .perms - The permissions allowed to the object class. [IdSet]
 .audit_msgs - The audit messages that generated this access vector [List of strings]
 .xperms - Extended permissions attached to the AV. [Dictionary {operation: xperm set}]
Nc                s   V'       d   V P                  V4       M/R V n        R V n        R V n        \        P
                  ! 4       V n        . V n        \        P                  V n
        . V n        / V n        R V n        R V n        R # N)	from_listsrc_typetgt_type	obj_classr    IdSetperms
audit_msgsr   TERULEtypedataxperms__hash__info_flow_dir)selfZ	init_list   &&r   __init__ZAccessVector.__init__S   si    NN9% DM DM!DN"*DJ$$		  "    c                s    \        V4      ^8  d   \        R\        V4      ,          4      hV^ ,          V n        V^,          V n        V^,          V n        \        P                  ! VR,          4      V n        R# )a(  Initialize an access vector from a list.

Initialize an access vector from a list treating the list as
positional arguments - i.e., 0 = src_type, 1 = tgt_type, etc.
All of the list elements 3 and greater are treated as perms.
For example, the list ['foo_t', 'bar_t', 'file', 'read', 'write']
would create an access vector list with the source type 'foo_t',
target type 'bar_t', object class 'file', and permissions 'read'
and 'write'.

This format is useful for very simple storage to strings or disc
(see to_list) and for initializing access vectors.
z+List must contain at least four elements %s:i   NNN)	r   r   Zstrr   r   r   r    r   r   )r   listr   r   r
   ZAccessVector.from_listh   sZ     t9q=JSQUYVWWQQa__T"X.
r   c                s    V P                   V P                  V P                  .pVP                  \	        V P
                  4      4       V# )z
Convert an access vector to a list.

Convert an access vector to a list treating the list as positional
values. See from_list for more information on how an access vector
is represented in a list.
)r   r   r   extendZsortedr   )r   l   & r   to_listZAccessVector.to_list}   s6     ]]DMM4>>:	

#$r   c                s@   V P                   P                  VP                   4       VP                   Fh  pW P                  9  d#   \        P                  ! 4       V P                  V&   V P                  V,          P                  VP                  V,          4       Kj  	  R# )z0Add permissions and extended permissions from AVN)r   updater   r    ZXpermSetr   )r   avZop   && r   mergeZAccessVector.merge   sd    

"((#))B$"+"4"4"6BKKO""299R=1 r   c                s"    V P                  4       # r	   )	to_stringr   r   r   __str__ZAccessVector.__str__   s    ~~r   c           	     s    R V P                   : RV P                  : RV P                  : RV P                  P	                  4       : R2	# )zallow Z Z:Z;)r   r   r   r   Zto_space_strr%   r   r   r$   ZAccessVector.to_string   s1    '+}}dmm(,

8O8O8QS 	Sr   c                sr    \        V P                  4      pV P                  V P                  V P                  V3p\        VP                  4      pVP                  4        VP                  4        VP                  VP                  VP                  V3pV! WF4      #   \        \        3 d
    \        u # i ; ir	   )	r   r   r   r   r   ZsortZAttributeErrorZ	TypeErrorZNotImplemented)r   ZotherZmethodZxaZyZbs   &&&    r   _compareZAccessVector._compare   s    
	"TZZ At~~qAAU[[!AFFHFFH!DA!<	* 	"!!	"s   BB B65B6)
r   r   r   r   r   r   r   r   r   r   r	   )__name__
__module____qualname____firstlineno____doc__r   r
   r   r#   r&   r$   r(   __static_attributes____classdictcell__Z__classdict__   @r   r   r   8   s3     4"*/*
2 S" "r   r   c                sF   \        V \        4      '       d   V .# . pV P                   Fu  pV P                   Fb  pV P                   FO  p\        4       pW%n        W5n        WEn        V P                  P                  4       Vn        VP                  V4       KQ  	  Kd  	  Kw  	  V# )a6  Convert an avrule into a list of access vectors.

AccessVectors and AVRules are similarly, but differ in that
an AVRule can more than one source type, target type, and
object class. This function expands a single avrule into a
list of one or more AccessVectors representing the access
defined in the AVRule.


)Z
isinstancer   Z	src_typesZ	tgt_typesZobj_classesr   r   r   r   Zcopyappend)Zavruler'   r   r   r   Zaccesss   &     r   avrule_to_access_vectorsr3      s     &,''x
A$$((H#//	%"*"*#, %||002  0 ) % Hr   c                   sp   a  ] tR t^t o RtR tR tR tR tR t	R]
P                  . 3R ltRR	 ltR
tV tR# )AccessVectorSeta  A non-overlapping set of access vectors.

An AccessVectorSet is designed to store one or more access vectors
that are non-overlapping. Access can be added to the set
incrementally and access vectors will be added or merged as
necessary.  For example, adding the following access vectors using
add_av:
   allow $1 etc_t : read;
   allow $1 etc_t : write;
   allow $1 var_log_t : read;
Would result in an access vector set with the access vectors:
   allow $1 etc_t : { read write};
   allow $1 var_log_t : read;
c                s"    / V n         RV n        R# )z)Initialize an access vector set.
        N)srcinfo_dirr%   r   r   r   ZAccessVectorSet.__init__   s      r   c              #  s   "   V P                   P                  4        F5  pVP                  4        F  pVP                  4        F  pVx  K	  	  K   	  K7  	  R# 5i)z9Iterate over all of the unique access vectors in the set.N)r5   values)r   tgtsobjsr!      &   r   __iter__ZAccessVectorSet.__iter__   s?     HHOO%D++-BH ( & &s   AAc                s    ^ pV P                   P                  4        F,  pVP                  4        F  pV\        V4      ,          pK  	  K.  	  V# )a  Return the number of unique access vectors in the set.

Because of the internal representation of the access vector set,
__len__ is not a constant time operation. Worst case is O(N)
where N is the number of unique access vectors, but the common
case is probably better.
)r5   r7   r   )r   r   r8   r9   r:   r   __len__ZAccessVectorSet.__len__   sB     HHOO%DCI~q & & r   c                sZ    . pV  F"  pVP                  VP                  4       4       K$  	  V# )a  Return the unique access vectors in the set as a list.

The format of the returned list is a set of nested lists,
each access vector represented by a list. This format is
designed to be simply  serializable to a file.

For example, consider an access vector set with the following
access vectors:
  allow $1 user_t : file read;
  allow $1 etc_t : file { read write};
to_list would return the following:
  [[$1, user_t, file, read]
   [$1, etc_t, file, read, write]]

See AccessVector.to_list for more information.
)r2   r   r   r   r!      &  r   r   ZAccessVectorSet.to_list   s,    " BHHRZZ\"  r   c                sL    V F  pV P                  \        V4      4       K  	  R# )zAdd access vectors stored in a list.

See to list for more information on the list format that this
method accepts.

This will add all of the access from the list. Any existing
access vectors in the set will be retained.
N)add_avr   r=   r"   r   r
   ZAccessVectorSet.from_list  s     BKKR() r   Nc                s    \        4       pWn        W(n        W8n        WHn        Wxn        Whn        V P                  W4       R# )z)Add an access vector to the set.
        N)r   r   r   r   r   r   r   r?   )	r   r   r   r   r   	audit_msgZavc_typer   r!   s	   &&&&&&&& r   addZAccessVectorSet.add  s5     ^ B"r   c                s   V P                   P                  VP                  / 4      pVP                  VP                  / 4      pVP                  VP
                  3V9   d/   WAP                  VP
                  3,          P                  V4       MWVP                  VP
                  3&   V'       d:   WAP                  VP
                  3,          P                  P                  V4       R# R# )z Add an access vector to the set.N)	r5   Z
setdefaultr   r   r   r   r#   r   r2   )r   r!   r@   ZtgtZclss   &&&  r   r?   ZAccessVectorSet.add_av  s    hh!!"++s3nnR[[#.LL"''"c)bgg%&,,R0)+bgg%&bgg%&1188C r   )r6   r5   r	   )r)   r*   r+   r,   r-   r   r;   r<   r   r
   r   r   rA   r?   r.   r/   r0   r1   r   r4   r4      sG     .
* CGQZQaQahj #D Dr   r4   c                 s    \         P                  ! 4       pV  F9  pVP                  VP                  4       VP                  VP                  4       K;  	  V# r	   )r    r   rA   r   r   )avstypesr!   r>   r   avs_extract_typesrD   *  s?    OOE		"++		"++  Lr   c                 s    / pV  Fe  pVP                   V9   d   WP                   ,          pM#\        P                  ! 4       pW1VP                   &   VP                  VP                  4       Kg  	  V# r	   )r   r    r   r    r   )rB   r   r!   Zsr:   r   avs_extract_obj_permsrE   2  sX    E<<5 ll#A!A"#",,	  Lr   c                   s<   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	RoleTypeSeti=  zA non-overlapping set of role type statements.

This class allows the incremental addition of role type statements and
maintains a non-overlapping list of statements.
c                s    / V n         R# )z Initialize an access vector set.N
role_typesr%   r   r   r   ZRoleTypeSet.__init__C  s	    r   c              #  sX   "   V P                   P                  4        F  pVx  K	  	  R# 5i)zAIterate over all of the unique role allows statements in the set.N)rH   r7   )r   	role_typer   r   r;   ZRoleTypeSet.__iter__G  s!     //1IO 2s   (*c                sH    \        V P                  P                  4       4      # )z2Return the unique number of role allow statements.)r   rH   Zkeysr%   r   r   r<   ZRoleTypeSet.__len__L  s    4??'')**r   c                s    WP                   9   d   V P                   V,          pM)\        P                  ! 4       pWn        W0P                   V&   VP                  P                  V4       R # r	   )rH   r    ZRoleTyperolerC   rA   )r   rJ   r   rI   s   &&& r   rA   ZRoleTypeSet.addP  sK    ??"-I!**,I!N$-OOD!D!r   rG   N)r)   r*   r+   r,   r-   r   r;   r<   rA   r.   r/   r0   r1   r   rF   rF   =  s#     

+" "r   rF   N)r-   Z r    r   Zselinuxr   r   Z
Comparisonr   r3   r4   rD   rE   rF   ) r   r   <module>rK      sU   (   "l"4?? l"^2hD hDT	" "r   