Password dialog rebuilt: a separate polkit agent, one state machine, explicit errors
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:
Claude committed 2026-11-26 05:09:49 +00:00
1 parent 2c33c4a847
commit 80af76fb15
22 files changed
+3462 -1806

No files matched your search

+356 -729
View File
File diff suppressed because it is too large. Load diff
+503
View File
@@ -0,0 +1,503 @@
///| Drawing the password dialog (auth.mbt) and its notice.
///| Colours the palette has no slot for: errors and warnings, readable on the card.
fn auth_colors(p : @scene.ThemePalette) -> (@scene.Rgba, @scene.Rgba) {
// A light card (bright foreground means dark theme).
let dark = p.foreground.r.to_int() + p.foreground.g.to_int() + p.foreground.b.to_int() > 384
if dark {
(@scene.Rgba::from_hex("#f87171"), @scene.Rgba::from_hex("#fbbf24"))
} else {
(@scene.Rgba::from_hex("#c62828"), @scene.Rgba::from_hex("#8a5a00"))
}
}
///| `text` broken into lines no wider than `max_w`, at word boundaries (long words by character).
fn wrap_text(text : String, size : Int, bold : Bool, mono : Bool, max_w : Int) -> Array[String] {
let out : Array[String] = []
for para in text.split("\n") {
let mut line = ""
for w in para.split(" ") {
let word = w.to_string()
let cand = if line == "" { word } else { line + " " + word }
if @renderer.text_width(cand, size, bold, mono) <= max_w {
line = cand
continue
}
if line != "" {
out.push(line)
line = ""
}
// A word wider than the line: split it.
let mut part = ""
for c in word {
let next = part + c.to_string()
if @renderer.text_width(next, size, bold, mono) > max_w && part != "" {
out.push(part)
part = c.to_string()
} else {
part = next
}
}
line = part
}
out.push(line)
}
out
}
///| A padlock, for requests without an app icon.
fn lock_glyph(x : Int, y : Int, s : Int, c : @scene.Rgba, bg : @scene.Rgba, ops : Array[@scene.DrawOp]) -> Unit {
let bw = s * 5 / 8
let bh = s / 2
let bx = x + (s - bw) / 2
let by = y + s - bh - s / 10
let sw = bw * 5 / 8
let shx = x + (s - sw) / 2
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(shx, by - bh * 3 / 4, sw, bh), c, s / 12 + 1, sw / 2))
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(bx, by, bw, bh), c, s / 10))
ops.push(@scene.DrawOp::Circle(x + s / 2, by + bh * 2 / 5, s / 14 + 1, bg, true))
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x + s / 2 - 1, by + bh * 2 / 5, 3, bh / 3), bg, 1))
}
///| A button: filled (the default action) or outlined; with a focus ring.
fn auth_button(
r : @scene.Rect,
label : String,
primary : Bool,
focused : Bool,
hover : Bool,
enabled : Bool,
p : @scene.ThemePalette,
fs : Int,
rad : Int,
ops : Array[@scene.DrawOp],
) -> Unit {
if primary {
let a = p.accent
let alpha = if enabled { if hover { 230 } else { 255 } } else { 120 }
ops.push(@scene.DrawOp::FillRect(r, @scene.Rgba::new(a.r.to_int(), a.g.to_int(), a.b.to_int(), alpha), rad))
ops.push(@scene.DrawOp::Text(r.x + r.w / 2, r.y + r.h / 2, label, fs, p.accent_foreground, @scene.TextAlign::Center, true))
} else {
if hover {
ops.push(@scene.DrawOp::FillRect(r, p.surface_hover, rad))
}
ops.push(@scene.DrawOp::StrokeRect(r, p.border, 1, rad))
ops.push(@scene.DrawOp::Text(r.x + r.w / 2, r.y + r.h / 2, label, fs, p.foreground, @scene.TextAlign::Center, false))
}
if focused {
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(r.x - 3, r.y - 3, r.w + 6, r.h + 6), p.accent, 2, rad + 3))
}
}
///| A face outline (head, eyes, smile) centred at (cx, cy), `r` the head's radius.
fn face_glyph(cx : Int, cy : Int, r : Int, c : @scene.Rgba, ops : Array[@scene.DrawOp]) -> Unit {
ops.push(@scene.DrawOp::Circle(cx, cy, r, c, false))
ops.push(@scene.DrawOp::Circle(cx - r * 2 / 5, cy - r / 4, r / 8 + 1, c, true))
ops.push(@scene.DrawOp::Circle(cx + r * 2 / 5, cy - r / 4, r / 8 + 1, c, true))
ops.push(@scene.DrawOp::Line(cx - r / 2, cy + r / 4, cx - r / 5, cy + r / 2, c, 2))
ops.push(@scene.DrawOp::Line(cx - r / 5, cy + r / 2, cx + r / 5, cy + r / 2, c, 2))
ops.push(@scene.DrawOp::Line(cx + r / 5, cy + r / 2, cx + r / 2, cy + r / 4, c, 2))
}
///| Point `k` of 12 on a circle of radius `r` (clockwise from the top).
fn ring_point(k : Int, r : Int) -> (Int, Int) {
// sin and cos of k * 30 degrees, times 1000.
let s = [0, 500, 866, 1000, 866, 500, 0, -500, -866, -1000, -866, -500]
let c = [1000, 866, 500, 0, -500, -866, -1000, -866, -500, 0, 500, 866]
(s[k % 12] * r / 1000, -c[k % 12] * r / 1000)
}
///| A right-pointing (`down`: down-pointing) chevron centred at (cx, cy).
fn chevron(cx : Int, cy : Int, s : Int, down : Bool, left : Bool, c : @scene.Rgba, ops : Array[@scene.DrawOp]) -> Unit {
if down {
ops.push(@scene.DrawOp::Line(cx - s, cy - s / 2, cx, cy + s / 2, c, 2))
ops.push(@scene.DrawOp::Line(cx, cy + s / 2, cx + s, cy - s / 2, c, 2))
} else if left {
ops.push(@scene.DrawOp::Line(cx + s / 2, cy - s, cx - s / 2, cy, c, 2))
ops.push(@scene.DrawOp::Line(cx - s / 2, cy, cx + s / 2, cy + s, c, 2))
} else {
ops.push(@scene.DrawOp::Line(cx - s / 2, cy - s, cx + s / 2, cy, c, 2))
ops.push(@scene.DrawOp::Line(cx + s / 2, cy, cx - s / 2, cy + s, c, 2))
}
}
///| Draw the dialog (everything below it dimmed) and note where its controls are.
fn ChandraCompositor::auth_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
let ui = match self.auth {
Some(u) => u
None => return ops
}
let d = ui.view
let now = @sys.monotonic_ms()
let p = self.theme.palette
let (err_c, warn_c) = auth_colors(p)
let fs = self.theme.font_size
let rad = self.theme.radius + 2
let sw = self.output_w
let sh = self.output_h
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), @scene.Rgba::new(0, 0, 0, 150), 0))
let w = (sw - 32).min(460)
let pad = 24
let inner = w - pad * 2
let hover = self.auth_hit(ui)
// Lay out top to bottom into `body` (card-relative y), then place the card.
let body : Array[@scene.DrawOp] = []
let hits : Array[(@scene.Rect, @polkit.Focus)] = []
let mut y = pad
// Header: icon, overline, title, subtitle.
let icon_s = 48
let tx = pad + icon_s + 16
let tw = w - tx - pad
let header_top = y
let mut hy = y
body.push(@scene.DrawOp::Text(tx, hy + 7, "AUTHENTICATION REQUIRED", fs - 3, p.accent, @scene.TextAlign::Left, true))
hy = hy + 18
let title_lines = wrap_text(d.title, fs + 3, true, false, tw)
for l in title_lines {
body.push(@scene.DrawOp::Text(tx, hy + (fs + 8) / 2, l, fs + 3, p.foreground, @scene.TextAlign::Left, true))
hy = hy + fs + 8
}
hy = hy + 2
for l in wrap_text(d.subtitle, fs - 1, false, false, tw) {
body.push(@scene.DrawOp::Text(tx, hy + (fs + 4) / 2, l, fs - 1, p.foreground_muted, @scene.TextAlign::Left, false))
hy = hy + fs + 4
}
// Icon tile.
let ix = pad
let iy = header_top + 2
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(ix, iy, icon_s, icon_s), p.surface_hover, 12))
if ui.icon != 0U {
body.push(@scene.DrawOp::Image(@scene.Rect::new(ix + 6, iy + 6, icon_s - 12, icon_s - 12), ui.icon))
} else {
lock_glyph(ix + 8, iy + 8, icon_s - 16, p.accent, p.surface_hover, body)
}
y = hy.max(iy + icon_s) + 14
// The command, as a shell would read it.
if d.command != "" {
let mfs = fs - 1
let lines = wrap_text(d.command, mfs, false, true, inner - 24)
let shown = if lines.length() > 4 { lines[:4].to_array() } else { lines }
if lines.length() > 4 {
shown[3] = shown[3] + " …"
}
let lh = mfs + 6
let bh = shown.length() * lh + 16
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(pad, y, inner, bh), p.surface_hover, rad))
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(pad, y, 3, bh), p.accent, 1))
for i, l in shown {
body.push(@scene.DrawOp::MonoText(pad + 14, y + 8 + i * lh + lh / 2, l, mfs, p.foreground, @scene.TextAlign::Left, false))
}
y = y + bh + 14
}
// Who authenticates.
match d.user() {
Some(u) => {
let rh = 40
let r = @scene.Rect::new(pad, y, inner, rh)
let many = d.users.length() > 1
if many {
if hover == Some(User) {
body.push(@scene.DrawOp::FillRect(r, p.surface_hover, rad))
}
hits.push((r, User))
}
let initial = if u.real_name != "" { u.real_name[:1].to_string() } else { u.name[:1].to_string() }
body.push(@scene.DrawOp::Circle(pad + 20, y + rh / 2, 15, p.accent, true))
body.push(@scene.DrawOp::Text(pad + 20, y + rh / 2, initial.to_upper(), fs, p.accent_foreground, @scene.TextAlign::Center, true))
let name = if u.real_name != "" && u.real_name != u.name { u.real_name } else { u.name }
body.push(@scene.DrawOp::Text(pad + 44, y + rh / 2 - 8, name, fs, p.foreground, @scene.TextAlign::Left, true))
let login = if u.uid == 0 { "root" } else { u.name }
let sub = if many {
login + " · account " + (d.user_sel + 1).to_string() + " of " + d.users.length().to_string()
} else {
login
}
body.push(@scene.DrawOp::Text(pad + 44, y + rh / 2 + 9, sub, fs - 2, p.foreground_muted, @scene.TextAlign::Left, false))
if many {
chevron(pad + inner - 34, y + rh / 2, 5, false, true, p.foreground_muted, body)
chevron(pad + inner - 14, y + rh / 2, 5, false, false, p.foreground_muted, body)
if d.focus == User {
body.push(@scene.DrawOp::StrokeRect(r, p.accent, 2, rad))
}
}
y = y + rh + 12
}
None => ()
}
// Face unlock: what the face module in the PAM stack is doing (docs/face-unlock.md).
if d.face != NoFace {
let rh = 48
let cx = pad + 25
let cy = y + rh / 2
let tint = match d.face {
FaceFailed(_) => warn_c
_ => p.accent
}
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(pad, y, inner, rh), p.surface_hover, rad))
face_glyph(cx, cy, 13, if d.face is FaceFailed(_) { p.foreground_muted } else { p.foreground }, body)
match d.face {
Scanning => {
// A ring of dots sweeping round the face.
let t = ((now - d.face_at) / 70UL).to_int()
for k = 0; k < 12; k = k + 1 {
let a = (k + t) % 12
let (dx, dy) = ring_point(a, 19)
let alpha = 40 + k * 18
body.push(@scene.DrawOp::Circle(cx + dx, cy + dy, 2, @scene.Rgba::new(p.accent.r.to_int(), p.accent.g.to_int(), p.accent.b.to_int(), alpha), true))
}
}
Matched => {
body.push(@scene.DrawOp::Circle(cx + 13, cy + 11, 8, p.accent, true))
body.push(@scene.DrawOp::Line(cx + 9, cy + 11, cx + 12, cy + 14, p.accent_foreground, 2))
body.push(@scene.DrawOp::Line(cx + 12, cy + 14, cx + 17, cy + 8, p.accent_foreground, 2))
}
FaceFailed(_) => {
body.push(@scene.DrawOp::Circle(cx + 13, cy + 11, 8, warn_c, true))
body.push(@scene.DrawOp::Line(cx + 10, cy + 8, cx + 16, cy + 14, p.surface_popup, 2))
body.push(@scene.DrawOp::Line(cx + 16, cy + 8, cx + 10, cy + 14, p.surface_popup, 2))
}
NoFace => ()
}
let (title, sub) = match d.face {
Scanning => ("Looking for your face…", "Or type your password")
Matched => ("Face recognized", "")
FaceFailed(why) => (why, "Type your password instead")
NoFace => ("", "")
}
let tx = pad + 54
if sub == "" {
body.push(@scene.DrawOp::Text(tx, cy, title, fs, tint, @scene.TextAlign::Left, true))
} else {
body.push(@scene.DrawOp::Text(tx, cy - 8, title, fs, tint, @scene.TextAlign::Left, true))
body.push(@scene.DrawOp::Text(tx, cy + 10, sub, fs - 2, p.foreground_muted, @scene.TextAlign::Left, false))
}
y = y + rh + 12
}
// The prompt and the field.
body.push(@scene.DrawOp::Text(pad, y + 7, d.prompt, fs - 1, p.foreground_muted, @scene.TextAlign::Left, true))
y = y + 20
let fh = 40
let field = @scene.Rect::new(pad, y, inner, fh)
let enabled = d.editable()
body.push(@scene.DrawOp::FillRect(field, p.surface, rad))
let edge = if d.error != "" && d.typed() == 0 { err_c } else if d.focus == Field { p.accent } else { p.border }
body.push(@scene.DrawOp::StrokeRect(field, edge, if d.focus == Field || d.error != "" { 2 } else { 1 }, rad))
hits.push((@scene.Rect::new(pad, y, inner - 70, fh), Field))
// Show / Hide (not for prompts that show the answer anyway).
let text_right = if d.echo { pad + inner - 12 } else { pad + inner - 76 }
if !d.echo {
let rr = @scene.Rect::new(pad + inner - 68, y + 6, 60, fh - 12)
if hover == Some(Reveal) || d.focus == Reveal {
body.push(@scene.DrawOp::FillRect(rr, p.surface_hover, rad - 2))
}
if d.focus == Reveal {
body.push(@scene.DrawOp::StrokeRect(rr, p.accent, 2, rad - 2))
}
body.push(@scene.DrawOp::Text(rr.x + rr.w / 2, rr.y + rr.h / 2, if d.reveal { "Hide" } else { "Show" }, fs - 1, p.accent, @scene.TextAlign::Center, true))
hits.push((rr, Reveal))
}
body.push(@scene.DrawOp::PushClip(@scene.Rect::new(pad + 8, y, text_right - pad - 8, fh)))
let cy = y + fh / 2
let mut caret_x = pad + 13
if d.typed() == 0 {
let hint = match d.phase {
Starting => if d.face == Scanning { "Type your password" } else { "Preparing…" }
Failed => "Type your password, or press Enter to try again"
_ => if d.echo { "Type your answer" } else { "Type your password" }
}
body.push(@scene.DrawOp::Text(pad + 18, cy, hint, fs, @scene.Rgba::new(p.foreground_muted.r.to_int(), p.foreground_muted.g.to_int(), p.foreground_muted.b.to_int(), 150), @scene.TextAlign::Left, false))
} else if d.echo || d.reveal {
// Keep the end of long text in view.
let t = d.field_text()
let tw2 = @renderer.text_width(t, fs + 1, false, false)
let avail = text_right - pad - 22
let x0 = if tw2 > avail { pad + 14 - (tw2 - avail) } else { pad + 14 }
body.push(@scene.DrawOp::Text(x0, cy, t, fs + 1, if enabled { p.foreground } else { p.foreground_muted }, @scene.TextAlign::Left, false))
caret_x = x0 + tw2 + 2
} else {
let n = d.typed()
let step = 14
let avail = text_right - pad - 22
let total = n * step
let x0 = if total > avail { pad + 14 - (total - avail) } else { pad + 14 }
for i = 0; i < n; i = i + 1 {
body.push(@scene.DrawOp::Circle(x0 + i * step + 5, cy, 4, if enabled { p.foreground } else { p.foreground_muted }, true))
}
caret_x = x0 + total + 2
}
if d.focus == Field && enabled {
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(caret_x, cy - fs / 2 - 2, 2, fs + 4), p.accent, 0))
}
body.push(@scene.DrawOp::PopClip)
y = y + fh + 10
// Status: busy, Caps Lock, error, PAM's information.
let status : Array[(String, @scene.Rgba, Bool)] = []
if d.phase == Checking {
status.push(("Checking…", p.foreground_muted, true))
}
if d.caps && !d.echo {
status.push(("Caps Lock is on", warn_c, false))
}
if d.error != "" {
status.push((d.error, err_c, false))
}
if d.phase == Failed {
status.push(("Nothing was checked. Press Enter or Try again to start over.", p.foreground_muted, false))
}
if d.info != "" {
status.push((d.info, p.foreground, false))
}
for s in status {
let lines = wrap_text(s.0, fs - 1, false, false, inner - 22)
// A marker: a spinner while busy, else a dot in the line's colour.
if s.2 {
let t = ((now - ui.opened) / 90UL).to_int()
for k = 0; k < 8; k = k + 1 {
let ang = (k + t) % 8
let (dx, dy) = match ang {
0 => (0, -6)
1 => (4, -4)
2 => (6, 0)
3 => (4, 4)
4 => (0, 6)
5 => (-4, 4)
6 => (-6, 0)
_ => (-4, -4)
}
let a = 50 + k * 29
body.push(@scene.DrawOp::Circle(pad + 6 + dx, y + 9 + dy, 2, @scene.Rgba::new(p.accent.r.to_int(), p.accent.g.to_int(), p.accent.b.to_int(), a), true))
}
} else {
body.push(@scene.DrawOp::Circle(pad + 6, y + 9, 3, s.1, true))
}
for l in lines {
body.push(@scene.DrawOp::Text(pad + 18, y + 9, l, fs - 1, s.1, @scene.TextAlign::Left, false))
y = y + fs + 5
}
y = y + 3
}
y = y + 6
// Details.
if d.details_open {
let rows : Array[(String, String)] = d.details.copy()
if d.message != "" && d.title != d.message {
rows.push(("polkit says", d.message))
}
let lw = 104
let dh0 = y
y = y + 10
let rows_ops : Array[@scene.DrawOp] = []
for r in rows {
let vl = wrap_text(r.1, fs - 2, false, r.0 == "Action" || r.0 == "Unit", inner - lw - 24)
rows_ops.push(@scene.DrawOp::Text(pad + 12, y + 8, r.0, fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
for l in vl {
if r.0 == "Action" || r.0 == "Unit" {
rows_ops.push(@scene.DrawOp::MonoText(pad + 12 + lw, y + 8, l, fs - 2, p.foreground, @scene.TextAlign::Left, false))
} else {
rows_ops.push(@scene.DrawOp::Text(pad + 12 + lw, y + 8, l, fs - 2, p.foreground, @scene.TextAlign::Left, false))
}
y = y + fs + 3
}
y = y + 4
}
y = y + 6
body.push(@scene.DrawOp::FillRect(@scene.Rect::new(pad, dh0, inner, y - dh0), p.surface_hover, rad))
body.append(rows_ops)
y = y + 12
}
// Bottom row: Details toggle on the left, Cancel and Authenticate on the right.
let bh = 36
let dl = if d.details_open { "Hide details" } else { "Details" }
let dw = @renderer.text_width(dl, fs - 1, false, false) + 30
let dr = @scene.Rect::new(pad - 6, y, dw, bh)
if hover == Some(Details) {
body.push(@scene.DrawOp::FillRect(dr, p.surface_hover, rad))
}
chevron(pad + 6, y + bh / 2, 4, d.details_open, false, p.foreground_muted, body)
body.push(@scene.DrawOp::Text(pad + 18, y + bh / 2, dl, fs - 1, p.foreground_muted, @scene.TextAlign::Left, false))
if d.focus == Details {
body.push(@scene.DrawOp::StrokeRect(dr, p.accent, 2, rad))
}
hits.push((dr, Details))
let main = d.main_label()
let allow_w = @renderer.text_width(main, fs, true, false) + 32
let cancel_w = @renderer.text_width("Cancel", fs, false, false) + 32
let ar = @scene.Rect::new(pad + inner - allow_w, y, allow_w, bh)
let cr = @scene.Rect::new(ar.x - 10 - cancel_w, y, cancel_w, bh)
auth_button(cr, "Cancel", false, d.focus == Cancel, hover == Some(Cancel), true, p, fs, rad, body)
auth_button(ar, main, true, d.focus == Allow, hover == Some(Allow), d.main_enabled(), p, fs, rad, body)
hits.push((cr, Cancel))
hits.push((ar, Allow))
y = y + bh + pad
// Place the card in the middle (shaking after a failure) with a soft shadow.
let h = y
let cx = (sw - w) / 2 + d.shake_offset(now)
let cyy = ((sh - h) / 2).max(8)
for k = 1; k <= 4; k = k + 1 {
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx - k * 2, cyy - k * 2 + 6, w + k * 4, h + k * 4), @scene.Rgba::new(0, 0, 0, 22), rad + 6 + k * 2))
}
let opaque = @scene.Rgba::new(p.surface_popup.r.to_int(), p.surface_popup.g.to_int(), p.surface_popup.b.to_int(), 255)
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx, cyy, w, h), opaque, rad + 6))
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(cx, cyy, w, h), p.border, 1, rad + 6))
ops.append(offset_ops_all(body, cx, cyy))
ui.hits.clear()
for hit in hits {
let r = hit.0
ui.hits.push((@scene.Rect::new(r.x + cx, r.y + cyy, r.w, r.h), hit.1))
}
ops
}
///| Move every op by (dx, dy).
fn offset_ops_all(ops : Array[@scene.DrawOp], dx : Int, dy : Int) -> Array[@scene.DrawOp] {
let mv = fn(r : @scene.Rect) { @scene.Rect::new(r.x + dx, r.y + dy, r.w, r.h) }
ops.map(op => match op {
FillRect(r, c, rad) => @scene.DrawOp::FillRect(mv(r), c, rad)
StrokeRect(r, c, w, rad) => @scene.DrawOp::StrokeRect(mv(r), c, w, rad)
Line(x0, y0, x1, y1, c, w) => @scene.DrawOp::Line(x0 + dx, y0 + dy, x1 + dx, y1 + dy, c, w)
Circle(x, y, r, c, f) => @scene.DrawOp::Circle(x + dx, y + dy, r, c, f)
Text(x, y, t, s, c, a, b) => @scene.DrawOp::Text(x + dx, y + dy, t, s, c, a, b)
MonoText(x, y, t, s, c, a, b) => @scene.DrawOp::MonoText(x + dx, y + dy, t, s, c, a, b)
PushClip(r) => @scene.DrawOp::PushClip(mv(r))
PopClip => PopClip
Image(r, h) => @scene.DrawOp::Image(mv(r), h)
})
}
///| The notice about the dialog itself (it couldn't start, it stopped), at the top of the screen.
fn ChandraCompositor::auth_notice_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
let n = match self.auth_notice {
Some(n) => n
None => return ops
}
let p = self.theme.palette
let (err_c, _) = auth_colors(p)
let fs = self.theme.font_size
let rad = self.theme.radius + 4
let w = (self.output_w - 32).min(560)
let pad = 16
let lines = wrap_text(n.text, fs, false, false, w - pad * 2 - 28)
let lh = fs + 6
let h = pad * 2 + 20 + lines.length() * lh + 6 + fs
let x = (self.output_w - w) / 2
let y = 16
for k = 1; k <= 3; k = k + 1 {
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x - k * 2, y - k * 2 + 4, w + k * 4, h + k * 4), @scene.Rgba::new(0, 0, 0, 22), rad + k * 2))
}
let opaque = @scene.Rgba::new(p.surface_popup.r.to_int(), p.surface_popup.g.to_int(), p.surface_popup.b.to_int(), 255)
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x, y, w, h), opaque, rad))
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(x, y, w, h), err_c, 2, rad))
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(x, y, 4, h), err_c, 2))
lock_glyph(x + pad, y + pad - 2, 20, err_c, opaque, ops)
ops.push(@scene.DrawOp::Text(x + pad + 28, y + pad + 8, "PASSWORD DIALOG", fs - 3, err_c, @scene.TextAlign::Left, true))
let mut ty = y + pad + 20
for l in lines {
ops.push(@scene.DrawOp::Text(x + pad + 28, ty + lh / 2, l, fs, p.foreground, @scene.TextAlign::Left, false))
ty = ty + lh
}
ops.push(@scene.DrawOp::Text(x + pad + 28, ty + 6 + fs / 2, "Click to dismiss", fs - 2, p.foreground_muted, @scene.TextAlign::Left, false))
n.rect = @scene.Rect::new(x, y, w, h)
ops
}
+499 -222
View File
@@ -1,7 +1,8 @@
///| Chandra's polkit agent and its dialog, against a mock polkit Authority on a private bus
/// (a real dbus-daemon) and a mock polkit-agent-helper-1 on a socket (the protocol polkit 126's
/// socket-activated helper speaks). Set CHANDRA_AUTH_SHOTS to a folder to get a PNG of each
/// dialog state.
///| Chandra's password dialog end to end: the compositor, chandra-polkit-agent's loop (run
/// in-process on a socket pair, and as the real program), a mock polkit Authority on a private
/// bus (a real dbus-daemon) and a mock polkit-agent-helper-1 on a socket (the protocol polkit
/// 126's socket-activated helper speaks). Set CHANDRA_AUTH_SHOTS to a folder to get a PNG of
/// each dialog state.
///| A private message bus for the test (dbus-daemon's session config), its socket path.
fn auth_bus(tag : String) -> String? {
@@ -72,9 +73,9 @@ fn MockAuthority::new(path : String) -> MockAuthority {
}
///| Ask the agent to authenticate, like polkitd does for run0.
fn MockAuthority::begin(self : MockAuthority, cookie : String, details : Array[(String, String)]) -> Unit {
fn MockAuthority::begin(self : MockAuthority, cookie : String, details : Array[(String, String)], uid? : UInt = 1000) -> Unit {
let ids : Array[@network.DValue] = [
Struct([Str("unix-user"), @network.dict("v", [("uid", Variant(U32(1000)))])]),
Struct([Str("unix-user"), @network.dict("v", [("uid", Variant(U32(uid)))])]),
Struct([Str("unix-group"), @network.dict("v", [("gid", Variant(U32(10)))])]),
]
ignore(
@@ -112,28 +113,85 @@ fn fake_request(args : Array[@network.DValue]) -> @polkit.AuthRequest? {
}
}
///| A compositor with the agent on `bus` and the helper at `helper` (a socket we listen on).
fn auth_comp(tag : String, bus : String, helper : String) -> @host.ChandraCompositor {
let comp = new_comp("auth-" + tag)
comp.auth_routes = [Socket(helper)]
comp.auth_describe = Some(fn(req) {
@polkit.describe(
req,
cmdline=pid => if pid == 15802 { ["run0", "gparted", "/dev/nvme0n1"] } else { [] },
who=pid => "run0 (pid " + pid.to_string() + "), started from konsole",
)
})
let subject = @network.DValue::Struct([Str("unix-session"), @network.dict("v", [("session-id", Variant(Str("2")))])])
comp.polkit = Some(@polkit.PolkitAgent::new(bus_path=bus, subject~, make_request=fake_request))
comp.start_auth_agent()
comp
///| A connected pair of stream sockets: (the compositor's end, the agent's end).
fn sock_pair(tag : String) -> (Int, Int) {
let path = "/tmp/chandra-auth-link-" + tag + "-" + @sys.getpid().to_string()
@sys.unlink(path)
let l = @sys.unix_listen(path)
let c = @sys.unix_connect(path)
let mut s = -1
for i = 0; i < 100 && s < 0; i = i + 1 {
s = @sys.unix_accept(l)
if s < 0 {
@sys.sleep_ms(5)
}
}
@sys.close_fd(l)
@sys.unlink(path)
(c, s)
}
///| Run both ends until `cond` holds (or about two seconds pass).
fn settle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool) -> Bool {
for i = 0; i < 200; i = i + 1 {
a.bus.pump()
comp.step()
///| A compositor, the mock polkitd (when there is a bus), and the agents it started in-process.
struct Rig {
comp : @host.ChandraCompositor
a : MockAuthority?
agents : Array[@polkit.AgentLoop]
}
///| A compositor whose agents run in this process: the session's on `bus` with the helper at
/// `helper` (a socket the test listens on), demos as `chandra-ctl auth-demo` starts them.
fn rig(tag : String, bus : String?, helper : String) -> Rig {
let comp = new_comp("auth-" + tag)
comp.login_session = true
let a = bus.map(b => MockAuthority::new(b))
let agents : Array[@polkit.AgentLoop] = []
let n : Ref[Int] = { val: 0 }
comp.auth_spawner = Some(fn(args) {
n.val = n.val + 1
let (mine, theirs) = sock_pair(tag + "-" + n.val.to_string())
let ag = match args {
["--demo", mode] => @polkit.AgentLoop::new_demo(theirs, mode)
_ => {
let subject = @network.DValue::Struct([Str("unix-session"), @network.dict("v", [("session-id", Variant(Str("2")))])])
@polkit.AgentLoop::new(
theirs,
@polkit.PolkitAgent::new(bus_path=bus.unwrap_or("/nonexistent/bus"), subject~, make_request=fake_request),
routes=[Socket(helper)],
describer=fn(req) {
@polkit.describe(
req,
cmdline=pid => if pid == 15802 { ["run0", "gparted", "/dev/nvme0n1"] } else { [] },
who=pid => "run0 (pid " + pid.to_string() + "), started from konsole",
)
},
)
}
}
ag.start()
agents.push(ag)
mine
})
{ comp, a, agents }
}
///| One pass of everything: polkitd, the agents, the compositor.
fn Rig::pass(self : Rig) -> Unit {
match self.a {
Some(a) => a.bus.pump()
None => ()
}
for ag in self.agents {
if !ag.finished() {
ag.step()
}
}
self.comp.step()
}
///| Run everything until `cond` holds (or about six seconds pass).
fn Rig::settle(self : Rig, cond : () -> Bool) -> Bool {
for i = 0; i < 600; i = i + 1 {
self.pass()
if cond() {
return true
}
@@ -142,10 +200,25 @@ fn settle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool)
false
}
///| The mock helper's side of one session: accept, read the user and cookie lines.
fn helper_accept(listen : Int, comp : @host.ChandraCompositor, a : MockAuthority) -> (Int, String) {
///| The session's agent registered with polkit.
fn Rig::ready(self : Rig) -> Bool {
self.comp.auth_agent.map(l => l.ready).unwrap_or(false)
}
///| The mock polkitd.
fn Rig::authority(self : Rig) -> MockAuthority {
self.a.unwrap()
}
///| The dialog's view (aborts when none is up).
fn Rig::view(self : Rig) -> @polkit.AuthView {
self.comp.auth_view().unwrap()
}
///| The mock helper's side of one check: accept, read the user and cookie lines.
fn Rig::helper_accept(self : Rig, listen : Int) -> (Int, String) {
let fd : Ref[Int] = { val: -1 }
ignore(settle(comp, a, fn() {
ignore(self.settle(fn() {
if fd.val < 0 {
fd.val = @sys.unix_accept(listen)
}
@@ -157,7 +230,7 @@ fn helper_accept(listen : Int, comp : @host.ChandraCompositor, a : MockAuthority
(fd.val, helper_lines(fd.val, 2))
}
///| Read `n` lines from the agent (joined with '|').
///| Read `n` lines (joined with '|').
fn helper_lines(fd : Int, n : Int) -> String {
let buf : FixedArray[Byte] = FixedArray::make(1024, b'\x00')
let got : Array[Byte] = []
@@ -216,14 +289,30 @@ fn auth_press(comp : @host.ChandraCompositor, code : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Key(code, false), 1U)
}
///| Alt+key.
fn auth_alt(comp : @host.ChandraCompositor, code : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
auth_press(comp, code)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
}
///| Click the dialog's control `f`.
fn auth_click(comp : @host.ChandraCompositor, f : @polkit.Focus) -> Unit {
ignore(comp.compose_frame())
let r = comp.auth.unwrap().hits.filter(x => x.1 == f)[0].0
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 4).to_double(), (r.y + 4).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
}
///| Save the screen as `<CHANDRA_AUTH_SHOTS>/<name>.png` when that is set.
fn auth_shot(comp : @host.ChandraCompositor, name : String) -> Unit {
let dir = @sys.getenv("CHANDRA_AUTH_SHOTS")
if dir == "" {
return
}
match comp.auth_dialog() {
Some(d) => d.shake_at = 0UL // the card at rest
match comp.auth_view() {
Some(v) => v.shake_at = 0UL // the card at rest
None => ()
}
comp.damage.mark_full()
@@ -240,87 +329,90 @@ let run0_details : Array[(String, String)] = [
("polkit.caller-pid", "1"),
]
///| A private bus and a listening mock helper socket for test `tag`.
fn helper_socket(tag : String) -> (String, Int) {
let hpath = "/tmp/chandra-auth-helper-" + tag + "-" + @sys.getpid().to_string()
@sys.unlink(hpath)
(hpath, @sys.unix_listen(hpath))
}
///|
test "polkit asks for run0: the dialog shows the command, a wrong password shakes, the right one authorizes" {
let bus = match auth_bus("ok") {
Some(b) => b
None => return // no dbus-daemon here
}
let a = MockAuthority::new(bus)
let hpath = "/tmp/chandra-auth-helper-ok-" + @sys.getpid().to_string()
let listen = @sys.unix_listen(hpath)
let comp = auth_comp("ok", bus, hpath)
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
let (hpath, listen) = helper_socket("ok")
let r = rig("ok", Some(bus), hpath)
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.ready() }))
let a = r.authority()
assert_true(a.agent != "")
a.begin("cookie-1", run0_details)
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
let d = comp.auth_dialog().unwrap()
assert_eq(d.desc.title, "Run a command as root")
assert_eq(d.desc.command, "gparted /dev/nvme0n1")
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
let d = r.view()
assert_eq(d.title, "Run a command as root")
assert_eq(d.command, "gparted /dev/nvme0n1")
// The user at the screen comes first; the wheel group adds ada.
assert_eq(d.req.users.map(u => u.name), ["nandi", "ada"])
assert_eq(d.users.map(u => u.name), ["nandi", "ada"])
// The helper is asked for nandi with polkit's cookie.
let (h, hello) = helper_accept(listen, comp, a)
let (h, hello) = r.helper_accept(listen)
assert_eq(hello, "nandi|cookie-1")
auth_shot(comp, "01-starting")
auth_shot(r.comp, "01-starting")
helper_say(h, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle(comp, a, fn() { d.phase == Prompt }))
auth_shot(comp, "02-idle")
auth_type(comp, "Hunter2")
assert_true(r.settle(fn() { d.phase == Asking }))
auth_shot(r.comp, "02-idle")
auth_type(r.comp, "Hunter2")
assert_eq(d.typed(), 7)
auth_shot(comp, "03-typing")
auth_shot(r.comp, "03-typing")
// Caps Lock on shows a warning.
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 2U, 0U), 1U)
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 2U, 0U), 1U)
assert_true(d.caps)
auth_shot(comp, "04-caps-lock")
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
auth_press(comp, 28U) // Enter
auth_shot(r.comp, "04-caps-lock")
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
auth_press(r.comp, 28U) // Enter
assert_eq(d.typed(), 0) // wiped once sent
assert_true(r.settle(fn() { d.phase == Checking }))
assert_eq(helper_lines(h, 1), "Hunter2")
assert_eq(d.phase, Checking)
auth_shot(comp, "05-busy")
// Wrong: the helper fails and exits; the dialog says so and starts a new session.
auth_shot(r.comp, "05-busy")
// Wrong: the helper fails and exits; the dialog shakes, says so, and a new check starts.
helper_say(h, "FAILURE")
@sys.close_fd(h)
assert_true(settle(comp, a, fn() { d.failures == 1 }))
assert_true(r.settle(fn() { d.failures == 1 }))
assert_eq(d.error, "Wrong password. Try again.")
let (h2, hello2) = helper_accept(listen, comp, a)
assert_true(d.shake_at != 0UL)
let (h2, hello2) = r.helper_accept(listen)
assert_eq(hello2, "nandi|cookie-1")
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle(comp, a, fn() { d.phase == Prompt }))
auth_shot(comp, "06-wrong-password")
assert_true(r.settle(fn() { d.phase == Asking }))
auth_shot(r.comp, "06-wrong-password")
// Details, then the right password.
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
auth_press(comp, 32U) // Alt+D
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
auth_alt(r.comp, 32U) // Alt+D
assert_true(d.details_open)
auth_type(comp, "hunter2")
auth_shot(comp, "07-details")
// Revealed text, then the light theme.
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
auth_press(comp, 19U) // Alt+R
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
auth_type(r.comp, "hunter2")
auth_shot(r.comp, "07-details")
auth_alt(r.comp, 19U) // Alt+R: show it
assert_true(d.reveal)
auth_shot(comp, "08-revealed")
comp.theme = @scene.ThemeTokens::moon_day()
auth_shot(comp, "09-light")
comp.handle_input(@nested.InputEvent::Modifiers(8U, 0U, 0U, 0U), 1U)
auth_press(comp, 19U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
auth_press(comp, 32U) // Alt is up: 'd' goes into the field
auth_press(comp, 14U) // and Backspace takes it out
auth_shot(comp, "10-light-details")
auth_press(comp, 96U) // keypad Enter
auth_shot(r.comp, "08-revealed")
r.comp.theme = @scene.ThemeTokens::moon_day()
auth_shot(r.comp, "09-light")
auth_alt(r.comp, 19U)
auth_press(r.comp, 32U) // Alt is up: 'd' goes into the field
auth_press(r.comp, 14U) // and Backspace takes it out
auth_shot(r.comp, "10-light-details")
auth_press(r.comp, 96U) // keypad Enter
assert_true(r.settle(fn() { d.phase == Checking }))
assert_eq(helper_lines(h2, 1), "hunter2")
helper_say(h2, "SUCCESS")
assert_true(settle(comp, a, fn() { comp.auth_dialog() is None }))
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
assert_true(r.settle(fn() { r.comp.auth_view() is None && a.answers.length() == 1 }))
assert_eq(a.answers, ["ok"])
// Key releases after the dialog closed don't leak to clients (nothing swallowed is left).
assert_eq(comp.auth_swallow.length(), 0)
assert_eq(r.comp.auth_swallow.length(), 0)
assert_true(r.comp.auth_notice_text() is None)
@sys.close_fd(h2)
@sys.close_fd(listen)
@sys.unlink(hpath)
comp.close()
r.comp.close()
}
///|
@@ -329,89 +421,339 @@ test "Escape dismisses: polkitd hears Cancelled; polkitd withdrawing a request c
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let hpath = "/tmp/chandra-auth-helper-cancel-" + @sys.getpid().to_string()
let listen = @sys.unix_listen(hpath)
let comp = auth_comp("cancel", bus, hpath)
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
let (hpath, listen) = helper_socket("cancel")
let r = rig("cancel", Some(bus), hpath)
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.ready() }))
let a = r.authority()
a.begin("c1", run0_details)
a.begin("c2", [])
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
let (h, _) = helper_accept(listen, comp, a)
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
let (h, _) = r.helper_accept(listen)
// A fingerprint reader: PAM informs and waits.
helper_say(h, "PAM_TEXT_INFO Place your finger on the fingerprint reader")
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.phase == Waiting).unwrap_or(false) }))
auth_shot(comp, "11-fingerprint")
// Two accounts can answer: Tab to the picker, Right picks ada and restarts the helper.
auth_press(comp, 15U)
auth_press(comp, 106U)
assert_eq(comp.auth_dialog().unwrap().user().map(u => u.name), Some("ada"))
let (h2, hello) = helper_accept(listen, comp, a)
assert_true(r.settle(fn() { r.view().info != "" }))
assert_eq(r.view().phase, Starting)
auth_shot(r.comp, "11-fingerprint")
// Two accounts can answer: Tab to the picker, Right picks ada and starts a check for her.
auth_press(r.comp, 15U)
auth_press(r.comp, 106U)
let (h2, hello) = r.helper_accept(listen)
assert_eq(hello, "ada|c1")
assert_true(r.settle(fn() { r.view().user().map(u => u.name) == Some("ada") }))
// Face unlock (pam_chandra_face.so): the face row scans, then gives way to the password.
helper_say(h2, "PAM_TEXT_INFO Face unlock: looking for ada…")
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.face == Scanning).unwrap_or(false) }))
assert_eq(comp.auth_dialog().unwrap().info, "") // the fingerprint message went with nandi's attempt
auth_shot(comp, "14-face-scanning")
assert_true(r.settle(fn() { r.view().face == Scanning }))
assert_eq(r.view().info, "") // the fingerprint message went with nandi's attempt
auth_shot(r.comp, "14-face-scanning")
helper_say(h2, "PAM_ERROR_MSG Face unlock: face not recognized")
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.phase == Prompt).unwrap_or(false) }))
assert_eq(comp.auth_dialog().unwrap().face, FaceFailed("Face not recognized"))
auth_shot(comp, "15-face-failed")
auth_shot(comp, "12-other-account")
auth_press(comp, 1U) // Escape
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
assert_true(r.settle(fn() { r.view().phase == Asking }))
assert_eq(r.view().face, FaceFailed("Face not recognized"))
auth_shot(r.comp, "15-face-failed")
auth_shot(r.comp, "12-other-account")
auth_press(r.comp, 1U) // Escape
assert_true(r.comp.auth_view() is None || r.view().id != "1")
assert_true(r.settle(fn() { a.answers.length() == 1 }))
assert_eq(a.answers, ["org.freedesktop.PolicyKit1.Error.Cancelled"])
// The second request comes up next; polkitd withdraws it.
assert_true(settle(comp, a, fn() { comp.auth_dialog().map(d => d.req.cookie == "c2").unwrap_or(false) }))
let d2 = comp.auth_dialog().unwrap()
assert_eq(d2.desc.title, "Run a command as root") // the unit name in the message still finds run0
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.id == "2").unwrap_or(false) }))
assert_eq(r.view().title, "Run a command as root") // the unit name in the message still finds run0
ignore(a.bus.call(@network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "CancelAuthentication", [Str("c2")])))
assert_true(settle(comp, a, fn() { comp.auth_dialog() is None }))
assert_true(settle(comp, a, fn() { a.answers.length() == 2 }))
assert_true(r.settle(fn() { r.comp.auth_view() is None }))
assert_true(r.settle(fn() { a.answers.length() == 2 }))
assert_eq(a.answers[1], "org.freedesktop.PolicyKit1.Error.Cancelled")
@sys.close_fd(h)
@sys.close_fd(h2)
@sys.close_fd(listen)
@sys.unlink(hpath)
comp.close()
r.comp.close()
}
///|
test "another agent already has the session: ours steps aside" {
test "polkit refuses the agent: a notice says why, and no other agent takes over" {
let bus = match auth_bus("refuse") {
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
a.refuse = "An authentication agent already exists for the given subject"
let comp = auth_comp("refuse", bus, "/nonexistent")
assert_true(settle(comp, a, fn() { comp.polkit is None }))
comp.close()
let r = rig("refuse", Some(bus), "/nonexistent")
r.authority().refuse = "An authentication agent already exists for the given subject"
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.comp.auth_notice_text() is Some(_) }))
assert_eq(
r.comp.auth_notice_text().unwrap(),
"Chandra's password dialog couldn't start: polkit refused the agent: An authentication agent already exists for the given subject.",
)
assert_true(r.comp.auth_agent is None)
assert_false(r.comp.fallback_agent_started)
let (out, ok) = r.comp.control_command("auth-status")
assert_true(ok)
assert_eq(out[0], "agent: not running")
auth_shot(r.comp, "16-notice")
// A click on it dismisses it.
ignore(r.comp.compose_frame())
r.comp.handle_input(@nested.InputEvent::PointerMove(640.0, 40.0), 1U)
r.comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
r.comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
assert_true(r.comp.auth_notice_text() is None)
r.comp.close()
}
///|
test "the helper can't be reached: the dialog says so instead of hanging" {
test "the agent can't be started, or quits at start: a notice says so" {
// No program to run.
let r = rig("nostart", None, "")
r.comp.auth_spawner = Some(fn(_) { -1 })
r.comp.start_auth_agent()
assert_eq(r.comp.auth_notice_text(), Some("Chandra's password dialog couldn't start: could not run chandra-polkit-agent."))
r.comp.close()
// Started, but polkit can't even be asked (no system bus): its error is the notice.
let r2 = rig("nobus", None, "")
r2.comp.start_auth_agent()
assert_true(r2.settle(fn() { r2.comp.auth_notice_text() is Some(_) }))
assert_true(r2.comp.auth_notice_text().unwrap().has_prefix("Chandra's password dialog couldn't start: polkit could not be asked: no system bus at /nonexistent/bus"))
r2.comp.close()
// It crashes before saying anything.
let r3 = rig("crash", None, "")
r3.comp.auth_spawner = Some(fn(_) {
let (mine, theirs) = sock_pair("crash")
@sys.close_fd(theirs)
mine
})
r3.comp.start_auth_agent()
assert_true(r3.settle(fn() { r3.comp.auth_notice_text() is Some(_) }))
assert_eq(
r3.comp.auth_notice_text().unwrap(),
"Chandra's password dialog couldn't start: chandra-polkit-agent stopped unexpectedly (see ~/.local/state/chandra/session.log).",
)
r3.comp.close()
}
///|
test "the agent stops after it was registered: it is started again, and a notice says so" {
let bus = match auth_bus("restart") {
Some(b) => b
None => return
}
let r = rig("restart", Some(bus), "/nonexistent")
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.ready() }))
let first = r.agents[0]
first.shutdown() // as if it crashed: its end of the link closes
assert_true(r.settle(fn() { r.comp.auth_notice_text() is Some(_) }))
assert_true(r.comp.auth_notice_text().unwrap().has_prefix("Chandra's password dialog stopped and was restarted"))
assert_true(r.settle(fn() { r.ready() }))
assert_eq(r.agents.length(), 2)
r.comp.close()
}
///|
test "polkit's helper can't be reached: the dialog says why and waits; Try again, then Cancel" {
let bus = match auth_bus("nohelper") {
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let comp = auth_comp("nohelper", bus, "/nonexistent/helper.socket")
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
let r = rig("nohelper", Some(bus), "/nonexistent/helper.socket")
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.ready() }))
let a = r.authority()
a.begin("c1", run0_details)
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
assert_eq(comp.auth_dialog().unwrap().error, "polkit's authentication helper could not be started.")
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
let d = r.view()
assert_eq(d.phase, Failed)
assert_eq(d.error, "polkit's password checker could not be started (tried socket /nonexistent/helper.socket)")
assert_eq(d.main_label(), "Try again")
auth_shot(r.comp, "17-failed")
// Enter tries again (and says the same).
auth_press(r.comp, 28U)
assert_true(r.settle(fn() { d.phase == Failed }))
// Clicking Cancel dismisses it.
ignore(comp.compose_frame())
let ui = comp.auth.unwrap()
let cancel = ui.hits.filter(h => h.1 == Cancel)[0].0
comp.handle_input(@nested.InputEvent::PointerMove((cancel.x + 5).to_double(), (cancel.y + 5).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
assert_true(comp.auth_dialog() is None)
auth_click(r.comp, Cancel)
assert_true(r.comp.auth_view() is None)
assert_true(r.settle(fn() { a.answers.length() == 1 }))
r.comp.close()
}
///|
test "typing reaches the dialog through handle_input on a real keymap; a check that quits early is not retried behind the user's back" {
let bus = match auth_bus("typing") {
Some(b) => b
None => return
}
let (hpath, listen) = helper_socket("typing")
let r = rig("typing", Some(bus), hpath)
// The keymap the real session hands clients (xkbcommon's text format), not the US fallback.
r.comp.server.set_keymap(@utf8.encode(real_keymap))
r.comp.start_auth_agent()
assert_true(r.settle(fn() { r.ready() }))
let a = r.authority()
a.begin("t1", run0_details)
assert_true(r.settle(fn() { r.comp.auth_view() is Some(_) }))
let d = r.view()
// The helper goes away without a word (socket helper refusing, account locked, ...).
let (h, _) = r.helper_accept(listen)
@sys.close_fd(h)
assert_true(r.settle(fn() { d.phase == Failed }))
assert_eq(d.error, "The password check quit before asking for a password.")
assert_eq(d.failures, 0) // not a wrong password
// Nothing starts another check on its own.
for i = 0; i < 30; i = i + 1 {
r.pass()
@sys.sleep_ms(10)
}
assert_true(@sys.unix_accept(listen) < 0)
// Typing lands in the field and stays there.
auth_type(r.comp, "Secret9")
assert_eq(d.typed(), 7)
// Shift+digit through the real keymap: '(' on 9.
r.comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 1U)
auth_press(r.comp, 10U)
r.comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
assert_eq(d.typed(), 8)
// Enter starts a new check, which gets the password when it asks.
auth_press(r.comp, 28U)
let (h2, hello) = r.helper_accept(listen)
assert_eq(hello, "nandi|t1")
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(r.settle(fn() { d.phase == Checking }))
assert_eq(helper_lines(h2, 1), "Secret9(")
helper_say(h2, "SUCCESS")
assert_true(r.settle(fn() { a.answers == ["ok"] }))
@sys.close_fd(h2)
@sys.close_fd(listen)
@sys.unlink(hpath)
r.comp.close()
}
///|
test "chandra-ctl auth-demo: the dialog without root; wrong, then the demo password" {
let r = rig("demo", None, "")
let (out, ok) = r.comp.control_command("auth-demo")
assert_true(ok)
assert_eq(out, ["ok the demo dialog opens; the password is \"demo\""])
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
let d = r.view()
assert_eq(d.command, "run0 systemctl restart chandra-demo.service")
auth_type(r.comp, "nope")
auth_press(r.comp, 28U)
assert_true(r.settle(fn() { d.failures == 1 }))
assert_eq(d.error, "Wrong password. Try again.")
assert_true(r.settle(fn() { d.phase == Asking }))
auth_type(r.comp, "demo")
auth_click(r.comp, Allow)
assert_true(r.settle(fn() { r.comp.auth_view() is None && r.comp.auth_demos.length() == 0 }))
assert_true(r.comp.auth_notice_text() is None)
assert_eq(r.comp.control_command("auth-demo bogus").1, false)
r.comp.close()
}
///|
test "auth-demo die and face: a check that quits shows why until Try again; the face row" {
let r = rig("demo-die", None, "")
ignore(r.comp.control_command("auth-demo die"))
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.phase == Failed).unwrap_or(false) }))
let d = r.view()
assert_eq(d.error, "The password check quit before asking for a password.")
auth_click(r.comp, Allow) // "Try again"
assert_true(r.settle(fn() { d.phase == Asking }))
assert_eq(d.error, "")
auth_press(r.comp, 1U) // Escape
assert_true(r.settle(fn() { r.comp.auth_demos.length() == 0 }))
ignore(r.comp.control_command("auth-demo face"))
assert_true(r.settle(fn() { r.comp.auth_view().map(v => v.face == Scanning).unwrap_or(false) }))
// Typed while it looks: goes in when PAM asks.
auth_type(r.comp, "demo")
auth_press(r.comp, 28U)
assert_true(r.settle(fn() { r.comp.auth_view() is None && r.comp.auth_demos.length() == 0 }))
r.comp.close()
}
///| The agent program the build made (release or debug), "" when it wasn't built.
fn built_agent() -> String {
for p in ["_build/native/release/build/compositor/authagent/authagent.exe", "_build/native/debug/build/compositor/authagent/authagent.exe"] {
if @sys.has_exe(p) {
return p
}
}
""
}
///| Run everything with the agent out of process: polkitd and the compositor.
fn settle_out(comp : @host.ChandraCompositor, a : MockAuthority?, cond : () -> Bool) -> Bool {
for i = 0; i < 500; i = i + 1 {
match a {
Some(a) => a.bus.pump()
None => ()
}
ignore(@sys.wait_readable(comp.auth_fds(), 10))
comp.step()
if cond() {
return true
}
}
false
}
///|
test "the real chandra-polkit-agent program: demo, and registered with (mock) polkit through its own process" {
let bin = built_agent()
if bin == "" {
println("skipped: build compositor/authagent first (just auth-agent)")
return
}
// The demo, started by the compositor itself through spawn_socket.
let comp = new_comp("auth-real-demo")
assert_true(comp.start_auth_demo("password") is Ok(_))
assert_true(settle_out(comp, None, fn() { comp.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
auth_type(comp, "demo")
auth_press(comp, 28U)
assert_true(settle_out(comp, None, fn() { comp.auth_view() is None && comp.auth_demos.length() == 0 }))
comp.close()
// The session agent: the system bus, session and helper socket point at the test's mocks.
let bus = match auth_bus("real") {
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let (hpath, listen) = helper_socket("real")
let comp2 = new_comp("auth-real")
comp2.login_session = true
comp2.auth_spawner = Some(fn(args) {
@sys.spawn_socket(
[
"/usr/bin/env", "DBUS_SYSTEM_BUS_ADDRESS=unix:path=" + bus, "XDG_SESSION_ID=2", "CHANDRA_POLKIT_HELPER=socket:" + hpath,
bin, ..args,
],
)
})
comp2.start_auth_agent()
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_agent.map(l => l.ready).unwrap_or(false) }))
a.begin("r1", run0_details, uid=@polkit.own_uid().reinterpret_as_uint())
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view() is Some(_) }))
let fd : Ref[Int] = { val: -1 }
assert_true(settle_out(comp2, Some(a), fn() {
if fd.val < 0 {
fd.val = @sys.unix_accept(listen)
}
fd.val >= 0
}))
ignore(helper_lines(fd.val, 2))
helper_say(fd.val, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view().map(v => v.phase == Asking).unwrap_or(false) }))
auth_type(comp2, "Right1")
auth_press(comp2, 28U)
assert_true(settle_out(comp2, Some(a), fn() { comp2.auth_view().map(v => v.phase == Checking).unwrap_or(false) }))
assert_eq(helper_lines(fd.val, 1), "Right1")
helper_say(fd.val, "SUCCESS")
assert_true(settle_out(comp2, Some(a), fn() { a.answers == ["ok"] }))
// Turning the switch off stops it (it unregisters and exits) and says there's no other agent.
comp2.shell.set_session_setting(3, false)
comp2.auth_agent_setting_changed()
assert_true(comp2.auth_agent is None)
@sys.close_fd(fd.val)
@sys.close_fd(listen)
@sys.unlink(hpath)
comp2.close()
}
///|
@@ -431,61 +773,6 @@ test "Settings > Session lists the password dialog switch, saved as :auth-agent
comp.close()
}
///|
test "typing reaches the dialog through handle_input, and a helper that dies at once doesn't wipe it in a loop" {
let bus = match auth_bus("typing") {
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let hpath = "/tmp/chandra-auth-helper-typing-" + @sys.getpid().to_string()
let listen = @sys.unix_listen(hpath)
let comp = auth_comp("typing", bus, hpath)
// The keymap the real session hands clients (xkbcommon's text format), not the US fallback.
comp.server.set_keymap(@utf8.encode(real_keymap))
assert_true(settle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
a.begin("t1", run0_details)
assert_true(settle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
let d = comp.auth_dialog().unwrap()
// The helper goes away without a word (socket helper refusing, account locked, ...).
let (h, _) = helper_accept(listen, comp, a)
@sys.close_fd(h)
assert_true(settle(comp, a, fn() { d.error != "" }))
assert_eq(d.failures, 0) // not a wrong password
// Typing still lands in the field and stays there.
auth_type(comp, "Secret9")
for i = 0; i < 20; i = i + 1 {
a.bus.pump()
comp.step()
}
assert_eq(d.typed(), 7)
// Shift+digit through the real keymap: '(' on 9.
comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 1U)
auth_press(comp, 10U)
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 1U)
assert_eq(d.typed(), 8)
auth_press(comp, 28U) // Enter: kept until PAM asks
// A second later the helper is started again; this time it asks.
let (h2, hello) = helper_accept(listen, comp, a)
assert_eq(hello, "nandi|t1")
helper_say(h2, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(settle(comp, a, fn() { d.phase == Checking }))
assert_eq(helper_lines(h2, 1), "Secret9(")
// The pointer works too: a click on Cancel dismisses it.
helper_say(h2, "FAILURE")
assert_true(settle(comp, a, fn() { d.failures == 1 }))
ignore(comp.compose_frame())
let cancel = comp.auth.unwrap().hits.filter(x => x.1 == Cancel)[0].0
comp.handle_input(@nested.InputEvent::PointerMove((cancel.x + 4).to_double(), (cancel.y + 4).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
assert_true(settle(comp, a, fn() { a.answers.length() == 1 }))
@sys.close_fd(h2)
@sys.close_fd(listen)
@sys.unlink(hpath)
comp.close()
}
///| An xkbcommon 1.6 keymap (xkbcli compile-keymap --layout us), cut down to what typing needs.
let real_keymap : String =
#|xkb_keymap {
@@ -564,19 +851,7 @@ let real_keymap : String =
#|
#|};
///| `settle`, composing frames too (the Face unlock window and Settings follow their tool there).
fn fsettle(comp : @host.ChandraCompositor, a : MockAuthority, cond : () -> Bool) -> Bool {
for i = 0; i < 300; i = i + 1 {
a.bus.pump()
comp.step()
ignore(comp.compose_frame())
if cond() {
return true
}
@sys.sleep_ms(10)
}
false
}
///|
test "Face unlock window: snaps, Apply, then the password dialog gets the keyboard and the click" {
@@ -584,27 +859,33 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
Some(b) => b
None => return
}
let a = MockAuthority::new(bus)
let hpath = "/tmp/chandra-auth-helper-faceapply-" + @sys.getpid().to_string()
let listen = @sys.unix_listen(hpath)
let comp = auth_comp("faceapply", bus, hpath)
let (hpath, listen) = helper_socket("faceapply")
let r = rig("faceapply", Some(bus), hpath)
let comp = r.comp
comp.server.set_keymap(@utf8.encode(real_keymap))
assert_true(fsettle(comp, a, fn() { comp.polkit.map(p => p.registered()).unwrap_or(false) }))
comp.start_auth_agent()
let fsettle = fn(cond : () -> Bool) {
r.settle(fn() {
ignore(comp.compose_frame())
cond()
})
}
assert_true(fsettle(fn() { r.ready() }))
let a = r.authority()
let dir = "/tmp/chandra-face-apply-" + @sys.getpid().to_string()
let tool = fake_face_tool(dir)
ignore(@sys.write_file_bytes(dir + "/wait", b""))
comp.shell.set_face_tool(["/bin/sh", tool])
assert_true(comp.shell.open_settings(Session))
assert_true(fsettle(comp, a, fn() { face_texts(comp).contains("Desk") }))
assert_true(fsettle(fn() { face_texts(comp).contains("Desk") }))
face_click(comp, "Add or remove faces…", 10U)
assert_true(fsettle(comp, a, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
assert_true(fsettle(fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
let w = comp.shell.face.window.unwrap()
face_key(comp, 57U, 20U)
assert_true(fsettle(comp, a, fn() { w.snaps.length() == 1 }))
assert_true(fsettle(fn() { w.snaps.length() == 1 }))
face_key(comp, 57U, 30U)
assert_true(fsettle(comp, a, fn() { w.snaps.length() == 2 }))
// Enter: Apply; the root step asks polkit, which asks us. Meanwhile the window steps aside:
// no dimming card, no input of its own (another agent's password window must be reachable).
assert_true(fsettle(fn() { w.snaps.length() == 2 }))
// Enter: Apply; the root step asks polkit, which asks us. Meanwhile the window steps aside.
face_key(comp, 28U, 40U)
assert_true(w.applying)
ignore(comp.compose_frame())
@@ -612,11 +893,11 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
comp.handle_input(@nested.InputEvent::Key(57U, false), 1U)
assert_eq(w.snaps.length(), 2)
a.begin("f1", run0_details)
assert_true(fsettle(comp, a, fn() { comp.auth_dialog() is Some(_) }))
let d = comp.auth_dialog().unwrap()
let (h, _) = helper_accept(listen, comp, a)
assert_true(fsettle(fn() { comp.auth_view() is Some(_) }))
let d = r.view()
let (h, _) = r.helper_accept(listen)
helper_say(h, "PAM_PROMPT_ECHO_OFF Password: ")
assert_true(fsettle(comp, a, fn() { d.phase == Prompt }))
assert_true(fsettle(fn() { d.phase == Asking }))
auth_shot(comp, "18-face-apply-password")
// Typing goes to the password dialog, not to the window under it (Space would snap).
auth_type(comp, "Secret9")
@@ -625,18 +906,14 @@ test "Face unlock window: snaps, Apply, then the password dialog gets the keyboa
assert_eq(d.typed(), 8)
assert_eq(w.snaps.length(), 2)
// The Authenticate button takes the click.
ignore(comp.compose_frame())
let allow = comp.auth.unwrap().hits.filter(x => x.1 == Allow)[0].0
comp.handle_input(@nested.InputEvent::PointerMove((allow.x + 4).to_double(), (allow.y + 4).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
assert_true(fsettle(comp, a, fn() { d.phase == Checking }))
auth_click(comp, Allow)
assert_true(fsettle(fn() { d.phase == Checking }))
assert_eq(helper_lines(h, 1), "Secret9 ")
helper_say(h, "SUCCESS")
assert_true(fsettle(comp, a, fn() { comp.auth_dialog() is None && a.answers.length() == 1 }))
assert_true(fsettle(fn() { comp.auth_view() is None && a.answers.length() == 1 }))
// The root step goes on; the window closes with what it said.
ignore(@sys.write_file_bytes(dir + "/go", b""))
assert_true(fsettle(comp, a, fn() { comp.shell.face.window is None }))
assert_true(fsettle(fn() { comp.shell.face.window is None }))
assert_eq(comp.shell.face.message, "Added Face 2 and removed 1 face")
@sys.close_fd(h)
@sys.close_fd(listen)
+24 -24
View File
@@ -256,22 +256,26 @@ pub(all) struct ChandraCompositor {
mut last_recording : String
/// `--kiosk`: one fullscreen app, locked down (kiosk.mbt). None: a normal desktop.
mut kiosk : Kiosk?
/// Chandra's polkit agent (auth.mbt), while it is registered; the system bus socket it uses
/// ("" finds it); the dialog while it is up; key releases it swallows; how to reach polkit's
/// helper (empty: the usual routes; tests set their own); the keymap typing goes through.
mut polkit : @polkit.PolkitAgent?
mut polkit_bus : String
/// The password dialog (auth.mbt): the session's chandra-polkit-agent and demo agents
/// (`chandra-ctl auth-demo`), the dialog while it is up, key releases the dialog or the Face
/// unlock window swallow, a notice about the dialog itself, how agents are started (tests run
/// them in-process), restarts after crashes, and whether "still waiting for polkit" was said.
mut auth_agent : AuthLink?
auth_demos : Array[AuthLink]
mut auth : AuthUi?
auth_swallow : Array[UInt]
mut auth_notice : AuthNotice?
mut auth_notice_press : Bool
mut auth_spawner : ((Array[String]) -> Int)?
mut auth_restarts : Int
mut auth_slow_said : Bool
/// The Face unlock window (face_window.mbt): where its controls were drawn, and the change of
/// it last drawn.
face_hits : Array[(@scene.Rect, FaceHit)]
mut face_rev : Int
mut auth_routes : Array[@polkit.HelperRoute]
/// The keymap the dialog types through (parsed from the one clients get).
mut keymap : (Bytes, @polkit.Keymap)?
/// How requests are put into words (tests pass their own process lookups); None: the usual.
mut auth_describe : ((@polkit.AuthRequest) -> @polkit.Description)?
/// A third-party polkit agent was started (when ours is off or couldn't register).
/// Another polkit agent was started (the Settings switch for Chandra's dialog is off).
mut fallback_agent_started : Bool
/// The rest of the xkb modifier state (`mods` holds the depressed modifiers).
mut mods_latched : UInt
@@ -313,15 +317,18 @@ pub fn ChandraCompositor::new(
theme,
dark_theme: theme,
sync_system_theme: false,
polkit: None,
polkit_bus: "",
auth_agent: None,
auth_demos: [],
auth: None,
auth_swallow: [],
auth_notice: None,
auth_notice_press: false,
auth_spawner: None,
auth_restarts: 0,
auth_slow_said: false,
face_hits: [],
face_rev: -1,
auth_routes: [],
keymap: None,
auth_describe: None,
fallback_agent_started: false,
mods_latched: 0U,
mods_locked: 0U,
@@ -447,11 +454,7 @@ pub fn ChandraCompositor::close(self : ChandraCompositor) -> Unit {
release_snapshot(win.surface)
}
self.stop_control()
self.close_auth(Some(Err("The session is ending")))
match self.polkit {
Some(a) => a.stop()
None => ()
}
self.auth_shutdown()
self.shell.shutdown()
match self.settings_portal {
Some(p) => p.close()
@@ -1108,6 +1111,7 @@ fn ChandraCompositor::build_scene(
panel_ops.append(self.screenshot_ops())
panel_ops.append(self.face_window_ops())
panel_ops.append(self.auth_ops())
panel_ops.append(self.auth_notice_ops())
self.frames_built = self.frames_built + 1
self.run_shell_actions()
// The wallpaper (the first ops) is cached by the renderer; the desktop card after it changes.
@@ -1869,12 +1873,8 @@ pub fn ChandraCompositor::handle_input(
}
_ => ()
}
// The authentication dialog takes all input while it is up.
if self.auth_input(ev) {
return
}
// So does the Face unlock window (below the password dialog it opens on Apply).
if self.face_window_input(ev) {
// The password dialog takes all input while it is up; else the Face unlock window does.
if self.grab_input(ev) {
return
}
match ev {
+36
View File
@@ -211,10 +211,46 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
"shortcut ID do what shortcut ID does (launcher, overview, show-desktop, ...)",
"kiosk [lock|unlock|status] kiosk mode (--kiosk): lock it down or unlock it for admin work",
"windows each window: frame, layout, box, shadow, size limits; and what is under the pointer",
"auth-demo [MODE] show the password dialog with a pretend check (password \"demo\"); MODE: " +
@polkit.demo_modes.join(", "),
"auth-status the password dialog's agent: running, registered, or why not",
"ok",
],
true,
)
"auth-demo" => {
if words.length() > 2 {
return (["error usage: auth-demo [" + @polkit.demo_modes.join("|") + "]"], false)
}
match self.start_auth_demo(if words.length() == 2 { words[1] } else { "" }) {
Ok(_) => (["ok the demo dialog opens; the password is \"" + @polkit.demo_password + "\""], true)
Err(why) => (["error " + why], false)
}
}
"auth-status" => {
let out : Array[String] = []
match self.auth_agent {
Some(l) => out.push(if l.ready { "agent: registered with polkit" } else { "agent: started, waiting for polkit" })
None =>
out.push(
if self.fallback_agent_started {
"agent: off in Settings; another polkit agent was started"
} else {
"agent: not running"
},
)
}
match self.auth_notice {
Some(n) => out.push("notice: " + n.text)
None => ()
}
match self.auth {
Some(ui) => out.push("dialog: up (" + @polkit.phase_name(ui.view.phase) + ")")
None => out.push("dialog: not shown")
}
out.push("ok")
(out, true)
}
"list" => {
let mods = self.shell.loaded_modules()
let out = mods.map(m => m.0 + " " + m.1 + " " + m.2)