
    qi                     v    S r SSKrSSKJrJr  SSKJr  SSKJr  Sr	\R                  " \5      r " S S\5      rg)	a  
Abstract base class of a domain controller (used by HTTPAuthenticator).

This ABC serves as base class for DomainControllers and provides some
default implementations.

Domain controllers are called by `HTTPAuthenticator` to handle these tasks:

- Basic authentication:
  Check if user_name/password is allowed to perform a request

- Digest authentication (optional):
  Check if user_name is allowed to perform a request and return the MD5 hash.

- Define permissions and roles for a given user (optional).


Note that there is no checking for `isinstance(BaseDomainController)` in the
code, so WsgiDAV also accepts duck-typed domain controllers.

Digest Authentication
---------------------

See https://en.wikipedia.org/wiki/Digest_access_authentication


Permissions and Roles
---------------------

A domain controller MAY add entries to the `environment["wsgidav.auth. ..."]`
namespace in order to define access permissions for the following middleware
(e.g. dir_browser) and DAV providers.

TODO: Work In Progress / Subject to change

    N)ABCabstractmethod)md5)utilreStructuredTextc                       \ rS rSrSrSrS rS rS r\	S 5       r
\	S 5       rS	 r\	S
 5       r\	S 5       rS rS rSrg)BaseDomainController2   )
browse_dirdelete_resourceedit_resource)admineditorreaderc                     Xl         X l        g )N)wsgidav_appconfig)selfr   r   s      G/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/dc/base_dc.py__init__BaseDomainController.__init__9   s    &    c                 4    U R                   R                   S3$ )Nz())	__class____name__r   s    r   __str__BaseDomainController.__str__=   s    ..))*"--r   c                 &   U(       a  US   nOU R                   R                  U5      u  pCU(       dK  [        R                  S[        R
                  " U[        R                  R                  5      < SS< 35        gUR                  nUS:X  a  SnU$ )zDInternal helper for derived classes to implement get_domain_realm().zwsgidav.providerz_calc_realm_from_path_provider(z): N /)
r   resolve_providerloggerwarningr   safe_re_encodesysstdoutencoding
share_path)r   	path_infoenvirondav_provider_sharerealms         r   _calc_realm_from_path_provider3BaseDomainController._calc_realm_from_path_provider@   s     ##56L $(#3#3#D#DY#O FNN1$2E2EiQTQ[Q[QdQd2e1hhklpkst ''B;Er   c                     [         e)a  Return the normalized realm name for a given URL.

This method is called

- On startup, to check if anonymous access is allowed for a given share.
  In this case, `environ` is None.
- For every request, before basic or digest authentication is handled.

A domain controller that uses the share path as realm name may use
the `_calc_realm_from_path_provider()` helper.

Args:
    path_info (str):
    environ (dict | None):
Returns:
    str
NotImplementedError)r   r*   r+   s      r   get_domain_realm%BaseDomainController.get_domain_realmV   s
    & "!r   c                     [         e)a  Return False to disable authentication for this request.

This method is called

- On startup, to check if anonymous access is allowed for a given share.
  In this case, `environ` is None.
- For every request, before basic or digest authentication is handled.
  If False is returned, we MAY also set environment variables for
  anonymous access::

        environment["wsgidav.auth.roles"] = (<role>, ...)
        environment["wsgidav.auth.permissions"] = (<perm>, ...)
        return False

Args:
    realm (str):
    environ (dict | None):
Returns:
    False to allow anonymous access
    True to force subsequent digest or basic authentication
r2   )r   r.   r+   s      r   require_authentication+BaseDomainController.require_authenticationk   s
    . "!r   c                 T    U R                  US5      nU R                  US5      (       + $ )zReturn true if anonymous access will be granted to the share path.

This method is called on start-up to print out info and warnings.

Returns:
    bool
N)r4   r7   )r   r*   r.   s      r   is_share_anonymous'BaseDomainController.is_share_anonymous   s,     %%i6..ud;;;r   c                     [         e)a  Check request access permissions for realm/user_name/password.

Called by http_authenticator for basic authentication requests.

Optionally set environment variables:

    environ["wsgidav.auth.roles"] = (<role>, ...)
    environ["wsgidav.auth.permissions"] = (<perm>, ...)

Args:
    realm (str):
    user_name (str):
    password (str):
    environ (dict):
Returns:
    False if user is not known or not authorized
    True if user is authorized
r2   )r   r.   	user_namepasswordr+   s        r   basic_auth_user$BaseDomainController.basic_auth_user   s
    ( "!r   c                     [         e)zSignal if this DC instance supports the HTTP digest authentication theme.

If true, `HTTPAuthenticator` will call `dc.digest_auth_user()`,
so this method must be implemented as well.

Returns:
    bool
r2   r   s    r   supports_http_digest_auth.BaseDomainController.supports_http_digest_auth   s
     "!r   c                 |    US-   U-   S-   U-   n[        [        R                  " U5      5      R                  5       nU$ )zGInternal helper for derived classes to compute a digest hash (A1 part).:)r   r   to_bytes	hexdigest)r   r.   r=   r>   dataA1s         r   _compute_http_digest_a1,BaseDomainController._compute_http_digest_a1   s;    3&,x7t$%//1	r   c                     [         e)aj  Check access permissions for realm/user_name.

Called by http_authenticator for basic authentication requests.

Compute the HTTP digest hash A1 part.

Any domain controller that returns true for `supports_http_digest_auth()`
MUST implement this method.

Optionally set environment variables:

    environ["wsgidav.auth.roles"] = (<role>, ...)
    environ["wsgidav.auth.permissions"] = (<perm>, ...)

Note that in order to calculate A1, we need either

- Access the plain text password of the user.
  In this case the method `self._compute_http_digest_a1()` can be used
  for convenience.
  Or

- Return a stored hash value that is associated with the user name
  (for example from Apache's htdigest files).

Args:
    realm (str):
    user_name (str):
    environ (dict):

Returns:
    str: MD5("{usern_name}:{realm}:{password}")
    or false if user is unknown or rejected
r2   )r   r.   r=   r+   s       r   digest_auth_user%BaseDomainController.digest_auth_user   s    D "!r   )r   r   N)r   
__module____qualname____firstlineno__known_permissionsknown_rolesr   r   r/   r   r4   r7   r:   r?   rB   rJ   rM   __static_attributes__ r   r   r	   r	   2   s~     K/K., " "( " "0	< " "* 	" 	":""r   r	   )__doc__r&   abcr   r   hashlibr   wsgidavr   __docformat__get_module_loggerr   r#   r	   rU   r   r   <module>r\      s<   #H  #  "				)y"3 y"r   