a BÒiÊ. ã @ sz d Z ddlmZ ddlmZ ddlmZ dd„ ZG dd „ d ejƒZd d„ Z G dd „ d ƒZ dd„ Zdd„ ZG dd„ dƒZ dS )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 C sN t | ƒdkrF| d dkrFzt| dd… ƒ W n ty@ Y dS 0 dS dS dS )z¬Determine 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 r r ú$NFT)ÚlenÚintÚ ValueError)Úid© r ú3/usr/lib/python3.9/site-packages/sepolgen/access.pyÚ is_idparam' s r c @ sJ e Zd ZdZddd„Zdd„ Zdd„ Zd d „ Zdd„ Zd d„ Z dd„ Z dS )Ú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 C sV |r| |¡ nd | _d | _d | _t ¡ | _g | _tj | _ g | _i | _d | _ d | _d S ©N)Ú from_listÚsrc_typeÚtgt_typeÚ obj_classr ÚIdSetÚpermsÚ audit_msgsr ÚTERULEÚtypeÚdataÚxpermsÚ__hash__Z info_flow_dir)ÚselfZ init_listr r r Ú__init__S s zAccessVector.__init__c C sR t |ƒdk rtdt|ƒ ƒ‚|d | _|d | _|d | _t |dd… ¡| _dS )ax 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 %sr r é é N) r r Ústrr r r r r r )r Úlistr r r r h s zAccessVector.from_listc C s$ | j | j| jg}| t| jƒ¡ |S )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 ÚextendÚsortedr )r Úlr r r Úto_list} s zAccessVector.to_listc C sL | j |j ¡ |jD ]2}|| jvr0t ¡ | j|<