Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /lib/python3/dist-packages/tracopt/perm/__pycache__/ |
Upload File : |
o �k�`�( � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZmZm Z d dl mZmZ d dl mZmZ d dlmZ d dlmZ G d d � d e�ZdS )� N)�fnmatchcase)�groupby)�ConfigurationError� PathOption�UnicodeConfigParser)� Component� implements)�IPermissionPolicy�PermissionSystem)�to_list)�exception_to_unicodec @ sN e Zd ZdZee� edddd�Zdd� Zdd � Z d d� Z dd � Zdd� ZdS )�AuthzPolicya� Permission policy using an authz-like configuration file. Refer to SVN documentation for syntax of the authz file. Groups are supported. As the fine-grained permissions brought by this permission policy are often used in complement of the other permission policies (like the `DefaultPermissionPolicy`), there's no need to redefine all the permissions here. Only additional rights or restrictions should be added. === Installation === Enabling this policy requires listing it in `trac.ini`:: {{{ [trac] permission_policies = AuthzPolicy, DefaultPermissionPolicy [authz_policy] authz_file = conf/authzpolicy.conf }}} This means that the `AuthzPolicy` permissions will be checked first, and only if no rule is found will the `DefaultPermissionPolicy` be used. === Configuration === The `authzpolicy.conf` file is a `.ini` style configuration file. - Each section of the config is a glob pattern used to match against a Trac resource descriptor. These descriptors are in the form:: {{{ <realm>:<id>@<version>[/<realm>:<id>@<version> ...] }}} Resources are ordered left to right, from parent to child. If any component is inapplicable, `*` is substituted. If the version pattern is not specified explicitely, all versions (`@*`) is added implicitly Example: Match the WikiStart page:: {{{ [wiki:*] [wiki:WikiStart*] [wiki:WikiStart@*] [wiki:WikiStart] }}} Example: Match the attachment ``wiki:WikiStart@117/attachment/FOO.JPG@*`` on WikiStart:: {{{ [wiki:*] [wiki:WikiStart*] [wiki:WikiStart@*] [wiki:WikiStart@*/attachment/*] [wiki:WikiStart@117/attachment/FOO.JPG] }}} - Sections are checked against the current Trac resource '''IN ORDER''' of appearance in the configuration file. '''ORDER IS CRITICAL'''. - Once a section matches, the current username is matched, '''IN ORDER''', against the keys of the section. If a key is prefixed with a `@`, it is treated as a group. If a key is prefixed with a `!`, the permission is denied rather than granted. The username will match any of 'anonymous', 'authenticated', <username> or '*', using normal Trac permission rules. Example configuration:: {{{ [groups] administrators = athomas [*/attachment:*] * = WIKI_VIEW, TICKET_VIEW [wiki:WikiStart@*] @administrators = WIKI_ADMIN anonymous = WIKI_VIEW * = WIKI_VIEW # Deny access to page templates [wiki:PageTemplates/*] * = # Match everything else [*] @administrators = TRAC_ADMIN anonymous = BROWSER_VIEW, CHANGESET_VIEW, FILE_VIEW, LOG_VIEW, MILESTONE_VIEW, POLL_VIEW, REPORT_SQL_VIEW, REPORT_VIEW, ROADMAP_VIEW, SEARCH_VIEW, TICKET_CREATE, TICKET_MODIFY, TICKET_VIEW, TIMELINE_VIEW, WIKI_CREATE, WIKI_MODIFY, WIKI_VIEW # Give authenticated users some extra permissions authenticated = REPO_SEARCH, XML_RPC }}} �authz_policy� authz_file� zqLocation of authz policy configuration file. Non-absolute paths are relative to the Environment `conf` directory.c C s d | _ d | _i | _d S )N)�authz�authz_mtime�groups_by_user)�self� r �;/usr/lib/python3/dist-packages/tracopt/perm/authz_policy.py�__init__� s zAuthzPolicy.__init__c C s� | j r tj�| j�| j kr| �� | �|�}| j�d||� | � ||�}|d u r*d S |g kr0dS t | j�}t|dd� d�D ]\}} |rR||� dd� | D ��v rR dS ||� | �v r\ dS q=d S ) NzChecking %s on %sFc S s | � d�S )N�!)� startswith)�pr r r �<lambda>� s z.AuthzPolicy.check_permission.<locals>.<lambda>)�keyc s s � | ] }|d d� V qdS )� Nr )�.0r r r r � <genexpr>� s � z/AuthzPolicy.check_permission.<locals>.<genexpr>T)r �os�path�getmtimer �parse_authz�normalise_resource�log�debug�authz_permissionsr �envr �expand_actions) r �action�username�resource�perm�resource_key�permissions�ps�deny�permsr r r �check_permission� s( ��zAuthzPolicy.check_permissionc s� �j �d�j� �js�j �d� t� �z tj��j�}W n ty5 } z�j �dt |�� t� �d }~ww t dd��_z �j��j� W n t jy^ } z�j �dt |�� t� �d }~ww i ��j�d�rx�j�d�D ] \}}t|��|<