File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/__pycache__/server.cpython-310.pyc
Back
o �h�v � @ sf d Z ddlZddlmZ ddlmZmZmZmZm Z G dd� d�Z G dd� d�ZG d d � d ej�Z dS )zD `.ServerInterface` is an interface to override for server support. � N)�util)�DEBUG�ERROR�'OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED�AUTH_FAILED�AUTH_SUCCESSFULc @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dd� Z edfdd�Zedfdd�Z dd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� Zd%d&� Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zd/d0� ZdS )1�ServerInterfacea This class defines an interface for controlling the behavior of Paramiko in server mode. Methods on this class are called from Paramiko's primary thread, so you shouldn't do too much work in them. (Certainly nothing that blocks or sleeps.) c C � t S )a. Determine if a channel request of a given type will be granted, and return ``OPEN_SUCCEEDED`` or an error code. This method is called in server mode when the client requests a channel, after authentication is complete. If you allow channel requests (and an ssh server that didn't would be useless), you should also override some of the channel request methods below, which are used to determine which services will be allowed on a given channel: - `check_channel_pty_request` - `check_channel_shell_request` - `check_channel_subsystem_request` - `check_channel_window_change_request` - `check_channel_x11_request` - `check_channel_forward_agent_request` The ``chanid`` parameter is a small number that uniquely identifies the channel within a `.Transport`. A `.Channel` object is not created unless this method returns ``OPEN_SUCCEEDED`` -- once a `.Channel` object is created, you can call `.Channel.get_id` to retrieve the channel ID. The return value should either be ``OPEN_SUCCEEDED`` (or ``0``) to allow the channel request, or one of the following error codes to reject it: - ``OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED`` - ``OPEN_FAILED_CONNECT_FAILED`` - ``OPEN_FAILED_UNKNOWN_CHANNEL_TYPE`` - ``OPEN_FAILED_RESOURCE_SHORTAGE`` The default implementation always returns ``OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED``. :param str kind: the kind of channel the client would like to open (usually ``"session"``). :param int chanid: ID of the channel :return: an `int` success or failure code (listed above) �r )�self�kind�chanid� r �E/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/server.py�check_channel_request, s +z%ServerInterface.check_channel_requestc C � dS )a\ Return a list of authentication methods supported by the server. This list is sent to clients attempting to authenticate, to inform them of authentication methods that might be successful. The "list" is actually a string of comma-separated names of types of authentication. Possible values are ``"password"``, ``"publickey"``, and ``"none"``. The default implementation always returns ``"password"``. :param str username: the username requesting authentication. :return: a comma-separated `str` of authentication types �passwordr �r �usernamer r r �get_allowed_authsY s z!ServerInterface.get_allowed_authsc C r )a Determine if a client may open channels with no (further) authentication. Return ``AUTH_FAILED`` if the client must authenticate, or ``AUTH_SUCCESSFUL`` if it's okay for the client to not authenticate. The default implementation always returns ``AUTH_FAILED``. :param str username: the username of the client. :return: ``AUTH_FAILED`` if the authentication fails; ``AUTH_SUCCESSFUL`` if it succeeds. :rtype: int �r r r r r �check_auth_nonej � zServerInterface.check_auth_nonec C r )a2 Determine if a given username and password supplied by the client is acceptable for use in authentication. Return ``AUTH_FAILED`` if the password is not accepted, ``AUTH_SUCCESSFUL`` if the password is accepted and completes the authentication, or ``AUTH_PARTIALLY_SUCCESSFUL`` if your authentication is stateful, and this key is accepted for authentication, but more authentication is required. (In this latter case, `get_allowed_auths` will be called to report to the client what options it has for continuing the authentication.) The default implementation always returns ``AUTH_FAILED``. :param str username: the username of the authenticating client. :param str password: the password given by the client. :return: ``AUTH_FAILED`` if the authentication fails; ``AUTH_SUCCESSFUL`` if it succeeds; ``AUTH_PARTIALLY_SUCCESSFUL`` if the password auth is successful, but authentication must continue. :rtype: int r )r r r r r r �check_auth_password} � z#ServerInterface.check_auth_passwordc C r )a� Determine if a given key supplied by the client is acceptable for use in authentication. You should override this method in server mode to check the username and key and decide if you would accept a signature made using this key. Return ``AUTH_FAILED`` if the key is not accepted, ``AUTH_SUCCESSFUL`` if the key is accepted and completes the authentication, or ``AUTH_PARTIALLY_SUCCESSFUL`` if your authentication is stateful, and this password is accepted for authentication, but more authentication is required. (In this latter case, `get_allowed_auths` will be called to report to the client what options it has for continuing the authentication.) Note that you don't have to actually verify any key signtature here. If you're willing to accept the key, Paramiko will do the work of verifying the client's signature. The default implementation always returns ``AUTH_FAILED``. :param str username: the username of the authenticating client :param .PKey key: the key object provided by the client :return: ``AUTH_FAILED`` if the client can't authenticate with this key; ``AUTH_SUCCESSFUL`` if it can; ``AUTH_PARTIALLY_SUCCESSFUL`` if it can authenticate with this key but must continue with authentication :rtype: int r )r r �keyr r r �check_auth_publickey� s z$ServerInterface.check_auth_publickeyc C r )a Begin an interactive authentication challenge, if supported. You should override this method in server mode if you want to support the ``"keyboard-interactive"`` auth type, which requires you to send a series of questions for the client to answer. Return ``AUTH_FAILED`` if this auth method isn't supported. Otherwise, you should return an `.InteractiveQuery` object containing the prompts and instructions for the user. The response will be sent via a call to `check_auth_interactive_response`. The default implementation always returns ``AUTH_FAILED``. :param str username: the username of the authenticating client :param str submethods: a comma-separated list of methods preferred by the client (usually empty) :return: ``AUTH_FAILED`` if this auth method isn't supported; otherwise an object containing queries for the user :rtype: int or `.InteractiveQuery` r )r r � submethodsr r r �check_auth_interactive� r z&ServerInterface.check_auth_interactivec C r )a� Continue or finish an interactive authentication challenge, if supported. You should override this method in server mode if you want to support the ``"keyboard-interactive"`` auth type. Return ``AUTH_FAILED`` if the responses are not accepted, ``AUTH_SUCCESSFUL`` if the responses are accepted and complete the authentication, or ``AUTH_PARTIALLY_SUCCESSFUL`` if your authentication is stateful, and this set of responses is accepted for authentication, but more authentication is required. (In this latter case, `get_allowed_auths` will be called to report to the client what options it has for continuing the authentication.) If you wish to continue interactive authentication with more questions, you may return an `.InteractiveQuery` object, which should cause the client to respond with more answers, calling this method again. This cycle can continue indefinitely. The default implementation always returns ``AUTH_FAILED``. :param responses: list of `str` responses from the client :return: ``AUTH_FAILED`` if the authentication fails; ``AUTH_SUCCESSFUL`` if it succeeds; ``AUTH_PARTIALLY_SUCCESSFUL`` if the interactive auth is successful, but authentication must continue; otherwise an object containing queries for the user :rtype: int or `.InteractiveQuery` r )r � responsesr r r �check_auth_interactive_response� s z/ServerInterface.check_auth_interactive_responseNc C � |t krt S tS )a� Authenticate the given user to the server if he is a valid krb5 principal. :param str username: The username of the authenticating client :param int gss_authenticated: The result of the krb5 authentication :param str cc_filename: The krb5 client credentials cache filename :return: ``AUTH_FAILED`` if the user is not authenticated otherwise ``AUTH_SUCCESSFUL`` :rtype: int :note: Kerberos credential delegation is not supported. :see: `.ssh_gss` :note: : We are just checking in L{AuthHandler} that the given user is a valid krb5 principal! We don't check if the krb5 principal is allowed to log in on the server, because there is no way to do that in python. So if you develop your own SSH server with paramiko for a certain platform like Linux, you should call C{krb5_kuserok()} in your local kerberos library to make sure that the krb5_principal has an account on the server and is allowed to log in as a user. :see: http://www.unix.com/man-page/all/3/krb5_kuserok/ �r r �r r �gss_authenticated�cc_filer r r �check_auth_gssapi_with_mic� s z*ServerInterface.check_auth_gssapi_with_micc C r! )a` Authenticate the given user to the server if he is a valid krb5 principal and GSS-API Key Exchange was performed. If GSS-API Key Exchange was not performed, this authentication method won't be available. :param str username: The username of the authenticating client :param int gss_authenticated: The result of the krb5 authentication :param str cc_filename: The krb5 client credentials cache filename :return: ``AUTH_FAILED`` if the user is not authenticated otherwise ``AUTH_SUCCESSFUL`` :rtype: int :note: Kerberos credential delegation is not supported. :see: `.ssh_gss` `.kex_gss` :note: : We are just checking in L{AuthHandler} that the given user is a valid krb5 principal! We don't check if the krb5 principal is allowed to log in on the server, because there is no way to do that in python. So if you develop your own SSH server with paramiko for a certain platform like Linux, you should call C{krb5_kuserok()} in your local kerberos library to make sure that the krb5_principal has an account on the server and is allowed to log in as a user. :see: http://www.unix.com/man-page/all/3/krb5_kuserok/ r"