
    XR_}'                     <   d Z ddlZddlZ ej        e          ZddlmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmc mZ g dZ G d dej        j        ej                  Z ed	          Zd
Z G d dej        j        ej                  Z G d dej                  ZdS )z.passlib.handlers.misc - misc generic handlers
    N)warn)to_native_strstr_consteq)unicodeuunicode_or_bytes_types)unix_disabledunix_fallback	plaintextc                   `     e Zd ZdZd ZdZed             Zd fd	Zd Z	edd            Z
 xZS )	r
   a  This class provides the fallback behavior for unix shadow files, and follows the :ref:`password-hash-api`.

    This class does not implement a hash, but instead provides fallback
    behavior as found in /etc/shadow on most unix variants.
    If used, should be the last scheme in the context.

    * this class will positively identify all hash strings.
    * for security, passwords will always hash to ``!``.
    * it rejects all passwords if the hash is NOT an empty string (``!`` or ``*`` are frequently used).
    * by default it rejects all passwords if the hash is an empty string,
      but if ``enable_wildcard=True`` is passed to verify(),
      all passwords will be allowed through if the hash is an empty string.

    .. deprecated:: 1.6
        This has been deprecated due to its "wildcard" feature,
        and will be removed in Passlib 1.8. Use :class:`unix_disabled` instead.
    )enable_wildcardc                 p    t          |t                    rdS t          j                            |d          NThash
isinstancer   uhexcExpectedStringErrorclsr   s     7/usr/lib/python3/dist-packages/passlib/handlers/misc.pyidentifyzunix_fallback.identify.   2    d233 	;4&,,T6:::    Fc                     t          dt                      t          t          |           j        di | || _        d S )Nzf'unix_fallback' is deprecated, and will be removed in Passlib 1.8; please use 'unix_disabled' instead. )r   DeprecationWarningsuperr
   __init__r   )selfr   kwds	__class__s      r   r    zunix_fallback.__init__5   sR     3  	! 	! 	! 	,mT""+33d333.r   c                 <    | j         r| j         S t          d          S )N!)checksumr   )r!   secrets     r   _calc_checksumzunix_fallback._calc_checksum=   s!    = 	 = S66Mr   c                     t          j        |           t          |t                    s t           j                            |d          |rdS |S )Nr   F)r   validate_secretr   r   r   r   )r   r'   r   r   s       r   verifyzunix_fallback.verifyE   sQ    
6"""$ 677 	#&,,T6::: 	#5""r   )F)__name__
__module____qualname____doc__namecontext_kwdsclassmethodr   r    r(   r+   __classcell__r#   s   @r   r
   r
      s         " D'L; ; [;/ / / / / /   # # # [# # # # #r   r
   z*!s   *!c                   `    e Zd ZdZd ZdZdZ e ee	                    Z
dej        v r ed          Zn ed          Zed fd	            Zed	             Zed
             Zed             Z ej        dd          edd                        Zedd            Zed             Z xZS )r	   a  This class provides disabled password behavior for unix shadow files,
    and follows the :ref:`password-hash-api`.

    This class does not implement a hash, but instead matches the "disabled account"
    strings found in ``/etc/shadow`` on most Unix variants. "encrypting" a password
    will simply return the disabled account marker. It will reject all passwords,
    no matter the hash string. The :meth:`~passlib.ifc.PasswordHash.hash`
    method supports one optional keyword:

    :type marker: str
    :param marker:
        Optional marker string which overrides the platform default
        used to indicate a disabled account.

        If not specified, this will default to ``"*"`` on BSD systems,
        and use the Linux default ``"!"`` for all other platforms.
        (:attr:`!unix_disabled.default_marker` will contain the default value)

    .. versionadded:: 1.6
        This class was added as a replacement for the now-deprecated
        :class:`unix_fallback` class, which had some undesirable features.
    markerr   bsd*r%   Nc                      t          t          |           j        di |}|.|                     |          st	          d|z            ||_        |S )Nzinvalid marker: %rr   )r   r	   usingr   
ValueErrordefault_marker)r   r7   r"   subclsr#   s       r   r;   zunix_disabled.usingx   sa    0}c**088488<<'' @ !5!>???$*F!r   c                     t          |t                    rt          }n=t          |t                    rt          }n t
          j                            |d          | p	|d         |v S )Nr   r   )r   r   _MARKER_CHARSbytes_MARKER_BYTESr   r   r   )r   r   starts      r   r   zunix_disabled.identify   sd      dG$$ 	;!EEe$$ 	;!EE&,,T6:::x+47e++r   c                     t          j        |           |                     |          st           j                            |           dS )NF)r   r*   r   r   InvalidHashError)r   r'   r   s      r   r+   zunix_disabled.verify   sB    
6"""||D!! 	/&))#...ur   c                     |r5t          j        | |            | j        di |                    |          S t          j        |           | j        }|r|                     |          sJ t          |d          S )Nr7   paramr   )r   warn_hash_settings_deprecationr;   r   r*   r=   r   r   )r   r'   r"   r7   s       r   r   zunix_disabled.hash   s     	2-c488839$$t$$))&111
6"""#.#,,v.....V84444r   1.72.0
deprecatedremovedc                    |                      |          st          j                            |           |r%t          j        |           t          |d          S ||                     |          } |                     |          S )NconfigrG   r6   )r   r   r   rE   r*   r   r;   r   )r   r'   rP   r7   s       r   genhashzunix_disabled.genhash   s     ||F## 		$&))#... 	$v&&& x8888!iivi..88F###r   c                     |                      d          }|Bt          |d          }|                     |          r|                     |          }|r||z  }|S )N r   rG   )r   r   r   enable)r   r   outs      r   disablezunix_disabled.disable   sd    hhrll V444D||D!! (zz$'' t
r   c                     t          |d          }| j        D ]C}|                    |          r,|t          |          d          }|r|c S t	          d          Dt
          j                            |           )Nr   rG   zcannot restore original hash)r   _disable_prefixes
startswithlenr<   r   r   rE   )r   r   prefixorigs       r   rT   zunix_disabled.enable   s    T000+ 	E 	EFv&& ECKKLL) EKKK$%CDDDE f%%c***r   N)r,   r-   r.   r/   r0   setting_kwdsr1   tuplestrr@   rX   sysplatformr   r=   r2   r;   r   r+   r   r   deprecated_methodrQ   rV   rT   r3   r4   s   @r   r	   r	   R   sr        , DLLcc-0011 3
 3     [ , , [,.   [ 5 5 [5 RUE:::
$ 
$ 
$ [ ;:
$ 	 	 	 [	 	+ 	+ [	+ 	+ 	+ 	+ 	+r   r	   c                       e Zd ZdZd ZdZdZdZed             Z	edd            Z
edd            Z ej        d	d
          ed                         Z ej        d	d
          edd                        ZdS )r   a~  This class stores passwords in plaintext, and follows the :ref:`password-hash-api`.

    The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the
    following additional contextual keyword:

    :type encoding: str
    :param encoding:
        This controls the character encoding to use (defaults to ``utf-8``).

        This encoding will be used to encode :class:`!unicode` passwords
        under Python 2, and decode :class:`!bytes` hashes under Python 3.

    .. versionchanged:: 1.6
        The ``encoding`` keyword was added.
    r   encodingzutf-8c                 p    t          |t                    rdS t          j                            |d          r   r   r   s     r   r   zplaintext.identify   r   r   Nc                 ^    t          j        |           |s| j        }t          ||d          S )Nr'   )r   r*   default_encodingr   )r   r'   rf   s      r   r   zplaintext.hash   s5    
6""" 	,+HVXx888r   c                     |s| j         }t          ||d          }|                     |          st          j                            |           t          |                     ||          |          S )Nr   )ri   r   r   r   r   rE   r   r   )r   r'   r   rf   s       r   r+   zplaintext.verify   sk     	,+HT8V44||D!! 	/&))#...388FH55t<<<r   rJ   rK   rL   c                 ,    |                      d          S )NrS   )r   )r   s    r   	genconfigzplaintext.genconfig   s     xx||r   c                     |                      |          st          j                            |           |                     ||          S )Nre   )r   r   r   rE   r   )r   r'   rP   rf   s       r   rQ   zplaintext.genhash  sD     ||F## 	/&))#...xxx222r   r]   )r,   r-   r.   r/   r0   r^   r1   ri   r2   r   r   r+   r   rc   rl   rQ   r   r   r   r   r      s        " DL L; ; [; 9 9 9 [9 = = = [= RUE:::  [ ;: RUE:::3 3 3 [ ;:3 3 3r   r   )r/   ra   logging	getLoggerr,   logwarningsr   passlib.utilsr   r   passlib.utils.compatr   r   r   passlib.utils.handlersutilshandlersr   __all__ifcDisabledHashStaticHandlerr
   r@   rB   MinimalHandlerr	   r   r   r   r   <module>r|      sh    


 'g'11       5 4 4 4 4 4 4 4 C C C C C C C C C C # # # # # # # # #  4# 4# 4# 4# 4#BF')9 4# 4# 4#l $|+ |+ |+ |+ |+BF'): |+ |+ |+|93 93 93 93 93! 93 93 93 93 93r   