pbin

package
v0.0.0-...-993558e Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: BSD-2-Clause-Patent Imports: 22 Imported by: 20

Documentation

Index

Constants

View Source
const (
	// MessageBufferSize is the starting size of the receive buffer. If
	// the buffer must be grown to accommodate larger messages, it is
	// expanded in increments of this value.
	MessageBufferSize = 1024
	// MaxMessageSize is the largest single message that can be written to
	// or read from the privileged binary.
	MaxMessageSize = MessageBufferSize * 1024
)
View Source
const (
	// DaosPrivHelperName is the name of the privileged helper.
	DaosPrivHelperName = "daos_server_helper"

	// DaosPrivHelperLogFileEnvVar is the name of the environment variable which
	// can be set to enable non-ERROR logging in the privileged helper.
	DaosPrivHelperLogFileEnvVar = "DAOS_HELPER_LOG_FILE"

	// DaosFWName is the name of the firmware helper.
	DaosFWName = "daos_firmware_helper"

	// DaosFWLogFileEnvVar is the name of the environment variable that
	// can be set to enable non-ERROR logging in the firmware helper.
	DaosFWLogFileEnvVar = "DAOS_FIRMWARE_LOG_FILE"
)
View Source
const PingMethod string = "Ping"

PingMethod is the string naming the ping method, which is universal to all privileged Apps.

Variables

This section is empty.

Functions

func CheckHelper

func CheckHelper(log logging.Logger, helperName string) error

CheckHelper attempts to invoke the helper to test for installation/setup problems. This function can be used to proactively identify problems and avoid console spam from multiple errors.

func PrivilegedHelperNotAvailable

func PrivilegedHelperNotAvailable(helperName string) *fault.Fault

func PrivilegedHelperNotPrivileged

func PrivilegedHelperNotPrivileged(helperName string) *fault.Fault

func PrivilegedHelperRequestFailed

func PrivilegedHelperRequestFailed(message string) *fault.Fault

func ReadMessage

func ReadMessage(conn io.Reader) ([]byte, error)

ReadMessage attempts to read a message from the sender and returns a buffer containing the message if successful. Relies on the writer being closed so that the reader gets an io.EOF to signal that the message is complete.

Types

type App

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

App is a framework for a privileged external helper application to be invoked by one or more DAOS processes.

func NewApp

func NewApp() *App

NewApp sets up a new privileged application.

func (*App) AddHandler

func (a *App) AddHandler(method string, handler RequestHandler)

AddHandler adds a new handler to the App for a given method. There is at most one handler per method.

func (*App) Name

func (a *App) Name() string

Name returns the name of this application.

func (*App) Run

func (a *App) Run() error

Run executes the helper application process.

func (*App) WithAllowedCallers

func (a *App) WithAllowedCallers(callers ...string) *App

WithAllowedCallers adds a list of process names allowed to call this application.

func (*App) WithInput

func (a *App) WithInput(reader io.ReadCloser) *App

WithInput adds a custom input source to the App.

func (*App) WithLogFile

func (a *App) WithLogFile(path string) *App

WithLogFile sets up App logging to a file at a given path.

func (*App) WithOutput

func (a *App) WithOutput(writer io.WriteCloser) *App

WithOutput adds a custom output sink to the App.

type ForwardChecker

type ForwardChecker interface {
	IsForwarded() bool
}

ForwardChecker defines an interface for any request that could have been forwarded.

type ForwardableRequest

type ForwardableRequest struct {
	Forwarded bool
}

ForwardableRequest is intended to be embedded into request types that can be forwarded to the privileged binary.

func (ForwardableRequest) IsForwarded

func (r ForwardableRequest) IsForwarded() bool

IsForwarded implements the ForwardChecker interface.

type Forwarder

type Forwarder struct {
	Disabled bool
	// contains filtered or unexported fields
}

Forwarder provides a common implementation of a request forwarder.

func NewForwarder

func NewForwarder(log logging.Logger, pbinName string) *Forwarder

NewForwarder returns a configured *Forwarder.

func (*Forwarder) CanForward

func (f *Forwarder) CanForward() bool

CanForward indicates whether commands can be forwarded to the forwarder's designated binary.

func (*Forwarder) GetBinaryName

func (f *Forwarder) GetBinaryName() string

GetBinaryName returns the name of the binary requests will be forwarded to.

func (*Forwarder) SendReq

func (f *Forwarder) SendReq(method string, fwdReq interface{}, fwdRes interface{}) error

SendReq is responsible for marshaling the forwarded request into a message that is sent to the privileged binary, then unmarshaling the response for the caller.

type PingResp

type PingResp struct {
	Version string
	AppName string
}

PingResp is the response from a privileged helper application to a Ping command.

type Process

type Process struct{}

Process is a mechanism to interact with the current process.

func (*Process) CurrentProcessName

func (p *Process) CurrentProcessName() string

CurrentProcessName fetches the name of the running process.

func (*Process) ElevatePrivileges

func (p *Process) ElevatePrivileges() error

ElevatePrivileges raises the process privileges.

func (*Process) IsPrivileged

func (p *Process) IsPrivileged() bool

IsPrivileged determines whether the process is running as a privileged user.

func (*Process) ParentProcessName

func (p *Process) ParentProcessName() (string, error)

ParentProcessName fetches the name of the parent process, or returns an error otherwise.

type Request

type Request struct {
	Method  string
	Payload json.RawMessage
}

Request represents a request sent to the privileged binary. The payload field contains a JSON-encoded representation of the wrapped request.

type RequestHandler

type RequestHandler interface {
	Handle(logging.Logger, *Request) *Response
}

RequestHandler is an interface that handles a pbin.Request.

type Response

type Response struct {
	Error   *fault.Fault
	Payload json.RawMessage
}

Response represents a response received from the privileged binary. The payload field contains a JSON-encoded representation of the wrapped response.

func ExecReq

func ExecReq(parent context.Context, log logging.Logger, binPath string, req *Request) (res *Response, err error)

ExecReq executes the supplied Request by starting a child process to service the request. Returns a Response if successful.

func NewResponseWithError

func NewResponseWithError(err error) *Response

NewResponseWithError creates a new pbin.Response indicating a failure.

func NewResponseWithPayload

func NewResponseWithPayload(payloadSrc interface{}) *Response

NewResponseWithPayload creates a new pbin.Response with a payload structure marshalled into JSON.

type StdioAddr

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

StdioAddr implements net.Addr to provide an emulated network address for use with StdioConn.

func (*StdioAddr) Network

func (s *StdioAddr) Network() string

func (*StdioAddr) String

func (s *StdioAddr) String() string

type StdioConn

type StdioConn struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StdioConn implements net.Conn to provide an emulated network connection between two processes over stdin/stdout.

func NewStdioConn

func NewStdioConn(localID, remoteID string, in io.ReadCloser, out io.WriteCloser) *StdioConn

func (*StdioConn) Close

func (sc *StdioConn) Close() error

func (*StdioConn) CloseRead

func (sc *StdioConn) CloseRead() error

func (*StdioConn) CloseWrite

func (sc *StdioConn) CloseWrite() error

func (*StdioConn) LocalAddr

func (sc *StdioConn) LocalAddr() net.Addr

func (*StdioConn) Read

func (sc *StdioConn) Read(b []byte) (int, error)

func (*StdioConn) RemoteAddr

func (sc *StdioConn) RemoteAddr() net.Addr

func (*StdioConn) SetDeadline

func (sc *StdioConn) SetDeadline(t time.Time) error

func (*StdioConn) SetReadDeadline

func (sc *StdioConn) SetReadDeadline(t time.Time) error

func (*StdioConn) SetWriteDeadline

func (sc *StdioConn) SetWriteDeadline(t time.Time) error

func (*StdioConn) String

func (sc *StdioConn) String() string

func (*StdioConn) Write

func (sc *StdioConn) Write(b []byte) (int, error)

type StdioListener

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

StdioListener wraps a *StdioConn to implement net.Listener.

func NewStdioListener

func NewStdioListener(conn *StdioConn) *StdioListener

func (*StdioListener) Accept

func (sl *StdioListener) Accept() (net.Conn, error)

func (*StdioListener) Addr

func (sl *StdioListener) Addr() net.Addr

func (*StdioListener) Close

func (sl *StdioListener) Close() error

Jump to

Keyboard shortcuts

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