Password dialog rebuilt: a separate polkit agent, one state machine, explicit errors
CI / test (push) Canceled after 21m14s
CI / test (push) Canceled after 21m14s
The first version ran polkit registration, polkit-agent-helper-1, the PAM conversation and the drawing inside the compositor's frame loop, with overlapping state in two layers. A helper that quit before asking was taken for a wrong password and restarted in a loop that wiped the field (typing seemed dead), a refused registration quietly started a third-party agent, and the dialog and the Face unlock window each grabbed the keyboard. Now: - chandra-polkit-agent (compositor/authagent, /usr/local/lib/chandra) does polkit and PAM. Each request runs one state machine (polkit/machine.mbt: starting, asking, checking, failed, done). A check that quits or can't start is Failed with the reason and waits for Try again; only a wrong password starts the next check by itself. It logs each step to stderr (the session log), never the typed text. - The compositor starts it on a socket pair and only draws what it says (host/auth.mbt, auth_draw.mbt; line protocol in polkit/wire.mbt). One input owner (grab_input): the dialog, else the Face unlock window. - No silent fallback: if the agent can't run, polkit refuses it, polkit doesn't answer in 10 s, or it dies, a notice on screen says why (a crash after it ran restarts it, up to 3 times, and says so). The third-party agent runs only when the Settings switch is off. - chandra-ctl auth-demo [password|face|face-ok|die|slow|users] shows the real dialog with a pretend check (password "demo"), no root needed; chandra-ctl auth-status says whether the agent is registered. - just install builds and installs the agent (just auth-agent). Tests: polkit_test (link, machine, view, helper Gone) and auth_test end to end through handle_input: the agent loop in-process against a mock polkit on a private dbus-daemon plus a mock helper, and the real agent program spawned by the compositor (demo, and registered with the mock polkit). Typing on a real xkb keymap, wrong password, cancel, withdrawal, helper quitting early or missing, polkit refusing, agent not starting or crashing, demo modes, Face unlock Apply. 170/170 host and 20/20 polkit tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
This commit is contained in:
22 files changed
+3462
-1806
No files matched your search
@@ -0,0 +1,126 @@
|
||||
///| `chandra-ctl auth-demo [MODE]`: the real dialog, link and state machine with a pretend
|
||||
/// password check in place of polkit and PAM, so the dialog can be tried without root and
|
||||
/// without anything actually running. The password is "demo".
|
||||
///
|
||||
/// Modes: password (the default), face (looks for a face, gives up, asks for the password),
|
||||
/// face-ok (a face is recognized), die (the first check quits before asking, like a broken
|
||||
/// polkit setup; Try again works), slow (asks after three seconds), users (two accounts).
|
||||
|
||||
///|
|
||||
pub let demo_password : String = "demo"
|
||||
|
||||
///|
|
||||
pub let demo_modes : Array[String] = ["password", "face", "face-ok", "die", "slow", "users"]
|
||||
|
||||
///| The pretend PAM conversation: events on a timer, and a verdict on the answer.
|
||||
pub struct FakePam {
|
||||
/// Events still to come: (due time in monotonic ms, event).
|
||||
script : Array[(UInt64, HelperEvent)]
|
||||
mut closed : Bool
|
||||
}
|
||||
|
||||
///| A pretend check in `mode`; `attempt` counts from 0 (the `die` mode only fails the first).
|
||||
pub fn FakePam::new(mode : String, attempt : Int) -> FakePam {
|
||||
let now = @sys.monotonic_ms()
|
||||
let at = fn(ms : Int, ev : HelperEvent) { (now + ms.to_uint64(), ev) }
|
||||
let ask = PromptEchoOff("Password: ")
|
||||
let script = match mode {
|
||||
"face" =>
|
||||
[
|
||||
at(0, TextInfo("Face unlock: looking for your face")),
|
||||
at(2500, ErrorMsg("Face unlock: face not recognized")),
|
||||
at(2500, ask),
|
||||
]
|
||||
"face-ok" =>
|
||||
[at(0, TextInfo("Face unlock: looking for your face")), at(2000, TextInfo("Face unlock: recognized")), at(2600, Success)]
|
||||
"die" => if attempt == 0 { [at(400, Gone)] } else { [at(0, ask)] }
|
||||
"slow" => [at(3000, ask)]
|
||||
_ => [at(0, ask)]
|
||||
}
|
||||
{ script, closed: false }
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Conversation for FakePam with poll(self) {
|
||||
let out : Array[HelperEvent] = []
|
||||
if self.closed {
|
||||
return out
|
||||
}
|
||||
let now = @sys.monotonic_ms()
|
||||
while self.script.length() > 0 && self.script[0].0 <= now {
|
||||
let ev = self.script.remove(0).1
|
||||
out.push(ev)
|
||||
if ev == Success || ev == Failure || ev == Gone {
|
||||
self.closed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Conversation for FakePam with answer(self, a) {
|
||||
if self.closed {
|
||||
return false
|
||||
}
|
||||
let ok = field_text(a) == demo_password
|
||||
let now = @sys.monotonic_ms()
|
||||
self.script.push((now + 700UL, if ok { Success } else { Failure }))
|
||||
true
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Conversation for FakePam with fd(_self) {
|
||||
-1
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Conversation for FakePam with close(self) {
|
||||
self.closed = true
|
||||
self.script.clear()
|
||||
}
|
||||
|
||||
///| The account at the screen: $USER (with its real name from /etc/passwd when there).
|
||||
fn demo_user() -> AuthUser {
|
||||
let uid = own_uid()
|
||||
let passwd = parse_passwd(@utf8.decode_lossy(@sys.read_file_bytes("/etc/passwd")))
|
||||
match passwd.get(uid) {
|
||||
Some((name, real)) => { uid, name, real_name: real }
|
||||
None => {
|
||||
let n = @sys.getenv("USER")
|
||||
{ uid, name: if n != "" { n } else { "you" }, real_name: "" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| The demo request and how the dialog words it.
|
||||
pub fn demo_request(mode : String) -> (AuthRequest, Description) {
|
||||
let me = demo_user()
|
||||
let users = if mode == "users" { [me, { uid: 0, name: "root", real_name: "root" }] } else { [me] }
|
||||
let req : AuthRequest = {
|
||||
action_id: "org.freedesktop.systemd1.manage-units",
|
||||
message: "Authentication is required to start transient unit 'run-p1-i1.service'.",
|
||||
icon_name: "",
|
||||
details: {},
|
||||
cookie: "demo",
|
||||
users,
|
||||
}
|
||||
let desc : Description = {
|
||||
title: "Run a command as root",
|
||||
subtitle: "A demo: nothing runs. The password is \"" + demo_password + "\".",
|
||||
command: "run0 systemctl restart chandra-demo.service",
|
||||
program: "",
|
||||
details: [("Demo", "chandra-ctl auth-demo " + mode), ("Runs as", "root"), ("Action", req.action_id)],
|
||||
}
|
||||
(req, desc)
|
||||
}
|
||||
|
||||
///| Starts the demo's pretend checks, counting attempts.
|
||||
pub fn demo_starter(mode : String) -> Starter {
|
||||
let attempts : Ref[Int] = { val: 0 }
|
||||
fn(_user, _cookie) {
|
||||
let n = attempts.val
|
||||
attempts.val = n + 1
|
||||
Ok(FakePam::new(mode, n) as &Conversation)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user