auth dialog: keep typed text when the polkit helper ends before asking
CI / test (push) Successful in 2m1s
CI / test (push) Successful in 2m1s
If polkit-agent-helper-1 exited (or the socket service refused) before sending a PAM prompt, the dialog counted it as a wrong password, wiped the field and restarted the helper immediately, in a tight loop, so typing seemed to do nothing. Now such an early end keeps what was typed, shows why, and retries after 1s/2s/4s (then on Enter). Every helper event and route is logged as "chandra: polkit helper ..." (never the typed text). Adds an end-to-end test that types through handle_input with a real xkbcommon keymap, including Shift, across a helper that dies at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
This commit is contained in:
4 files changed
+237
-4
No files matched your search
@@ -22,6 +22,10 @@ pub(all) struct AuthUi {
|
||||
hits : Array[(@scene.Rect, @polkit.Focus)]
|
||||
/// When it opened (the spinner's clock).
|
||||
opened : UInt64
|
||||
/// Helper runs in a row that ended before anything was answered, and when to try again
|
||||
/// (monotonic ms, 0: not waiting).
|
||||
mut quick_failures : Int
|
||||
mut retry_at : UInt64
|
||||
}
|
||||
|
||||
///| The dialog that is up, if any.
|
||||
@@ -125,6 +129,12 @@ fn ChandraCompositor::auth_tick(self : ChandraCompositor) -> Unit {
|
||||
self.close_auth(None)
|
||||
} else {
|
||||
self.auth_helper_events(ui)
|
||||
// A helper that ended early is tried again after a pause.
|
||||
if ui.helper is None && ui.retry_at != 0UL && @sys.monotonic_ms() >= ui.retry_at {
|
||||
ui.retry_at = 0UL
|
||||
self.auth_start_helper(ui)
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -157,6 +167,8 @@ fn ChandraCompositor::open_auth(self : ChandraCompositor, req : @polkit.AuthRequ
|
||||
icon,
|
||||
hits: [],
|
||||
opened: @sys.monotonic_ms(),
|
||||
quick_failures: 0,
|
||||
retry_at: 0UL,
|
||||
}
|
||||
self.auth = Some(ui)
|
||||
// Nothing else gets the keyboard or the pointer while it is up.
|
||||
@@ -191,6 +203,27 @@ fn ChandraCompositor::auth_helper_events(self : ChandraCompositor, ui : AuthUi)
|
||||
Some(h) => {
|
||||
let evs = h.read()
|
||||
for ev in evs {
|
||||
// What PAM said, for the session log (never what was typed: that only goes out).
|
||||
@sys.log(
|
||||
"chandra: polkit helper: " +
|
||||
(match ev {
|
||||
PromptEchoOff(t) => "password prompt \"" + t + "\""
|
||||
PromptEchoOn(t) => "prompt \"" + t + "\""
|
||||
ErrorMsg(t) => "error \"" + t + "\""
|
||||
TextInfo(t) => "info \"" + t + "\""
|
||||
Success => "SUCCESS"
|
||||
Failure => "FAILURE"
|
||||
}),
|
||||
)
|
||||
match ev {
|
||||
PromptEchoOff(_) | PromptEchoOn(_) => {
|
||||
ui.quick_failures = 0
|
||||
if ui.dialog.info == "Press Enter to try again." {
|
||||
ui.dialog.info = ""
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
self.auth_effect(ui, ui.dialog.helper(ev, @sys.monotonic_ms()))
|
||||
if self.auth is None {
|
||||
return
|
||||
@@ -215,7 +248,27 @@ fn ChandraCompositor::auth_effect(self : ChandraCompositor, ui : AuthUi, e : @po
|
||||
}
|
||||
@polkit.zero(b)
|
||||
}
|
||||
Restart => self.auth_start_helper(ui)
|
||||
Restart => {
|
||||
ui.quick_failures = 0
|
||||
ui.retry_at = 0UL
|
||||
self.auth_start_helper(ui)
|
||||
}
|
||||
RetryLater => {
|
||||
match ui.helper {
|
||||
Some(h) => h.close()
|
||||
None => ()
|
||||
}
|
||||
ui.helper = None
|
||||
ui.quick_failures = ui.quick_failures + 1
|
||||
@sys.log("chandra: polkit helper ended before asking anything (" + ui.quick_failures.to_string() + " in a row): " + ui.dialog.error)
|
||||
// Try again after 1, 2, 4 s; then wait for Enter.
|
||||
if ui.quick_failures <= 3 {
|
||||
ui.retry_at = @sys.monotonic_ms() + (1000UL << (ui.quick_failures - 1))
|
||||
} else {
|
||||
ui.retry_at = 0UL
|
||||
ui.dialog.info = "Press Enter to try again."
|
||||
}
|
||||
}
|
||||
Cancelled => self.close_auth(Some(Err("The user dismissed the authentication dialog")))
|
||||
Authorized => self.close_auth(Some(Ok(())))
|
||||
}
|
||||
@@ -283,6 +336,16 @@ fn ChandraCompositor::auth_input(self : ChandraCompositor, ev : @nested.InputEve
|
||||
let mods = self.mods | self.mods_latched | self.mods_locked
|
||||
let ch = self.auth_keymap().char_for(code, mods, self.mods_group)
|
||||
self.auth_effect(ui, ui.dialog.key(code, self.mods, ch))
|
||||
// Enter with no helper running (it ended, or couldn't start): try again now.
|
||||
if (code == @polkit.key_enter || code == @polkit.key_kp_enter) && self.auth is Some(_) &&
|
||||
ui.helper is None {
|
||||
ui.retry_at = 0UL
|
||||
ui.quick_failures = 0
|
||||
if ui.dialog.info == "Press Enter to try again." {
|
||||
ui.dialog.info = ""
|
||||
}
|
||||
self.auth_start_helper(ui)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -335,7 +398,11 @@ fn ChandraCompositor::auth_cursor(self : ChandraCompositor, ui : AuthUi) -> UInt
|
||||
///| Whether the dialog animates (a failed attempt shakes it; a spinner while PAM checks).
|
||||
fn ChandraCompositor::auth_animating(self : ChandraCompositor) -> Bool {
|
||||
match self.auth {
|
||||
Some(ui) => ui.dialog.shaking(@sys.monotonic_ms()) || ui.dialog.phase == Checking || ui.dialog.face == Scanning
|
||||
Some(ui) =>
|
||||
ui.dialog.shaking(@sys.monotonic_ms()) ||
|
||||
ui.dialog.phase == Checking ||
|
||||
ui.dialog.face == Scanning ||
|
||||
ui.retry_at != 0UL
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user