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 ¶
const GreetdSockEnv = "GREETD_SOCK"
GreetdSockEnv names the IPC socket greetd hands its greeter.
Variables ¶
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 ¶
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 ¶
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 ¶
NewGreetdFromEnv connects to the socket in $GREETD_SOCK. cmd is called once, at start_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.
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 (*PAM) Run ¶
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 ¶
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.