Current File : //proc/353637/cwd/lib/python3/dist-packages/twisted/plugins/__pycache__/cred_unix.cpython-312.pyc |
�
Ϫ�f? � �� � d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ d � Z ee� G d
� d� � ZdZ eeej$ � G d
� d� � Z e� Zy)z%
Cred plugin for UNIX user accounts.
� )�implementer)�plugin)�ICredentialsChecker)�IUsernamePassword)�UnauthorizedLogin)�ICheckerFactory)�deferc �\ � ddl }|�t d� �t |t � r|j d� }t | t � r| j d� } |j || � }t |t � r|j d� }|| k( S # t $ r d}Y ��w xY w# t $ r Y yw xY w)a�
Use L{crypt.crypt} to Verify that an unencrypted
password matches the encrypted password.
@param crypted: The encrypted password, obtained from
the Unix password database or Unix shadow
password database.
@param pw: The unencrypted password.
@return: L{True} if there is successful match, else L{False}.
@rtype: L{bool}
r Nz(cred_unix not supported on this platform�utf-8F)�crypt�ImportError�NotImplementedError�
isinstance�bytes�decode�OSError)�crypted�pwr �
crypted_checks �;/usr/lib/python3/dist-packages/twisted/plugins/cred_unix.py�verifyCryptedPasswordr s� � ���
�}�!�"L�M�M��"�e��
�Y�Y�w�
���'�5�!��.�.��)������B��0�
��m�U�+�)�0�0��9�M���'�'�� � ����� � ���s# �B �7B �B�B� B+�*B+c �( � e Zd ZdZefZd� Zd� Zd� Zy)�UNIXCheckera
A credentials checker for a UNIX server. This will check that
an authenticating username/password is a valid user on the system.
Does not work on Windows.
Right now this supports Python's pwd and spwd modules, if they are
installed. It does not support PAM.
c �" � t |t � r|j d� }|j |� j }|dv ryt ||� rt
j |� S y# t $ r t
j t � � cY S w xY w)a3
Obtain the encrypted password for C{username} from the Unix password
database using L{pwd.getpwnam}, and see if it it matches it matches
C{password}.
@param pwd: Module which provides functions which
access to the Unix password database.
@type pwd: C{module}
@param username: The user to look up in the Unix password database.
@type username: L{unicode}/L{str} or L{bytes}
@param password: The password to compare.
@type username: L{unicode}/L{str} or L{bytes}
r )�*�xN)r r r �getpwnam� pw_passwdr r �succeed�KeyError�failr )�self�pwd�username�password�cryptedPasss r �checkPwdzUNIXChecker.checkPwdC s� � � /��(�E�*�#�?�?�7�3���,�,�x�0�:�:�K� �j�(��&�{�H�=��}�}�X�.�.� >��
� 3��:�:�/�1�2�2� 3�s �<A% �%&B�
Bc �~ � t |t � r|j d� }t |j dd� r|j |� j }n|j |� j }t ||� rt j |� S y# t $ r t j t � � cY S w xY w)aE
Obtain the encrypted password for C{username} from the
Unix shadow password database using L{spwd.getspnam},
and see if it it matches it matches C{password}.
@param spwd: Module which provides functions which
access to the Unix shadow password database.
@type spwd: C{module}
@param username: The user to look up in the Unix password database.
@type username: L{unicode}/L{str} or L{bytes}
@param password: The password to compare.
@type username: L{unicode}/L{str} or L{bytes}
r �sp_pwdpN)r r r �getattr�struct_spwd�getspnamr) �sp_pwdr r r r r! r )r"