Package paramiko :: Class ServerInterface
[show private | hide private]
[frames | no frames]

Type ServerInterface

object --+
         |
        ServerInterface


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.)
Method Summary
int or InteractiveQuery check_auth_interactive(self, username, submethods)
Begin an interactive authentication challenge, if supported.
int or InteractiveQuery check_auth_interactive_response(self, responses)
Continue or finish an interactive authentication challenge, if supported.
int check_auth_none(self, username)
Determine if a client may open channels with no (further) authentication.
int check_auth_password(self, username, password)
Determine if a given username and password supplied by the client is acceptable for use in authentication.
int check_auth_publickey(self, username, key)
Determine if a given key supplied by the client is acceptable for use in authentication.
bool check_channel_exec_request(self, channel, command)
Determine if a shell command will be executed for the client.
bool check_channel_pty_request(self, channel, term, width, height, pixelwidth, pixelheight, modes)
Determine if a pseudo-terminal of the given dimensions (usually requested for shell access) can be provided on the given channel.
int check_channel_request(self, kind, chanid)
Determine if a channel request of a given type will be granted, and return OPEN_SUCCEEDED or an error code.
bool check_channel_shell_request(self, channel)
Determine if a shell will be provided to the client on the given channel.
bool check_channel_subsystem_request(self, channel, name)
Determine if a requested subsystem will be provided to the client on the given channel.
bool check_channel_window_change_request(self, channel, width, height, pixelwidth, pixelheight)
Determine if the pseudo-terminal on the given channel can be resized.
bool check_global_request(self, kind, msg)
Handle a global request of the given kind.
str get_allowed_auths(self, username)
Return a list of authentication methods supported by the server.
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

check_auth_interactive(self, username, submethods)

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.
Parameters:
username - the username of the authenticating client
           (type=str)
submethods - a comma-separated list of methods preferred by the client (usually empty)
           (type=str)
Returns:
AUTH_FAILED if this auth method isn't supported; otherwise an object containing queries for the user
           (type=int or InteractiveQuery)

check_auth_interactive_response(self, responses)

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.
Parameters:
responses - list of responses from the client
           (type=list(str))
Returns:
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
           (type=int or InteractiveQuery)

check_auth_none(self, username)

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.
Parameters:
username - the username of the client.
           (type=str)
Returns:
AUTH_FAILED if the authentication fails; AUTH_SUCCESSFUL if it succeeds.
           (type=int)

check_auth_password(self, username, password)

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.
Parameters:
username - the username of the authenticating client.
           (type=str)
password - the password given by the client.
           (type=str)
Returns:
AUTH_FAILED if the authentication fails; AUTH_SUCCESSFUL if it succeeds; AUTH_PARTIALLY_SUCCESSFUL if the password auth is successful, but authentication must continue.
           (type=int)

check_auth_publickey(self, username, key)

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.
Parameters:
username - the username of the authenticating client
           (type=str)
key - the key object provided by the client
           (type=PKey)
Returns:
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
           (type=int)

check_channel_exec_request(self, channel, command)

Determine if a shell command will be executed for the client. If this method returns True, the channel should be connected to the stdin, stdout, and stderr of the shell command.

The default implementation always returns False.
Parameters:
channel - the Channel the request arrived on.
           (type=Channel)
command - the command to execute.
           (type=str)
Returns:
True if this channel is now hooked up to the stdin, stdout, and stderr of the executing command; False if the command will not be executed.
           (type=bool)

Since: 1.1

check_channel_pty_request(self, channel, term, width, height, pixelwidth, pixelheight, modes)

Determine if a pseudo-terminal of the given dimensions (usually requested for shell access) can be provided on the given channel.

The default implementation always returns False.
Parameters:
channel - the Channel the pty request arrived on.
           (type=Channel)
term - type of terminal requested (for example, "vt100").
           (type=str)
width - width of screen in characters.
           (type=int)
height - height of screen in characters.
           (type=int)
pixelwidth - width of screen in pixels, if known (may be 0 if unknown).
           (type=int)
pixelheight - height of screen in pixels, if known (may be 0 if unknown).
           (type=int)
Returns:
True if the psuedo-terminal has been allocated; False otherwise.
           (type=bool)

check_channel_request(self, kind, chanid)

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:

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.
Parameters:
kind - the kind of channel the client would like to open (usually "session").
           (type=str)
chanid - ID of the channel
           (type=int)
Returns:
a success or failure code (listed above)
           (type=int)

check_channel_shell_request(self, channel)

Determine if a shell will be provided to the client on the given channel. If this method returns True, the channel should be connected to the stdin/stdout of a shell (or something that acts like a shell).

The default implementation always returns False.
Parameters:
channel - the Channel the request arrived on.
           (type=Channel)
Returns:
True if this channel is now hooked up to a shell; False if a shell can't or won't be provided.
           (type=bool)

check_channel_subsystem_request(self, channel, name)

Determine if a requested subsystem will be provided to the client on the given channel. If this method returns True, all future I/O through this channel will be assumed to be connected to the requested subsystem. An example of a subsystem is sftp.

The default implementation checks for a subsystem handler assigned via Transport.set_subsystem_handler. If one has been set, the handler is invoked and this method returns True. Otherwise it returns False.
Parameters:
channel - the Channel the pty request arrived on.
           (type=Channel)
name - name of the requested subsystem.
           (type=str)
Returns:
True if this channel is now hooked up to the requested subsystem; False if that subsystem can't or won't be provided.
           (type=bool)

Note: Because the default implementation uses the Transport to identify valid subsystems, you probably won't need to override this method.

check_channel_window_change_request(self, channel, width, height, pixelwidth, pixelheight)

Determine if the pseudo-terminal on the given channel can be resized. This only makes sense if a pty was previously allocated on it.

The default implementation always returns False.
Parameters:
channel - the Channel the pty request arrived on.
           (type=Channel)
width - width of screen in characters.
           (type=int)
height - height of screen in characters.
           (type=int)
pixelwidth - width of screen in pixels, if known (may be 0 if unknown).
           (type=int)
pixelheight - height of screen in pixels, if known (may be 0 if unknown).
           (type=int)
Returns:
True if the terminal was resized; False if not.
           (type=bool)

check_global_request(self, kind, msg)

Handle a global request of the given kind. This method is called in server mode and client mode, whenever the remote host makes a global request. If there are any arguments to the request, they will be in msg.

There aren't any useful global requests defined, aside from port forwarding, so usually this type of request is an extension to the protocol.

If the request was successful and you would like to return contextual data to the remote host, return a tuple. Items in the tuple will be sent back with the successful result. (Note that the items in the tuple can only be strings, ints, longs, or bools.)

The default implementation always returns False, indicating that it does not support any global requests.
Parameters:
kind - the kind of global request being made.
           (type=str)
msg - any extra arguments to the request.
           (type=Message)
Returns:
True or a tuple of data if the request was granted; False otherwise.
           (type=bool)

get_allowed_auths(self, username)

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".
Parameters:
username - the username requesting authentication.
           (type=str)
Returns:
a comma-separated list of authentication types
           (type=str)

Generated by Epydoc 2.1 on Sun Dec 4 11:16:47 2005 http://epydoc.sf.net