https://t.me/RX1948
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/tracopt/perm/__pycache__/authz_policy.cpython-310.pyc
o

�k�`�(�@s�ddlZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZddl
mZmZddlmZddlmZGd	d
�d
e�ZdS)�N)�fnmatchcase)�groupby)�ConfigurationError�
PathOption�UnicodeConfigParser)�	Component�
implements)�IPermissionPolicy�PermissionSystem)�to_list)�exception_to_unicodec@sNeZdZdZee�edddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�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.cCsd|_d|_i|_dS)N)�authz�authz_mtime�groups_by_user)�self�r�;/usr/lib/python3/dist-packages/tracopt/perm/authz_policy.py�__init__�s
zAuthzPolicy.__init__c
Cs�|jr
tj�|j�|jkr|��|�|�}|j�d||�|�	||�}|dur*dS|gkr0dSt
|j�}t|dd�d�D]\}}	|rR||�
dd�|	D��vrRdS||�
|	�vr\dSq=dS)	NzChecking %s on %sFcSs
|�d�S)N�!)�
startswith)�prrr�<lambda>�s
z.AuthzPolicy.check_permission.<locals>.<lambda>)�keycss�|]	}|dd�VqdS)�Nr)�.0rrrr�	<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�permsrrr�check_permission�s(

��zAuthzPolicy.check_permissionc
s��j�d�j��js�j�d�t��z	tj��j�}Wnty5}z�j�dt	|��t��d}~wwt
dd��_z	�j��j�Wnt
jy^}z�j�dt	|��t��d}~wwi��j�d�rx�j�d�D]
\}}t|��|<qmi�_���fdd�����D]\}}�d	||�q�tt�j����}tj��j�}�j��D]1}|dkr�q��j�|�D]#\}}	t|	�D]}
|
�d
�r�|
dd�}
|
|vr׈j�d|
||�q�q�q�|�_dS)
Nz Parsing authz security policy %szYThe `[authz_policy] authz_file` configuration option in trac.ini is empty or not defined.z.Error parsing authz permission policy file: %sF)�ignorecase_option�groupscsF|D]}|�d�r�|�|dd��q�j�|t���|�qdS)N�@r)rr�
setdefault�set�add)�group�items�item��	add_itemsr5rrrr>�s

�z*AuthzPolicy.parse_authz.<locals>.add_itemsr6rrz>The action %s in the [%s] section of %s is not a valid action.)r%r&r�errorrr r!r"�OSErrorrrr�read�configparser�ParsingError�has_sectionr;rrr8r
r(�get_actions�basename�sectionsr�warningr)rr�er:�users�all_actions�authz_basename�section�user�actionsr*rr=rr#�sd�������
����
zAuthzPolicy.parse_authzcs$dd����fdd��d��|��S)NcSs,|j}d|jpd|dur|nd|jpdfS)Nz%s:%s@%s�*)�id�realm�version)r,rQrrr�
to_descriptor�s

�z5AuthzPolicy.normalise_resource.<locals>.to_descriptorcsl|sdgS�|�}|js|jdur|gS|j}|r*|j|jkr*|j}|r*|j|jks|r3�|�|gS|gS)Nz*:*@*)rRrQ�parent)r,�
descriptorrU��flattenrTrrrX�s�z/AuthzPolicy.normalise_resource.<locals>.flatten�/)�join)rr,rrWrr$�szAuthzPolicy.normalise_resourcecCs�|r
|dkr
ddd|g}nddg}dd�|j��D�D]H}|}d|vr'|d7}t||�rc|j�|�D]0\}}t|�}||vsG||j�|g�vrb|j�d|||�t	|t
�r\|gS|Sq2qdS)	N�	anonymousrP�
authenticatedcSsg|]}|dkr|�qS)r5r)r�arrr�
<listcomp>�s�z1AuthzPolicy.authz_permissions.<locals>.<listcomp>r6z@*z!%s matched section %s for user %s)rrGrr;rr�getr%r&�
isinstance�str)rr.r+�valid_users�resource_section�
resource_glob�whor/rrrr'�s*
�
��zAuthzPolicy.authz_permissionsN)
�__name__�
__module__�__qualname__�__doc__rr	rrrr3r#r$r'rrrrr
sc�6r
)rBr �fnmatchr�	itertoolsr�trac.configrrr�	trac.corerr�	trac.permr	r
�	trac.utilr�trac.util.textrr
rrrr�<module>s

https://t.me/RX1948 - 2025