PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` 3 Klf.@szdZddlmZddlmZddlmZddZGdd d ejZd d Z Gd d d Z ddZ ddZ GdddZ dS)aV 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 faciliate 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 CsNt|dkrF|ddkrFyt|ddWntk r@dSXdSdSdS)zDetermine if an id is a paramater in the form $N, where N is an integer. Returns: True if the id is a paramater False if the id is not a paramater rr$NFT)lenint ValueError)idr /usr/lib/python3.6/access.py is_idparam'sr c@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ 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}] NcCsV|r|j|nd|_d|_d|_tj|_g|_tj |_ g|_ i|_ d|_ d|_dS)N) from_listsrc_typetgt_type obj_classrIdSetperms audit_msgsrTERULEtypedataxperms__hash__Z info_flow_dir)selfZ init_listr r r __init__Ss  zAccessVector.__init__cCsRt|dkrtdt||d|_|d|_|d|_tj|dd|_dS)axInitialize 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 %srrN) rr strrrrrrr)rlistr r r rhs     zAccessVector.from_listcCs$|j|j|jg}|jt|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. )rrrextendsortedr)rlr r r to_list}szAccessVector.to_listcCsP|jj|jx<|jD]2}||jkr2tj|j|<|j|j|j|qWdS)z0Add permissions and extended permissions from AVN)rupdaterrZXpermSetr")ravopr r r merges   zAccessVector.mergecCs|jS)N) to_string)rr r r __str__szAccessVector.__str__cCsd|j|j|j|jjfS)Nzallow %s %s:%s %s;)rrrrZ to_space_str)rr r r r*s zAccessVector.to_stringc CspyRt|j}|j|j|j|f}t|j}|j|j|j|j|j|f}|||Sttfk rjtSXdS)N) r!rrrrsortAttributeError TypeErrorNotImplemented)rothermethodxaybr r r _compares   zAccessVector._compare)N) __name__ __module__ __qualname____doc__rrr%r)r+r*r6r r r r r8s   rcCsvt|tr|gSg}x\|jD]R}xL|jD]B}x<|jD]2}t}||_||_||_|jj |_|j |q4Wq(WqW|S)aQConvert an avrule into a list of access vectors. AccessVectors and AVRules are similary, 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. ) isinstancerZ src_typesZ tgt_typesZ obj_classesrrrrcopyappend)Zavruler3rrraccessr r r avrule_to_access_vectorss     r?c@sTeZdZdZddZddZddZdd Zd d Zd e j gfd dZ dddZ d S)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; cCsi|_d|_dS)z)Initialize an access vector set. N)srcZinfo_dir)rr r r rszAccessVectorSet.__init__ccsBx<|jjD].}x(|jD]}x|jD] }|Vq(WqWq WdS)z9Iterate over all of the unique access vectors in the set.N)rAvalues)rtgtsobjsr'r r r __iter__szAccessVectorSet.__iter__cCs:d}x0|jjD]"}x|jD]}|t|7}qWqW|S)a5Return the number of unique access vectors in the set. Because of the inernal 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. r)rArBr)rr$rCrDr r r __len__s zAccessVectorSet.__len__cCs$g}x|D]}|j|jq W|S)abReturn 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. )r=r%)rr$r'r r r r%s zAccessVectorSet.to_listcCs x|D]}|jt|qWdS)aAdd 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)rr$r'r r r rs zAccessVectorSet.from_listNc Cs:t}||_||_||_||_||_||_|j||dS)z)Add an access vector to the set. N)rrrrrrrrG) rrrrr audit_msgZavc_typerr'r r r addszAccessVectorSet.addcCsv|jj|ji}|j|ji}|j|jf|krF||j|jfj|n|||j|jf<|rr||j|jfjj|dS)z Add an access vector to the set.N) rA setdefaultrrrrr)rr=)rr'rHZtgtclsr r r rGszAccessVectorSet.add_av)N) r7r8r9r:rrErFr%rrrrIrGr r r r r@s   r@cCs2tj}x$|D]}|j|j|j|jqW|S)N)rrrIrr)avstypesr'r r r avs_extract_types*s   rNcCsJi}x@|D]8}|j|kr$||j}ntj}|||j<|j|jq W|S)N)rrrr&r)rLrr'sr r r avs_extract_obj_perms2s    rPc@s0eZdZdZddZddZddZdd Zd S) RoleTypeSetzA non-overlapping set of role type statements. This clas allows the incremental addition of role type statements and maintains a non-overlapping list of statements. cCs i|_dS)z Initialize an access vector set.N) role_types)rr r r rCszRoleTypeSet.__init__ccsx|jjD] }|Vq WdS)zAIterate over all of the unique role allows statements in the set.N)rRrB)r role_typer r r rEGszRoleTypeSet.__iter__cCst|jjS)z2Return the unique number of role allow statements.)rrRkeys)rr r r rFLszRoleTypeSet.__len__cCs>||jkr|j|}ntj}||_||j|<|jj|dS)N)rRrZRoleTyperolerMrI)rrUrrSr r r rIPs    zRoleTypeSet.addN)r7r8r9r:rrErFrIr r r r rQ=s rQN)r:rrZselinuxrr Z Comparisonrr?r@rNrPrQr r r r  s   oj