command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package command checks the argv an agent asks the console to run, turns it into the remote command line, and matches it against a profile's allow rules. The agent never writes shell syntax: every argument is quoted for a POSIX shell, so ";", "|" or "$(...)" stay literal arguments.

Index

Constants

View Source
const (
	MaxArgs     = 64
	MaxArgBytes = 4096
	MaxBytes    = 16 << 10
)

Bounds of one argv.

Variables

This section is empty.

Functions

func Canonical

func Canonical(texts []string) []string

Canonical is the canonical text of each rule text that parses; others are kept as they are (ParseRules refuses them).

func Check

func Check(argv []string) error

Check validates argv: 1 to MaxArgs arguments, valid UTF-8, no NUL and no control or format character but tab, argv[0] not empty. Its errors name the argument's position, never its text.

func Display

func Display(argv []string) string

Display is argv for a screen: arguments that need quoting are quoted, the others shown as they are.

func Line

func Line(argv []string) string

Line is the remote command line of argv: every argument quoted. The server's login shell reads it; it cannot run anything but argv[0] with argv[1:] as its arguments.

func Quote

func Quote(s string) string

Quote quotes s for a POSIX shell: single quotes, each ' written '\”.

Types

type Rule

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

Rule is one allow rule: an argv pattern.

func ParseRule

func ParseRule(s string) (Rule, error)

ParseRule parses an allow rule: tokens separated by spaces. A token with *, ? or [ is a glob over one argument (path.Match: * and ? never match "/"); a last token ** matches zero or more remaining arguments. The first token is the program: it is a literal (no glob), so that a rule never opens another program. Its errors never quote the rule.

func (Rule) Match

func (r Rule) Match(argv []string) bool

Match reports whether argv matches the rule.

func (Rule) String

func (r Rule) String() string

String is the rule's canonical text (tokens joined by one space).

type Rules

type Rules []Rule

Rules is a list of allow rules.

func ParseRules

func ParseRules(texts []string) (Rules, error)

ParseRules parses each rule; the error names the rule's position.

func (Rules) Find

func (rs Rules) Find(argv []string) (Rule, bool)

Find returns the first rule argv matches.

Jump to

Keyboard shortcuts

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