shexec

package
v0.0.0-...-c6a8797 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 36 Imported by: 3

Documentation

Index

Constants

View Source
const ClientCommandFmt = `` /* 221-byte string literal not displayed */
View Source
const DefaultMaxPtySize = 1024 * 1024
View Source
const FirstExtraFilesFdNum = 3
View Source
const ForceDebugRcFile = false
View Source
const ForceDebugReturnState = false
View Source
const InstallCommandFmt = `` /* 350-byte string literal not displayed */
View Source
const MaxFdNum = 1023
View Source
const MaxMaxPtySize = 100 * 1024 * 1024
View Source
const MaxRunDataSize = 1024 * 1024
View Source
const MaxTermCols = 1024
View Source
const MaxTermRows = 1024
View Source
const MaxTotalRunDataSize = 10 * MaxRunDataSize
View Source
const MinMaxPtySize = 16 * 1024
View Source
const MinTermCols = 10
View Source
const MinTermRows = 2
View Source
const NotFoundVersion = "v0.0"
View Source
const ReturnStateReadWaitTime = 2 * time.Second
View Source
const RtnStateFdNum = 20
View Source
const ShellVarName = "SHELL"
View Source
const SigKillWaitTime = 2 * time.Second

Variables

This section is empty.

Functions

func AddRunData

func AddRunData(pk *packet.RunPacketType, data string, dataType string) (int, error)

func DetectGoArch

func DetectGoArch(uname string) (string, string, error)

func GetTerminalSize

func GetTerminalSize() (int, int, error)

func GetWinsize

func GetWinsize(p *packet.RunPacketType) *pty.Winsize

func HasDupStdin

func HasDupStdin(fds []packet.RemoteFd) bool

func IgnoreSigPipe

func IgnoreSigPipe()

in detached run mode, we don't want mshell to die from signals since we want mshell to persist even if the mshell --server is terminated

func MakeAndCopyStdinFifo

func MakeAndCopyStdinFifo(dst *os.File, fifoName string) error

this will never return (unless there is an error creating/opening the file), as fifoFile will never EOF

func MakeClientCommandStr

func MakeClientCommandStr() string

func MakeDetachedExecCmd

func MakeDetachedExecCmd(pk *packet.RunPacketType, cmdTty *os.File) (*exec.Cmd, error)

func MakeEnv0

func MakeEnv0(envMap map[string]string) []byte

func MakeInitPacket

func MakeInitPacket() *packet.InitPacketType

func MakeInstallCommandStr

func MakeInstallCommandStr() string

func MakeLocalExecCmd

func MakeLocalExecCmd(cmdStr string, sapi shellapi.ShellApi) *exec.Cmd

func MakeMShellSingleCmd

func MakeMShellSingleCmd() (*exec.Cmd, error)

func MakeRunnerExec

func MakeRunnerExec(ck base.CommandKey) (*exec.Cmd, error)

func MakeServerInitPacket

func MakeServerInitPacket() (*packet.InitPacketType, error)

func MakeSimpleStaticWriterPipe

func MakeSimpleStaticWriterPipe(data []byte) (*os.File, error)

returns (pr, err)

func MaxFdNumInPacket

func MaxFdNumInPacket(pk *packet.RunPacketType) int

func NextFreeFdNum

func NextFreeFdNum(pk *packet.RunPacketType) (int, error)

func ParseEnv0

func ParseEnv0(env []byte) map[string]string

func RunInstallFromCmd

func RunInstallFromCmd(ctx context.Context, ecmd ConnInterface, tryDetect bool, mshellStream io.Reader, mshellReaderFn MShellBinaryReaderFn, msgFn func(string)) error

func SendRunPacketAndRunData

func SendRunPacketAndRunData(ctx context.Context, sender *packet.PacketSender, runPacket *packet.RunPacketType) error

func SetupSignalsForDetach

func SetupSignalsForDetach()

in detached run mode, we don't want mshell to die from signals since we want mshell to persist even if the mshell --server is terminated

func ValidateRemoteFds

func ValidateRemoteFds(rfds []packet.RemoteFd) error

func ValidateRunPacket

func ValidateRunPacket(pk *packet.RunPacketType) error

Types

type ClientOpts

type ClientOpts struct {
	SSHOpts      SSHOpts
	Command      string
	Fds          []packet.RemoteFd
	Cwd          string
	Debug        bool
	Sudo         bool
	SudoWithPass bool
	SudoPw       string
	Detach       bool
	UsePty       bool
}

type ClientProc

type ClientProc struct {
	Cmd          ConnInterface
	InitPk       *packet.InitPacketType
	StartTs      time.Time
	StdinWriter  io.WriteCloser
	StdoutReader io.ReadCloser
	StderrReader io.ReadCloser
	Input        *packet.PacketSender
	Output       *packet.PacketParser
}

func MakeClientProc

func MakeClientProc(ctx context.Context, ecmd ConnInterface) (*ClientProc, error)

returns (clientproc, initpk, error)

func (*ClientProc) Close

func (cproc *ClientProc) Close()

func (*ClientProc) ProxySingleOutput

func (cproc *ClientProc) ProxySingleOutput(ck base.CommandKey, sender *packet.PacketSender, packetCallback func(packet.PacketType))

type CmdWrap

type CmdWrap struct {
	Cmd *exec.Cmd
}

func (CmdWrap) Kill

func (cw CmdWrap) Kill()

func (CmdWrap) Parser

func (CmdWrap) Sender

func (cw CmdWrap) Sender() (*packet.PacketSender, io.WriteCloser, error)

func (CmdWrap) Start

func (cw CmdWrap) Start() error

func (CmdWrap) StderrPipe

func (cw CmdWrap) StderrPipe() (io.ReadCloser, error)

func (CmdWrap) StdinPipe

func (cw CmdWrap) StdinPipe() (io.WriteCloser, error)

func (CmdWrap) StdoutPipe

func (cw CmdWrap) StdoutPipe() (io.ReadCloser, error)

func (CmdWrap) Wait

func (cw CmdWrap) Wait() error

type ConnInterface

type ConnInterface interface {
	Kill()
	Wait() error
	Sender() (*packet.PacketSender, io.WriteCloser, error)
	Parser() (*packet.PacketParser, io.ReadCloser, io.ReadCloser, error)
	Start() error
	StdinPipe() (io.WriteCloser, error)
	StdoutPipe() (io.ReadCloser, error)
	StderrPipe() (io.ReadCloser, error)
}

type FdContext

type FdContext interface {
	GetWriter(fdNum int) io.WriteCloser
	GetReader(fdNum int) io.ReadCloser
}

type InstallOpts

type InstallOpts struct {
	SSHOpts SSHOpts
	ArchStr string
	OptName string
	Detect  bool
	CmdPty  *os.File
}

type InvalidPacketError

type InvalidPacketError struct {
	InvalidPk *packet.PacketType
}

func (InvalidPacketError) Error

func (ipe InvalidPacketError) Error() string

type MShellBinaryReaderFn

type MShellBinaryReaderFn func(version string, goos string, goarch string) (io.ReadCloser, error)

type ReturnStateBuf

type ReturnStateBuf struct {
	Lock     *sync.Mutex
	Buf      []byte
	Done     bool
	Err      error
	Reader   *os.File
	FdNum    int
	EndBytes []byte
	DoneCh   chan bool
}

func MakeReturnStateBuf

func MakeReturnStateBuf() *ReturnStateBuf

func (*ReturnStateBuf) Run

func (rs *ReturnStateBuf) Run()

TODO limit size of read state buffer

type SSHOpts

type SSHOpts struct {
	SSHHost        string
	SSHOptsStr     string
	SSHIdentity    string
	SSHUser        string
	SSHPort        int
	SSHErrorsToTty bool
	BatchMode      bool
}

func (SSHOpts) MakeMShellSSHOpts

func (opts SSHOpts) MakeMShellSSHOpts() string

func (SSHOpts) MakeSSHExecCmd

func (opts SSHOpts) MakeSSHExecCmd(remoteCommand string, sapi shellapi.ShellApi) *exec.Cmd

type SessionWrap

type SessionWrap struct {
	Session  *ssh.Session
	StartCmd string
}

func (SessionWrap) Kill

func (sw SessionWrap) Kill()

func (SessionWrap) Parser

func (SessionWrap) Sender

func (SessionWrap) Start

func (sw SessionWrap) Start() error

func (SessionWrap) StderrPipe

func (sw SessionWrap) StderrPipe() (io.ReadCloser, error)

func (SessionWrap) StdinPipe

func (sw SessionWrap) StdinPipe() (io.WriteCloser, error)

func (SessionWrap) StdoutPipe

func (sw SessionWrap) StdoutPipe() (io.ReadCloser, error)

func (SessionWrap) Wait

func (sw SessionWrap) Wait() error

type ShExecType

type ShExecType struct {
	Lock           *sync.Mutex // only locks "Exited" field
	StartTs        time.Time
	CK             base.CommandKey
	FileNames      *base.CommandFileNames
	Cmd            *exec.Cmd
	CmdPty         *os.File
	MaxPtySize     int64
	Multiplexer    *mpio.Multiplexer
	Detached       bool
	DetachedOutput *packet.PacketSender
	RunnerOutFd    *os.File
	MsgSender      *packet.PacketSender // where to send out-of-band messages back to calling proceess
	ReturnState    *ReturnStateBuf
	Exited         bool   // locked via Lock
	TmpRcFileName  string // file *or* directory holding temporary rc file(s)
	SAPI           shellapi.ShellApi
	ShellPrivKey   *ecdh.PrivateKey
	SudoWriter     *os.File
}

func RunCommandSimple

func RunCommandSimple(pk *packet.RunPacketType, sender *packet.PacketSender, fromServer bool) (rtnShExec *ShExecType, rtnErr error)

func (*ShExecType) Close

func (c *ShExecType) Close()

func (*ShExecType) IsExited

func (c *ShExecType) IsExited() bool

func (*ShExecType) MakeCmdStartPacket

func (c *ShExecType) MakeCmdStartPacket(reqId string) *packet.CmdStartPacketType

func (*ShExecType) ProcWait

func (c *ShExecType) ProcWait() error

func (*ShExecType) RunRemoteIOAndWait

func (cmd *ShExecType) RunRemoteIOAndWait(packetParser *packet.PacketParser, sender *packet.PacketSender)

func (*ShExecType) SendSignal

func (s *ShExecType) SendSignal(sig syscall.Signal)

func (*ShExecType) WaitForCommand

func (c *ShExecType) WaitForCommand() *packet.CmdDonePacketType

called in waveshell --single mode (returns the real cmddone packet)

type ShExecUPR

type ShExecUPR struct {
	ShExec *ShExecType
	UPR    packet.UnknownPacketReporter
}

func (ShExecUPR) UnknownPacket

func (s ShExecUPR) UnknownPacket(pk packet.PacketType)

type StdContext

type StdContext struct{}

func (StdContext) GetReader

func (StdContext) GetReader(fdNum int) io.ReadCloser

func (StdContext) GetWriter

func (StdContext) GetWriter(fdNum int) io.WriteCloser

type WaveshellLaunchError

type WaveshellLaunchError struct {
	InitPk *packet.InitPacketType
}

func (WaveshellLaunchError) Error

func (wle WaveshellLaunchError) Error() string

Jump to

Keyboard shortcuts

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