a qéqeDã@s¢ddlZddlmZddlmZddlmZmZmZddl m Z ddl m Z m Z mZmZGdd „d ƒZGd d „d ƒZGd d „d ƒZGdd„dƒZGdd„dƒZdS)éN)ÚLogger)ÚIterableé)ÚCriteriaDescriptorÚCriteriaSetDescriptorÚCriteriaPermissionSetDescriptor)ÚContext)Ú match_in_setÚ match_regexÚ match_rangeÚmatch_regex_or_setc@s>eZdZUdZedƒZdZeed<e ddœdd„Z dd „Z dS) Ú MatchAliasz'Mixin for matching an object's aliases.Ú alias_regexFN©ÚlogÚreturncCs| d |¡¡dS)z+Emit log debugging info for alias matching.z(Alias: {0.alias}, regex: {0.alias_regex}N©ÚdebugÚformat©Úselfr©rú4/usr/lib64/python3.9/site-packages/setools/mixins.pyÚ_match_alias_debugszMatchAlias._match_alias_debugcCs|js dSt| ¡|j|jƒS)z‡ Match the alias criteria Parameter: obj An object with an alias generator method named "aliases" T)Úaliasr Úaliasesr©rÚobjrrrÚ _match_aliasszMatchAlias._match_alias) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrÚboolÚ__annotations__rrrrrrrr s  r c@s¬eZdZUdZeddƒZdZeed<eddƒZ dZ eed<eddƒZ dZ eed<ed d �Z dZeed <dZeed <dZeed <dZeed<edœdd„Zeedœdd„ZdS)Ú MatchContextaL Mixin for matching contexts. Class attributes: user The user to match in the context. user_regex If true, regular expression matching will be used on the user. role The role to match in the context. role_regex If true, regular expression matching will be used on the role. type_ The type to match in the context. type_regex If true, regular expression matching will be used on the type. range_ The range to match in the context. range_subset If true, the criteria will match if it is a subset of the context's range. range_overlap If true, the criteria will match if it overlaps any of the context's range. range_superset If true, the criteria will match if it is a superset of the context's range. range_proper If true, use proper superset/subset on range matching operations. No effect if not using set operations. Ú user_regexZ lookup_userFÚ role_regexZ lookup_roleÚ type_regexZ lookup_typeZ lookup_range)Zlookup_functionÚ range_overlapÚ range_subsetÚrange_supersetÚ range_proper©rcCsD| d |¡¡| d |¡¡| d |¡¡| d |¡¡dS)z-Emit log debugging info for context matching.z'User: {0.user!r}, regex: {0.user_regex}z'Role: {0.role!r}, regex: {0.role_regex}z(Type: {0.type_!r}, regex: {0.type_regex}z�Range: {0.range_!r}, subset: {0.range_subset}, overlap: {0.range_overlap}, superset: {0.range_superset}, proper: {0.range_proper}NrrrrrÚ_match_context_debugQs ÿz!MatchContext._match_context_debug)ÚcontextrcCs€|jrt|j|j|jƒsdS|jr8t|j|j|jƒs8dS|jrTt|j|j|jƒsTdS|jr|t|j|j|j |j |j |j ƒs|dSdS)z© Match the context criteria. Parameter: obj An object with context attributes "user", "role", "type_" and "range_". FT) Úuserr r&Úroler'Útype_r(Úrange_r r*r)r+r,)rr/rrrÚ_match_contextYs8 ýýýúzMatchContext._match_contextN)rr r!r"rr0r&r#r$r1r'r2r(r3r)r*r+r,rr.rr4rrrrr%*s            r%c@sJeZdZUdZedƒZdZeed<dZ eed<e ddœdd„Z d d „Z dS) Ú MatchNamez=Mixin for matching an object's name with alias dereferencing.Ú name_regexFÚ alias_derefNrcCs| d |¡¡dS)z)Log debugging messages for name matching.z?Name: {0.name!r}, regex: {0.name_regex}, deref: {0.alias_deref}NrrrrrÚ_match_name_debugˆszMatchName._match_name_debugcCsH|js dS|jr4t||j|jƒp2t| ¡|j|jƒSt||j|jƒSdS)z&Match the object to the name criteria.TN)Únamer7r r6r rrrrrÚ _match_nameŒsÿzMatchName._match_name) rr r!r"rr9r6r#r$r7rr8r:rrrrr5€s   r5c@s@eZdZUdZeddƒZdZeed<e ddœdd„Z d d „Z dS) Ú MatchObjClassz%Mixin for matching an object's class.Ú tclass_regexZ lookup_classFNrcCs| d |¡¡dS)ú0Emit log debugging info for permission matching.z,Class: {0.tclass!r}, regex: {0.tclass_regex}NrrrrrÚ_match_object_class_debug sz'MatchObjClass._match_object_class_debugcCs6|js dS|jr&t|j t|jƒ¡ƒS|j|jvSdS)z� Match the object class criteria Parameter: obj An object with an object class attribute named "tclass" TN)Útclassr<r#ÚsearchÚstrrrrrÚ_match_object_class¤s z!MatchObjClass._match_object_class) rr r!r"rr?r<r#r$rr>rBrrrrr;™s   r;c@sVeZdZUdZedd�ZdZeed<dZ eed<dZ eed<e dœdd „Z d d „Z d S) ÚMatchPermissionz+Mixin for matching an object's permissions.Ú perms_regex)r6FÚ perms_equalÚ perms_subsetr-cCs| d |¡¡dS)r=z[Perms: {0.perms!r}, regex: {0.perms_regex}, eq: {0.perms_equal}, subset: {0.perms_subset!r}NrrrrrÚ_match_perms_debug¾sÿz"MatchPermission._match_perms_debugcCs6|js dS|jr|j|jkSt|j|j|j|jƒSdS)z‘ Match the permission criteria Parameter: obj An object with a permission set class attribute named "perms" TN)ÚpermsrFr rErDrrrrÚ _match_permsÃs  zMatchPermission._match_permsN)rr r!r"rrHrEr#r$rDrFrrGrIrrrrrCµs     rC)ÚreZloggingrÚtypingrZ descriptorsrrrZ policyreprÚutilr r r r r r%r5r;rCrrrrÚs   V