auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 17 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 auth is the backend-agnostic authentication conversation (crates/wayle-auth): a backend — PAM for the lock screen, greetd for the greeter — asks one or more questions (password, OTP, "your password expired, enter a new one") and the UI answers each in turn.

A backend implements Conversation and drives the whole exchange on a worker goroutine, calling ask whenever it needs the user. Spawn wires ask to the UI: every prompt goes out through onEvent, and the UI replies through the returned Handle. The package has no GUI dependency, so the lock screen and the greeter drive it identically.

Index

Constants

View Source
const GreetdSockEnv = "GREETD_SOCK"

GreetdSockEnv names the IPC socket greetd hands its greeter.

Variables

View Source
var ErrCancelled = errors.New("cancelled")

ErrCancelled is the failure a backend reports when the user cancelled an input prompt.

Functions

func CurrentUsername

func CurrentUsername() string

CurrentUsername is the session user's login name from the environment: USER, then LOGNAME, then "". A locked graphical session always carries one of them.

func UnlockLoginKeyring

func UnlockLoginKeyring(password string)

UnlockLoginKeyring hands the just-verified password to the running gnome-keyring daemon, so the login collection unlocks here. Under greetd autologin no password is typed at boot and the daemon starts locked: the lock screen is the first place the password appears. Best effort — failures are logged, never blocking or denying the unlock the user already earned.

Types

type Ask

type Ask func(Prompt) (answer string, ok bool)

Ask is how a backend reaches the user. For prompts that want input it blocks until the UI answers and returns the answer, with ok false when the user cancelled; for info and error prompts it returns ("", false) at once.

type Conversation

type Conversation interface {
	Run(username string, ask Ask) error
}

Conversation is a backend that drives one authentication to completion. Run executes on a worker goroutine (blocking I/O is fine) and must never touch the GUI. username may be empty to let the backend ask for it. The error is the failure reason.

type Event

type Event struct {
	Kind EventKind
	// Prompt is set for EventPrompt.
	Prompt Prompt
	// Reason is set for EventFailure.
	Reason string
}

Event is surfaced to the UI as a conversation progresses.

type EventKind

type EventKind uint8

EventKind is what an Event reports.

const (
	// EventPrompt: the backend asks something (see Prompt.WantsInput).
	EventPrompt EventKind = iota
	// EventSuccess: authentication succeeded; the conversation is over.
	EventSuccess
	// EventFailure: authentication failed or was aborted; the
	// conversation is over, a retry starts a fresh one.
	EventFailure
)

Event kinds.

type Greetd

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

Greetd is the pre-login backend (greetd_backend.rs): an unprivileged greeter does not talk to PAM, greetd does, over its IPC socket — a native-endian u32 length prefix before each JSON body. One Run is the whole login: create the session, answer every auth message, and on success start the session; greetd then replaces the greeter.

func NewGreetd

func NewGreetd(conn io.ReadWriter, cmd func() []string, env []string) *Greetd

NewGreetd runs the protocol over an established connection.

func NewGreetdFromEnv

func NewGreetdFromEnv(cmd func() []string, env []string) (*Greetd, error)

NewGreetdFromEnv connects to the socket in $GREETD_SOCK. cmd is called once, at start_session.

func (*Greetd) Close

func (g *Greetd) Close() error

Close closes the connection when it is closable.

func (*Greetd) Run

func (g *Greetd) Run(username string, ask Ask) error

Run implements Conversation: create_session, one post_auth_message_response per auth message, then start_session. A greetd error or a cancelled input prompt cancels the session.

type Handle

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

Handle is the UI's side of a running conversation: it answers the pending prompt. The zero value is not usable; Spawn returns one.

func Spawn

func Spawn(conv Conversation, username string, onEvent func(Event)) *Handle

Spawn runs conv on a worker goroutine. Prompts reach onEvent (called from the worker: marshal it onto the UI loop), and the UI answers through the returned Handle. Exactly one terminal EventSuccess or EventFailure is emitted before the worker exits.

func (*Handle) Answer

func (h *Handle) Answer(text string)

Answer replies to the prompt on screen. A reply nothing waits for — the conversation already ended — is dropped, never blocking the UI.

func (*Handle) Cancel

func (h *Handle) Cancel()

Cancel aborts the conversation: a backend blocked in ask sees a cancellation, and every later ask does too. Idempotent.

type PAM

type PAM struct {
	// Service is the PAM service name (/etc/pam.d/<service>).
	Service string
	// contains filtered or unexported fields
}

PAM authenticates against a PAM service (e.g. system-auth): the in-session backend of the lock screen. The conversation runs on the worker goroutine Spawn creates, locked to its OS thread for the transaction's lifetime, so the UI loop never blocks on PAM. The password is never logged.

func NewPAM

func NewPAM(service string) *PAM

NewPAM returns the backend for service over the system libpam.

func (*PAM) Run

func (p *PAM) Run(username string, ask Ask) error

Run implements Conversation. The transaction opens for username (the session user when empty), authenticates, then checks the account (pam_authenticate + pam_acct_mgmt), and always ends with pam_end carrying the last call's status, as nonstick's transaction does; it sets no credentials, an unlock needs none. On success the last secret answered unlocks the gnome-keyring login collection, best effort.

type Prompt

type Prompt struct {
	Kind PromptKind
	Text string
}

Prompt is one thing a backend wants from the user.

func (Prompt) WantsInput

func (p Prompt) WantsInput() bool

WantsInput reports whether the prompt expects a typed answer.

type PromptKind

type PromptKind uint8

PromptKind is what a prompt wants from the user.

const (
	// PromptSecret is echo-off input (password, PIN).
	PromptSecret PromptKind = iota
	// PromptVisible is echo-on input (username, OTP).
	PromptVisible
	// PromptInfo is informational text; no answer.
	PromptInfo
	// PromptError is error text; no answer.
	PromptError
)

Prompt kinds.

func (PromptKind) String

func (k PromptKind) String() string

String names the kind for logs.

Jump to

Keyboard shortcuts

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