fakesshserver

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package fakesshserver implements a fake SSH server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(cmd string) (Process, bool)

Handler receives a command requested by an SSH client and decides whether to handle the request. If it returns true, a reply is sent to the client indicating that the command is accepted, and returned Process is called with stdin/stdout/stderr. If it returns false, an unsuccessful reply is sent to the client.

func ExactMatchHandler

func ExactMatchHandler(cmd string, proc Process) Handler

ExactMatchHandler constructs a Handler that replies to a command request by proc if it exactly matches with cmd.

func ShellHandler

func ShellHandler(prefix string) Handler

ShellHandler constructs a Handler that replies to a command request by running it as is with "sh -c" if its prefix matches with the given prefix.

type Process

type Process func(stdin io.Reader, stdout, stderr io.Writer) int

Process implements a simulated process started by a fake SSH server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server maintains resources related to a fake SSH server.

func Start

func Start(userKey *rsa.PublicKey, hostKey *rsa.PrivateKey, handlers []Handler) (*Server, error)

Start starts a new fake SSH server.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the address the server listens to.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the fake SSH server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL