← Back
Editing: cred_unix.cpython-38.pyc
U W[ � @ s� d Z ddlmZmZ ddlmZ ddlmZ ddlm Z ddl mZ ddlm Z ddlmZ dd lmZ dd lmZ dd� Zee�G d d� de��ZdZee ej�G dd� de��Ze� ZdS )z% Cred plugin for UNIX user accounts. � )�absolute_import�division)�implementer)�plugin)�ICheckerFactory)�ICredentialsChecker)�IUsernamePassword)�UnauthorizedLogin)�defer)� StringTypec C sn zddl }W n tk r$ d}Y nX |dkr6td��t|t�sJ|�d�}t| t�s^| �d�} |� || �| kS )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-8)�crypt�ImportError�NotImplementedError� isinstancer �decode)ZcryptedZpwr � r �;/usr/lib/python3/dist-packages/twisted/plugins/cred_unix.py�verifyCryptedPassword s r c @ s. e Zd ZdZefZdd� Zdd� Zdd� ZdS ) �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 C sj z$t |t�s|�d�}|�|�j}W n tk rD t�t� � Y S X |dkrRdS t ||�rft� |�S dS )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_passwd�KeyErrorr �failr r �succeed)�self�pwd�username�password�cryptedPassr r r �checkPwdA s zUNIXChecker.checkPwdc C sz z@t |t�s|�d�}t|jdd�r2|�|�j}n|�|�j}W n tk r` t � t� � Y S X t||�rvt � |�S dS )aC 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 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 �sp_pwdpN)r r r �getattrZstruct_spwdZgetspnamr# Zsp_pwdr r r r r r )r �spwdr r r! r r r � checkSpwd] s zUNIXChecker.checkSpwdc C s� |j |j }}zdd l}W n tk r2 d }Y nX |d k rV| �|||�}|d k rV|S zdd l}W n tk rz d }Y nX |d k r�| �|||�}|d k r�|S t�t � �S )Nr ) r r r r r"