uxid

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package uxid resolves the uid of a local process to its login and groups, as the name service of the node says them, without letting a name service not answering hold its callers.

A lookup asks the name service, which may be a directory server not answering: nothing interrupts it. So a lookup is given up after a deadline, the lookup itself left to end on its own; at most a few run at once, a caller finding them all taken refused at once rather than piling threads up; and the answers are cached a short time, so a membership changed or an account removed is seen soon. An identity looked up lately is kept longer for when the name service does not answer: a directory down only hits the identities not seen lately, and keeps the others as they were last seen, but a name service answering always has the last word.

Index

Constants

View Source
const (
	DefaultTimeout     = 3 * time.Second
	DefaultMaxInFlight = 8
	DefaultPositiveTTL = 10 * time.Second
	DefaultNegativeTTL = 10 * time.Second

	// DefaultStaleTTL is how long an identity looked up is used past its
	// positive TTL, while the name service does not answer.
	DefaultStaleTTL = 5 * time.Minute
)

Variables

View Source
var (
	// ErrBusy is returned when the lookups running are at their cap: the
	// name service is slow, or not answering.
	ErrBusy = errors.New("the name service lookups running are at their cap")

	// ErrTimeout is returned when the name service did not answer in time.
	ErrTimeout = errors.New("the name service did not answer in time")
)

Functions

This section is empty.

Types

type Identity

type Identity struct {
	UID   uint32
	Login string

	// Groups are the names of the groups the login is a member of,
	// its primary group included.
	Groups []string
}

Identity is a uid as the name service says it.

func SystemLookup

func SystemLookup(uid uint32) (Identity, error)

SystemLookup resolves uid with the name service of the system.

Built without cgo, the os/user package reads /etc/passwd and /etc/group alone, and the accounts of a directory do not resolve.

type LookupFunc

type LookupFunc func(uid uint32) (Identity, error)

LookupFunc resolves a uid, asking the name service.

type Resolver

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

Resolver resolves uids with a deadline, a cap on the lookups running, and a cache.

func New

func New(lookup LookupFunc) *Resolver

New returns a resolver asking the name service through lookup, nil for the one of the system, with the default deadline, cap and cache times.

func (*Resolver) Flush

func (t *Resolver) Flush()

Flush forgets the identities cached.

func (*Resolver) Resolve

func (t *Resolver) Resolve(ctx context.Context, uid uint32) (Identity, error)

Resolve returns the identity of uid, from the cache when it holds a fresh one. Concurrent callers of one uid share a lookup. When the name service does not answer, at the cap or past the deadline, the identity last looked up is returned, if it is recent enough.

Jump to

Keyboard shortcuts

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