connectors.tunnel_dispatcher

Provides a stdin/stdout based protocol to safely dispatch commands and return their results over any connection that forwards both stdin/stdout, as well as some other needed remote system related utilities.

class tunnel_dispatcher.RemoteOSError

An exception type for remote OSErrors.

class tunnel_dispatcher.Connection

Represents a connection to this dispatcher via an input and output buffer.

def Connection.flush()

def Connection.flush(self) -> None:

Flushes the output buffer.

def Connection.read()

def Connection.read(self, count: int) -> bytes:

Reads exactly the given amount of bytes.

def Connection.write()

def Connection.write(self, data: bytes, count: int) -> None:

Writes exactly the given amount of bytes from data.

def Connection.write_packet()

Writes the given packet.

class tunnel_dispatcher.PacketOk

This packet is used by some requests as a generic successful status indicator.

class tunnel_dispatcher.PacketAck

This packet is used to acknowledge a previous PacketCheckAlive packet.

class tunnel_dispatcher.PacketCheckAlive

This packet is used to check whether a connection is alive. The receiver must answer with PacketAck immediately.

def PacketCheckAlive.handle()

Responds with PacketAck.

class tunnel_dispatcher.PacketExit

This packet is used to signal the server to close the connection and end the dispatcher.

def PacketExit.handle()

Signals the connection to close.

class tunnel_dispatcher.PacketOSError

This packet is sent when an OSError occurs.

class tunnel_dispatcher.PacketInvalidField

This packet is used when an invalid value was given in a previous packet.

class tunnel_dispatcher.PacketProcessCompleted

This packet is used to return the results of a process.

class tunnel_dispatcher.PacketProcessError

This packet is used to indicate an error when running a process or when running the preexec_fn.

class tunnel_dispatcher.PacketProcessRun

This packet is used to run a process.

def PacketProcessRun.handle()

Runs the requested command.

class tunnel_dispatcher.PacketStatResult

This packet is used to return the results of a stat packet.

class tunnel_dispatcher.PacketStat

This packet is used to retrieve information about a file or directory.

def PacketStat.handle()

Stats the requested path.

class tunnel_dispatcher.PacketResolveResult

This packet is used to return the results of a resolve packet.

class tunnel_dispatcher.PacketResolveUser

This packet is used to canonicalize a user name / uid and to ensure it exists. If None is given, it queries the current user.

def PacketResolveUser.handle()

Resolves the requested user.

class tunnel_dispatcher.PacketResolveGroup

This packet is used to canonicalize a group name / gid and to ensure it exists. If None is given, it queries the current group.

def PacketResolveGroup.handle()

Resolves the requested group.

class tunnel_dispatcher.PacketUpload

This packet is used to upload the given content to the remote and save it as a file. Overwrites existing files. Responds with PacketOk if saving was successful, or PacketInvalidField if any field contained an invalid value.

def PacketUpload.handle()

Saves the content under the given path.

class tunnel_dispatcher.PacketDownloadResult

This packet is used to return the content of a file.

class tunnel_dispatcher.PacketDownload

This packet is used to download the contents of a given file. Responds with PacketDownloadResult if reading was successful, or PacketInvalidField if any field contained an invalid value.

def PacketDownload.handle()

Reads the file.

class tunnel_dispatcher.PacketUserEntry

This packet is used to return information about a user.

Attributes

attr name

The name of the user

attr uid

The numerical user id

attr group

The name of the primary group

attr gid

The numerical primary group id

attr groups

All names of the supplementary groups this user belongs to

attr password_hash

The password hash from shadow

attr gecos

The comment (GECOS) field of the user

attr home

The home directory of the user

attr shell

The default shell of the user

class tunnel_dispatcher.PacketQueryUser

This packet is used to get information about a group via pwd.getpw*.

Attributes

attr user

User name or decimal uid

attr query_password_hash

Whether the current password hash from shadow should also be returned

def PacketQueryUser.handle()

Queries the requested user.

class tunnel_dispatcher.PacketGroupEntry

This packet is used to return information about a group.

Attributes

attr name

The name of the group

attr gid

The numerical group id

attr members

All the group member's user names

class tunnel_dispatcher.PacketQueryGroup

This packet is used to get information about a group via grp.getgr*.

Attributes

attr group

Group name or decimal gid

def PacketQueryGroup.handle()

Queries the requested group.

class tunnel_dispatcher.PacketEnvironVar

This packet is used to return an environment variable.

Attributes

attr value

The value of the environment variable, if it was set.

class tunnel_dispatcher.PacketGetenv

This packet is used to get an environment variable.

Attributes

attr key

The environment variable to retrieve

def PacketGetenv.handle()

Gets the requested environment variable.

Functions

def tunnel_dispatcher.Packet()

Decorator for packet types. Registers the packet and generates read and write methods.

def tunnel_dispatcher.receive_packet()

Receives the next packet from the given connection.

Parameters

  • conn: The connection

  • request: The corresponding request packet, if any.

Returns

  • Any: The received packet

Raises

  • RemoteOSError: An OSError occurred on the remote host.

  • IOError: When an issue on the connection occurs.

  • ValueError: When an PacketInvalidField is received as the response and a corresponding request packet was given.

Last updated