control

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package control is the delivery daemon's control socket: a Unix socket in a directory only its owner can open, which accepts a connection only when the kernel reports that the peer runs as the same OS user. When the peer's user can't be read, the connection is refused. It implements the delivery package's Control port.

Index

Constants

View Source
const SocketName = "daemon.sock"

SocketName is the socket's file name in the state directory.

Variables

View Source
var ErrPeerRefused = errors.New("control connection refused")

ErrPeerRefused means a connection came from another user, or its user couldn't be read.

View Source
var ErrUnsafe = errors.New("socket directory is not private")

ErrUnsafe means the socket's directory can be opened by other users or belongs to someone else.

Functions

func Allow

func Allow(want, got int, readErr error) error

Allow decides whether a peer may talk to the daemon: only when its user was read and matches. It fails closed.

func CheckDir

func CheckDir(dir string) error

CheckDir checks that dir belongs to this user and is closed to everyone else.

func Dial

func Dial(ctx context.Context, path string) (net.Conn, error)

Dial connects to the daemon's socket.

func Path

func Path(stateDir string) string

Path returns where the daemon's socket lives for a state directory: in the directory itself, or, when that path is too long for a socket, in a directory of this user's own under /tmp named after a hash of the state directory.

func PeerUID

func PeerUID(c *net.UnixConn) (int, error)

PeerUID reads the user id of the process on the other end of c from the kernel.

func PrepareDir

func PrepareDir(dir string) error

PrepareDir creates the socket's directory with mode 0700 if needed and checks that it belongs to this user and that nobody else can open it.

func SelfTest

func SelfTest() error

SelfTest checks that the kernel reports a socket peer's user on this system, by reading it over a connected pair of sockets.

Types

type Listener

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

Listener accepts control connections from this OS user only.

func Listen

func Listen(path string) (*Listener, error)

Listen creates the socket at path, replacing a stale one, readable only by its owner. The caller must hold the daemon lock, so no live daemon's socket is removed.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept returns the next connection. A connection whose peer isn't this user is closed, and Accept returns ErrPeerRefused for it.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening and removes the socket.

Jump to

Keyboard shortcuts

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