system

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package system implements cross-platform abstractions for user-management access-control and sub-process execution geared at executing sub-process with best-effort sandboxing.

The system package provides the following platform specific types and methods.

 system.User
 system.User.Remove()
 system.Group
 system.Process
 system.Process.Wait() bool
 system.Process.Kill()
 system.SetSize(columns, rows uint16) error
	system.CreateUser(homeFolder string, groups []*Group) (*User, error)
 system.FindGroup(name string) (*Group, error)
	system.StartProcess(options ProcessOptions) (*Process, error)
	system.KillByOwner(user *User) error

Index

Constants

This section is empty.

Variables

View Source
var ErrUserGroupNotFound = errors.New("User group doesn't exist!")

ErrUserGroupNotFound indicates that a given user-group doesn't exist.

Functions

func KillByOwner

func KillByOwner(user *User) error

KillByOwner will kill all process with the given owner.

Types

type Group

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

Group is a representation of a system user-group.

func FindGroup

func FindGroup(name string) (*Group, error)

FindGroup will find the user-group given by name.

type Process

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

Process is a representation of a system process.

func StartProcess

func StartProcess(options ProcessOptions) (*Process, error)

StartProcess starts a new process with given arguments, environment variables, and current working folder, running as given user.

Returns an human readable error explaining why the sub-process couldn't start if not successful.

func (*Process) Kill

func (p *Process) Kill()

Kill the process

func (*Process) SetSize

func (p *Process) SetSize(columns, rows uint16)

SetSize of the TTY, if running as TTY or do nothing.

func (*Process) Wait

func (p *Process) Wait() bool

Wait for process to terminate, returns true, if exited zero.

type ProcessOptions

type ProcessOptions struct {
	Arguments     []string          // Command and arguments, default to shell
	Environment   map[string]string // Environment variables
	WorkingFolder string            // Working directory, if not HOME
	Owner         *User             // User to run process as, nil to use current
	Stdin         io.ReadCloser     // Stream with stdin, or nil if nothing
	Stdout        io.WriteCloser    // Stream for stdout
	Stderr        io.WriteCloser    // Stream for stderr, or nil if using stdout
	TTY           bool              // Start as TTY, if supported, ignores stderr
}

ProcessOptions are the arguments given for StartProcess. This structure is platform independent.

type User

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

User is a representation of a system user account.

func CreateUser

func CreateUser(homeFolder string, groups []*Group) (*User, error)

CreateUser will create a new user, with the given homeFolder, set the user owner of the homeFolder, and assign the user membership of given groups.

func (*User) Name added in v0.0.7

func (u *User) Name() string

Name returns the user name

func (*User) Remove

func (u *User) Remove()

Remove will remove a user and all associated resources.

Jump to

Keyboard shortcuts

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